All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
multiway_cut_example.cpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Smulewicz
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/graph/adjacency_list.hpp>
20 
21 int main() {
22  // sample data
23  std::vector<std::pair<int,int>> edges_p{{0,3},{1,3},
24  {0,4},{2,4},
25  {1,5},{2,5},
26  {3,6},{4,6},
27  {3,7},{5,7},
28  {4,8},{5,8},
29  {6,7},{6,8},{7,8}
30  };
31  const int vertices_num = 9;
32  std::vector<int> cost_edges{100,100,100,100,100,100,10,10,10,10,10,10,1,1,1};
33 
34  std::vector<int> terminals = { 0, 1, 2 };
35  boost::adjacency_list<
36  boost::vecS, boost::vecS, boost::undirectedS,
37  boost::property<boost::vertex_index_t, int,
38  boost::property<boost::vertex_color_t, int>>,
39  boost::property<boost::edge_weight_t, int>
40  > graph(edges_p.begin(), edges_p.end(), cost_edges.begin(), vertices_num);
41 
42  for (std::size_t i = 1; i <= terminals.size(); ++i) {
43  put(boost::vertex_color, graph, terminals[i - 1], i);
44  }
45 
46  //solve
47  std::vector<std::pair<int,int>> vertices_parts;
48  auto cost_cut = paal::multiway_cut(graph, back_inserter(vertices_parts));
49 
50  //print result
51  std::cout << "cost cut: " << cost_cut << std::endl;
52  std::cout << "vertices (part)" << std::endl;
53  for(auto i: vertices_parts) {
54  std::cout << " " << i.first << " ( " << i.second << " )" << std::endl;
55  }
56  paal::lp::glp::free_env();
57 }
int main()
[Multiway Cut Example]
auto multiway_cut(const Graph &g, OutputIterator out, const boost::bgl_named_params< P, T, R > &params, Rand &&random_engine=std::default_random_engine(5426u)) -> typename boost::property_traits< puretype(boost::choose_const_pmap(get_param(params, boost::edge_weight), g, boost::edge_weight))>::value_type
detail