Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

SaveStatic.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/Graph.h>
36 #include <ogdf/basic/basic.h>
39 #include <ogdf/tree/LCA.h>
40 
41 namespace ogdf::steiner_tree {
42 template<typename T>
43 class Triple;
44 } // namespace ogdf::steiner_tree
45 
46 namespace ogdf {
47 template<typename T>
48 class EdgeWeightedGraphCopy;
49 
50 namespace steiner_tree {
51 
56 template<typename T>
57 class SaveStatic : public Save<T> {
58 public:
59  explicit SaveStatic(EdgeWeightedGraphCopy<T>& steinerTree)
60  : Save<T>()
61  , m_tree()
62  , m_treeEdge(m_tree, nullptr)
63  , m_steinerTree(&steinerTree)
64  , m_cTerminals(*m_steinerTree, nullptr) {
66  m_lca = new LCA(m_tree, m_root);
67  }
68 
69  virtual ~SaveStatic() { delete m_lca; }
70 
77  virtual T saveWeight(node u, node v) const { return m_steinerTree->weight(saveEdge(u, v)); }
78 
85  virtual edge saveEdge(node u, node v) const {
86  OGDF_ASSERT(m_steinerTree->copy(u));
87  OGDF_ASSERT(m_steinerTree->copy(v));
88  node anc = lca(m_steinerTree->copy(u), m_steinerTree->copy(v));
89  OGDF_ASSERT(anc);
90  return m_treeEdge[anc];
91  }
92 
100  virtual T gain(node u, node v, node w) const {
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  m_tree.clear();
115  m_cTerminals.fill(nullptr);
117  delete m_lca;
118  m_lca = new LCA(m_tree, m_root);
119  }
120 
129  virtual void update(const Triple<T>& t) {
130  const edge save0 = saveEdge(t.s0(), t.s1());
131  const edge save1 = saveEdge(t.s0(), t.s2());
132  const edge save2 = saveEdge(t.s1(), t.s2());
133  contractTripleInSteinerTree(t, *m_steinerTree, save0, save1, save2);
134 
135  rebuild();
136  }
137 
144  node lca(node u, node v) const { return m_lca->call(m_cTerminals[u], m_cTerminals[v]); }
145 
146 protected:
147 private:
154 };
155 
156 }
157 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::steiner_tree::contractTripleInSteinerTree
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...
Definition: common_algorithms.h:159
ogdf::steiner_tree::Triple
This class represents a triple used by various contraction-based minimum Steiner tree approximations.
Definition: common_algorithms.h:48
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::steiner_tree::SaveStatic::saveEdge
virtual edge saveEdge(node u, node v) const
Determines the save edge between two nodes by a LCA query.
Definition: SaveStatic.h:85
ogdf::steiner_tree::SaveStatic::saveWeight
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:77
ogdf::steiner_tree::Triple::s2
node s2() const
Definition: Triple.h:54
ogdf::steiner_tree::SaveStatic::SaveStatic
SaveStatic(EdgeWeightedGraphCopy< T > &steinerTree)
Definition: SaveStatic.h:59
ogdf::steiner_tree::SaveStatic::rebuild
void rebuild()
Rebuild the data structure (necessary if the tree has changed)
Definition: SaveStatic.h:113
ogdf::steiner_tree::Triple::s1
node s1() const
Definition: Triple.h:52
ogdf::steiner_tree::SaveStatic::m_lca
LCA * m_lca
The LCA data structure for m_tree.
Definition: SaveStatic.h:152
ogdf::LCA::call
node call(node u, node v) const
Returns the LCA of two nodes u and v.
ogdf::steiner_tree::Save
This class serves as an interface for different approaches concerning the calculation of save edges.
Definition: Save.h:50
ogdf::steiner_tree::SaveStatic::gain
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:100
ogdf::steiner_tree::SaveStatic::update
virtual void update(const Triple< T > &t)
Updates the weighted tree data structure given a contracted triple.
Definition: SaveStatic.h:129
ogdf::steiner_tree::SaveStatic::lca
node lca(node u, node v) const
Returns the node corresponding to the LCA between two given nodes.
Definition: SaveStatic.h:144
LCA.h
The Sparse Table Algorithm for the Least Common Ancestor problem as proposed by Bender and Farach-Col...
ogdf::steiner_tree
Definition: MinSteinerTreeMehlhorn.h:297
ogdf::steiner_tree::buildHeaviestEdgeInComponentTree
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...
Definition: common_algorithms.h:69
ogdf::Graph::clear
virtual void clear()
Removes all nodes and all edges from the graph.
common_algorithms.h
Algorithms used by at least two functions of Steiner tree code or its internal helpers.
ogdf::steiner_tree::SaveStatic::m_cTerminals
NodeArray< node > m_cTerminals
Definition: SaveStatic.h:153
ogdf::steiner_tree::SaveStatic::~SaveStatic
virtual ~SaveStatic()
Definition: SaveStatic.h:69
ogdf::steiner_tree::SaveStatic::m_steinerTree
EdgeWeightedGraphCopy< T > * m_steinerTree
A pointer to the tree we represent the save for.
Definition: SaveStatic.h:150
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::LCA
Implements the <O(n log n), O(1)>-time "sparse table" algorithm by Bender and Farach-Colton to comput...
Definition: LCA.h:54
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::steiner_tree::SaveStatic::m_root
node m_root
The root of m_tree.
Definition: SaveStatic.h:151
ogdf::steiner_tree::Triple::s0
node s0() const
Definition: Triple.h:50
ogdf::steiner_tree::SaveStatic::m_tree
Graph m_tree
The weighted binary tree to represent the edge weight hierarchy.
Definition: SaveStatic.h:148
basic.h
Basic declarations, included by all source files.
ogdf::steiner_tree::SaveStatic::m_treeEdge
NodeArray< edge > m_treeEdge
Maps each inner node of m_tree to an edge in m_steinerTree.
Definition: SaveStatic.h:149
ogdf::EdgeWeightedGraphCopy
Definition: EdgeWeightedGraphCopy.h:44
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
Save.h
Interface for various LCA methods.
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::steiner_tree::SaveStatic
This class behaves basically the same as SaveDynamic except that the update of the weighted graph is ...
Definition: SaveStatic.h:57