Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
SPQRTree.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
35#include <ogdf/basic/List.h>
36#include <ogdf/basic/SList.h>
37#include <ogdf/basic/basic.h>
40
41namespace ogdf {
42
74public:
76 enum class NodeType { SNode, PNode, RNode };
77
78 // destructor
79 virtual ~SPQRTree() { }
80
82 SPQRTree(const SPQRTree& copy) = delete;
83 SPQRTree(SPQRTree&& move) = delete;
84 SPQRTree& operator=(const SPQRTree& copy) = delete;
85 SPQRTree& operator=(SPQRTree&& move) = delete;
86
89
91 virtual const Graph& originalGraph() const = 0;
92
94 virtual const Graph& tree() const = 0;
95
97 virtual edge rootEdge() const = 0;
98
100 virtual node rootNode() const = 0;
101
103 virtual int numberOfSNodes() const = 0;
104
106 virtual int numberOfPNodes() const = 0;
107
109 virtual int numberOfRNodes() const = 0;
110
115 virtual NodeType typeOf(node v) const = 0;
116
118 virtual List<node> nodesOfType(NodeType t) const = 0;
119
124 virtual Skeleton& skeleton(node v) const = 0;
125
130 virtual const Skeleton& skeletonOfReal(edge e) const = 0;
131
136 virtual edge copyOfReal(edge e) const = 0;
137
142 void pertinentGraph(node v, PertinentGraph& Gp) const {
143 if (m_cpV == nullptr) {
144 m_cpV = new NodeArray<node>(originalGraph(), nullptr);
145 }
146 NodeArray<node>& cpV = *m_cpV;
147
148 Gp.init(v);
149 cpRec(v, Gp);
150
151 const Skeleton& S = skeleton(v);
152
153 edge e = Gp.m_skRefEdge = S.referenceEdge();
154 if (e != nullptr) {
155 e = Gp.m_P.newEdge(cpV[S.original(e->source())], cpV[S.original(e->target())]);
156 }
157 Gp.m_vEdge = e;
158
159 while (!m_cpVAdded.empty()) {
160 cpV[m_cpVAdded.popFrontRet()] = nullptr;
161 }
162 }
163
167
172 virtual node rootTreeAt(edge e) = 0;
173
178 virtual node rootTreeAt(node v) = 0;
179
180 void directSkEdge(node vT, edge e, node src) {
181 OGDF_ASSERT(e != nullptr);
182 OGDF_ASSERT(src == e->source() || src == e->target());
183
184 if (e->source() != src) {
185 skeleton(vT).getGraph().reverseEdge(e);
186 }
187 }
188
190 Graph& M = skeleton(vT).getGraph();
191 M.reverseEdge(M.split(e));
192 }
193
194 // !@}
195
196protected:
201 virtual void cpRec(node v, PertinentGraph& Gp) const = 0;
202
204 edge cpAddEdge(edge eOrig, PertinentGraph& Gp) const {
205 edge eP = Gp.m_P.newEdge(cpAddNode(eOrig->source(), Gp), cpAddNode(eOrig->target(), Gp));
206 Gp.m_origE[eP] = eOrig;
207 return eP;
208 }
209
211 node cpAddNode(node vOrig, PertinentGraph& Gp) const {
212 node& vP = (*m_cpV)[vOrig];
213 if (vP == nullptr) {
214 m_cpVAdded.pushBack(vOrig);
215 Gp.m_origV[vP = Gp.m_P.newNode()] = vOrig;
216 }
217 return vP;
218 }
219
220 // auxiliary members used for computing pertinent graphs
223};
224
225}
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Declaration of class PertinentGraph.
Declaration of singly linked lists and iterators.
Declaration of class Skeleton.
Basic declarations, included by all source files.
Class for the representation of edges.
Definition Graph_d.h:364
node target() const
Returns the target node of the edge.
Definition Graph_d.h:402
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
void reverseEdge(edge e)
Reverses the edge e, i.e., exchanges source and target node.
node newNode(int index=-1)
Creates a new node and returns it.
Definition Graph_d.h:1061
edge newEdge(node v, node w, int index=-1)
Creates a new edge (v,w) and returns it.
Definition Graph_d.h:1080
virtual edge split(edge e)
Splits edge e into two edges introducing a new node.
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Class for the representation of nodes.
Definition Graph_d.h:241
Pertinent graphs of nodes in an SPQR-tree.
edge m_vEdge
reference edge (in m_P)
edge m_skRefEdge
reference edge (in skeleton(m_vT))
Graph m_P
actual graph
EdgeArray< edge > m_origE
corresp.
NodeArray< node > m_origV
corresp.
void init(node vT)
Initialization of a pertinent graph of tree node vT.
Singly linked lists (maintaining the length of the list).
Definition SList.h:845
Linear-time implementation of static SPQR-trees.
Definition SPQRTree.h:73
virtual List< node > nodesOfType(NodeType t) const =0
Returns the list of all nodes with type t.
virtual int numberOfSNodes() const =0
Returns the number of S-nodes in T.
virtual edge copyOfReal(edge e) const =0
Returns the skeleton edge that corresponds to the real edge e.
node cpAddNode(node vOrig, PertinentGraph &Gp) const
Add a node to Gp corresponding to vOrig if required.
Definition SPQRTree.h:211
SPQRTree & operator=(const SPQRTree &copy)=delete
edge cpAddEdge(edge eOrig, PertinentGraph &Gp) const
Add an edge to Gp corresponding to eOrig.
Definition SPQRTree.h:204
virtual NodeType typeOf(node v) const =0
Returns the type of node v.
SPQRTree(SPQRTree &&move)=delete
void pertinentGraph(node v, PertinentGraph &Gp) const
Returns the pertinent graph of tree node v in Gp.
Definition SPQRTree.h:142
void replaceSkEdgeByPeak(node vT, edge e)
Definition SPQRTree.h:189
SPQRTree(const SPQRTree &copy)=delete
virtual const Graph & tree() const =0
Returns a reference to the tree T.
virtual node rootTreeAt(node v)=0
Roots T at node v and returns v.
virtual int numberOfPNodes() const =0
Returns the number of P-nodes in T.
NodeArray< node > * m_cpV
node in pertinent graph corresponding to an original node (auxiliary member)
Definition SPQRTree.h:221
virtual void cpRec(node v, PertinentGraph &Gp) const =0
Recursively performs the task of adding edges (and nodes) to the pertinent graph Gp for each involved...
SList< node > m_cpVAdded
list of added nodes (auxiliary member)
Definition SPQRTree.h:222
SPQRTree & operator=(SPQRTree &&move)=delete
void directSkEdge(node vT, edge e, node src)
Definition SPQRTree.h:180
virtual const Graph & originalGraph() const =0
Returns a reference to the original graph G.
virtual int numberOfRNodes() const =0
Returns the number of R-nodes in T.
virtual edge rootEdge() const =0
Returns the edge of G at which T is rooted.
virtual Skeleton & skeleton(node v) const =0
Returns the skeleton of node v.
virtual const Skeleton & skeletonOfReal(edge e) const =0
Returns the skeleton that contains the real edge e.
NodeType
The type of a tree node in T.
Definition SPQRTree.h:76
virtual node rootNode() const =0
Returns the root node of T.
virtual ~SPQRTree()
Definition SPQRTree.h:79
virtual node rootTreeAt(edge e)=0
Roots T at edge e and returns the new root node of T.
Skeleton graphs of nodes in an SPQR-tree.
Definition Skeleton.h:60
virtual node original(node v) const =0
Returns the vertex in the original graph G that corresponds to v.
edge referenceEdge() const
Returns the reference edge of S in M.
Definition Skeleton.h:87
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.