Skip to content

Commit 07b8d0f

Browse files
committed
fixed changes requested
1 parent 50e06e4 commit 07b8d0f

4 files changed

Lines changed: 14 additions & 167 deletions

File tree

PathPlanning/ParticleSwarmOptimization/particle_swarm_optimization.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ class Particle:
4141
max_velocity: Maximum velocity allowed in each dimension (5% of search space range)
4242
position: Current 2D position [x, y] in search space
4343
velocity: Current velocity vector [vx, vy]
44-
pbest_position: Personal best position found so far
45-
pbest_value: Fitness value at personal best position
44+
personla_best_position: Personal best position found so far
45+
personla_best_value: Fitness value at personal best position
4646
path: List of all positions visited by this particle
4747
"""
4848
def __init__(self, search_bounds, spawn_bounds):
4949
self.search_bounds = search_bounds
5050
self.max_velocity = np.array([(b[1] - b[0]) * 0.05 for b in search_bounds])
5151
self.position = np.array([np.random.uniform(b[0], b[1]) for b in spawn_bounds])
5252
self.velocity = np.random.randn(2) * 0.1
53-
self.pbest_position = self.position.copy()
54-
self.pbest_value = np.inf
53+
self.personla_best_position = self.position.copy()
54+
self.personla_best_value = np.inf
5555
self.path = [self.position.copy()]
5656
def update_velocity(self, gbest_pos, w, c1, c2):
5757
"""Update particle velocity using PSO equation:
58-
v = w*v + c1*r1*(pbest - x) + c2*r2*(gbest - x)
58+
v = w*v + c1*r1*(personla_best - x) + c2*r2*(gbest - x)
5959
"""
6060
r1 = np.random.rand(2)
6161
r2 = np.random.rand(2)
62-
cognitive = c1 * r1 * (self.pbest_position - self.position)
62+
cognitive = c1 * r1 * (self.personla_best_position - self.position)
6363
social = c2 * r2 * (gbest_pos - self.position)
6464
self.velocity = w * self.velocity + cognitive + social
6565
self.velocity = np.clip(self.velocity, -self.max_velocity, self.max_velocity)
@@ -149,9 +149,9 @@ def step(self):
149149
for particle in self.particles:
150150
value = self.fitness(particle.position)
151151
# Update personal best
152-
if value < particle.pbest_value:
153-
particle.pbest_value = value
154-
particle.pbest_position = particle.position.copy()
152+
if value < particle.personla_best_value:
153+
particle.personla_best_value = value
154+
particle.personla_best_position = particle.position.copy()
155155
# Update global best
156156
if value < self.gbest_value:
157157
self.gbest_value = value
@@ -183,7 +183,7 @@ def main():
183183
"""Run PSO path planning algorithm demonstration.
184184
This function demonstrates PSO-based path planning with the following setup:
185185
- 15 particles exploring a (-50,50) x (-50,50) search space
186-
- Start zone: (-45,-35) to (-35,-35)
186+
- Start zone: (-45,-45) to (-35,-35)
187187
- Target: (40, 35)
188188
- 4 circular obstacles with collision avoidance
189189
- Real-time visualization showing particle convergence (if show_animation=True)
@@ -194,7 +194,7 @@ def main():
194194
print(__file__ + " start!!")
195195
# Set matplotlib backend for headless environments
196196
if not show_animation:
197-
matplotlib.use("Agg") # Use non-GUI backend for testing
197+
plt.switch_backend("Agg") # Use non-GUI backend for testing
198198
# Setup parameters
199199
N_PARTICLES = 15
200200
MAX_ITER = 150

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,15 @@ This is a 2D grid based coverage path planning simulation.
359359

360360
### Particle Swarm Optimization (PSO)
361361

362-
This is a 2D path planning with Particle Swarm Optimization algorithm.
362+
This is a 2D path planning simulation using the Particle Swarm Optimization algorithm.
363363

364364
![PSO](https://github.com/AtsushiSakai/PythonRoboticsGifs/raw/master/PathPlanning/ParticleSwarmOptimization/animation.gif)
365365

366366
PSO is a metaheuristic optimization algorithm inspired by bird flocking behavior. In path planning, particles explore the search space to find collision-free paths while avoiding obstacles.
367367

368368
The animation shows particles (blue dots) converging towards the optimal path (yellow line) from start (green area) to goal (red star).
369369

370-
Reference
370+
References
371371

372372
- [Particle swarm optimization - Wikipedia](https://en.wikipedia.org/wiki/Particle_swarm_optimization)
373373

docs/modules/5_path_planning/particleSwarmOptimization/particleSwarmOptimization.rst

Lines changed: 0 additions & 153 deletions
This file was deleted.

docs/modules/5_path_planning/particleSwarmOptimization/particleSwarmOptimization_main.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Particle Swarm Optimization Path Planning
44
------------------------------------------
55

6-
This is a 2D path planning implementation using Particle Swarm Optimization (PSO).
6+
This is a 2D path planning simulation using the Particle Swarm Optimization algorithm.
77

88
PSO is a metaheuristic optimization algorithm inspired by the social behavior of bird flocking or fish schooling. In path planning, particles represent potential solutions that explore the search space to find collision-free paths from start to goal.
99

0 commit comments

Comments
 (0)