This is a simple metaheuristic library design for class
auto instance = MH::Trajectory::Instance<Encoding>();
Encoding
is the type of the encoded solution.
instance.generationLimit
: Limit of search generations.- prototype
uint64_t generationLimit;
instance.neighborhood
: neighbourhood generator.- prototype
std::vector<Encoding> (*neighbourhood)(Encoding &);
instance.evaluate
: solution fitness evaluator.- prototype
double (*evaluate)(Encoding &, void *inf);
instance.inf
: additional information provide to evaluator.- prototype
void *inf;
ItrativeImprovement (II) :
auto II = MH::Trajectory::II<SelectionStrategy>();
or use the aliasMH::Trajectory::ItrativeImprovement
SelectionStrategy
is the seleciton strategy of II.MH::Trajectory::II_BestImproving
MH::Trajecotry::II_FirstImproving
Simulated Annealing (SA) :
auto SA = MH::Trajectory::SA();
or use the aliasMH::Trajectory::SimulatedAnnealing
TabuSearch (TS) :
auto TS = MH::Trajectory::TS<Encoding, TraitType>();
or use the aliasMH::Trajectory::TabuSearch
Encoding
is the type of the encoded solution.TraitType
is the type of the trait that will be stored in the tabu list.
II : None
SA :
SA.epoch_length
: epoch length.uint64_t epoch_length;
SA.init_temperature
: initial temperature.double init_temperature;
SA.cooling
: cooling function.double (*cooling)(double);
TS :
TS.length
: tabu tenure.uint8_t length;
TS.trait
: trait convert function.TraitType (*trait)(Encoding&, void *);
- The second parameter is
instance.inf
instance.search(algortihm, init_solution);
auto instance = MH::Evolutionary::Instance<Encoding>();
Encoding
is the type of the encoded solution.
instance.generationLimit
: limit of search generation。- prototype
uint64_t generationLimit;
instance.neighborhood
: neighbourhood generator.- prototype
std::vector<Encoding> (*neighbourhood)(Encoding &);
instance.evaluate
: solution fitness evaluator.- prototype
double (*evaluate)(Encoding &, void *inf);
instance.inf
: additional information provide to evaluator.void *inf;
Differential Evolution(DE) :
auto DE = MH::Evolutionary::DE<Selection, Crossover>();
or use the alias MH::Evolutionary::DifferentialEvolution
Selection
is the selection strategy of DE.MH::Evolutionary::DE_Random
MH::Evolutionary::DE_Best
MH::Evolutionary::DE_CurrentToRandom
MH::Evolutionary::DE_CurrentToBest
Crossover
is the crossover strategy of DE.MH::Evolutionary::DE_Binomial
MH::Evolutionary::DE_Exponential
DE :
DE.crossover_rate
: crossover rate, should be in the interval (0, 1].double crossover_rate;
DE.current_factor
: scaling factor of xToCurrent policy.- Only required for
DE_CurrentToRandom
orDE_CurrentToBest
. double current_factor;
DE.scaling_factor
: scaling factor of mutant vector.double scaling_factor;
DE.num_of_diff_vectors
: the number of mutant vectors to be generated。uint8_t num_of_diff_vectors;
instance.evolution(algorithm, init_solution)
About Encoding:
should provide the operator==()
.