16 #ifndef PAAL_STEINER_COMPONENT_HPP
17 #define PAAL_STEINER_COMPONENT_HPP
23 #include <boost/range/algorithm/transform.hpp>
24 #include <boost/range/join.hpp>
37 template <
typename Vertex,
typename Dist>
40 using Edge =
typename std::pair<Vertex, Vertex>;
41 using Vertices =
typename std::vector<Vertex>;
44 template<
typename Metric,
typename Terminals>
46 m_terminals(std::move(terminals)), m_size(m_terminals.size()) {
48 auto all_elements = boost::join(m_terminals, steiner_vertices);
50 fast_metric(cost_map, all_elements);
51 auto term_nr = boost::distance(m_terminals);
52 auto all_elements_nr = boost::distance(all_elements);
55 irange(
int(term_nr),
int(all_elements_nr)));
57 m_cost = dw.get_cost();
58 auto &steiner = dw.get_steiner_elements();
59 m_steiner_elements.resize(steiner.size());
60 auto id_to_elem = [&](
int i){
62 return m_terminals[i];
64 return steiner_vertices[i - term_nr];
67 boost::transform(steiner, m_steiner_elements.begin(), id_to_elem);
68 m_edges.resize(dw.get_edges().size());
69 boost::transform(dw.get_edges(), m_edges.begin(), [=](std::pair<int, int> e) {
70 return std::make_pair(id_to_elem(e.first), id_to_elem(e.second));
80 return m_terminals[version];
93 return m_steiner_elements;
99 const std::vector<Edge> &
get_edges()
const {
return m_edges; }
116 for (
int i = 0; i < component.m_size; i++) {
117 stream << component.m_terminals[i] <<
" ";
120 for (
auto edge : component.m_edges) {
121 stream <<
"(" << edge.first <<
"," << edge.second <<
") ";
123 stream << component.m_cost;
128 const Vertices m_terminals;
131 Vertices m_steiner_elements;
133 std::vector<Edge> m_edges;
139 #endif // PAAL_STEINER_COMPONENT_HPP
dreyfus_wagner< Metric, Terminals, NonTerminals, TerminalsLimit > make_dreyfus_wagner(const Metric &metric, const Terminals &terminals, const NonTerminals &non_terminals)
Creates a dreyfus_wagner object.
Class represents k-components of Steiner Tree. Component is a subtree whose terminals coincide with l...
int count_terminals() const
Finds optimal Steiner Tree in exponential time.
steiner_component(const Metric &cost_map, Vertices terminals, const Terminals &steiner_vertices)
constructor
const Vertices & get_terminals() const
auto irange(T begin, T end)
irange
friend std::ostream & operator<<(std::ostream &stream, const steiner_component &component)
Vertex get_sink(int version) const
Each component has versions, where sink is chosen from its terminals.
this metric is rectangle_array_metric with N == M.
Terminals
enum indicates if given color represents terminal or NONTERMINAL.
const Vertices & get_steiner_elements() const
const std::vector< Edge > & get_edges() const