All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
steiner_components.hpp
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 #ifndef PAAL_STEINER_COMPONENTS_HPP
16 #define PAAL_STEINER_COMPONENTS_HPP
17 
19 
20 namespace paal {
21 namespace ir {
22 
29 template <typename Vertex, typename Dist> class steiner_components {
30  public:
31  steiner_components() : m_size(0) {}
32 
36  void add(const steiner_component<Vertex, Dist> &component) {
37  for (int i = 0; i < (int)component.count_terminals(); ++i) {
38  ++m_size;
39  m_original_id.push_back(m_components.size());
40  m_version.push_back(i);
41  }
42  m_components.push_back(component);
43  }
44 
48  int size() const { return m_size; }
49 
53  const steiner_component<Vertex, Dist> &find(int id) const {
54  assert(id >= 0 && id < m_size);
55  return m_components[m_original_id[id]];
56  }
57 
61  int find_version(int id) const { return m_version[id]; }
62 
66  void clear() {
67  m_components.clear();
68  m_version.clear();
69  m_original_id.clear();
70  m_size = 0;
71  }
72 
73  private:
74  std::vector<steiner_component<Vertex, Dist>> m_components; // generated
75  // components
76  std::vector<int> m_version; // id -> version map
77  std::vector<int> m_original_id; // id -> place in m_components vector
78  int m_size; // m_version.size(), but not m_components.size()
79 };
80 
81 } // ir
82 } // paal
83 
84 #endif // PAAL_STEINER_COMPONENTS_HPP
Class represents k-components of Steiner Tree. Component is a subtree whose terminals coincide with l...
const steiner_component< Vertex, Dist > & find(int id) const
void add(const steiner_component< Vertex, Dist > &component)