21 #include <boost/graph/adjacency_list.hpp>
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;
33 std::vector<std::pair<int, int>> edges {{0,1},{0,2},{1,2},{1,3},{1,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};
38 Graph g(edges.begin(), edges.end(), costs.begin(), 6);
41 std::vector<Edge> result_tree;
45 g, degree_bounds, std::back_inserter(result_tree));
46 auto error = bdmst.check_input_validity();
48 std::cerr <<
"The input is not valid!" << std::endl;
49 std::cerr << *error << std::endl;
55 g, degree_bounds, std::back_inserter(result_tree));
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;
63 std::cout <<
"Cost of the solution: " << *(result.second) << std::endl;
65 std::cout <<
"The instance is infeasible" << std::endl;
67 paal::lp::glp::free_env();
auto make_bounded_degree_mst(const Graph &g, const DegreeBounds °_bounds, const boost::bgl_named_params< P, T, R > ¶ms, 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
int main()
[Bounded-Degree Minimum Spanning Tree Example]
IRResult bounded_degree_mst_iterative_rounding(const Graph &g, const DegreeBounds °_bounds, const boost::bgl_named_params< P, T, R > ¶ms, SpanningTreeOutputIterator result_spanning_tree, IRcomponents components=IRcomponents(), Oracle oracle=Oracle(), Visitor visitor=Visitor())
Solves the Bounded Degree MST problem using Iterative Rounding. Named version.