A position vector is a particle’s location in the search space: its coordinates represent one candidate solution. In particle swarm optimization (PSO), each particle keeps its current position alongside its velocity and the best position it has found so far. section 7.4 section 7.5
Think of each particle as a scout exploring possible answers. Its position says where it is now; its best position records a promising place it has already visited. A fitness function scores a position so the algorithm can compare solutions. section 7.4 section 7.5
Positions change throughout a PSO search:
- Initialize particles at random positions in every dimension. Spreading them across the search space helps avoid leaving regions unexplored. section 7.6
- Evaluate fitness, then update each particle’s velocity and position. Movement is influenced by inertia, the particle’s best position, and the swarm’s best position. section 7.5 section 7.8
- Evaluate the new positions and repeat until the stopping condition is met. Return the best position found by the swarm. section 7.5
A two-coordinate position
A particle starts at (-10, 1), where the coordinates represent aluminum and plastic. After an update, its position is approximately (-7.71, 3.3). Its fitness improves from 801 to 358.8, so the new position becomes its recorded best. section 7.6 section 7.8
class Particle:
def __init__(self, x, y, inertia,
➥cognitive_constant, social_constant):
self.x = x #A
self.y = y #A
self.fitness = math.inf
self.velocity = (0.0, 0.0) #B
self.best_x = x
self.best_y = y #C
self.best_fitness = math.inf #D
self.inertia = inertia
self.cognitive_constant = cognitive_constant
self.social_constant = social_constant
See how a Python particle stores current coordinates, velocity, and best coordinates separately. section 7.4
Table 7.6 Data attributes for each particle
|
Particle |
Velocity |
Current aluminum |
Current plastic |
Current fitness |
Best aluminum |
Best plastic |
Best fitness |
| 1 |
0 |
7 |
1 |
104 |
7 |
1 |
104 |
| 2 |
1.52 |
0.52 |
10.52 |
255.3 |
-1 |
9 |
104 |
| 3 |
2.295 |
-7.71 |
3.3 |
358.8 |
-7.71 |
3.3 |
358.8 |
| 4 |
1.46 |
–0.54 |
-3.54 |
306.3 |
-0.54 |
-3.54 |
306.3 |
Compare current and best coordinates after particles move and their fitness is evaluated again. section 7.8


