All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
dreyfus_wagner_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 //=======================================================================
15 #include "test/test_utils/sample_graph.hpp"
17 
19 
20 #include <boost/range/algorithm/copy.hpp>
21 
22 #include <iostream>
23 
24 int main() {
25  // prepare metric
26  typedef sample_graphs_metrics SGM;
27  auto gm = SGM::get_graph_metric_steiner();
28 
29  // prepare terminals and Steiner vertices
30  std::vector<int> terminals = { SGM::A, SGM::B, SGM::C, SGM::D };
31  std::vector<int> nonterminals = { SGM::E };
32 
33  // run algorithm
34  auto dw =
35  paal::make_dreyfus_wagner(gm, terminals, nonterminals);
36  dw.solve();
37 
38  // print result
39  std::cout << "Cost = " << dw.get_cost() << std::endl;
40  std::cout << "Steiner points:" << std::endl;
41  boost::copy(dw.get_steiner_elements(),
42  std::ostream_iterator<int>(std::cout, "\n"));
43  std::cout << "Edges:" << std::endl;
44  for (auto edge : dw.get_edges()) {
45  std::cout << "(" << edge.first << "," << edge.second << ")"
46  << std::endl;
47  }
48 
49  return 0;
50 }
dreyfus_wagner< Metric, Terminals, NonTerminals, TerminalsLimit > make_dreyfus_wagner(const Metric &metric, const Terminals &terminals, const NonTerminals &non_terminals)
Creates a dreyfus_wagner object.
Finds optimal Steiner Tree in exponential time.
int main()
[Dreyfus Wagner Example]