Bug Description

  • Operating system: Windows 11
  • IDE: PyCharm 2023.2
  • Language: Python

I used PyQt5 in Python to develop a GUI for a simple program. After the development was completed, I packaged the program to generate an exe file. But when I run this exe file and click the button on the GUI, a new window will pop up. If I click the button repeatedly, new windows keep being generated. This problem does not occur when debugging and running the program in PyCharm.


Read more »

String.startsWith()

Used to detect whether a string starts with a specified prefix.

1
2
3
4
5
6
7
8
9
public class test {
public static void main(String[] args) {
String str = "Test string: hello world!";
boolean flag1 = str.startsWith("Test");
System.out.println("str starts with 'Test': " + flag1);
boolean flag2 = str.startsWith("hello");
System.out.println("str starts with 'hello': " + flag2);
}
}

The output of the code is as follows:

1
2
str starts with 'Test': true
str starts with 'hello': false
Read more »

Formula

Given vectors AB\vec{AB} and CD\vec{CD}, A=(x1,y1)A=(x_1,y_1), B=(x2,y2)B=(x_2,y_2), C=(x3,y3)C=(x_3,y_3), D=(x4,y4)D=(x_4,y_4), then:

AB=(x2x1,y2y1)CD=(x4x3,y4y3)\vec{AB}=(x_2-x_1, y_2-y_1)\\ \vec{CD}=(x_4-x_3, y_4-y_3)

Let the angle between the vectors AB\vec{AB} and CD\vec{CD} be θ\theta:

cos(θ)=ABCDABCDcos(\theta)=\frac{\vec{AB} \cdot \vec{CD}}{||\vec{AB}|| \cdot ||\vec{CD}||}

Read more »

For example, there is such a Text file, as shown in the figure below. We need to read the data and then save the data to different folders in different directories.

The Python code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os

# Read data in Text
students_data = []
with open('./data.txt', 'r') as f:
line = f.readline()
while line:
print(line)

line_data = line.split(',')

# Skip the first line
if line_data[0] == 'name':
line = f.readline()
continue

# Read the data of current row
curr_student_info = {}
curr_student_info["name"] = str(line_data[0])
curr_student_info["id"] = str(line_data[1])
curr_student_info["score"] = float(line_data[2])
curr_student_info["ranking"] = float(line_data[3])
students_data.append(curr_student_info)

# Continue reading the next line of data
line = f.readline()

# Save the data in different files
for curr_info in students_data:
path = "./student_data/" + str(curr_info["name"])
os.makedirs(path)

f_temp = open('./student_data/' + str(curr_info["name"]) + '/info.txt', 'w')
f_temp.write("id: " + str(curr_info["id"]) + "\n")
f_temp.write("score: " + str(curr_info["score"]) + "\n")
f_temp.write("ranking: " + str(curr_info["ranking"]) + "\n")
f_temp.close()

The data in Text can be read through the above code, as shown below:

Read more »

In nonlinear programming, the Karush–Kuhn–Tucker (KKT) conditions are necessary conditions to determine whether a point is an extreme point. The necessary condition here means that the solution that satisfies the KKT conditions is not necessarily the optimal solution (e.g., saddle point), but if the KKT conditions are not satisfied, it must not be the optimal solution.

For convex programming, the KKT conditions are sufficient and necessary conditions to determine whether a point is an extreme point. If a point satisfies the conditions, it must be an extreme point and must be a global optimal solution.

Note: In a convex optimization problem, the objective function is convex and the domain is defined as a convex set.


Lagrangian Function

Read more »

Basic Concept

Tabu Search (TS) is a meta-heuristic algorithm that was first proposed by Glover in 1986. The algorithm avoids repeated searches by introducing a tabu table, and pardons some good solutions or states in tabu table through amnesty rules, so as to achieve a better global optimization effect.


Steps

Tabu Search algorithm typically includes the following key steps:

Read more »

Particle swarm optimization (PSO) was first proposed by James Kennedy and Russell Eberhart in 1995, also known as particle swarm algorithm.

The basic idea of the particle swarm algorithm comes from the study of the foraging behavior of bird flocks. Each particle can be regarded as a bird, and the process of searching for a solution is similar to the process of a flock of birds looking for food. In the process of searching for food, each bird knows the best location it has found. At the same time, information is shared within the flock, so that each bird also knows the best location the entire flock has found.

The advantage of PSO is that it is simple, easy to implement, has fewer parameters that need to be adjusted, and has better global optimization capabilities.


Basic Concept

Read more »
0%