bounded_degree_mst_example.cpp
Go to the documentation of this file.
1 //=======================================================================
3 //
5 // accompanying file LICENSE_1_0.txt or copy at
7 //=======================================================================
19 #include "paal/utils/functors.hpp"
20
22
23 #include <iostream>
24 #include <vector>
25
26 int main() {
27  using Graph = boost::adjacency_list<boost::vecS, boost::vecS,
28  boost::undirectedS, boost::no_property,
29  boost::property<boost::edge_weight_t, int>>;
30  using Edge = boost::graph_traits<Graph>::edge_descriptor;
31
32  // sample problem
33  std::vector<std::pair<int, int>> edges {{0,1},{0,2},{1,2},{1,3},{1,4},
34  {1,5},{5,0},{3,4}};
35  std::vector<int> costs {1,2,1,2,1,1,1,5};
36  std::vector<int> bounds {3,2,2,2,2,2};
37
38  Graph g(edges.begin(), edges.end(), costs.begin(), 6);
39  auto degree_bounds = paal::utils::make_array_to_functor(bounds);
40
41  std::vector<Edge> result_tree;
42
43  // optional input validity checking
45  g, degree_bounds, std::back_inserter(result_tree));
46  auto error = bdmst.check_input_validity();
47  if (error) {
48  std::cerr << "The input is not valid!" << std::endl;
49  std::cerr << *error << std::endl;
50  return -1;
51  }
52
53  // solve it
55  g, degree_bounds, std::back_inserter(result_tree));
56
57  // print result
58  if (result.first == paal::lp::OPTIMAL) {
59  std::cout << "Edges in the spanning tree" << std::endl;
60  for (auto e : result_tree) {
61  std::cout << "Edge " << e << std::endl;
62  }
63  std::cout << "Cost of the solution: " << *(result.second) << std::endl;
64  } else {
65  std::cout << "The instance is infeasible" << std::endl;
66  }
67  paal::lp::glp::free_env();
68  return 0;
69 }
auto make_bounded_degree_mst(const Graph &g, const DegreeBounds &deg_bounds, const boost::bgl_named_params< P, T, R > &params, SpanningTreeOutputIterator result_spanning_tree, Oracle oracle=Oracle()) -> bounded_degree_mst< Graph, DegreeBounds, decltype(choose_const_pmap(get_param(params, boost::edge_weight), g, boost::edge_weight)), decltype(choose_const_pmap(get_param(params, boost::vertex_index), g, boost::vertex_index)), SpanningTreeOutputIterator, Oracle >
This file contains set of simple useful functors or functor adapters.
auto make_array_to_functor(const Array &a, int offset=0)
make function for array_to_functor
Definition: functors.hpp:364
int main()
[Bounded-Degree Minimum Spanning Tree Example]
IRResult bounded_degree_mst_iterative_rounding(const Graph &g, const DegreeBounds &deg_bounds, const boost::bgl_named_params< P, T, R > &params, SpanningTreeOutputIterator result_spanning_tree, IRcomponents components=IRcomponents(), Oracle oracle=Oracle(), Visitor visitor=Visitor())
Solves the Bounded Degree MST problem using Iterative Rounding. Named version.