19 #ifndef included_DifferentialEvolution_h
20 #define included_DifferentialEvolution_h
65 if (candidate <= upper && candidate >=
lower)
142 unsigned int populationSize,
146 bool shouldCheckConstraints =
true,
160 std::vector<double>
Optimize(
int min_iterations,
int max_iterations,
161 double cost_tolerance,
162 bool verbose =
true);
169 bool CheckConstraints(std::vector<double> agent);
174 void InitPopulation();
179 void SelectionAndCrossing();
184 std::vector<double> GetBestAgent()
const;
189 double GetBestCost()
const;
194 std::vector<std::pair<std::vector<double>,
double>> GetPopulationWithCosts()
200 void PrintPopulation()
const;
210 unsigned int m_populationSize;
225 unsigned int m_numberOfParameters;
230 bool m_shouldCheckConstraints;
245 std::default_random_engine m_generator;
250 std::vector<std::vector<double>> m_population;
255 std::vector<double> m_minCostPerAgent;
260 std::vector<IOptimizable::Constraints> m_constraints;
265 int m_bestAgentIndex;
275 static constexpr
double g_defaultLowerConstraint =
276 -std::numeric_limits<double>::infinity();
277 static constexpr
double g_defaultUpperConstraint =
278 std::numeric_limits<double>::infinity();
DifferentialEvolution(const IOptimizable &costFunction, unsigned int populationSize, double F=0.8, double CR=0.9, int randomSeed=1, bool shouldCheckConstraints=true, std::function< void(const DifferentialEvolution &)> callback=nullptr, std::function< bool(const DifferentialEvolution &)> terminationCondition=nullptr)
Constructor.
std::vector< double > Optimize(int min_iterations, int max_iterations, double cost_tolerance, bool verbose=true)
Constructor.
virtual ~IOptimizable()
Destructor.
virtual double EvaluateCost(std::vector< double > inputs) const =0
Evaluate the cost function with the current set of inputs.
virtual unsigned int NumberOfParameters() const =0
Return the number of parameters.
virtual std::vector< Constraints > GetConstraints() const =0
Return the list of constraints.
Constraints to be fulfilled by the variable candidates.
double upper
Upper bound for constraint.
double lower
Lower bound for constraint.
Constraints(double lower=0.0, double upper=1.0, bool isConstrained=false)
Constructor.
bool Check(double candidate)
Check whether the current variable candidate fulfills the constraints.
bool isConstrained
Whether to check the constraints.