metaheuristic_designer.strategies.swarm package#

Submodules#

Module contents#

Swarm intelligence strategies.

class PSO(initializer, lower_bound=-100, upper_bound=100, name='PSO', w=0.7, c1=1.5, c2=1.5, encoding=None, rng=None, **kwargs)[source]#

Bases: PopulationBasedStrategy

Particle Swarm Optimization (PSO).

Each individual (particle) has a position and a velocity. The velocity is updated using personal and global bests, and the position is moved accordingly. This requires a ParameterExtendingEncoding that stores a speed vector; if not supplied, a default PSOEncoding is created.

Parameters:
initializerInitializer

Initializer for the solution part. An ExtendedInitializer is automatically created to handle the velocity parameter.

lower_boundfloat, optional

Lower bound of the search space (default -100).

upper_boundfloat, optional

Upper bound of the search space (default 100).

namestr, optional

Display name (default "PSO").

wfloat, optional

Inertia weight (default 0.7).

c1float, optional

Cognitive acceleration coefficient (default 1.5).

c2float, optional

Social acceleration coefficient (default 1.5).

encodingParameterExtendingEncoding, optional

Encoding that includes a "speed" parameter. If None, a PSOEncoding is used.

rngRNGLike, optional

Random number generator.

**kwargs

Forwarded to StaticPopulationStrategy.

Attributes:
params

Access parameter values by attribute-style lookup.

population_size

Gets the amount of individuals in the population.

Parameters:

Methods

reset

initialize(objfunc)[source]#

Set up the initial population and attach velocity constraints.

Parameters:
objfuncObjectiveFunc

The objective function. Its constraint handler is extended with a BounceBoundConstraint for the velocity so that speeds stay within the feasible range.

.. warning::
There is a known bug: the objective function **does not**
automatically remove the extended constraint handler after
a PSO run finishes. Reusing the same objective function
instance for other algorithms may cause unexpected
behavior. This will be resolved in a future release.
Returns:
Population

The initialized and evaluated population.

Parameters:

objfunc (ObjectiveFunc)