API (C++)

The C++ API provides access to the core optimization algorithms and benchmark functions implemented in Minion.

class ABC : public minion::MinimizerBase
#include <abc.h>

A class for performing Artificial Bee Colony (ABC) optimization.

This class implements the ABC algorithm for optimization. It inherits from the MinimizerBase class.

Public Functions

inline ABC(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for ABC.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

virtual MinionResult optimize() override

Optimizes the objective function.

Returns:

The result of the optimization.

virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

std::vector<std::vector<double>> population
std::vector<double> fitness
std::vector<double> best
double best_fitness
size_t populationSize
size_t Nevals = 0
size_t limit = 100

Protected Functions

virtual void init()

Initializes the population and other parameters.

Private Members

std::vector<size_t> trialCounters
class AGSK : public minion::Differential_Evolution
#include <agsk.h>

Adaptive Gaining-Sharing Knowledge-based algorithm (AGSK).

Reference: Ali W. Mohamed, Anas A. Hadi, Ali K. Mohamed, and Noor H. Awad, “Evaluation of Adaptive Gaining-Sharing Knowledge Based Algorithm on CEC 2020,” IEEE CEC 2020.

Public Functions

inline AGSK(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())
virtual void initialize() override

Pure virtual function to process algirithm settings.

virtual void adaptParameters() override

Adapts parameters of the algorithm.

virtual void doDE_operation(std::vector<std::vector<double>> &trials) override

Performs a differential evolution operation to generate trial solutions.

Parameters:

trials – The generated trial solutions.

virtual void postEvaluation(const std::vector<std::vector<double>>&, const std::vector<double>&) override

Hook executed after trial vectors are evaluated but before selection.

Parameters:
  • trials – Generated trial vectors.

  • trial_fitness – Fitness values of the trial vectors.

Private Functions

void initializeKnowledgeParameters()
void ensurePopulationReduction()
void updateKnowledgeWeights()
void assignKnowledgeControls()
std::tuple<std::vector<size_t>, std::vector<size_t>, std::vector<size_t>> generateJuniorTriplets(const std::vector<size_t> &sorted_indices) const
std::tuple<std::vector<size_t>, std::vector<size_t>, std::vector<size_t>> generateSeniorTriplets(const std::vector<size_t> &sorted_indices) const
std::vector<size_t> sampleFromPool(size_t popSize, const std::vector<size_t> &pool) const

Private Members

size_t minPopulationSize = 12
size_t maxPopulationSize = 0
std::vector<double> knowledgeParameterK
std::vector<double> KF_values
std::vector<double> KR_values
std::vector<int> knowledgeAssignment
std::array<double, 4> knowledgeWeights = {0.85, 0.05, 0.05, 0.05}
std::array<double, 4> improvementShare = {0.25, 0.25, 0.25, 0.25}
const std::array<double, 4> KF_pool = {0.1, 1.0, 0.5, 1.0}
const std::array<double, 4> KR_pool = {0.2, 0.1, 0.9, 0.9}
class ARRDE : public minion::Differential_Evolution
#include <arrde.h>

Class implementing the Adaptive Restart-Refine Differential Evolution algorithm.

Public Functions

inline ARRDE(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

virtual void adaptParameters() override

Adapts parameters of the algorithm.

This function overrides the adaptParameters function in the Differential_Evolution class.

virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

std::vector<double> M_CR
std::vector<double> M_F
size_t memorySize = 50
std::vector<std::vector<double>> population_records
std::vector<std::vector<double>> archive_records
std::vector<double> fitness_records
std::vector<double> archive_fitness_records
std::vector<double> MCR_records
std::vector<double> MF_records
std::vector<std::vector<double>> first_run_archive
std::vector<double> first_run_archive_fitness
double memorySizeRatio = 2.0
int minPopSize = 4
size_t first_run_archive_max_size = 0

Public Static Attributes

static constexpr size_t archiveRecordMaxSize = 1000

Protected Functions

virtual void onBestUpdated(const std::vector<double> &candidate, double fitnessValue, bool improved) override

Hook that runs whenever the global best is updated.

Parameters:
  • candidate – The new global best candidate.

  • fitnessValue – The fitness of the candidate.

  • improved – True if the candidate improves the previous best.

Private Functions

bool checkIsBetween(double x, double low, double high)

Checks if a value is between two bounds.

Parameters:
  • x – The value to check.

  • low – The lower bound.

  • high – The upper bound.

Returns:

True if x is between low and high, false otherwise.

bool checkOutsideLocals(double x, const std::vector<std::pair<double, double>> &local)

Checks if a value is outside of all given local intervals.

Parameters:
  • x – The value to check.

  • local – The list of local intervals.

Returns:

True if x is outside all intervals, false otherwise.

std::vector<std::pair<double, double>> merge_intervals(const std::vector<std::pair<double, double>> &intervals)

Merges overlapping intervals.

Parameters:

intervals – The list of intervals to merge.

Returns:

A list of merged intervals.

std::vector<std::vector<std::pair<double, double>>> merge_intervals(std::vector<std::vector<std::pair<double, double>>> &intervals)

Merges overlapping intervals for multiple variables.

Parameters:

intervals – The list of interval lists to merge.

Returns:

A list of merged interval lists.

double sample_outside_local_bounds(double low, double high, const std::vector<std::pair<double, double>> &local_bounds)

Samples a value outside of the given local bounds.

Parameters:
  • low – The lower bound of the entire range.

  • high – The upper bound of the entire range.

  • local_bounds – The local bounds to avoid.

Returns:

A sampled value outside of the local bounds.

std::vector<double> applyLocalConstraints(const std::vector<double> &p)

Applies local constraints to a given solution.

Parameters:

p – The solution to constrain.

Returns:

The constrained solution.

void update_locals()

Updates the local constraints based on the current population.

void adjustPopulationSize()
void adjustArchiveSize()
void processRestartCycle()
void executeRestart(size_t targetSize)
void executeRefine(size_t targetSize)
void updateParameterMemory()
void resampleControlParameters()
void addToFirstRunArchive(const std::vector<double> &candidate, double fitnessValue)

Private Members

double archive_size_ratio
size_t memoryIndex = 0
size_t Neval_stratrefine = 0
std::string reduction_strategy
bool popreduce
bool do_refine = false
double spread
bool refine = false
bool restart = false
bool first_run = true
bool population_converged = false
double bestOverall = std::numeric_limits<double>::max()
double decrease = 0.9
double reltol
double restartRelTol
double refineRelTol
size_t Nrestart = 1
std::vector<std::vector<std::pair<double, double>>> locals
bool update_records = false
double maxRestart = 2
size_t newPopulationSize = 0
class BIPOP_aCMAES : public minion::MinimizerBase
#include <bipop_acmaes.h>

Class implementing the BIPOP-aCMA-ES algorithm.

Reference: Nikolaus Hansen. 2009. Benchmarking a BI-population CMA-ES on the BBOB-2009 function testbed. In Proceedings of the 11th Annual Conference Companion on Genetic and Evolutionary Computation Conference: Late Breaking Papers (GECCO ‘09). Association for Computing Machinery, New York, NY, USA, 2389–2396. https://doi.org/10.1145/1570256.1570333

The BIPOP_aCMAES class implements an adaptive variant of the BIPOP (bi-population) Covariance Matrix Adaptation Evolution Strategy (CMA-ES). It manages multiple restart strategies with varying population sizes and maintains evolution paths, covariance updates, and step-size control to efficiently explore and exploit the search space.

Public Functions

BIPOP_aCMAES(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())
virtual void initialize() override

Pure virtual function to process algirithm settings.

virtual MinionResult optimize() override

Virtual function to perform the optimization.

Throws:

std::logic_error – if the function is not implemented in a derived class.

Returns:

A MinionResult object containing the result of the optimization.

Private Functions

std::vector<double> applyBounds(const std::vector<double> &candidate) const
void sampleOffsprings()
size_t evaluatePopulation()
void rankAndSort()
void updateBest()
void assignNewMean()
void updateEvolutionPaths()
void updateWeights()
void updateCovarianceMatrix()
void updateStepsize()
void updateEigenDecomposition()
void checkStoppingCriteria()
void recordHistory(double relRange)
std::vector<double> eigenToStd(const Eigen::VectorXd &vec) const
void applyCovarianceScale()

Private Members

Parameter era
size_t dimension = 0
bool useBounds = false
std::string boundStrategy = "reflect-random"
size_t lambda0 = 0
size_t mu0 = 0
size_t maxRestarts = 0
size_t maxIterations = 0
double sigma0 = 0.0
double avg_range = 1.0
std::vector<double> cov_scale
Eigen::VectorXd initialMean
std::vector<double> best
double best_fitness = std::numeric_limits<double>::infinity()
size_t Nevals = 0
size_t globalGeneration = 0
std::vector<double> diversity
std::vector<double> currentFitness
bool support_tol = true
bool should_stop_run = false
bool should_stop_optimization = false
class CEC2011Functions : public minion::CECBase
#include <cec2011.h>

Class encapsulating the 20 real-world CEC2011 benchmark problems.

Public Functions

CEC2011Functions(int function_number, int dimension)

Construct a new evaluator for a specific CEC2011 problem.

Parameters:
  • function_number – Problem index as defined by the original suite (1-20).

  • dimension – Decision vector dimension for the selected problem.

~CEC2011Functions() = default
class CEC2014Functions : public minion::CECBase
#include <cec2014.h>

Class encapsulating CEC2014 test functions.

Public Functions

CEC2014Functions(int function_number, int dimension)

Constructor for CEC2014Functions.

Parameters:
  • function_number – Function number (1-30).

  • dimension – Dimension of the problem.

inline ~CEC2014Functions()

Destructor.

class CEC2017Functions : public minion::CECBase
#include <cec2017.h>

Class encapsulating CEC2017 test functions.

Public Functions

CEC2017Functions(int function_number, int dimension)

Constructor for CEC2017Functions.

Parameters:
  • function_number – Function number (1-30).

  • dimension – Dimension of the problem.

inline ~CEC2017Functions()

Destructor.

class CEC2019Functions : public minion::CECBase
#include <cec2019.h>

Class encapsulating CEC2019 test functions.

Public Functions

CEC2019Functions(int function_number, int dimension)

Constructor for CEC2019Functions.

Parameters:
  • function_number – Function number (1-10).

  • dimension – Dimension of the problem.

inline ~CEC2019Functions()

Destructor.

class CEC2020Functions : public minion::CECBase
#include <cec2020.h>

Class encapsulating CEC2020 test functions.

Public Functions

CEC2020Functions(int function_number, int dimension)

Constructor for CEC2020Functions.

Parameters:
  • function_number – Function number (1-10).

  • dimension – Dimension of the problem.

inline ~CEC2020Functions()

Destructor.

class CEC2022Functions : public minion::CECBase
#include <cec2022.h>

Class encapsulating CEC2022 test functions.

Public Functions

CEC2022Functions(int function_number, int dimension)

Constructor for CEC2022Functions.

Parameters:
  • function_number – Function number (1-10).

  • dimension – Dimension of the problem.

inline ~CEC2022Functions()

Destructor.

class CECBase
#include <cec.h>

base class for all CEC functions.

Subclassed by minion::CEC2011Functions, minion::CEC2014Functions, minion::CEC2017Functions, minion::CEC2019Functions, minion::CEC2020Functions, minion::CEC2022Functions

Public Functions

CECBase(int function_number, int dimension)

Constructor.

Parameters:
  • function_number – Function number (1-10).

  • dimension – Dimension of the problem.

virtual ~CECBase() = default

destructor

virtual std::vector<double> operator()(const std::vector<std::vector<double>> &X)

Operator to evaluate CEC2020 test functions.

Parameters:

X – Input vectors to evaluate.

Returns:

Vector of function values corresponding to each input vector.

Public Members

size_t Ncalls = 0

Protected Attributes

int dimension_

Dimension of the problem.

int function_number_

Function number.

CECTestFunc testfunc
class CMAES : public minion::MinimizerBase
#include <cmaes.h>

Class implementing the Covariance Matrix Adaptation Evolution Strategy (CMA-ES). Reference : N. Hansen and A. Ostermeier, “Adapting arbitrary normal mutation distributions in evolution strategies:

the covariance matrix adaptation,” Proceedings of IEEE International Conference on Evolutionary Computation, Nagoya, Japan, 1996, pp. 312-317, doi: 10.1109/ICEC.1996.542381.

CMA-ES maintains a multivariate normal search distribution whose mean and covariance are adapted from successful samples, enabling efficient search in non-separable, ill-conditioned landscapes.

Public Functions

CMAES(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Construct a CMAES optimizer.

Parameters:
  • func – Objective function to minimise.

  • bounds – Search-space bounds for each decision variable.

  • x0 – Optional collection of initial guesses. When multiple candidates are provided, the best according to func is used to seed the distribution mean.

  • data – Additional opaque data forwarded to func.

  • callback – Optional callback invoked with intermediate results.

  • tol – Relative convergence tolerance (see stopping criterion).

  • maxevals – Maximum number of function evaluations.

  • seed – Seed for the pseudo-random number generator (-1 keeps the global setting).

  • options – Algorithm-specific configuration overrides.

virtual void initialize() override

Prepare internal state using the supplied configuration.

virtual MinionResult optimize() override

Run the optimisation loop until a stopping criterion is met.

Returns:

Best-known result collected during the search.

Private Functions

void updateEigenDecomposition()

Refresh the eigen decomposition of the covariance matrix.

std::vector<double> ensureBounds(std::vector<double> candidate) const

Clamp a candidate to the feasible domain when bounds are used.

Private Members

size_t lambda = 0
size_t mu = 0
double muEff = 0.0
double sigma = 0.3
double cc = 0.0
double cs = 0.0
double c1 = 0.0
double cmu = 0.0
double damps = 0.0
double chiN = 0.0
std::vector<double> diversity
std::vector<double> best
double best_fitness
size_t Nevals = 0
std::vector<double> weights
Eigen::VectorXd mean
Eigen::MatrixXd C
Eigen::MatrixXd B
Eigen::VectorXd D
Eigen::VectorXd ps
Eigen::VectorXd pc
bool useBounds = false
size_t dimension = 0
bool support_tol = true
class DefaultSettings
#include <default_options.h>

Default option presets for Minion optimizers.

Public Functions

inline std::map<std::string, ConfigValue> getDefaultSettings(std::string algo)

Public Members

std::map<std::string, ConfigValue> default_settings_DE = {{"population_size", 0}, {"mutation_rate", 0.5}, {"crossover_rate", 0.8}, {"mutation_strategy", std::string("best1bin")}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_ARRDE = {{"population_size", 0}, {"bound_strategy", std::string("reflect-random")},}
std::map<std::string, ConfigValue> default_settings_GWO_DE = {{"population_size", 0}, {"mutation_rate", 0.5}, {"crossover_rate", 0.7}, {"elimination_prob", 0.1}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_j2020 = {{"population_size", 0}, {"tau1", 0.1}, {"tau2", 0.1}, {"myEqs", 0.4}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_LSRTDE = {{"population_size", 0}, {"memory_size", 5}, {"success_rate", 0.5}, {"bound_strategy", std::string("random")}}
std::map<std::string, ConfigValue> default_settings_NLSHADE_RSP = {{"population_size", 0}, {"minimum_population_size", 4}, {"memory_size", 100}, {"archive_size_ratio", 2.6}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_NLSHADE_LBC = {{"population_size", 0}, {"minimum_population_size", 4}, {"memory_size", 0}, {"archive_size_ratio", 1.0}, {"bound_strategy", std::string("midpoint-target")}}
std::map<std::string, ConfigValue> default_settings_JADE = {{"population_size", 0}, {"c", 0.1}, {"mutation_strategy", std::string("current_to_pbest_A_1bin")}, {"archive_size_ratio", 1.0}, {"minimum_population_size", 4}, {"reduction_strategy", std::string("linear")}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_NJADE = {{"population_size", 0}, {"mutation_strategy", std::string("current_to_pbest_A_1bin")}, {"memory_size", 5}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_jSO = {{"population_size", 0}, {"memory_size", 5}, {"archive_size_ratio", 1.0}, {"minimum_population_size", 4}, {"reduction_strategy", std::string("linear")}, {"bound_strategy", std::string("random")}}
std::map<std::string, ConfigValue> default_settings_IMODE = {{"population_size", 0}, {"minimum_population_size", 4}, {"memory_size", 0}, {"archive_size_ratio", 2.6}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_AGSK = {{"population_size", 0}, {"minimum_population_size", 12}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_LSHADE = {{"population_size", 0}, {"memory_size", 6}, {"mutation_strategy", std::string("current_to_pbest_A_1bin")}, {"archive_size_ratio", 2.6}, {"minimum_population_size", 4}, {"reduction_strategy", std::string("linear")}, {"bound_strategy", std::string("random")}}
std::map<std::string, ConfigValue> default_settings_ABC = {{"population_size", 0}, {"limit", 100}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_PSO = {{"population_size", 0}, {"inertia_weight", 0.7}, {"cognitive_coefficient", 1.5}, {"social_coefficient", 1.5}, {"velocity_clamp", 0.2}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_SPSO2011 = {{"population_size", 0}, {"inertia_weight", 0.729844}, {"cognitive_coefficient", 1.49618}, {"social_coefficient", 1.49618}, {"phi_personal", 1.49618}, {"phi_social", 1.49618}, {"neighborhood_size", 3}, {"informant_degree", 3}, {"velocity_clamp", 0.0}, {"normalize", false}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_DMSPSO = {{"population_size", 0}, {"inertia_weight", 0.7}, {"cognitive_coefficient", 1.2}, {"social_coefficient", 1.0}, {"local_coefficient", 1.4}, {"global_coefficient", 0.8}, {"subswarm_count", 4}, {"regroup_period", 5}, {"velocity_clamp", 0.2}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_LSHADE_cnEpSin = {{"population_size", 0}, {"memory_size", 5}, {"archive_rate", 1.4}, {"minimum_population_size", 4}, {"p_best_fraction", 0.11}, {"rotation_probability", 0.4}, {"neighborhood_fraction", 0.5}, {"freq_init", 0.5}, {"learning_period", 20}, {"sin_freq_base", 0.5}, {"epsilon", 1e-8}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_CMAES = {{"population_size", 0}, {"mu", 0}, {"initial_step", 0.3}, {"cc", 0.0}, {"cs", 0.0}, {"c1", 0.0}, {"cmu", 0.0}, {"damps", 0.0}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_BIPOP_aCMAES = {{"population_size", 0}, {"max_iterations", 100000}, {"initial_step", 0.3}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_RCMAES = {{"population_size", 0}, {"initial_step", 0.2}, {"bound_strategy", std::string("reflect-random")}}
std::map<std::string, ConfigValue> default_settings_DA = {{"acceptance_par", -5.0}, {"visit_par", 2.67}, {"initial_temp", 5230.0}, {"restart_temp_ratio", 2e-5}, {"use_local_search", true}, {"local_search_algo", "L_BFGS_B"}, {"func_noise_ratio", 1e-16}, {"N_points_derivative", 3}, {"bound_strategy", std::string("periodic")}}
std::map<std::string, ConfigValue> default_settings_NelderMead = {{"locality_factor", 0.05}, {"bound_strategy", std::string("reflect-random")},}
std::map<std::string, ConfigValue> default_settings_LBFGSB = {{"max_iterations", 100000}, {"m", 10}, {"g_epsilon", 1e-5}, {"g_epsilon_rel", 0.0}, {"f_reltol", 1e-9}, {"max_linesearch", 20}, {"c_1", 1e-3}, {"c_2", 0.9}, {"func_noise_ratio", 0.0}, {"N_points_derivative", 3}}
std::map<std::string, ConfigValue> default_settings_LBFGS = {{"max_iterations", 100000}, {"m", 10}, {"g_epsilon", 1e-5}, {"g_epsilon_rel", 0.0}, {"f_reltol", 1e-9}, {"max_linesearch", 20}, {"c_1", 1e-3}, {"c_2", 0.9}, {"func_noise_ratio", 0.0}, {"N_points_derivative", 3}}
std::map<std::string, std::map<std::string, ConfigValue>> algoToSettingsMap = {{"DE", default_settings_DE}, {"LSHADE", default_settings_LSHADE}, {"JADE", default_settings_JADE}, {"NJADE", default_settings_NJADE}, {"j2020", default_settings_j2020}, {"NLSHADE_RSP", default_settings_NLSHADE_RSP}, {"NLSHADE_LBC", default_settings_NLSHADE_LBC}, {"LSRTDE", default_settings_LSRTDE}, {"ARRDE", default_settings_ARRDE}, {"jSO", default_settings_jSO}, {"IMODE", default_settings_IMODE}, {"AGSK", default_settings_AGSK}, {"GWO_DE", default_settings_GWO_DE}, {"NelderMead", default_settings_NelderMead}, {"ABC", default_settings_ABC}, {"PSO", default_settings_PSO}, {"SPSO2011", default_settings_SPSO2011}, {"DMSPSO", default_settings_DMSPSO}, {"LSHADE_cnEpSin", default_settings_LSHADE_cnEpSin}, {"CMAES", default_settings_CMAES}, {"BIPOP_aCMAES", default_settings_BIPOP_aCMAES}, {"RCMAES", default_settings_RCMAES}, {"DA", default_settings_DA}, {"L_BFGS_B", default_settings_LBFGSB}, {"L_BFGS", default_settings_LBFGS}}

Public Static Functions

static inline std::string normalizeName(const std::string &name)
class Differential_Evolution : public minion::MinimizerBase
#include <de.h>

A class for performing differential evolution optimization.

This class implements the differential evolution algorithm for optimization. It inherits from the MinimizerBase class.

Subclassed by minion::AGSK, minion::ARRDE, minion::IMODE, minion::JADE, minion::LSHADE, minion::LSHADE_cnEpSin, minion::j2020, minion::jSO

Public Functions

inline Differential_Evolution(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for Differential_Evolution.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

virtual MinionResult optimize() override

Optimizes the objective function.

Returns:

The result of the optimization.

virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

std::vector<std::vector<double>> population
std::vector<double> fitness
std::vector<double> best
double best_fitness
std::vector<std::vector<double>> archive
std::vector<double> archive_fitness
size_t populationSize
size_t Nevals = 0
std::vector<double> meanCR
std::vector<double> meanF
std::vector<double> stdCR
std::vector<double> stdF
std::vector<double> diversity
std::vector<double> F
std::vector<double> CR
std::vector<size_t> p
std::string mutation_strategy
bool useLatin = false
double pA = 0.5
bool support_tol = true

Protected Functions

std::vector<double> mutate(size_t idx)

Mutates a given individual.

Parameters:

idx – Index of the individual to mutate.

Returns:

A mutated individual.

std::vector<double> _crossover_bin(const std::vector<double> &target, const std::vector<double> &mutant, double CR)

Performs binomial crossover.

Parameters:
  • target – The target vector.

  • mutant – The mutant vector.

  • CR – The crossover rate.

Returns:

The result of the crossover.

std::vector<double> _crossover_exp(const std::vector<double> &target, const std::vector<double> &mutant, double CR)

Performs exponential crossover.

Parameters:
  • target – The target vector.

  • mutant – The mutant vector.

  • CR – The crossover rate.

Returns:

The result of the crossover.

std::vector<double> crossover(const std::vector<double> &target, const std::vector<double> &mutant, double CR)

Performs crossover.

Parameters:
  • target – The target vector.

  • mutant – The mutant vector.

  • CR – The crossover rate.

Returns:

The result of the crossover.

inline virtual void onBestUpdated(const std::vector<double> &candidate, double fitnessValue, bool improved)

Hook that runs whenever the global best is updated.

Parameters:
  • candidate – The new global best candidate.

  • fitnessValue – The fitness of the candidate.

  • improved – True if the candidate improves the previous best.

virtual void init()

Initializes the population and other parameters.

virtual bool checkStopping()

Checks stopping criteria for the optimization.

Returns:

True if stopping criteria are met, false otherwise.

virtual void adaptParameters()

Adapts parameters of the algorithm.

virtual void doDE_operation(std::vector<std::vector<double>> &trials)

Performs a differential evolution operation to generate trial solutions.

Parameters:

trials – The generated trial solutions.

inline virtual void postEvaluation(const std::vector<std::vector<double>> &trials, const std::vector<double> &trial_fitness)

Hook executed after trial vectors are evaluated but before selection.

Parameters:
  • trials – Generated trial vectors.

  • trial_fitness – Fitness values of the trial vectors.

Protected Attributes

std::vector<double> trial_fitness
std::vector<double> fitness_before
size_t no_improve_counter = 0
double Fw = 1.0
std::vector<size_t> sorted_indices
class DMSPSO : public minion::PSO
#include <dmspso.h>

Dynamic Multi-Swarm Particle Swarm Optimization built on top of the base PSO implementation.

Public Functions

inline DMSPSO(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Construct the dynamic multi-swarm PSO variant.

Parameters:
  • func – Objective function to minimize.

  • bounds – Search-space bounds.

  • x0 – Optional set of initial particles.

  • data – User payload forwarded to the objective.

  • callback – Per-iteration callback receiving the best solution.

  • tol – Diversity tolerance used by the base stop criterion.

  • maxevals – Maximum number of objective evaluations.

  • seed – RNG seed (negative -> random seed).

  • options – Configuration map (sub-swarm count, regroup period, etc.).

virtual void initialize() override

Pure virtual function to process algirithm settings.

Protected Functions

virtual void init() override
virtual void updateVelocitiesAndPositions() override

Private Functions

void rebuildSubswarmAssignments()
void updateSubswarmBests()

Private Members

size_t subswarmCount = 4
size_t regroupPeriod = 5
double localCoefficient = 1.4
double globalCoefficient = 0.8
size_t iterationCounter = 0
std::vector<std::vector<size_t>> subswarms
std::vector<size_t> subswarmBestIndices
std::vector<size_t> particleToSubswarm
class Dual_Annealing : public minion::MinimizerBase
#include <dual_annealing.h>

A class for performing dual annealing algorithm.

Reference : Tsallis C, Stariolo DA. Generalized Simulated Annealing. Physica A, 233, 395-406 (1996). This class inherits from the MinimizerBase class.

Public Functions

inline Dual_Annealing(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for DA.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. Minion will pick the best guess from x0 as the the actual initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

virtual MinionResult optimize() override

Optimizes the objective function.

Returns:

The result of the optimization.

virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

size_t Nevals = 0
double acceptance_par
double visit_par
double initial_temp
double restart_temp_ratio
double local_search_start
std::string local_min_algo
bool useLocalSearch = true
size_t max_no_improve
double func_noise_ratio = 1e-10
int der_N_points = 3

Private Functions

void init(bool useX0 = true)
std::vector<double> visit_fn(double temperature, int dim)
std::vector<double> generate_candidate(std::vector<double> cand, int j, double temp)
void accept_reject(const std::vector<double> &cand, const double &Energy)
void step(int iter, double temp)

Private Members

size_t N_no_improve = 0
std::vector<double> best_cand
std::vector<double> current_cand
double best_E = std::numeric_limits<double>::max()
double current_E
double temp_step
double factor2
double factor3
double factor4p
double factor5
double d1
double factor6
double tail_limit = 1e+8
double pi = 3.14159265358979323846
struct ExclusionBox

Public Members

std::vector<double> low
std::vector<double> high
class GWO_DE : public minion::MinimizerBase
#include <gwo_de.h>

Combined Grey Wolf Optimizer with Differential Evolution algorithm.

Public Functions

inline GWO_DE(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for Differential_Evolution.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

virtual MinionResult optimize() override

Performs the optimization process.

Returns:

MinionResult containing the best found solution and associated information.

void initialize_population()

Initializes the population randomly within the given bounds.

void evaluate_population()

Evaluates the fitness of the entire population.

void update_leaders()

Updates the alpha, beta, and delta wolves based on the current population fitness.

std::vector<double> update_position(const std::vector<double> &X, const std::vector<double> &A1, const std::vector<double> &C1, const std::vector<double> &A2, const std::vector<double> &C2, const std::vector<double> &A3, const std::vector<double> &C3) const

Updates the position of a given solution based on the GWO strategy.

Parameters:
  • X – Current position of the solution.

  • A1 – Attraction coefficient vector for the alpha leader.

  • C1 – Distance control coefficient vector for the alpha leader.

  • A2 – Attraction coefficient vector for the beta leader.

  • C2 – Distance control coefficient vector for the beta leader.

  • A3 – Attraction coefficient vector for the delta leader.

  • C3 – Distance control coefficient vector for the delta leader.

Returns:

New position of the solution.

std::vector<std::vector<double>> differential_evolution() const

Performs the Differential Evolution process to generate new solutions.

Returns:

New population generated by Differential Evolution.

void eliminate()

Performs the elimination process to introduce diversity into the population.

std::vector<std::vector<double>> generate_gwo_candidates(double a) const
virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

double CR
double F
double elimination_prob = 0.1
size_t dimension
double alpha_score
double beta_score
double delta_score
size_t eval_count
std::vector<double> alpha_pos
std::vector<double> beta_pos
std::vector<double> delta_pos
std::vector<std::vector<double>> population
std::vector<double> fitness
class IMODE : public minion::Differential_Evolution
#include <imode.h>

Improved Multi-Operator Differential Evolution.

Reference: Karam M. Sallam, Saber M. Elsayed, Ripon K. Chakrabortty, and Michael J. Ryan. 2020. Improved Multi-operator Differential Evolution Algorithm for Solving Unconstrained Problems. In 2020 IEEE Congress on Evolutionary Computation (CEC). IEEE Press, 1–8. https://doi.org/10.1109/CEC48606.2020.9185577

IMODE mixes multiple mutation operators with success-history based parameter adaptation and linear population size reduction.

Public Functions

inline IMODE(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())
virtual void initialize() override

Initialize the algorithm given the input settings.

virtual void adaptParameters() override

Adapts parameters of the algorithm.

virtual void doDE_operation(std::vector<std::vector<double>> &trials) override

Performs a differential evolution operation to generate trial solutions.

Parameters:

trials – The generated trial solutions.

Protected Functions

virtual void postEvaluation(const std::vector<std::vector<double>>&, const std::vector<double>&) override

Hook executed after trial vectors are evaluated but before selection.

Parameters:
  • trials – Generated trial vectors.

  • trial_fitness – Fitness values of the trial vectors.

virtual void onBestUpdated(const std::vector<double> &candidate, double fitnessValue, bool improved) override

Hook that runs whenever the global best is updated.

Parameters:
  • candidate – The new global best candidate.

  • fitnessValue – The fitness of the candidate.

  • improved – True if the candidate improves the previous best.

Private Functions

void reducePopulation()
void trimArchive()
void sortPopulationByFitness()
void updateOperatorProbabilities(const std::vector<double> &rewards)
void updateParameterMemory(const std::vector<double> &goodF, const std::vector<double> &goodCR, const std::vector<double> &improvement)
double sampleScalingFactor(double meanF) const
double sampleCrossover(double meanCR) const
void applyHanBoundary(std::vector<std::vector<double>> &mutants, const std::vector<std::vector<double>> &parents)
void maybeRunLocalSearch()
bool shouldRunLocalSearch() const
bool runLocalSearch()

Private Members

size_t memorySize = 0
std::vector<double> memoryF
std::vector<double> memoryCR
size_t memoryIndex = 0
double archive_size_ratio = 2.6
size_t minPopulationSize = 4
size_t initialPopulationSize = 0
std::vector<double> operatorProbabilities = {1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0}
std::vector<int> operatorAssignment
double probLocalSearch = 0.1
double localSearchStartFraction = 0.85
double localSearchBudgetFraction = 0.02
size_t lastLocalSearchEval = 0
bool pendingLocalSearchAttempt = false
struct InternalState

Public Functions

inline explicit InternalState(const LBFGSParam &param)

Public Members

SolverCore core
struct InternalState

Public Functions

inline explicit InternalState(const LBFGSBParam &param)

Public Members

SolverCore core
class j2020 : public minion::Differential_Evolution
#include <j2020.h>

A class implementing a differential evolution optimization algorithm.

This class derives from the MinimizerBase class and implements the j2020 algorithm for global optimization. It includes methods for initializing the population, computing distances, crowding mechanisms, and optimizing a given objective function.

Public Functions

inline j2020(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())
virtual void initialize() override

Initialize the algorithm given the input settings.

virtual MinionResult optimize() override

Optimizes the objective function.

Returns:

The result of the optimization.

Private Functions

double distance_squared(const std::vector<double> &a, const std::vector<double> &b) const
size_t crowding_index(const std::vector<double> &candidate) const
bool too_many_equals(const std::vector<double> &costs, size_t count, double bestCost) const
void reinitialize_range(size_t start, size_t end, size_t skipIndex = std::numeric_limits<size_t>::max())

Private Members

size_t desiredPopulation = 0
size_t bigPopulationSize = 0
size_t smallPopulationSize = 0
double tau1 = 0.1
double tau2 = 0.1
double myEqs = 0.25
const double baseF = 0.5
const double baseCR = 0.9
const double eps = 1e-12
const double Fu = 1.1
long nReset = 0
long sReset = 0
long age = 0
class JADE : public minion::Differential_Evolution
#include <jade.h>

Class implementing the JADE algorithm. Reference : J. Zhang and A. C. Sanderson, “JADE: Adaptive Differential Evolution With Optional External Archive,” in IEEE Transactions on Evolutionary Computation, vol. 13, no. 5, pp. 945-958, Oct. 2009, doi: 10.1109/TEVC.2009.2014613.

The JADE class is an extension of the Differential Evolution algorithm with mechanisms for self-adaptation of control parameters.

Public Functions

inline JADE(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for JADE.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

virtual void adaptParameters() override

Adapts parameters of the JADE algorithm.

This function overrides the adaptParameters function in the Differential_Evolution class.

virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

double c = 0.1
double muCR = 0.5
double muF = 0.5

Private Members

double archive_size_ratio
size_t minPopSize
std::string reduction_strategy
bool popreduce
class jSO : public minion::Differential_Evolution
#include <jso.h>

Class implementing the jSO algorithm.

Reference : J. Brest, M. S. Maučec and B. Bošković, “Single objective real-parameter optimization: Algorithm jSO,” 2017 IEEE Congress on Evolutionary Computation (CEC), Donostia, Spain, 2017, pp. 1311-1318, doi: 10.1109/CEC.2017.7969456.

The jSO class is an extension of the Differential Evolution algorithm with mechanisms for self-adaptation of control parameters.

Public Functions

inline jSO(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for jSO.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

virtual void adaptParameters() override

Adapts parameters of the jSO algorithm.

This function overrides the adaptParameters function in the Differential_Evolution class.

virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

std::vector<double> M_CR
std::vector<double> M_F
size_t memorySize

Private Members

size_t memoryIndex = 0
double archive_size_ratio
size_t minPopSize
std::string reduction_strategy
bool popreduce
class L_BFGS : public minion::MinimizerBase
#include <l_bfgs.h>

A class for the L-BFGS optimization algorithm.

This class implements the Limited-memory BFGS unconstrained (L-BFGS) algorithm. It inherits from the MinimizerBase class and provides methods for unconstrained optimization. The implementation follows the LBFGSpp library structure, while incorporating selected line-search and finite-difference handling choices used elsewhere in Minion.

Public Functions

inline L_BFGS(MinionFunction func, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for L-BFGS.

Parameters:
  • func – The objective function to minimize.

  • x0 – The initial solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. Minion will pick the best guess from x0 as the the actual initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

~L_BFGS()

Destructor.

virtual MinionResult optimize() override

Optimizes the objective function.

Returns:

The result of the optimization.

virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

size_t Nevals = 0
std::vector<double> best
double f_best = std::numeric_limits<double>::max()
int N_points = 1
double func_noise_ratio = 1e-10

Private Functions

double fun_and_grad(const VectorXd &x, VectorXd &grad)

Evaluates the function and its gradient.

Parameters:
  • x – Current point.

  • grad – Gradient vector (output parameter).

Returns:

Function value at x.

Private Members

InternalState *state = nullptr
double epsilon = std::numeric_limits<double>::epsilon()
double last_f = 1.0
double fin_diff_rel_step = sqrt(std::numeric_limits<double>::epsilon())
class L_BFGS_B : public minion::MinimizerBase
#include <l_bfgs_b.h>

A class for the L-BFGS-B optimization algorithm.

This class implements the Limited-memory BFGS with Box constraints (L-BFGS-B) algorithm. It inherits from the MinimizerBase class and provides methods for constrained optimization. The implementation is based primarily on the LBFGSpp library structure, with selected elements adapted from SciPy’s L-BFGS-B implementation, including the dcstep-based line search and related reference workflow details.

Public Functions

inline L_BFGS_B(MinionFunction func, const std::vector<std::pair<double, double>> &bounds_, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for L-BFGS-B.

Parameters:
  • func – The objective function to minimize.

  • bounds_ – The bounds for the variables.

  • x0 – Optional initial guesses. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. Minion will pick the best guess from x0 as the actual initialization. If omitted, a random point sampled from the bounds is used.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

~L_BFGS_B()

Destructor.

virtual MinionResult optimize() override

Optimizes the objective function.

Returns:

The result of the optimization.

virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

size_t Nevals = 0
std::vector<double> best
double f_best = std::numeric_limits<double>::max()
int N_points = 1
double func_noise_ratio = 1e-10

Private Functions

double fun_and_grad(const VectorXd &x, VectorXd &grad)

Evaluates the function and its gradient.

Parameters:
  • x – Current point.

  • grad – Gradient vector (output parameter).

Returns:

Function value at x.

Private Members

InternalState *state = nullptr
double epsilon = std::numeric_limits<double>::epsilon()
double last_f = 1.0
double fin_diff_rel_step = sqrt(std::numeric_limits<double>::epsilon())
double dist_min = 1e-7
std::vector<std::pair<double, double>> actual_bounds
class LSHADE : public minion::Differential_Evolution
#include <lshade.h>

Class implementing the LSHADE algorithm. Reference : R. Tanabe and A. S. Fukunaga, “Improving the search performance of SHADE using linear population size reduction,” 2014 IEEE Congress on Evolutionary Computation (CEC), Beijing, China, 2014, pp. 1658-1665, doi: 10.1109/CEC.2014.6900380.

The LSHADE class is an extension of the Differential Evolution algorithm with mechanisms for self-adaptation of control parameters.

Public Functions

inline LSHADE(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for LSHADE.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

virtual void adaptParameters() override

Adapts parameters of the LSHADE algorithm.

This function overrides the adaptParameters function in the Differential_Evolution class.

virtual void initialize() override

Initialize the algorithm given the input settings.

Public Members

std::vector<double> M_CR
std::vector<double> M_F
size_t memorySize

Private Members

size_t memoryIndex = 0
double archive_size_ratio
size_t minPopSize
std::string reduction_strategy
bool popreduce
class LSHADE_cnEpSin : public minion::Differential_Evolution
#include <lshadecnepsin.h>

Ensemble sinusoidal L-SHADE with covariance learning and Euclidean neighbourhoods.

This implementation mirrors the reference MATLAB code proposed by Awad et al. for CEC 2017. Two sinusoidal strategies compete during the first half of the run, frequency memories are updated via Lehmer means, population size is linearly reduced, and crossover can be performed in a locally learned eigen space.

Public Functions

inline LSHADE_cnEpSin(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Construct the LSHADE-cnEpSin optimizer.

Parameters:
  • func – Objective function to minimize.

  • bounds – Variable bounds for the DE population.

  • x0 – Optional set of initial individuals.

  • data – User payload passed to the objective.

  • callback – Progress callback invoked with the best-so-far state.

  • tol – Relative tolerance used by the inherited stop criterion.

  • maxevals – Maximum number of objective evaluations.

  • seed – RNG seed (negative -> random seed).

  • options – Configuration map (population multiplier, archive rate, etc.).

virtual void initialize() override

Initialize the algorithm given the input settings.

virtual MinionResult optimize() override

Optimizes the objective function.

Returns:

The result of the optimization.

Private Functions

size_t computeGmax(size_t dimension) const
void sampleParameters(const std::vector<size_t> &sortedIndices, std::vector<double> &muSF, std::vector<double> &muCR, std::vector<double> &muFreq, std::vector<size_t> &memIndices, std::vector<double> &CRvec, std::vector<double> &Fvec, std::vector<double> &freqVec, bool &usedStrategy1, bool &usedStrategy2)
void updateHistories(bool usedStrategy1, bool usedStrategy2, size_t good1, size_t bad1, size_t good2, size_t bad2)
void updateMemories(const std::vector<size_t> &successIndices, const std::vector<double> &difValues, const std::vector<double> &CRvec, const std::vector<double> &Fvec, const std::vector<double> &freqVec)
void updateArchive(const std::vector<std::vector<double>> &newEntries, const std::vector<double> &newFitness)
void reducePopulationIfNeeded()
void buildNeighbourCovariance(const std::vector<size_t> &sortedIndices, Eigen::MatrixXd &eigenBasis, Eigen::MatrixXd &eigenBasisT, size_t currentPopSize)

Private Members

size_t learningPeriod = 20
double sinFreqBase = 0.5
double epsilon = 1e-8
double pBestRate = 0.11
double archiveRate = 1.4
double rotationProbability = 0.4
double neighbourhoodFraction = 0.5
double freqInit = 0.5
size_t memorySize = 5
size_t maxPopulationSize = 0
size_t minPopulationSize = 4
size_t generationCounter = 0
size_t estimatedMaxGenerations = 1
std::vector<double> memorySF
std::vector<double> memoryCR
std::vector<double> memoryFreq
size_t memoryPos = 0
std::deque<size_t> successHistory1
std::deque<size_t> failureHistory1
std::deque<size_t> successHistory2
std::deque<size_t> failureHistory2
std::vector<double> lastCR
std::vector<double> lastF
std::vector<double> lastFreq
class LSRTDE : public minion::MinimizerBase
#include <lsrtde.h>

A class implementing the LSRTDE optimization algorithm.

The LSRTDE class inherits from MinimizerBase and provides functionality to perform optimization using a modified version of the L-SHADE algorithm with an archive and a memory mechanism to store previous successes.

Public Functions

inline LSRTDE(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for Differential_Evolution.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization. Additional Note : LSRTDE does not support initial guesses. This argument is added for consistency purpose.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

inline ~LSRTDE()

Destructor for the LSRTDE class.

This destructor cleans up any allocated memory used by the class.

inline virtual MinionResult optimize() override

Optimizes the objective function.

Returns:

The result of the optimization.

virtual void initialize() override

Initialize the algorithm given the input settings.

Private Functions

void initialize_population(int newNInds, int newNVars)

Initialize the LSRTDE algorithm parameters.

This function initializes the population, memory, and other parameters required for the optimization process.

Parameters:
  • newNInds – Number of individuals in the initial population.

  • newNVars – Number of variables in the optimization problem.

void Clean()

Clean up allocated memory.

This function deallocates any memory used by the class to prevent memory leaks.

void MainCycle()

Main optimization cycle of the algorithm.

This function performs the main loop of the optimization algorithm, iteratively evolving the population and updating memory and archives.

void FindNSaveBest(bool init, int ChosenOne)

Find and save the best individual.

This function identifies the best individual in the current population and saves its information.

Parameters:
  • init – Indicates if the best individual should be initialized.

  • ChosenOne – The index of the chosen individual to evaluate.

void UpdateMemoryCr()

Update memory with successful Cr and F values.

This function updates the memory arrays with recently successful crossover probabilities and differential weights.

double MeanWL(std::vector<double> Vector, std::vector<double> TempWeights)
void RemoveWorst(int NInds, int NewNInds)

Remove the worst individuals.

This function removes the worst individuals from the population to reach a new number of individuals.

Parameters:
  • NInds – Current number of individuals.

  • NewNInds – New target number of individuals.

void qSort2int(double *Mass, int *Mass2, int low, int high)

Perform quicksort on an array with a secondary integer array.

This function sorts the Mass array and rearranges the Mass2 array accordingly using the quicksort algorithm.

Parameters:
  • Mass – The primary array to sort.

  • Mass2 – The secondary array to rearrange according to Mass.

  • low – The starting index for sorting.

  • high – The ending index for sorting.

Private Members

int MemorySize
int MemoryIter
int SuccessFilled
int MemoryCurrentIndex
int NVars
int NIndsCurrent
int NIndsFront
int NIndsFrontMax
int newNIndsFront
int PopulSize
int func_num
int func_index
int TheChosenOne
int Generation
int PFIndex
double bestfit
double SuccessRate
double F
double Cr
std::vector<std::vector<double>> Popul
std::vector<std::vector<double>> PopulFront
std::vector<std::vector<double>> PopulTemp
std::vector<double> FitArr
std::vector<double> FitArrCopy
std::vector<double> FitArrFront
std::vector<double> Trial
std::vector<double> tempSuccessCr
std::vector<double> MemoryCr
std::vector<double> FitDelta
std::vector<double> Weights
int *Indices
int *Indices2
int LastFEcount = 0
int NFEval = 0
int MaxFEval = 0
int GNVars
double tempF[1]
double fopt
char buffer[500]
double globalbest
bool globalbestinit = false
bool TimeComplexity = true
class MaxevalExceedError : public std::exception
#include <exception.h>

Exception class for exceeding maximum evaluations.

Public Functions

inline explicit MaxevalExceedError(const std::string &msg)

Constructor for MaxevalExceedError.

Parameters:

msg – Error message.

inline const char *what() const noexcept override

Returns the error message.

Returns:

C-string containing the error message.

Private Members

std::string message
class Minimizer
#include <minimizer.h>

A generic form optimization algorithms.

Public Functions

inline Minimizer(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, std::string algo = "ARRDE", double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the decision variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization in the population-population based algorithms, or minion will pick teh best one in L-BFGS or NelderMead.

  • data – Additional data to pass to the objective function.

  • callback – A callback function to call after each iteration.

  • algo – Algorithm to use : “LSHADE”, “AGSK”, “DE”, “JADE”, “jSO”, “IMODE”, “NelderMead”, “LSRTDE”, “NLSHADE_RSP”, “NLSHADE_LBC”, “j2020”, “GWO_DE”, “PSO”, “SPSO2011”, “DMSPSO”, “LSHADE_cnEpSin”

  • tol – The relative tolerance for convergence.

  • maxevals – The maximum number of function evaluations.

  • seed – global seed

  • options – Option object, which specify further configurational settings for the algorithm.

inline Minimizer(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<double> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, std::string algo = "ARRDE", double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the decision variables.

  • x0 – The initial guess for the solution.

  • data – Additional data to pass to the objective function.

  • callback – A callback function to call after each iteration.

  • algo – Algorithm to use : “LSHADE”, “DE”, “JADE”, “jSO”, “DE”, “NelderMead”, “LSRTDE”, “NLSHADE_RSP”, “NLSHADE_LBC”, “j2020”, “GWO_DE”, “PSO”, “SPSO2011”, “DMSPSO”, “LSHADE_cnEpSin”

  • tol – The relative tolerance for convergence.

  • maxevals – The maximum number of function evaluations.

  • seed – global seed

  • options – Option object, which specify further configurational settings for the algorithm.

inline ~Minimizer()

destructor

inline MinionResult operator()()

function to perform the optimization.

Throws:

std::logic_error – if the function is not implemented in a derived class.

Returns:

A MinionResult object containing the result of the optimization.

inline MinionResult optimize()

function to perform the optimization.

Throws:

std::logic_error – if the function is not implemented in a derived class.

Returns:

A MinionResult object containing the result of the optimization.

Public Members

std::vector<MinionResult> history

Private Members

MinimizerBase *optimizer

Private Static Functions

static inline std::string normalizeAlgo(std::string algo)
class MinimizerBase
#include <minimizer_base.h>

A base class for optimization algorithms.

Subclassed by minion::ABC, minion::BIPOP_aCMAES, minion::CMAES, minion::Differential_Evolution, minion::Dual_Annealing, minion::GWO_DE, minion::LSRTDE, minion::L_BFGS, minion::L_BFGS_B, minion::NLSHADE_LBC, minion::NLSHADE_RSP, minion::NelderMead, minion::PSO, minion::RCMAES

Public Functions

inline MinimizerBase(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for MinimizerBase.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the decision variables.

  • x0 – The initial guesses for the solution.

  • data – Additional data to pass to the objective function.

  • callback – A callback function to call after each iteration.

  • tol – The relative tolerance for convergence.

  • maxevals – The maximum number of function evaluations.

  • seed – global seed

  • options – Option object, which specify further configurational settings for the algorithm.

inline MinimizerBase(MinionFunction func, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for MinimizerBase for unconstrained optimization.

Parameters:
  • func – The objective function to minimize.

  • x0 – The initial guess for the solution.

  • data – Additional data to pass to the objective function.

  • callback – A callback function to call after each iteration.

  • tol – The relative tolerance for convergence.

  • maxevals – The maximum number of function evaluations.

  • seed – global seed

  • options – Option object, which specify further configurational settings for the algorithm.

virtual ~MinimizerBase() = default

destructor

inline virtual MinionResult optimize()

Virtual function to perform the optimization.

Throws:

std::logic_error – if the function is not implemented in a derived class.

Returns:

A MinionResult object containing the result of the optimization.

inline virtual void initialize()

Pure virtual function to process algirithm settings.

Public Members

MinionFunction func
std::vector<std::pair<double, double>> bounds
std::vector<std::vector<double>> x0
double stoppingTol
size_t maxevals
MinionResult minionResult
std::vector<MinionResult> history
std::string boundStrategy
int seed
std::function<void(MinionResult*)> callback

Protected Functions

inline MinionResult getBestFromHistory()
inline std::vector<double> findBestPoint(const std::vector<std::vector<double>> &Xvec)

Protected Attributes

std::map<std::string, ConfigValue> optionMap
bool hasInitialized = false
void *data = nullptr
struct MinionResult
#include <minimizer_base.h>

A structure to store the result of an optimization process.

Public Functions

inline MinionResult()

Default constructor.

inline MinionResult(const std::vector<double> &x_, double fun_, size_t nit_, size_t nfev_, bool success_, const std::string &message_)

Parameterized constructor.

Parameters:
  • x_ – The solution vector.

  • fun_ – The objective function value at the solution.

  • nit_ – The number of iterations performed.

  • nfev_ – The number of function evaluations performed.

  • success_ – Whether the optimization was successful.

  • message_ – A message describing the result.

inline ~MinionResult()

Destructor.

inline MinionResult &operator=(const MinionResult &other)

Assignment operator.

Parameters:

other – The other MinionResult object to assign from.

Returns:

Reference to the assigned MinionResult object.

Public Members

std::vector<double> x
double fun
size_t nit
size_t nfev
bool success
std::string message
class NelderMead : public minion::MinimizerBase
#include <nelder_mead.h>

Implements the Nelder-Mead optimization algorithm.

This class derives from MinimizerBase and implements the Nelder-Mead method for function optimization over a bounded domain.

Public Functions

inline NelderMead(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for Differential_Evolution.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – Optional initial guesses for the solution. If omitted, a random point sampled from the bounds is used.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

virtual MinionResult optimize() override

Performs optimization using the Nelder-Mead method.

Returns:

MinionResult containing the optimized point, function value, and optimization statistics.

virtual void initialize() override

Initialize the algorithm given the input settings.

Private Functions

std::vector<std::vector<double>> build_simplex(const std::vector<double> &center) const

Private Members

std::vector<double> best
double fbest = std::numeric_limits<double>::max()
size_t bestIndex = 0
double simplex_scale = 0.05
double alpha = 1.0
double gamma = 2.0
double rho = 0.5
double sigma = 0.5
std::vector<double> xinit
class NLSHADE_LBC : public minion::MinimizerBase

Public Functions

inline NLSHADE_LBC(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())
inline ~NLSHADE_LBC()
inline virtual MinionResult optimize() override

Virtual function to perform the optimization.

Throws:

std::logic_error – if the function is not implemented in a derived class.

Returns:

A MinionResult object containing the result of the optimization.

virtual void initialize() override

Pure virtual function to process algirithm settings.

Private Functions

void initialize_population(int newNInds, int newNVars, int NewMemSize, double NewArchSizeParam)
void Clean()
void MainCycle()
void FindNSaveBest(bool init, int ChosenOne)
inline double GetValue(const int index, const int curNInds, const int j)
void CopyToArchive(double *RefusedParent, double RefusedFitness)
void SaveSuccessCrF(double Cr, double F, double FitD)
void UpdateMemoryCrF()
double MeanWL_general(double *Vector, double *TempWeights, int Size, double g_p, double g_m)
void RemoveWorst(int curNInds, int NewNInds)
std::vector<std::vector<double>> convertToVector(double **popul, int rows, int cols)
void qSort2int(double *Mass, int *Mass2, int low, int high)
void qSort1(double *Mass, int low, int high)
bool CheckGenerated(const int num, int *Rands, const int Prohib)
void GenerateNextRandUnif(const int num, const int Range, int *Rands, const int Prohib)
void GenerateNextRandUnifOnlyArch(const int num, const int Range, const int Range2, int *Rands, const int Prohib)
void FindLimits(double *Ind, double *Parent, int CurNVars, double CurLeft, double CurRight)

Private Members

bool FitNotCalculated = true
int Int_ArchiveSizeParam = 0
int MemorySize = 0
int MemoryIter = 0
int SuccessFilled = 0
int MemoryCurrentIndex = 0
int NVars = 0
int NInds = 0
int NIndsMax = 0
int NIndsMin = 4
int besti = 0
int Generation = 0
int ArchiveSize = 0
int CurrentArchiveSize = 0
double MWLp1 = 3.5
double MWLp2 = 1.0
double MWLm = 1.5
double LBC_fin = 1.5
double F = 0.5
double Cr = 0.9
double bestfit = 0.0
double ArchiveSizeParam = 1.0
double Right = 100.0
double Left = -100.0
int *Rands = nullptr
int *Indexes = nullptr
int *BackIndexes = nullptr
double *Weights = nullptr
double *Donor = nullptr
double *Trial = nullptr
double *FitMass = nullptr
double *FitMassTemp = nullptr
double *FitMassCopy = nullptr
double *BestInd = nullptr
double *tempSuccessCr = nullptr
double *tempSuccessF = nullptr
double *FGenerated = nullptr
double *CrGenerated = nullptr
double *MemoryCr = nullptr
double *MemoryF = nullptr
double *FitDelta = nullptr
double *FitMassArch = nullptr
double **Popul = nullptr
double **PopulTemp = nullptr
double **Archive = nullptr
bool globalbestinit = false
double globalbest = 0.0
std::vector<double> FitTemp3
int NFEval = 0
int MaxFEval = 0
bool buffersAllocated = false
class NLSHADE_RSP : public minion::MinimizerBase
#include <nlshadersp.h>

A class implementing the NLSHADE_RSP optimization algorithm.

The NLSHADE_RSP class inherits from MinimizerBase and provides functionality to perform optimization using a modified version of the L-SHADE algorithm with an archive and a memory mechanism to store previous successes.

Public Functions

inline NLSHADE_RSP(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Constructor for Differential_Evolution.

Parameters:
  • func – The objective function to minimize.

  • bounds – The bounds for the variables.

  • x0 – The initial guesses for the solution. Note that Minion assumes multiple initial guesses, thus, x0 is an std::vector<std::vector<double>> object. These guesses will be used for population initialization.

  • data – Additional data for the objective function.

  • callback – Callback function for intermediate results.

  • tol – The tolerance for stopping criteria.

  • maxevals – The maximum number of evaluations.

  • seed – The seed for random number generation.

  • options – Option map that specifies further configurational settings for the algorithm.

inline ~NLSHADE_RSP()

Destructor for the NLSHADE_RSP class.

This destructor cleans up any allocated memory used by the class.

inline virtual MinionResult optimize() override

Optimizes the objective function.

Returns:

The result of the optimization.

virtual void initialize() override

Initialize the algorithm given the input settings.

Private Functions

void initialize_population(int newNInds, int newNVars, int NewMemSize, double NewArchSizeParam)

Initialize the NLSHADE_RSP algorithm parameters.

This function initializes the population, memory, and other parameters required for the optimization process.

Parameters:
  • newNInds – Number of individuals in the initial population.

  • newNVars – Number of variables in the optimization problem.

  • NewMemSize – Size of the memory for storing previous successes.

  • NewArchSizeParam – Parameter for determining the archive size.

void Clean()

Clean up allocated memory.

This function deallocates any memory used by the class to prevent memory leaks.

void MainCycle()

Main optimization cycle of the algorithm.

This function performs the main loop of the optimization algorithm, iteratively evolving the population and updating memory and archives.

void FindNSaveBest(bool init, int ChosenOne)

Find and save the best individual.

This function identifies the best individual in the current population and saves its information.

Parameters:
  • init – Indicates if the best individual should be initialized.

  • ChosenOne – The index of the chosen individual to evaluate.

inline double GetValue(const int index, const int NInds, const int j)

Get the value of an individual at a specific index.

This inline function retrieves the value of an individual in the population.

Parameters:
  • index – Index of the individual.

  • NInds – Number of individuals.

  • j – The variable index to retrieve.

Returns:

The value at the specified index.

void CopyToArchive(double *RefusedParent, double RefusedFitness)

Copy an individual to the archive.

This function copies a refused parent individual and its fitness to the archive.

Parameters:
  • RefusedParent – Pointer to the refused parent’s vector.

  • RefusedFitness – Fitness value of the refused parent.

void SaveSuccessCrF(double Cr, double F, double FitD)

Save successful crossover probabilities and differential weights.

This function stores the successful Cr and F values along with the fitness difference achieved.

Parameters:
  • Cr – Crossover probability.

  • F – Differential weight.

  • FitD – Fitness difference.

void UpdateMemoryCrF()

Update memory with successful Cr and F values.

This function updates the memory arrays with recently successful crossover probabilities and differential weights.

double MeanWL_general(double *Vector, double *TempWeights, int Size, double g_p, double g_m)
void RemoveWorst(int NInds, int NewNInds)

Remove the worst individuals.

This function removes the worst individuals from the population to reach a new number of individuals.

Parameters:
  • NInds – Current number of individuals.

  • NewNInds – New target number of individuals.

std::vector<std::vector<double>> convertToVector(double **popul, int rows, int cols)

Convert a 2D array to a vector of vectors.

This function converts a double pointer array to a std::vector<std::vector<double>>.

Parameters:
  • popul – The 2D array of doubles.

  • rows – Number of rows in the array.

  • cols – Number of columns in the array.

Returns:

A vector of vectors representing the same data.

void qSort2int(double *Mass, int *Mass2, int low, int high)

Perform quicksort on an array with a secondary integer array.

This function sorts the Mass array and rearranges the Mass2 array accordingly using the quicksort algorithm.

Parameters:
  • Mass – The primary array to sort.

  • Mass2 – The secondary array to rearrange according to Mass.

  • low – The starting index for sorting.

  • high – The ending index for sorting.

void qSort1(double *Mass, int low, int high)

Perform quicksort on an array.

This function sorts the Mass array using the quicksort algorithm.

Parameters:
  • Mass – The array to sort.

  • low – The starting index for sorting.

  • high – The ending index for sorting.

bool CheckGenerated(const int num, int *Rands, const int Prohib)

Check if a number is already generated.

This function checks if a given number has been generated, considering the prohibited index.

Parameters:
  • num – The number to check.

  • Rands – The array of generated random numbers.

  • Prohib – The prohibited index.

Returns:

True if the number is generated, false otherwise.

void GenerateNextRandUnif(const int num, const int Range, int *Rands, const int Prohib)

Generate the next random number uniformly.

This function generates the next random number uniformly within a given range, considering the prohibited index.

Parameters:
  • num – The number of random numbers to generate.

  • Range – The range for random number generation.

  • Rands – The array to store generated random numbers.

  • Prohib – The prohibited index.

void GenerateNextRandUnifOnlyArch(const int num, const int Range, const int Range2, int *Rands, const int Prohib)

Generate the next random number uniformly within archive ranges.

This function generates the next random number uniformly within two given ranges, considering the prohibited index.

Parameters:
  • num – The number of random numbers to generate.

  • Range – The first range for random number generation.

  • Range2 – The second range for random number generation.

  • Rands – The array to store generated random numbers.

  • Prohib – The prohibited index.

void FindLimits(double *Ind, double *Parent, int CurNVars, std::vector<std::pair<double, double>> currBounds)

Find and set limits for an individual.

This function finds and sets the limits for an individual’s variables within the given bounds.

Parameters:
  • Ind – The individual’s vector.

  • Parent – The parent’s vector.

  • CurNVars – Current number of variables.

  • currBounds – The vector of pairs representing variable bounds.

Private Members

bool FitNotCalculated
int Int_ArchiveSizeParam
int MemorySize
int MemoryIter
int SuccessFilled
int MemoryCurrentIndex
int NVars
int NInds
int NIndsMax
int NIndsMin
int besti
int Generation
int ArchiveSize
int CurrentArchiveSize
double F
double Cr
double bestfit
double ArchiveSizeParam
int *Rands
int *Indexes
int *BackIndexes
double *Weights
double *Donor
double *Trial
double *FitMass
double *FitMassTemp
double *FitMassCopy
double *BestInd
double *tempSuccessCr
double *tempSuccessF
double *FGenerated
double *CrGenerated
double *MemoryCr
double *MemoryF
double *FitDelta
double *ArchUsages
double **Popul
double **PopulTemp
double **Archive
bool globalbestinit = false
double globalbest
std::vector<double> FitTemp3
int NFEval = 0
int MaxFEval
class Options
#include <minimizer_base.h>

A flexible configuration class for managing key-value pairs with varying data types.

The Options class allows storing, retrieving, and managing settings using key-value pairs. Values can be of any type, making it suitable for dynamic configuration needs.

Public Functions

inline Options()

Default constructor for the Options class.

inline Options(std::map<std::string, ConfigValue> inputSettings)

Parameterized constructor to initialize settings with a predefined map.

Parameters:

inputSettings – A map of key-value pairs to initialize the configuration.

inline void print() const

Prints the configuration settings.

inline ~Options()

Destructor for the Options class.

template<typename T>
inline void set(const std::string &key, const T &value)

Set a value for a given key in the settings.

This method allows adding or updating a key-value pair in the settings.

Template Parameters:

T – The type of the value being set.

Parameters:
  • key – The key to associate with the value.

  • value – The value to store, of type T.

template<typename T>
inline T get(const std::string &key) const

Retrieve a value for a given key from the settings.

This method retrieves the value associated with the specified key. If the key does not exist or the type does not match, an exception is thrown.

Template Parameters:

T – The expected type of the value.

Parameters:

key – The key whose associated value is to be retrieved.

Throws:

std::runtime_error – If the key is not found or the type does not match.

Returns:

The value associated with the key, cast to the specified type.

template<typename T>
inline T get(const std::string &key, T defaultValue) const

Retrieve a value for a given key from the settings.

This method retrieves the value associated with the specified key. If the key does not exist or the type does not match, an exception is thrown.

Template Parameters:

T – The expected type of the value.

Parameters:
  • key – The key whose associated value is to be retrieved.

  • defaultValue – default value when there is a problem when accessing the key value.

Throws:

std::runtime_error – If the key is not found or the type does not match.

Returns:

The value associated with the key, cast to the specified type.

Private Members

std::map<std::string, ConfigValue> settings
struct Parameter

Public Functions

void reserve(size_t n_offsprings_reserve_, size_t n_parents_reserve_, size_t n_params_)
void reinit(size_t n_offsprings_, size_t n_parents_, size_t n_params_, const Eigen::VectorXd &x_mean_, double sigma_)

Public Members

size_t n_offsprings = 0
size_t n_offsprings_reserve = 0
size_t n_parents = 0
size_t n_parents_reserve = 0
size_t n_params = 0
size_t i_iteration = 0
size_t i_func_eval = 0
double n_mu_eff = 0.0
Eigen::MatrixXd x_offsprings
Eigen::MatrixXd x_parents_ranked
Eigen::MatrixXd z_offsprings
Eigen::MatrixXd y_offsprings
Eigen::MatrixXd y_offsprings_ranked
Eigen::VectorXd f_offsprings
Eigen::VectorXd w
Eigen::VectorXd w_var
Eigen::VectorXd y_mean
Eigen::VectorXd x_mean
Eigen::VectorXd x_mean_old
Eigen::VectorXd p_c
Eigen::VectorXd p_s
Eigen::VectorXd eigvals_C
Eigen::MatrixXd C
Eigen::MatrixXd C_invsqrt
Eigen::MatrixXd B
Eigen::MatrixXd D
std::vector<size_t> keys_offsprings
double c_c = 0.0
double c_s = 0.0
double c_1 = 0.0
double c_mu = 0.0
double d_s = 0.0
double chi = 0.0
double p_c_fact = 0.0
double p_s_fact = 0.0
double sigma = 0.0
bool h_sig = false
struct Parameter

Public Functions

void reserve(size_t n_offsprings_reserve_, size_t n_parents_reserve_, size_t n_params_)
void reinit(size_t n_offsprings_, size_t n_parents_, size_t n_params_, const Eigen::VectorXd &x_mean_, double sigma_, size_t nevals, double best_fitness)
void resize(size_t n_offsprings_, size_t n_parents_, size_t n_params_)

Public Members

size_t n_offsprings = 0
size_t n_offsprings_reserve = 0
size_t n_parents = 0
size_t n_parents_reserve = 0
size_t n_params = 0
size_t i_iteration = 0
size_t i_func_eval = 0
double n_mu_eff = 0.0
Eigen::MatrixXd x_offsprings
Eigen::MatrixXd x_parents_ranked
Eigen::MatrixXd z_offsprings
Eigen::MatrixXd y_offsprings
Eigen::MatrixXd y_offsprings_ranked
Eigen::VectorXd f_offsprings
Eigen::VectorXd w
Eigen::VectorXd w_var
Eigen::VectorXd y_mean
Eigen::VectorXd x_mean
Eigen::VectorXd x_mean_old
Eigen::VectorXd p_c
Eigen::VectorXd p_s
Eigen::VectorXd eigvals_C
Eigen::MatrixXd C
Eigen::MatrixXd C_invsqrt
Eigen::MatrixXd B
Eigen::MatrixXd D
std::vector<size_t> keys_offsprings
double c_c = 0.0
double c_s = 0.0
double c_1 = 0.0
double c_mu = 0.0
double d_s = 0.0
double chi = 0.0
double p_c_fact = 0.0
double p_s_fact = 0.0
double sigma = 0.0
bool h_sig = false
class PSO : public minion::MinimizerBase
#include <pso.h>

Basic particle swarm optimizer that serves as the foundation for other PSO variants.

Subclassed by minion::DMSPSO, minion::SPSO2011

Public Functions

inline PSO(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Construct a PSO minimizer with the standard global-best topology.

Parameters:
  • func – Objective function to minimize.

  • bounds – Search-space bounds for each variable.

  • x0 – Optional initial particle locations.

  • data – User data forwarded to the objective.

  • callback – Per-iteration callback invoked with the current best.

  • tol – Relative tolerance used in the diversity-based stop test.

  • maxevals – Maximum number of objective evaluations.

  • seed – RNG seed (negative -> random seed).

  • options – Configuration map (inertia weight, coefficients, etc.).

virtual void initialize() override

Pure virtual function to process algirithm settings.

virtual MinionResult optimize() override

Virtual function to perform the optimization.

Throws:

std::logic_error – if the function is not implemented in a derived class.

Returns:

A MinionResult object containing the result of the optimization.

Public Members

std::vector<std::vector<double>> population
std::vector<std::vector<double>> velocities
std::vector<std::vector<double>> personalBestPositions
std::vector<double> personalBestFitness
std::vector<double> fitness
std::vector<double> best
double best_fitness = std::numeric_limits<double>::infinity()
size_t populationSize = 0
size_t Nevals = 0
double inertiaWeight = 0.7
double cognitiveCoeff = 1.5
double socialCoeff = 1.5
double velocityClamp = 0.2
bool useLatin = true
bool support_tol = true
std::vector<double> diversity
std::vector<double> spatialDiversity

Protected Functions

virtual void init()
virtual void updateVelocitiesAndPositions()
virtual void recordMetrics()
virtual bool checkStopping() const
void configureFromOptions(const Options &options)
class RCMAES : public minion::MinimizerBase
#include <rcmaes.h>

Active CMA-ES without restarts.

Public Functions

RCMAES(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())
virtual void initialize() override

Pure virtual function to process algirithm settings.

virtual MinionResult optimize() override

Virtual function to perform the optimization.

Throws:

std::logic_error – if the function is not implemented in a derived class.

Returns:

A MinionResult object containing the result of the optimization.

Private Functions

std::vector<double> applyBounds(const std::vector<double> &candidate) const
void sampleOffsprings()
size_t evaluatePopulation()
void rankAndSort()
void updateBest()
void assignNewMean()
void updateEvolutionPaths()
void updateWeights()
void updateCovarianceMatrix()
void updateStepsize()
void updateEigenDecomposition()
void checkStoppingCriteria()
void recordHistory(double relRange)
std::vector<double> eigenToStd(const Eigen::VectorXd &vec) const
std::vector<double> denormalizePoint(const std::vector<double> &candidate) const
ExclusionBox buildExclusionBox(const std::vector<double> &best) const
bool isExcludedPoint(const std::vector<double> &candidate) const

Private Members

Parameter era
size_t dimension = 0
bool useBounds = false
std::string boundStrategy = "reflect-random"
size_t lambda = 0
size_t lambda_min = 0
size_t mu = 0
double mu_ratio = 0.5
double sigma0 = 0.0
Eigen::VectorXd initialMean
std::vector<std::pair<double, double>> original_bounds
std::vector<double> best
double best_fitness = std::numeric_limits<double>::infinity()
size_t Nevals = 0
size_t generation = 0
std::vector<double> diversity
std::vector<double> currentFitness
bool support_tol = true
bool should_stop = false
std::vector<std::vector<double>> restart_bests
std::vector<ExclusionBox> exclusion_boxes
size_t exclusion_max_attempts = 50
class SPSO2011 : public minion::PSO
#include <spso2011.h>

Implementation of the stochastic PSO 2011 variant built on top of the base PSO.

Public Functions

inline SPSO2011(MinionFunction func, const std::vector<std::pair<double, double>> &bounds, const std::vector<std::vector<double>> &x0 = {}, void *data = nullptr, std::function<void(MinionResult*)> callback = nullptr, double tol = 0.0001, size_t maxevals = 100000, int seed = -1, std::map<std::string, ConfigValue> options = std::map<std::string, ConfigValue>())

Construct the SPSO2011 variant.

Parameters:
  • func – Objective function to minimize.

  • bounds – Search-space bounds.

  • x0 – Optional initial swarm positions.

  • data – User payload for the objective.

  • callback – Progress callback invoked with the best-so-far state.

  • tol – Diversity tolerance that governs early stopping.

  • maxevals – Maximum number of objective evaluations.

  • seed – RNG seed (negative -> random seed).

  • options – Configuration map (phi values, neighbourhood size, etc.).

virtual void initialize() override

Pure virtual function to process algirithm settings.

virtual MinionResult optimize() override

Virtual function to perform the optimization.

Throws:

std::logic_error – if the function is not implemented in a derived class.

Returns:

A MinionResult object containing the result of the optimization.

Protected Functions

virtual void init() override
virtual void updateVelocitiesAndPositions() override

Private Functions

void randomizeInformants()
std::vector<double> samplePointInSphere(const std::vector<double> &center, double radius) const

Private Members

double c1 = 0.5 + std::log(2.0)
double c2 = 0.5 + std::log(2.0)
double inertia = 1.0 / (2.0 * std::log(2.0))
size_t informantDegree = 3
bool normalizeSpace = false
std::vector<std::vector<size_t>> informants
bool topologyDirty = true
size_t stagnationCounter = 0
double lastBestFitness = std::numeric_limits<double>::infinity()
std::vector<std::vector<double>> normPositions
std::vector<std::vector<double>> normPersonalBest
namespace minion

Typedefs

using ConfigValue = std::variant<bool, int, double, std::string>

Alias for the variant type to hold different types of configuration values.

typedef Eigen::Matrix<double, Eigen::Dynamic, 1> Vector
typedef std::function<std::vector<double>(const std::vector<std::vector<double>>&, void*)> MinionFunction

A function type that takes a vector of vectors of doubles and a void pointer and returns a vector of doubles.

using CECTestFunc = void (*)(double*, double*, int, int, int)

Functions

std::vector<double> sphere(const std::vector<std::vector<double>> &X)
std::vector<double> rosenbrock(const std::vector<std::vector<double>> &X)
std::vector<double> rastrigin(const std::vector<std::vector<double>> &X)
std::vector<double> griewank(const std::vector<std::vector<double>> &X)
std::vector<double> ackley(const std::vector<std::vector<double>> &X)
std::vector<double> zakharov(const std::vector<std::vector<double>> &X)
std::vector<double> michalewicz(const std::vector<std::vector<double>> &X)
std::vector<double> levy(const std::vector<std::vector<double>> &X)
std::vector<double> dixon_price(const std::vector<std::vector<double>> &X)
std::vector<double> bent_cigar(const std::vector<std::vector<double>> &X)
std::vector<double> discus(const std::vector<std::vector<double>> &X)
std::vector<double> weierstrass(const std::vector<std::vector<double>> &X)
std::vector<double> happy_cat(const std::vector<std::vector<double>> &X)
std::vector<double> hgbat(const std::vector<std::vector<double>> &X)
std::vector<double> hcf(const std::vector<std::vector<double>> &X)
std::vector<double> grie_rosen(const std::vector<std::vector<double>> &X)
std::vector<double> easom(const std::vector<std::vector<double>> &X)
std::vector<double> drop_wave(const std::vector<std::vector<double>> &X)
void set_global_seed(unsigned int seed)

Set the global seed for the random number generator.

Parameters:

seed – The seed to set.

std::mt19937 &get_rng()

Get the global random number generator.

Returns:

A reference to the global random number generator.

double rand_gen(double low = 0.0, double high = 1.0)

Generate a random double in the range [low, high).

Parameters:
  • low – The lower bound of the range.

  • high – The upper bound of the range.

Returns:

A random double in the specified range.

std::vector<double> rand_gen(double low, double high, size_t N)

Generate random numbers within a specified range.

Generates Nsample random numbers uniformly distributed within the range [low, high].

Parameters:
  • low – Lower bound of the range (inclusive).

  • high – Upper bound of the range (inclusive).

  • N – Number of random samples to generate.

Returns:

Vector containing Nsample random numbers within the specified range.

std::vector<size_t> random_choice(size_t Ninput, size_t N, bool replace = false)

Create a vector of length N with elements selected randomly from 0 to Ninput - 1.

Parameters:
  • Ninput – The length of the initial vector (0 to Ninput - 1).

  • N – The number of elements to select.

  • replace – If true, selection is done with replacement.

Returns:

A vector of length N with randomly selected elements from 0 to Ninput - 1.

size_t rand_int(size_t n)

Generate a random integer in the range [0, n-1].

Parameters:

n – The upper bound of the range.

Returns:

A random integer in the specified range.

double rand_norm(double mu, double s)

Sample from a normal distribution.

Generates a random number from a normal distribution with specified mean and standard deviation using the global random number generator.

Parameters:
  • mu – Mean of the normal distribution.

  • s – Variance (or standard deviation) of the normal distribution.

Returns:

Random sample from the normal distribution.

double rand_cauchy(double location, double scale)

Generate a random number from a Cauchy distribution.

This function generates a random number using a Cauchy distribution with a specified location (median) and scale (half-width at half-maximum).

Parameters:
  • location – The location parameter of the Cauchy distribution.

  • scale – The scale parameter of the Cauchy distribution.

Returns:

A random number from the Cauchy distribution.

std::vector<size_t> argsort(const std::vector<double> &v, bool ascending = true)

Get the indices that would sort a vector.

Parameters:
  • v – The input vector.

  • ascending – Whether to sort in ascending order (default is true).

Returns:

A vector of indices that would sort the input vector.

std::vector<std::vector<double>> latin_hypercube_sampling(const std::vector<std::pair<double, double>> &bounds, size_t population_size)

Perform Latin Hypercube Sampling.

Parameters:
  • bounds – The bounds for each dimension.

  • population_size – The number of samples to generate.

Returns:

A vector of vectors containing the samples.

std::vector<std::vector<double>> random_sampling(const std::vector<std::pair<double, double>> &bounds, size_t population_size)

Perform random Sampling.

Parameters:
  • bounds – The bounds for each dimension.

  • population_size – The number of samples to generate.

Returns:

A vector of vectors containing the samples.

std::tuple<double, double> getMeanStd(const std::vector<double> &arr, const std::vector<double> &weight)

Calculate the mean and standard deviation of a vector.

Parameters:
  • arr – The input vector.

  • weight – The weights for each element.

Returns:

A tuple containing the mean and standard deviation.

double calcMean(const std::vector<double> &vec)

Calculate the mean of a vector.

Parameters:

vec – The input vector.

Returns:

The mean of the vector.

double calcStdDev(const std::vector<double> &vec)

Calculate the standard deviation of a vector.

Parameters:

vec – The input vector.

Returns:

The standard deviation of the vector.

void enforce_bounds(std::vector<std::vector<double>> &new_candidates, const std::vector<std::pair<double, double>> &bounds, const std::string &strategy)

Enforce bounds on a set of candidate solutions.

Parameters:
  • new_candidates – The candidate solutions to enforce bounds on.

  • bounds – The bounds for each dimension.

  • strategy – The strategy for enforcing the bounds.

void enforce_bounds(std::vector<double> &new_candidate, const std::vector<std::pair<double, double>> &bounds, const std::string &strategy)

Enforce bounds on a a candidate solution.

Parameters:
  • new_candidate – The candidate solution to enforce bounds on.

  • bounds – The bounds for each dimension.

  • strategy – The strategy for enforcing the bounds.

void printVectorOfVectors(const std::vector<std::vector<double>> &vec)

Print a vector of vectors to standard error.

Parameters:

vec – The input vector of vectors.

std::vector<double> normalize_vector(const std::vector<double> &input)

Normalize the elements of a vector.

Parameters:

input – The input vector.

Returns:

A vector with normalized elements.

double euclideanDistance(const std::vector<double> &a, const std::vector<double> &b)

Computes the Euclidean distance between two points represented by vectors.

Parameters:
  • a – The first point as a vector of doubles.

  • b – The second point as a vector of doubles.

Returns:

The Euclidean distance between points a and b.

std::vector<double> calculateCenter(const std::vector<std::vector<double>> &particles)

Calculates the center of a group of particles.

Parameters:

particles – A vector of vectors where each inner vector represents the position of a particle.

Returns:

A vector representing the center of the particles.

double averageEuclideanDistance(const std::vector<std::vector<double>> &particles)

Calculates the average Euclidean distance of each particle to the center of all particles.

Parameters:

particles – A vector of vectors where each inner vector represents the position of a particle.

Returns:

The average Euclidean distance from each particle to the center.

template<typename T>
std::vector<T> random_choice(const std::vector<T> &v, size_t n, bool replace = false)

Select a random subset of elements from a vector.

Template Parameters:

T – The type of the elements in the vector.

Parameters:
  • v – The input vector.

  • n – The number of elements to select.

  • replace – If true, selection is done with replacement.

Returns:

A vector containing n randomly selected elements from the input vector.

template<typename T>
std::vector<T> random_choice(const std::vector<T> &v, size_t n, const std::vector<double> &probability)
template<typename T>
T findMin(const std::vector<T> &vec)

Template function to find the minimum value in a vector.

This function takes a vector of any numeric type and returns the minimum value in the vector. If the vector is empty, it throws a std::runtime_error.

Template Parameters:

T – The type of the elements in the vector.

Parameters:

vec – The vector containing the elements.

Throws:

std::runtime_error – If the vector is empty.

Returns:

The minimum value in the vector.

template<typename T>
T findMax(const std::vector<T> &vec)

Template function to find the maximum value in a vector.

This function takes a vector of any numeric type and returns the maximum value in the vector. If the vector is empty, it throws a std::runtime_error.

Template Parameters:

T – The type of the elements in the vector.

Parameters:

vec – The vector containing the elements.

Throws:

std::runtime_error – If the vector is empty.

Returns:

The maximum value in the vector.

template<typename T>
std::size_t findArgMin(const std::vector<T> &vec)

Template function to find the index of the minimum value in a vector.

This function takes a vector of any type and returns the index of the minimum value in the vector. If the vector is empty, it throws a std::runtime_error.

Template Parameters:

T – The type of the elements in the vector.

Parameters:

vec – The vector containing the elements.

Throws:

std::runtime_error – If the vector is empty.

Returns:

The index of the minimum value in the vector.

template<typename T>
std::size_t findArgMax(const std::vector<T> &vec)

Template function to find the index of the maximum value in a vector.

This function takes a vector of any type and returns the index of the maximum value in the vector. If the vector is empty, it throws a std::runtime_error.

Template Parameters:

T – The type of the elements in the vector.

Parameters:

vec – The vector containing the elements.

Throws:

std::runtime_error – If the vector is empty.

Returns:

The index of the maximum value in the vector.

template<typename T>
T clamp(T value, T low, T high)

Clamp a value between a low and high range.

Template Parameters:

T – The type of the value.

Parameters:
  • value – The value to clamp.

  • low – The lower bound.

  • high – The upper bound.

Returns:

The clamped value.

template<typename T>
void printVector(const std::vector<T> &vec)

Print the elements of a vector to standard error.

Template Parameters:

T – The type of the elements in the vector.

Parameters:

vec – The input vector.

template<typename T>
bool contains(const std::vector<T> &vec, const T &element)

Checks if an element is present in a vector.

This function searches for the specified element within a vector and returns true if the element is found, otherwise false.

Template Parameters:

T – The type of elements stored in the vector.

Parameters:
  • vec – A constant reference to the vector to be searched.

  • element – A constant reference to the element to search for.

Returns:

true if the element is found in the vector, otherwise false.

std::string getLibraryPath()
std::string getLibraryDirectory()
std::string getResourcePath()

Variables

thread_local unsigned int global_seed = std::random_device{}()
thread_local double *OShift
thread_local double *M
thread_local double *y
thread_local double *z
thread_local double *x_bound
thread_local int ini_flag = 0
thread_local int n_flag
thread_local int func_flag
thread_local int *SS
const std::string dirPath = getResourcePath()
namespace CEC2011

Functions

void evaluate(double *x, double *f, int nx, int mx, int func_num)

Evaluate CEC2011 test functions.

Parameters:
  • x – Flattened decision vectors (mx consecutive blocks of nx values).

  • f – Output buffer receiving mx objective values.

  • nx – Decision vector dimension.

  • mx – Number of vectors to evaluate.

  • func_num – Problem number (1-20).

namespace CEC2014

Functions

void cec14_test_func(double *x, double *f, int nx, int mx, int func_num)

All function below are unmodified from the original source : https://github.com/P-N-Suganthan/CEC2014

void sphere_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void ellips_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void bent_cigar_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void discus_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void dif_powers_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void rosenbrock_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void schaffer_F7_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void ackley_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void weierstrass_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void griewank_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void step_rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void schwefel_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void katsuura_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void bi_rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void grie_rosen_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void escaffer6_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void happycat_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void hgbat_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void hf01(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf02(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf03(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf04(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf05(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf06(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void cf01(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf02(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf03(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf04(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf05(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf06(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf07(double *x, double *f, int nx, double *Os, double *Mr, int *SS, int r_flag)
void cf08(double *x, double *f, int nx, double *Os, double *Mr, int *SS, int r_flag)
void shiftfunc(double *x, double *xshift, int nx, double *Os)
void rotatefunc(double *x, double *xrot, int nx, double *Mr)
void sr_func(double *x, double *sr_x, int nx, double *Os, double *Mr, double sh_rate, int s_flag, int r_flag)
void asyfunc(double *x, double *xasy, int nx, double beta)
void oszfunc(double *x, double *xosz, int nx)
void cf_cal(double *x, double *f, int nx, double *Os, double *delta, double *bias, double *fit, int cf_num)
namespace CEC2017

Functions

void cec17_test_func(double *x, double *f, int nx, int mx, int func_num)

All function below are unmodified from the original source : https://github.com/P-N-Suganthan/CEC2017-BoundContrained

void sphere_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void ellips_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void sum_diff_pow_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void zakharov_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void levy_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void dixon_price_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void bent_cigar_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void discus_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void dif_powers_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void rosenbrock_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void schaffer_F7_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void ackley_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void weierstrass_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void griewank_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void step_rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void schwefel_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void katsuura_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void bi_rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void grie_rosen_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void escaffer6_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void happycat_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void hgbat_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void hf01(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf02(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf03(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf04(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf05(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf06(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf07(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf08(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf09(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf10(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void cf01(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf02(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf03(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf04(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf05(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf06(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf07(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf08(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf09(double *x, double *f, int nx, double *Os, double *Mr, int *SS, int r_flag)
void cf10(double *x, double *f, int nx, double *Os, double *Mr, int *SS, int r_flag)
void shiftfunc(double *x, double *xshift, int nx, double *Os)
void rotatefunc(double *x, double *xrot, int nx, double *Mr)
void sr_func(double *x, double *sr_x, int nx, double *Os, double *Mr, double sh_rate, int s_flag, int r_flag)
void asyfunc(double *x, double *xasy, int nx, double beta)
void oszfunc(double *x, double *xosz, int nx)
void cf_cal(double *x, double *f, int nx, double *Os, double *delta, double *bias, double *fit, int cf_num)
namespace CEC2019

Functions

void cec19_test_func(double *x, double *f, int nx, int mx, int func_num)
void schaffer_F7_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void griewank_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void ackley_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void weierstrass_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void step_rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void schwefel_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void escaffer6_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void happycat_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void shiftfunc(double *x, double *xshift, int nx, double *Os)
void rotatefunc(double *x, double *xrot, int nx, double *Mr)
void sr_func(double *x, double *sr_x, int nx, double *Os, double *Mr, double sh_rate, int s_flag, int r_flag)
void asyfunc(double *x, double *xasy, int nx, double beta)
void oszfunc(double *x, double *xosz, int nx)
void Lennard_Jones(double *x, int D, double *f)

All function below are unmodified from the original source : https://github.com/P-N-Suganthan/CEC2019

void Hilbert(double *x, int D, double *f)
void Chebyshev(double *x, int D, double *f)
namespace CEC2020

Functions

void cec20_test_func(double *x, double *f, int nx, int mx, int func_num0)

All function below are unmodified from the original source : https://github.com/7zaa/IEEE-Congress-on-Evolutionary-Computation-Benchmark-functions-suite

void sphere_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void ellips_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void sum_diff_pow_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void zakharov_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void levy_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void dixon_price_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void bent_cigar_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void discus_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void dif_powers_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void rosenbrock_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void schaffer_F7_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void ackley_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void weierstrass_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void griewank_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void step_rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void schwefel_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void katsuura_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void bi_rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void grie_rosen_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void escaffer6_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void happycat_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void hgbat_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void hf01(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf02(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf03(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf04(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf05(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf06(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf07(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf08(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf09(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf10(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void cf01(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf02(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf03(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf04(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf05(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf06(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf07(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf08(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf09(double *x, double *f, int nx, double *Os, double *Mr, int *SS, int r_flag)
void cf10(double *x, double *f, int nx, double *Os, double *Mr, int *SS, int r_flag)
void shiftfunc(double *x, double *xshift, int nx, double *Os)
void rotatefunc(double *x, double *xrot, int nx, double *Mr)
void sr_func(double *x, double *sr_x, int nx, double *Os, double *Mr, double sh_rate, int s_flag, int r_flag)
void asyfunc(double *x, double *xasy, int nx, double beta)
void oszfunc(double *x, double *xosz, int nx)
void cf_cal(double *x, double *f, int nx, double *Os, double *delta, double *bias, double *fit, int cf_num)
namespace CEC2022

Functions

void cec22_test_func(double *x, double *f, int nx, int mx, int func_num)

All function below are unmodified from the original source : https://github.com/P-N-Suganthan/2022-SO-BO

void ellips_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void bent_cigar_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void discus_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void rosenbrock_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void ackley_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void griewank_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void schwefel_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void grie_rosen_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void escaffer6_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void happycat_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void hgbat_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void schaffer_F7_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void step_rastrigin_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void levy_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void zakharov_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void katsuura_func(double *x, double *f, int nx, double *Os, double *Mr, int s_flag, int r_flag)
void hf02(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf10(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void hf06(double *x, double *f, int nx, double *Os, double *Mr, int *S, int s_flag, int r_flag)
void cf01(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf02(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf06(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void cf07(double *x, double *f, int nx, double *Os, double *Mr, int r_flag)
void shiftfunc(double *x, double *xshift, int nx, double *Os)
void rotatefunc(double *x, double *xrot, int nx, double *Mr)
void sr_func(double *x, double *sr_x, int nx, double *Os, double *Mr, double sh_rate, int s_flag, int r_flag)
void asyfunc(double *x, double *xasy, int nx, double beta)
void oszfunc(double *x, double *xosz, int nx)
void cf_cal(double *x, double *f, int nx, double *Os, double *delta, double *bias, double *fit, int cf_num)
namespace mgadsm
namespace std
file cec.cpp
#include “cec.h
#include <filesystem>
#include <string>
#include <dlfcn.h>
file cec.h
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <exception>

Defines

INF
EPS
E
PI
file cec2011.cpp
#include “cec2011.h
#include <algorithm>
#include <array>
#include <cmath>
#include <limits>
#include <numeric>
#include <stdexcept>
#include <vector>
#include <Eigen/Dense>
#include “cec2011_f4_reference.inl

Variables

double R1
double R2
double A
double B
double lambda1
double lambda2
double lambda3
double c
double d
double n
double gamma
double h
int from
int to
double reactance
double capacity
double cost
double limit
double lower
double upper
double pmin
double pmax
double a
double b
double e
double f
double upRamp
double downRamp
double initial
std::vector<ProhibitedZone> zones
std::vector<double> B1
std::vector<double> B2
double B3
int units
int hours
std::vector<double> demand
std::vector<UnitData> unitData
LossCoefficients loss
double penaltyBalance
double penaltyCapacity
double penaltyRamp
double penaltyPoz
bool roundLoss
double qmin
double qmax
double phMin
double phMax
double vmin
double vmax
double vInitial
double vFinal
int delay
int upstreamCount
std::array<double, 6> coeffs
std::vector<double> inflow
std::vector<ProhibitedZone> poz
double balance
double hydroCapacity
double thermalCapacity
double discharge
double storage
double reservoir
double ptMin
double ptMax
HydroThermalWeights weights
bool valvePoint
std::vector<int> sequence
MGADSMObjectiveType objective
double rpTarget
double eTarget
Eigen::Vector3d v1
Eigen::Vector3d v2
double semiMajor
double p
Eigen::MatrixXd X
std::array<double, kProblem9Lines.size()> fcWeights = {}
std::array<double, kProblem9GeneratorBuses.size()> btRowSums = {}
std::array<double, kProblem9LoadBuses.size()> btColSums = {}
file cec2011.h
#include “cec.h
#include <Eigen/Dense>
file cec2011_f4_reference.inl

Variables

static constexpr std::array<double, 5001> kProblem4Reference
file cec2014.cpp
#include “cec2014.h
file cec2014.h
#include “cec.h
file cec2017.cpp
#include “cec2017.h
file cec2017.h
#include “cec.h
file cec2019.cpp
#include “cec2019.h
file cec2019.h
#include “cec.h
file cec2020.cpp
#include “cec2020.h
file cec2020.h
#include “cec.h
file cec2022.cpp
#include “cec2022.h
file cec2022.h
#include “cec.h
file abc.h
#include “minimizer_base.h
#include “default_options.h
file agsk.h
#include “de.h
#include <array>
#include <tuple>
file arrde.h
#include <algorithm>
#include <cmath>
#include <iostream>
#include “de.h
#include “utility.h
file bipop_acmaes.h
#include “minimizer_base.h
#include <Eigen/Dense>
#include <limits>
#include <string>
file cmaes.h
#include “minimizer_base.h
#include <Eigen/Dense>
file de.h
#include “minimizer_base.h
#include “default_options.h
file default_options.h
#include <any>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <map>
#include <string>
#include “minimizer_base.h
file dmspso.h
#include “pso.h
file dual_annealing.h
#include “minimizer_base.h
#include “default_options.h
#include <cmath>
#include <algorithm>
#include “nelder_mead.h
#include “l_bfgs_b.h
file exception.h
#include <exception>
#include <string>
file gwo_de.h
#include <vector>
#include <random>
#include <algorithm>
#include <functional>
#include <limits>
#include <numeric>
#include “utility.h
#include “minimizer_base.h
file imode.h
#include “de.h
file j2020.h
#include “de.h
#include <limits>

Header file for the j2020 class.

Implementation of the j2020 algorithm. Reference : J. Brest, M. S. Maučec and B. Bošković, “Differential Evolution Algorithm for Single Objective Bound-Constrained Optimization: Algorithm j2020,” 2020 IEEE Congress on Evolutionary Computation (CEC), Glasgow, UK, 2020, pp. 1-8, doi: 10.1109/CEC48606.2020.9185551.

file jade.h
#include “de.h
file jso.h
#include “de.h
file l_bfgs.h
#include “minimizer_base.h
#include “default_options.h
#include <cmath>
#include <algorithm>
#include “nelder_mead.h
#include “exception.h
#include “types.h
file l_bfgs_b.h
#include “minimizer_base.h
#include “default_options.h
#include <cmath>
#include <algorithm>
#include “nelder_mead.h
#include “exception.h
#include “types.h
file lshade.h
#include “de.h
file lshadecnepsin.h
#include “de.h
#include <array>
#include <deque>
#include <Eigen/Dense>
file lsrtde.h
#include <math.h>
#include <iostream>
#include <time.h>
#include <fstream>
#include <random>
#include “minimizer_base.h

Header file for the LSRTDE class, which implements a minimization algorithm.

This code is adapted from the original LSRTDE code from Suganthan’s GitHub repository. Reference : V. Stanovov and E. Semenkin, “Success Rate-based Adaptive Differential Evolution L-SRTDE for CEC 2024 Competition,” 2024 IEEE Congress on Evolutionary Computation (CEC), Yokohama, Japan, 2024, pp. 1-8, doi: 10.1109/CEC60901.2024.10611907.

file minimizer.h
#include “minimizer_base.h
#include “exception”
#include “j2020.h
#include “jade.h
#include “jso.h
#include “lsrtde.h
#include “nelder_mead.h
#include “lshade.h
#include “agsk.h
#include “imode.h
#include “arrde.h
#include “de.h
#include “gwo_de.h
#include “nlshadersp.h
#include “nl_shade_lbc.h
#include “abc.h
#include “pso.h
#include “spso2011.h
#include “dmspso.h
#include “lshadecnepsin.h
#include “cmaes.h
#include “rcmaes.h
#include “bipop_acmaes.h
#include “dual_annealing.h
#include “l_bfgs_b.h
#include “l_bfgs.h
#include <algorithm>
#include <cctype>
file minimizer_base.h
#include <vector>
#include <functional>
#include <stdexcept>
#include <cmath>
#include “utility.h
#include <exception>
#include <variant>
#include <map>
file minion.h
#include “utility.h
#include “minimizer_base.h
#include “default_options.h
#include “de.h
#include “gwo_de.h
#include “lshade.h
#include “agsk.h
#include “arrde.h
#include “nlshadersp.h
#include “nl_shade_lbc.h
#include “j2020.h
#include “jade.h
#include “jso.h
#include “lsrtde.h
#include “nelder_mead.h
#include “minimizer.h
#include “imode.h
#include “abc.h
#include “dual_annealing.h
#include “l_bfgs_b.h
#include “l_bfgs.h
#include “pso.h
#include “spso2011.h
#include “dmspso.h
#include “lshadecnepsin.h
#include “bipop_acmaes.h
#include “rcmaes.h
#include “cmaes.h
#include “test_functions.h
file minion_cec.h
#include “cec.h
#include “cec2011.h
#include “cec2014.h
#include “cec2017.h
#include “cec2019.h
#include “cec2020.h
#include “cec2022.h
file nelder_mead.h
#include “minimizer_base.h
#include <limits>
file nl_shade_lbc.h
#include <math.h>
#include <iostream>
#include <time.h>
#include <fstream>
#include <random>
#include “minimizer_base.h
file nlshadersp.h
#include <math.h>
#include <iostream>
#include <time.h>
#include <fstream>
#include <random>
#include “minimizer_base.h

Header file for the NLSHADE_RSP class, which implements a minimization algorithm.

This code is adapted from the original NLSHADE_RSP code from Suganthan’s GitHub repository. Reference : V. Stanovov, S. Akhmedova and E. Semenkin, “NL-SHADE-RSP Algorithm with Adaptive Archive and Selective Pressure for CEC 2021 Numerical Optimization,” 2021 IEEE Congress on Evolutionary Computation (CEC), Kraków, Poland, 2021, pp. 809-816, doi: 10.1109/CEC45853.2021.9504959.

file pso.h
#include “minimizer_base.h
#include “default_options.h
#include <limits>
file rcmaes.h
#include “minimizer_base.h
#include <Eigen/Dense>
#include <limits>
#include <string>
file spso2011.h
#include “pso.h
#include <cmath>
#include <limits>
file test_functions.h
#include <vector>
#include <cmath>
file types.h
#include <Eigen/Core>
file utility.h
#include <vector>
#include <random>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <functional>
#include <iostream>
file abc.cpp
#include “abc.h
#include <algorithm>
#include <cmath>
#include <numeric>
file agsk.cpp
#include “agsk.h
#include <algorithm>
#include <cmath>
#include <numeric>
file arrde.cpp
#include “arrde.h
#include <cstddef>
#include <stdexcept>
file bindings.cpp
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/functional.h>
#include <pybind11/chrono.h>
#include <pybind11/complex.h>
#include “minion.h
#include “minion_cec.h
#include <exception>
#include <pybind11/stl_bind.h>
#include <any>
#include <map>
#include <string>
#include <vector>

Functions

void translate_exception(const std::exception &e)
PYBIND11_MODULE(minionpycpp, m)
file bipop_acmaes.cpp
#include “bipop_acmaes.h
#include “default_options.h
#include “utility.h
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
file cmaes.cpp
#include “cmaes.h
#include “default_options.h
#include “utility.h
#include <algorithm>
#include <cmath>
#include <numeric>
file de.cpp
#include “de.h
file dmspso.cpp
#include “dmspso.h
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <numeric>
#include <random>
file dual_annealing.cpp
#include “dual_annealing.h
file gwo_de.cpp
#include “gwo_de.h
#include <algorithm>
#include <numeric>
#include <random>
#include <cmath>
#include “default_options.h
file imode.cpp
#include “imode.h
#include <algorithm>
#include <cstddef>
#include <cmath>
#include <iostream>
#include <numeric>
#include <limits>
#include “utility.h

Variables

bool success = false
std::vector<double> x
double fun = std::numeric_limits<double>::infinity()
size_t evaluations = 0
MinionFunction func
const std::vector<std::pair<double, double>> &bounds
void *data
double gradTolerance
double stepTolerance
size_t dimension
size_t budget = 0
size_t evaluationsUsed = 0
bool budgetReached = false
file j2020.cpp
#include “j2020.h
#include “default_options.h
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
file jade.cpp
#include “jade.h
file jso.cpp
#include “jso.h
file l_bfgs.cpp
#include “l_bfgs.h

Variables

int m = 10
double epsilon = 1e-10
double epsilon_rel = 1e-10
int past = 3
double delta = 1e-20
int max_iterations = 0
int max_linesearch = 20
double min_step = 1e-20
double max_step = 1e20
double ftol = 1e-4
double wolfe = 0.9
int n_ = 0
int m_ = 0
int ncorr_ = 0
double theta_ = 1.0
Matrix S_
Matrix Y_
Vector ys_
LBFGSParam param
CompactLBFGSMatrix bfgs
Vector fx_hist
Vector xp
Vector grad
Vector gradp
Vector drt
double gnorm = 0.0
bool had_issue = false
std::string message
file l_bfgs_b.cpp
#include “l_bfgs_b.h
#include <Eigen/Cholesky>
#include <Eigen/LU>

Variables

int m = 10
double epsilon = 1e-10
double epsilon_rel = 1e-10
int past = 3
double delta = 1e-20
int max_iterations = 0
int max_submin = 10
int max_linesearch = 20
double min_step = 1e-20
double max_step = 1e20
double ftol = 1e-4
double wolfe = 0.9
int n_ = 0
int m_ = 0
int ncorr_ = 0
double theta_ = 1.0
Matrix S_
Matrix Y_
Vector ys_
Matrix Minv_
Matrix M_
Eigen::LDLT<Matrix> Minv_solver_
bool brackt = false
int stage = 1
double finit = 0.0
double ginit = 0.0
double gtest = 0.0
double gx = 0.0
double gy = 0.0
double fx = 0.0
double fy = 0.0
double stx = 0.0
double sty = 0.0
double stmin = 0.0
double stmax = 0.0
double width = 0.0
double width1 = 0.0
LBFGSBParam param
CompactBFGSMatrix bfgs
Vector fx_hist
Vector xp
Vector grad
Vector gradp
Vector drt
double projgnorm = 0.0
bool had_issue = false
std::string message
file lshade.cpp
#include “lshade.h
file lshadecnepsin.cpp
#include “lshadecnepsin.h
#include “default_options.h
#include “utility.h
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
#include <random>
#include <stdexcept>
file lsrtde.cpp
#include “lsrtde.h
#include “default_options.h
file nelder_mead.cpp
#include “nelder_mead.h
#include “default_options.h
#include <algorithm>
#include <cmath>
file nl_shade_lbc.cpp
#include “nl_shade_lbc.h
#include “default_options.h
file nlshadersp.cpp
#include “nlshadersp.h
#include “default_options.h
file pso.cpp
#include “pso.h
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdexcept>
file rcmaes.cpp
#include “rcmaes.h
#include “default_options.h
#include “utility.h
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
#include <random>
file spso2011.cpp
#include “spso2011.h
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <limits>
#include <numeric>
#include <stdexcept>
file test_functions.cpp
#include <vector>
#include <cmath>
#include <numeric>
#include “test_functions.h

Defines

M_PI
file utility.cpp
#include “utility.h
dir minion/cec
dir minion/include
dir minion
dir minion/src
example /home/docs/checkouts/readthedocs.org/user_builds/minion-py/checkouts/latest/minion/include/utility.h

Selects n random elements from the input vector v based on given probabilities.

Selects n random elements from the input vector v based on given probabilities.This function samples elements with replacement, meaning the same element can be selected multiple times.

std::vector<char> items = {'A', 'B', 'C', 'D'};
std::vector<double> probs = {0.1, 0.3, 0.4, 0.2};
auto chosen = random_choice(items, 5, probs);
for (char c : chosen) {
    std::cout << c << " ";
}
#ifndef UTILITY_H
#define UTILITY_H

#if defined(_WIN32)
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#endif

#include <vector>
#include <random>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <functional>
#include <iostream>

namespace minion {
extern thread_local unsigned int global_seed;

typedef std::function<std::vector<double>(const std::vector<std::vector<double>>&, void*)> MinionFunction;

void set_global_seed(unsigned int seed);

std::mt19937& get_rng();

template <typename T>
std::vector<T> random_choice(const std::vector<T>& v, size_t n, bool replace = false) {
    std::vector<T> result;
    std::mt19937& rng = get_rng();

    if (replace) {
        std::uniform_int_distribution<size_t> dist(0, v.size() - 1);
        for (size_t i = 0; i < n; ++i) {
            result.push_back(v[dist(rng)]);
        }
    } else {
        std::vector<T> copy = v;
        std::shuffle(copy.begin(), copy.end(), rng);
        result.insert(result.end(), copy.begin(), copy.begin() + n);
    }

    return result;
}


template <typename T>
std::vector<T> random_choice(const std::vector<T>& v, size_t n, const std::vector<double>& probability) {
    if (v.size() != probability.size()) {
        throw std::invalid_argument("Size of probability vector must match size of input vector.");
    }
    
    if (v.empty() || n == 0) {
        return {};  // Return empty vector if input is empty or n is 0
    }

    std::mt19937 rng = get_rng();

    // Normalize probabilities to sum to 1
    double sum = std::accumulate(probability.begin(), probability.end(), 0.0);
    std::vector<double> normalized_prob(probability.size());
    std::transform(probability.begin(), probability.end(), normalized_prob.begin(),
                   [sum](double p) { return p / sum; });

    std::vector<T> result;
    result.reserve(n);

    std::discrete_distribution<size_t> dist(normalized_prob.begin(), normalized_prob.end());

    for (size_t i = 0; i < n; ++i) {
        result.push_back(v[dist(rng)]);
    }

    return result;
}
template <typename T>
T findMin(const std::vector<T>& vec) {
    // Check if the vector is empty
    if (vec.empty()) {
        throw std::runtime_error("The vector is empty");
    }

    // Use std::min_element to find the minimum element
    auto minIt = std::min_element(vec.begin(), vec.end());

    // Dereference the iterator to get the value
    return *minIt;
}

template <typename T>
T findMax(const std::vector<T>& vec) {
    // Check if the vector is empty
    if (vec.empty()) {
        throw std::runtime_error("The vector is empty");
    }

    // Use std::max_element to find the maximum element
    auto maxIt = std::max_element(vec.begin(), vec.end());

    // Dereference the iterator to get the value
    return *maxIt;
}

template <typename T>
std::size_t findArgMin(const std::vector<T>& vec) {
    // Check if the vector is empty
    if (vec.empty()) {
        throw std::runtime_error("The vector is empty");
    }

    // Use std::min_element to find the minimum element
    auto minIt = std::min_element(vec.begin(), vec.end());

    // Get the index of the minimum element
    return std::distance(vec.begin(), minIt);
}

template <typename T>
std::size_t findArgMax(const std::vector<T>& vec) {
    // Check if the vector is empty
    if (vec.empty()) {
        throw std::runtime_error("The vector is empty");
    }

    // Use std::max_element to find the maximum element
    auto maxIt = std::max_element(vec.begin(), vec.end());

    // Get the index of the maximum element
    return std::distance(vec.begin(), maxIt);
}

std::vector<size_t> random_choice(size_t Ninput, size_t N, bool replace = false);


std::vector<double> normalize_vector(const std::vector<double>& input);

double rand_gen(double low=0.0, double high=1.0);

std::vector<double> rand_gen(double low, double high, size_t N);

size_t rand_int(size_t n);

double rand_norm(double mu, double s);

double rand_cauchy(double location, double scale);

std::vector<size_t> argsort(const std::vector<double>& v, bool ascending = true);

template <typename T>
T clamp(T value, T low, T high) {
    if (value < low) {
        return low;
    } else if (value > high) {
        return high;
    } else {
        return value;
    }
}

template<typename T>
void printVector(const std::vector<T>& vec) {
    std::cerr << "[ ";
    for (const auto& elem : vec) {
        std::cerr << elem << " ";
    }
    std::cerr << "]" << std::endl;
}

template <typename T>
bool contains(const std::vector<T>& vec, const T& element) {
    // Use std::find to search for the element in the vector
    auto it = std::find(vec.begin(), vec.end(), element);
    // Return true if the element is found, otherwise return false
    return it != vec.end();
}

std::vector<std::vector<double>> latin_hypercube_sampling(const std::vector<std::pair<double, double>>& bounds, size_t population_size);

std::vector<std::vector<double>> random_sampling(const std::vector<std::pair<double, double>>& bounds, size_t population_size);

std::tuple<double, double> getMeanStd(const std::vector<double>& arr, const std::vector<double>& weight);

double calcMean(const std::vector<double>& vec);

double calcStdDev(const std::vector<double>& vec);

void enforce_bounds(std::vector<std::vector<double>>& new_candidates, const std::vector<std::pair<double, double>>& bounds, const std::string& strategy);

void enforce_bounds(std::vector<double>& new_candidate, const std::vector<std::pair<double, double>>& bounds, const std::string& strategy);

void printVectorOfVectors(const std::vector<std::vector<double>>& vec);

double euclideanDistance(const std::vector<double>& a, const std::vector<double>& b);

std::vector<double> calculateCenter(const std::vector<std::vector<double>>& particles);

double averageEuclideanDistance(const std::vector<std::vector<double>>& particles);

}

#endif

Note

The function uses std::discrete_distribution for weighted sampling.

tparam T:

Type of elements in the input vector.

param v:

The input vector from which elements are sampled.

param n:

The number of elements to select.

param probability:

A vector of probabilities corresponding to each element in v.

throws std::invalid_argument:

If the size of probability does not match v.size().

return:

std::vector<T> A vector containing n randomly chosen elements from v.