saealib.PSO

class saealib.PSO(w=0.7, c1=1.5, c2=1.5, v_max=None)[source]

Bases: Algorithm

Particle Swarm Optimization (PSO) for single-objective problems.

The global best (leader) is selected from the personal bests of all particles using ctx.comparator, so the ranking adapts automatically to any single-objective Comparator.

Multi-objective PSO (MOPSO) requires a dedicated subclass with a separate Pareto archive for leader selection.

Parameters:
  • w (float)

  • c1 (float)

  • c2 (float)

  • v_max (float | None)

w

Inertia weight.

Type:

float

c1

Cognitive coefficient (personal best attraction).

Type:

float

c2

Social coefficient (global best attraction).

Type:

float

v_max

Maximum velocity magnitude per dimension. None disables clamping.

Type:

float or None

Methods

__init__

Initialize PSO.

ask

Update particle velocities and positions.

create_pareto_archive

Create a ParetoArchive with the correct direction for the problem.

get_required_attrs

Return PSO-specific attributes required by the Population.

tell

Update the population and personal bests from evaluated offspring.

Method Details

PSO.__init__(w=0.7, c1=1.5, c2=1.5, v_max=None)[source]

Initialize PSO.

Parameters:
  • w (float, optional) – Inertia weight. Defaults to 0.7.

  • c1 (float, optional) – Cognitive coefficient. Defaults to 1.5.

  • c2 (float, optional) – Social coefficient. Defaults to 1.5.

  • v_max (float or None, optional) – Maximum velocity per dimension. Defaults to None (no clamping).

PSO.ask(ctx, provider, n_offspring=None)[source]

Update particle velocities and positions.

Parameters:
  • ctx (OptimizationContext) – Current optimization context.

  • provider (ComponentProvider) – Component provider.

  • n_offspring (int or None, optional) – Ignored; output count equals population size.

Returns:

Candidates with updated x and velocity.

Return type:

Population

PSO.create_pareto_archive(attrs, init_capacity, problem)

Create a ParetoArchive with the correct direction for the problem.

Parameters:
Return type:

ParetoArchive

PSO.get_required_attrs(problem)[source]

Return PSO-specific attributes required by the Population.

Parameters:

problem (Problem) – The Problem object being referenced.

Returns:

velocity, pbest_x, pbest_f, and pbest_cv attributes.

Return type:

list[PopulationAttribute]

PSO.tell(ctx, provider, offspring)[source]

Update the population and personal bests from evaluated offspring.

Parameters:
  • ctx (OptimizationContext) – Current optimization context.

  • provider (ComponentProvider) – Component provider.

  • offspring (Population) – Evaluated offspring population.

Return type:

None