Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

SaveStatic.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/tree/LCA.h>
39 
40 namespace ogdf {
41 namespace steiner_tree {
42 
47 template<typename T>
48 class SaveStatic: public Save<T> {
49 public:
50  explicit SaveStatic(EdgeWeightedGraphCopy<T> &steinerTree)
51  : Save<T>()
52  , m_tree()
53  , m_treeEdge(m_tree, nullptr)
54  , m_steinerTree(&steinerTree)
55  , m_cTerminals(*m_steinerTree, nullptr)
56  {
58  m_lca = new LCA(m_tree, m_root);
59  }
60 
61  virtual ~SaveStatic()
62  {
63  delete m_lca;
64  }
65 
72  virtual T saveWeight(node u, node v) const
73  {
74  return m_steinerTree->weight(saveEdge(u, v));
75  }
76 
83  virtual edge saveEdge(node u, node v) const
84  {
85  OGDF_ASSERT(m_steinerTree->copy(u));
86  OGDF_ASSERT(m_steinerTree->copy(v));
87  node anc = lca(m_steinerTree->copy(u), m_steinerTree->copy(v));
88  OGDF_ASSERT(anc);
89  return m_treeEdge[anc];
90  }
91 
99  virtual T gain(node u, node v, node w) const
100  {
101  node save0 = lca(m_steinerTree->copy(u), m_steinerTree->copy(v));
102  node save1 = lca(m_steinerTree->copy(u), m_steinerTree->copy(w));
103  if (save0 == save1) {
104  save1 = lca(m_steinerTree->copy(v), m_steinerTree->copy(w));
105  }
106  return (save0 ? m_steinerTree->weight(m_treeEdge[save0]) : 0)
107  + (save1 ? m_steinerTree->weight(m_treeEdge[save1]) : 0);
108  }
109 
113  void rebuild()
114  {
115  m_tree.clear();
116  m_cTerminals.fill(nullptr);
118  delete m_lca;
119  m_lca = new LCA(m_tree, m_root);
120  }
121 
130  virtual void update(const Triple<T> &t)
131  {
132  const edge save0 = saveEdge(t.s0(), t.s1());
133  const edge save1 = saveEdge(t.s0(), t.s2());
134  const edge save2 = saveEdge(t.s1(), t.s2());
135  contractTripleInSteinerTree(t, *m_steinerTree, save0, save1, save2);
136 
137  rebuild();
138  }
139 
146  node lca(node u, node v) const
147  {
148  return m_lca->call(m_cTerminals[u], m_cTerminals[v]);
149  }
150 
151 protected:
152 
153 private:
160 };
161 
162 } // end namespace steiner_tree
163 } // end namespace ogdf
NodeArray< node > m_cTerminals
Definition: SaveStatic.h:159
Implements the <O(n log n), O(1)>-time "sparse table" algorithm by Bender and Farach-Colton to comput...
Definition: LCA.h:52
virtual void update(const Triple< T > &t)
Updates the weighted tree data structure given a contracted triple.
Definition: SaveStatic.h:130
This class behaves basically the same as SaveDynamic except that the update of the weighted graph is ...
Definition: SaveStatic.h:48
virtual void clear()
Removes all nodes and all edges from the graph.
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
virtual T gain(node u, node v, node w) const
Returns the gain (sum of the save edges) of a node triple by an LCA query.
Definition: SaveStatic.h:99
node buildHeaviestEdgeInComponentTree(const EdgeWeightedGraphCopy< T > &inputTree, NodeArray< node > &externalNodes, NodeArray< edge > &treeEdge, Graph &outputTree)
Given an edge-weighted tree, builds an auxiliary arborescence where each arc of the input tree is a n...
Graph m_tree
The weighted binary tree to represent the edge weight hierarchy.
Definition: SaveStatic.h:154
node call(node u, node v) const
Returns the LCA of two nodes u and v.
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
node lca(node u, node v) const
Returns the node corresponding to the LCA between two given nodes.
Definition: SaveStatic.h:146
virtual edge saveEdge(node u, node v) const
Determines the save edge between two nodes by a LCA query.
Definition: SaveStatic.h:83
EdgeWeightedGraphCopy< T > * m_steinerTree
A pointer to the tree we represent the save for.
Definition: SaveStatic.h:156
Class for the representation of edges.
Definition: Graph_d.h:291
void rebuild()
Rebuild the data structure (necessary if the tree has changed)
Definition: SaveStatic.h:113
Class for the representation of nodes.
Definition: Graph_d.h:167
The Sparse Table Algorithm for the Least Common Ancestor problem as proposed by Bender and Farach-Col...
Definition of a Triple used in contraction-based approximation algorithm for the minimum Steiner tree...
virtual T saveWeight(node u, node v) const
Determines the weight of the save edge between two nodes by a LCA query.
Definition: SaveStatic.h:72
SaveStatic(EdgeWeightedGraphCopy< T > &steinerTree)
Definition: SaveStatic.h:50
LCA * m_lca
The LCA data structure for m_tree.
Definition: SaveStatic.h:158
Interface for various LCA methods.
node m_root
The root of m_tree.
Definition: SaveStatic.h:157
Algorithms used by at least two functions of Steiner tree code or its internal helpers.
The namespace for all OGDF objects.
NodeArray< edge > m_treeEdge
Maps each inner node of m_tree to an edge in m_steinerTree.
Definition: SaveStatic.h:155
This class serves as an interface for different approaches concerning the calculation of save edges...
Definition: Save.h:45
void contractTripleInSteinerTree(const Triple< T > &t, EdgeWeightedGraphCopy< T > &st, edge save0, edge save1, edge save2, edge &ne0, edge &ne1)
Updates the Steiner tree by deleting save edges, removing all direct connections between the terminal...
This class represents a triple used by various contraction-based minimum Steiner tree approximations...
Definition: Triple.h:44
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41