Skip to content

Included Solvers

cilpy.solver.pso.PSO

Bases: Solver[List[float], float]

A canonical Particle Swarm Optimization (PSO) solver.

The implementation uses a global best (gbest) topology (star topology), and uses inertial weight.

__init__(problem, name, swarm_size, w, c1, c2, **kwargs)

Initializes the Particle Swarm Optimization solver.

Parameters:

Name Type Description Default
problem Problem[List[float], float]

The optimization problem to solve.

required
swarm_size int

The number of particles in the swarm.

required
w float

The inertia weight, controlling the influence of the previous velocity.

required
c1 float

The cognitive coefficient, scaling the influence of the particle's personal best.

required
c2 float

The social coefficient, scaling the influence of the swarm's global best.

required
**kwargs

Additional keyword arguments (not used in this canonical PSO).

{}

_initialize_positions()

Creates the initial particle positions.

step()

Performs one iteration of the PSO algorithm.

get_result()

Returns the global best solution found by the swarm.

cilpy.solver.ga.GA

Bases: Solver[List[float], float]

A canonical Genetic Algorithm (GA) for single-objective optimization.

The algorithm uses: - Tournament selection to choose parents. - Single-point crossover for reproduction. - Gaussian mutation to introduce genetic diversity. - Elitism to preserve the best solution across generations.

__init__(problem, name, population_size, crossover_rate, mutation_rate, tournament_size=2, **kwargs)

Initializes the Genetic Algorithm solver.

Parameters:

Name Type Description Default
problem Problem[List[float], float]

The optimization problem to solve.

required
name str

the name of the solver

required
population_size int

The number of individuals in the population.

required
crossover_rate float

The probability of crossover (pc) occurring between two parents.

required
mutation_rate float

The probability of mutation (pm) for each gene in an offspring.

required
tournament_size int

The number of individuals to select for each tournament. Defaults to 2.

2
**kwargs

Additional keyword arguments (not used in this canonical GA).

{}

step()

Performs one generation of the Genetic Algorithm.

get_result()

Returns the best solution found in the current population.

cilpy.solver.de.DE

Bases: Solver[List[float], float]

A canonical Differential Evolution (DE) solver for single-objective optimization.

This is a DE/rand/1/bin implementation. It creates a trial vector for each member of the population and replaces the member if the trial vector has better or equal fitness.

The algorithm uses: - rand strategy for selecting vectors for mutation. - 1 difference vector in the mutation step. - bin (binomial) crossover.

__init__(problem, name, population_size, crossover_rate, f_weight, **kwargs)

Initializes the Differential Evolution solver.

Parameters:

Name Type Description Default
problem Problem[List[float], float]

The optimization problem to solve.

required
name str

the name of the solver

required
population_size int

The number of individuals (ns) in the population.

required
crossover_rate float

The crossover probability (CR) in the range [0, 1].

required
f_weight float

The differential weight (F) for mutation, typically in the range [0, 2].

required
**kwargs

Additional keyword arguments (not used in this canonical DE).

{}

step()

Performs one generation of the Differential Evolution algorithm.

get_result()

Returns the best solution found in the current population.