OptiPy
Loading...
Searching...
No Matches
Optimizer Class Referenceabstract

Abstract base class for all optimization algorithms. More...

#include <Optimizer.h>

Inheritance diagram for Optimizer:
Blind LocalSearch ParticleSwarm

Public Member Functions

 Optimizer (std::shared_ptr< SolutionBuilder > solutionBuilder, std::shared_ptr< Problem > problem, int maxIterations)
 Constructs an Optimizer.
virtual ~Optimizer ()=default
 Virtual destructor for safe polymorphic deletion.
virtual std::vector< double > optimize ()=0
 Runs the optimization algorithm.
Accessors
double getBestFitness ()
std::vector< double > & getBestSolution ()
std::vector< double > & getBestFitnesses ()
std::vector< std::vector< double > > & getSolutions ()
int getMaxIterations ()
std::shared_ptr< ProblemgetProblem ()
std::shared_ptr< SolutionBuildergetSolutionBuilder ()

Protected Attributes

std::shared_ptr< Problemproblem
 Optimization problem definition.
std::shared_ptr< SolutionBuildersolutionBuilder
 Solution generation utility.
int maxIterations
 Maximum number of iterations.
std::vector< double > bestSolution
 Best solution found.
std::vector< double > bestFitnesses
 Best fitness value so far per iteration.
std::vector< std::vector< double > > solutions
 All generated solutions.

Detailed Description

Abstract base class for all optimization algorithms.

The Optimizer class defines a common interface and shared state for optimization algorithms operating on benchmark problems. Derived classes must implement the optimize() method. Results for each run are stored in fields and accessed through getter methods

Constructor & Destructor Documentation

◆ Optimizer()

Optimizer::Optimizer ( std::shared_ptr< SolutionBuilder > solutionBuilder,
std::shared_ptr< Problem > problem,
int maxIterations )
inline

Constructs an Optimizer.

Parameters
solutionBuilderShared pointer to the solution generator.
problemShared pointer to the optimization problem.
maxIterationsMaximum number of iterations allowed.

Member Function Documentation

◆ getBestFitness()

double Optimizer::getBestFitness ( )
inline
Returns
The final best fitness value

◆ getBestFitnesses()

std::vector< double > & Optimizer::getBestFitnesses ( )
inline
Returns
Best fitness value so far per iteration

◆ getBestSolution()

std::vector< double > & Optimizer::getBestSolution ( )
inline
Returns
Reference to the best solution vector

◆ getMaxIterations()

int Optimizer::getMaxIterations ( )
inline
Returns
Maximum number of iterations

◆ getProblem()

std::shared_ptr< Problem > Optimizer::getProblem ( )
inline
Returns
Reference to the optimization problem

◆ getSolutionBuilder()

std::shared_ptr< SolutionBuilder > Optimizer::getSolutionBuilder ( )
inline
Returns
Reference to the solution builder

◆ getSolutions()

std::vector< std::vector< double > > & Optimizer::getSolutions ( )
inline
Returns
All solutions evaluated during optimization

◆ optimize()

virtual std::vector< double > Optimizer::optimize ( )
pure virtual

Runs the optimization algorithm.

Returns
Execution time of the algorithm

Implemented in Blind, LocalSearch, and ParticleSwarm.


The documentation for this class was generated from the following file:
  • src/opti_py/cpp/include/opti_py/Optimizer/Optimizer.h