All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
2_local_search_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 //=======================================================================
16 #include "test/test_utils/sample_graph.hpp"
18 
22 
23 #include <vector>
24 #include <iostream>
25 
26 using namespace paal::local_search;
27 using namespace paal;
28 
29 int main() {
30  // sample data
31  typedef sample_graphs_metrics SGM;
32  auto gm = SGM::get_graph_metric_small();
33  const int size = gm.size();
34  std::cout << size << std::endl;
35  std::vector<int> v(size);
36  std::iota(v.begin(), v.end(), 0);
37 
38  // create random solution
39  std::random_shuffle(v.begin(), v.end());
41  Cycle cycle(v.begin(), v.end());
42  std::cout << "Length \t" << get_cycle_length(gm, cycle) << std::endl;
43 
44  // search
46 
47  // printing
48  std::cout << "Length \t" << get_cycle_length(gm, cycle) << std::endl;
49 
50  return 0;
51 }
This is the simplest implementation of the Cycle concept based on the list.
auto get_default_two_local_components(const Metric &m)
get default two local search components
Metric::DistanceType get_cycle_length(const Metric &m, const Cycle &cm)
computes length of the cycle
Definition: cycle_algo.hpp:39
bool local_search(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess succ, ContinueOnFail fail, components...comps)
detail
bool tsp_first_improving(Cycle &cycle, components...comps)
simple version of two_local_search