30 auto f = [](
int x) {
return -x * x + 12 * x - 27; };
35 std::vector<int> neighb{ 10, -10, 1, -1 };
37 auto getMoves = [ = ](int) {
38 return boost::make_iterator_range(neighb.begin(), neighb.end());
41 auto gain = [ = ](
int sol,
int move) {
return f(sol + move) - f(sol); };
43 auto commit = [](
int & sol,
int move) {
53 std::cout <<
"Local search solution: " << solution << std::endl;
68 std::cout <<
"Simulated annealing solution: " << solution << std::endl;
70 int currentSolution(0);
74 std::default_random_engine engine;
75 std::uniform_int_distribution<> dist(0, 4);
76 auto getMovesRandom = [ = ](int)
mutable {
77 auto iter = neighb.begin() + dist(engine);
78 return boost::make_iterator_range(iter, iter + 1);
98 recordSolutionCommit));
101 std::cout <<
"Random walk solution: " << best << std::endl;
120 std::cout <<
"Tabu solution: " << best << std::endl;
This strategy chooses the best possible move and if it is improving applies it to the solution...
tabu_gain_adaptor< TabuList, Gain, AspirationCriteria > make_tabu_gain_adaptor(TabuList tabuList, Gain gain=Gain(), AspirationCriteria aspirationCriteria=AspirationCriteria())
make function for tabu_gain_adaptor
auto make_search_components(Args &&...args)
make function for search components
bool first_improving(Solution &solution, components...comps)
record_solution_commit_adapter< Commit, Solution, Condition > make_record_solution_commit_adapter(Solution &s, Commit commit, Condition c)
make function for record_solution_commit_adapter
bool best(Solution &solution, ContinueOnSuccess on_success, components...comps)
This local search chooses the best possible move and applies it to the solution. Note that this strat...
This functors returns potential (temperature) using the following schema. The start potential equals ...
This is custom StopCondition , it returns true after given count limit.
auto make_functor_to_comparator(Functor functor, Compare compare=Compare())
make for functor to comparator
int main()
[Local Search Example]
auto make_not_functor(Functor functor)
make for Not
This Tabu list remember both current solution and move It is implemented as tabu_list_remember_move<p...
auto make_simulated_annealing_gain_adaptor(Gain gain, GetTemperature getTemperature, random_generator rand=random_generator())
make function for simulated_annealing_gain_adaptor
bool local_search(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess succ, ContinueOnFail fail, components...comps)
detail
This strategy uses find_positive_predicate as stop condition.