Skip to content

PSO

python_motion_planning.global_planner.evolutionary_search.pso.PSO

Bases: EvolutionarySearcher

Class for Particle Swarm Optimization (PSO) motion planning.

Parameters:

Name Type Description Default
start tuple

start point coordinate

required
goal tuple

goal point coordinate

required
env Env

environment

required
heuristic_type str

heuristic function type

'euclidean'
n_particles int

number of particles

300
w_inertial float

inertial weight

1.0
w_cognitive float

cognitive weight

1.0
w_social float

social weight

1.0
point_num int

number of position points contained in each particle

5
max_speed int

The maximum velocity of particle motion

6
max_iter int

maximum iterations

200
init_mode int

Set the generation mode for the initial position points of the particle swarm

GEN_MODE_RANDOM

Examples:

Python Console Session
>>> import python_motion_planning as pmp
>>> planner = pmp.PSO((5, 5), (45, 25), pmp.Grid(51, 31))
>>> cost, path, fitness_history = planner.plan(verbose=True)     # planning results only
>>> cost_curve = [-f for f in fitness_history]
>>> planner.plot.animation(path, str(planner), cost, cost_curve=cost_curve)  # animation
>>> planner.run()       # run both planning and animation

calFitnessValue(position)

Calculate the value of fitness function.

Parameters:

Name Type Description Default
position list

control points calculated by PSO

required

Returns:

Name Type Description
fitness float

the value of fitness function

initializePositions()

Generate n particles with pointNum_ positions each within the map range.

Returns:

Name Type Description
init_positions list

initial position sequence of particle swarm

isCollision(p1, p2)

Judge collision when moving from node1 to node2 using Bresenham.

Parameters:

Name Type Description Default
p1 tuple

start point

required
p2 tuple

end point

required

Returns:

Name Type Description
collision bool

True if collision exists, False otherwise.

optimizeParticle(particle)

Particle update optimization iteration

Parameters:

Name Type Description Default
particle Particle

the particle

required

plan(verbose=False)

Particle Swarm Optimization (PSO) motion plan function.

Parameters:

Name Type Description Default
verbose bool

print the best fitness value of each iteration

False

Returns:

Name Type Description
cost float

path cost

path list

planning path

run()

Running both plannig and animation.

updateParticlePosition(particle)

A function to update the particle position

Parameters:

Name Type Description Default
particle Particle

the particle

required

updateParticleVelocity(particle)

A function to update the particle velocity

Parameters:

Name Type Description Default
particle Particle

the particle

required