All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
local_search_lambda_example.cpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
18 
19 #include <vector>
20 #include <iostream>
21 
22 int main() {
23  namespace ls = paal::local_search;
24 
25  auto f = [](int x) { return -x * x + 12 * x - 27; };
26  int solution{ 0 };
27 
28  const std::vector<int> neighb{ 10, -10, 1, -1 };
29 
30  auto getMoves = [neighb](int) {
31  return boost::make_iterator_range(neighb.begin(), neighb.end());
32  };
33 
34  auto gain = [f](int sol, int move) { return f(sol + move) - f(sol); };
35 
36  auto commit = [](int & sol, int move) {
37  sol = sol + move;
38  return true;
39  };
40 
41  ls::first_improving(solution,
43 
44  std::cout << "Local search solution: " << solution << std::endl;
45  return 0;
46 }
auto make_search_components(Args &&...args)
make function for search components
bool first_improving(Solution &solution, components...comps)
bool local_search(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess succ, ContinueOnFail fail, components...comps)
detail
int main()
[Local Search Example]