All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
n_queens_example.cpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c)
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 <boost/range/algorithm_ext/iota.hpp>
20 #include <boost/range/algorithm/random_shuffle.hpp>
21 
22 void print(const std::vector<int> &queens) {
23  for (int q : queens) {
24  for (int i = 0; i < q; ++i) {
25  std::cout << "-";
26  }
27  std::cout << "x";
28  for (int i = 0; i < int(queens.size()) - q - 1; ++i) {
29  std::cout << "-";
30  }
31  std::cout << std::endl;
32  }
33 }
34 
35 int main() {
36  namespace ls = paal::local_search;
37 
38  // creating initial solution
39  std::vector<int> queens(9);
40  boost::iota(queens, 0);
41  boost::random_shuffle(queens);
42 
43  // print before
44  std::cout << "start configuration" << std::endl;
45  print(queens);
46 
47  // local search
50 
51  // print after
52  std::cout << "final configuration" << std::endl;
53  print(queens);
54 }
void n_queens_solution_first_improving(NQueensPositionsVector &pos, components...nQueenscomponents)
n queen local search (simple version)
data_structures::components< data_structures::NameWithDefault< GetMoves, n_queensget_moves >, data_structures::NameWithDefault< Gain, n_queens_gain >, data_structures::NameWithDefault< Commit, n_queens_commit >>::type< Args...> n_queens_local_search_components
NQueen Compoenents.
bool local_search(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess succ, ContinueOnFail fail, components...comps)
detail