docs/modules/5_path_planning/particleSwarmOptimization/particleSwarmOptimization_main.rst
.. _particle_swarm_optimization:
This is a 2D path planning simulation using the Particle Swarm Optimization algorithm.
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.
Algorithm Overview ++++++++++++++++++
The PSO algorithm maintains a swarm of particles that move through the search space according to simple mathematical rules:
Mathematical Foundation +++++++++++++++++++++++
The core PSO velocity update equation is:
.. math::
v_{i}(t+1) = w \cdot v_{i}(t) + c_1 \cdot r_1 \cdot (p_{i} - x_{i}(t)) + c_2 \cdot r_2 \cdot (g - x_{i}(t))
Where:
v_{i}(t) = velocity of particle i at time tx_{i}(t) = position of particle i at time tw = inertia weight (controls exploration vs exploitation)c_1 = cognitive coefficient (attraction to personal best)c_2 = social coefficient (attraction to global best)r_1, r_2 = random numbers in [0,1]p_{i} = personal best position of particle ig = global best positionPosition update:
.. math::
x_{i}(t+1) = x_{i}(t) + v_{i}(t+1)
Fitness Function ++++++++++++++++
The fitness function combines distance to target with obstacle penalties:
.. math::
f(x) = ||x - x_{goal}|| + \sum_{j} P_{obs}(x, O_j)
Where:
||x - x_{goal}|| = Euclidean distance to goalP_{obs}(x, O_j) = penalty for obstacle jO_j = obstacle j with position and radiusThe obstacle penalty function is defined as:
.. math::
P_{obs}(x, O_j) = \begin{cases} 1000 & \text{if } ||x - O_j|| < r_j \text{ (inside obstacle)} \ \frac{50}{||x - O_j|| - r_j + 0.1} & \text{if } r_j \leq ||x - O_j|| < r_j + R_{influence} \text{ (near obstacle)} \ 0 & \text{if } ||x - O_j|| \geq r_j + R_{influence} \text{ (safe distance)} \end{cases}
Where:
r_j = radius of obstacle jR_{influence} = influence radius (typically 5 units)Collision Detection +++++++++++++++++++
Line-circle intersection is used to detect collisions between particle paths and circular obstacles:
.. math::
||P_0 + t \cdot \vec{d} - C|| = r
Where:
P_0 = start point of path segment\vec{d} = direction vector of pathC = obstacle centerr = obstacle radiust \in [0,1] = parameter along line segmentAlgorithm Parameters ++++++++++++++++++++
Key parameters affecting performance:
Typical values:
Advantages ++++++++++
Disadvantages +++++++++++++
Code Link +++++++++
.. autofunction:: PathPlanning.ParticleSwarmOptimization.particle_swarm_optimization.main
Usage Example +++++++++++++
.. code-block:: python
import matplotlib.pyplot as plt from PathPlanning.ParticleSwarmOptimization.particle_swarm_optimization import main
main()
References ++++++++++
Particle swarm optimization - Wikipedia <https://en.wikipedia.org/wiki/Particle_swarm_optimization>__A Gentle Introduction to Particle Swarm Optimization <https://machinelearningmastery.com/a-gentle-introduction-to-particle-swarm-optimization/>__