114 void enforceBounds(Particle& p);
123 std::vector<Particle> m_swarm;
126 bool m_initialized =
false;
132 size_t m_current_iter = 0;
Abstract base class for all optimization algorithms.
std::function< void(const Solution ¤t_best, size_t iteration)> StepCallback
Callback invoked after each step/generation.
Particle Swarm Optimization algorithm.
Solution optimize() override
Execute the optimization loop for max_iterations.
const std::vector< Particle > & getParticles() const
Access the current swarm state (particles).
void setBounds(const Coordinates &lower, const Coordinates &upper) override
Set lower/upper bounds of the search hyper-rectangle.
void setCallback(StepCallback cb) override
Register a callback invoked after each step().
void setObjectiveFunction(ObjectiveFunction func) override
Set the objective function to optimize.
Solution getBestSolution() const override
Get the best solution found so far.
void step() override
Perform one PSO iteration: update velocity/position, evaluate, update personal and global bests.
void setMode(OptimizationMode mode) override
Set optimization mode (minimize or maximize).
OptimizationMode
Optimization goal.
std::function< Real(const Coordinates &)> ObjectiveFunction
Objective function signature.
std::vector< Real > Coordinates
A point in the N-dimensional search space.
double Real
Scalar precision used across optimizers.
Abstract optimizer interface for PSO, GA, and future algorithms.
Configuration parameters for PSO.
size_t population_size
Number of particles in the swarm.
Real social_coeff
Social coefficient (c2): scales attraction to global best.
Real cognitive_coeff
Cognitive coefficient (c1): scales attraction to particle best.
Real inertia_weight
Inertia weight (w): scales previous velocity.
size_t max_iterations
Number of iterations to run the optimizer.
A single particle in the swarm.
Real current_value
Objective value at the current position.
Real best_value
Best objective value found by this particle.
Coordinates velocity
Current velocity vector.
Coordinates best_position
Best position found by this particle.
Coordinates position
Current position in the search space.
Represents a candidate solution in the search space.