Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
DynamicSPQRForest.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/basic.h>
39
40#include <iosfwd>
41
42namespace ogdf {
43template<class E>
44class SList;
45
57public:
59 enum class TNodeType {
60 SComp = static_cast<int>(
61 SPQRTree::NodeType::SNode),
62 PComp = static_cast<int>(
63 SPQRTree::NodeType::PNode),
64 RComp = static_cast<int>(
65 SPQRTree::NodeType::RNode)
66 };
67
68protected:
70 mutable Graph m_T;
71
80
90
100
111
115
118
121
125
129
132
136
140
144
146 void init();
147
158 inline node newSPQRNode(node vB, const TNodeType spqrNodeType) const {
159 node vT = m_T.newNode();
160 m_tNode_owner[vT] = vT;
161 m_tNode_type[vT] = spqrNodeType;
162 m_tNode_hEdges[vT] = new List<edge>;
163
164 if (spqrNodeType == TNodeType::PComp) {
165 m_bNode_numP[vB]++;
166 } else if (spqrNodeType == TNodeType::SComp) {
167 m_bNode_numS[vB]++;
168 } else if (spqrNodeType == TNodeType::RComp) {
169 m_bNode_numR[vB]++;
170 }
171
172 return vT;
173 }
174
181 inline void addHEdge(edge eH, node vT) const {
182 m_hEdge_position[eH] = m_tNode_hEdges[vT]->pushBack(eH);
183 m_hEdge_tNode[eH] = vT;
184 }
185
193 inline void delHEdge(edge eH, node vT) const {
194 m_tNode_hEdges[vT]->del(m_hEdge_position[eH]);
195 m_H.delEdge(eH);
196 }
197
205 inline edge newTwinEdge(edge eH, node vT) const {
206 edge fH = m_H.newEdge(eH->source(), eH->target());
207 addHEdge(fH, vT);
208 m_hEdge_twinEdge[eH] = fH;
209 m_hEdge_twinEdge[fH] = eH;
210 return fH;
211 }
212
227
235 node findSPQR(node vT) const;
237
249 node findNCASPQR(node sT, node tT) const;
250
264 SList<node>& findPathSPQR(node sH, node tH, node& rT) const;
266
281
297
298public:
309 explicit DynamicSPQRForest(Graph& G, bool not_connected = false)
310 : DynamicSPQRForest(G, nullptr, not_connected) { }
311
323 DynamicSPQRForest(Graph& G, node vG, bool not_connected = false)
324 : DynamicBCTree(G, vG, not_connected) {
325 init();
326 }
327
329 for (auto pList : m_tNode_hEdges) {
330 delete pList;
331 }
332 }
333
345 node spqrproper(edge eH) const { return m_hEdge_tNode[eH] = findSPQR(m_hEdge_tNode[eH]); }
346
362 void createSPQR(node vB) const;
363
371 node spqrroot(node vB) const { return m_bNode_SPQR[vB]; }
372
380 int numberOfSNodes(node vB) const { return m_bNode_numS[vB]; }
381
389 int numberOfPNodes(node vB) const { return m_bNode_numP[vB]; }
390
398 int numberOfRNodes(node vB) const { return m_bNode_numR[vB]; }
399
401 const Graph& spqrTree() const { return m_T; }
402
404 node spqrParent(node vT) const {
405 edge p_e = m_tNode_hRefEdge[vT];
406 if (p_e == nullptr) {
407 return nullptr;
408 }
409 edge p_et = twinEdge(p_e);
410 OGDF_ASSERT(p_et != nullptr);
411 node p = m_hEdge_tNode[p_et];
412 OGDF_ASSERT(p != nullptr);
413 OGDF_ASSERT(m_T.searchEdge(vT, p) != nullptr);
414 return p;
415 }
416
418 edge spqrParentEdge(node vT) const { return m_tNode_hRefEdge[vT]; }
419
421 node spqrNodeOf(edge eH) const { return m_hEdge_tNode[eH]; }
422
430 edge twinEdge(edge eH) const { return m_hEdge_twinEdge[eH]; }
431
433
444 TNodeType typeOfTNode(node vT) const { return m_tNode_type[vT]; }
445
457 const List<edge>& hEdgesSPQR(node vT) const { return *m_tNode_hEdges[vT]; }
458
472
488 edge virtualEdge(node vT, node wT) const;
490
505
521
523};
524
525OGDF_EXPORT std::ostream& operator<<(std::ostream& os, DynamicSPQRForest::TNodeType t);
526
527}
Declaration of class DynamicBCTree.
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Declaration of class SPQRTree.
Basic declarations, included by all source files.
Dynamic BC-trees.
Dynamic SPQR-forest.
Graph m_T
A Graph structure containing all SPQR-trees.
int numberOfSNodes(node vB) const
Returns the number of S-nodes in the SPQR-tree for a given B-component of the BC-tree.
node spqrroot(node vB) const
Returns the root of the SPQR-tree for a given B-component of the BC-tree.
void delHEdge(edge eH, node vT) const
Deletes edge eH from m_H and removes its connection to a vertex vT of the SPQRForest.
node spqrNodeOf(edge eH) const
The SPQR-tree-vertex which a real or virtual edge eH belongs to, if the SPQR-tree has been created us...
NodeArray< int > m_bNode_numS
The numbers of S-components.
void addHEdge(edge eH, node vT) const
Adds edge eH to a vertex vT of the SPQRForest.
NodeArray< TNodeType > m_tNode_type
The types of the SPQR-tree-vertices.
node updateInsertedNode(edge eG, edge fG) override
Updates the whole data structure after a new vertex has been inserted into the original graph by spli...
EdgeArray< ListIterator< edge > > m_hEdge_position
The positions of real and virtual edges in their m_tNode_hEdges lists.
edge updateInsertedEdgeSPQR(node vB, edge eG)
int numberOfRNodes(node vB) const
Returns the number of R-nodes in the SPQR-tree for a given B-component of the BC-tree.
NodeArray< List< edge > * > m_tNode_hEdges
Lists of real and virtual edges belonging to SPQR-tree vertices.
NodeArray< node > m_bNode_SPQR
SList< node > & findPathSPQR(node sH, node tH) const
Finds the shortest path between the two sets of SPQR-tree-vertices which sH and tH are belonging to.
node findSPQR(node vT) const
Finds the proper representative of an SPQR-tree-vertex (FIND part of UNION/FIND).
node updateInsertedNodeSPQR(node vB, edge eG, edge fG)
Updates an SPQR-tree after a new vertex has been inserted into the original graph by splitting an edg...
DynamicSPQRForest(Graph &G, node vG, bool not_connected=false)
A constructor.
void init()
Initialization.
const List< edge > & hEdgesSPQR(node vT) const
Returns a linear list of the edges in m_H belonging to the triconnected component represented by a gi...
edge updateInsertedEdge(edge eG) override
NodeArray< bool > m_tNode_isMarked
Auxiliary array used by findNCASPQR()
node uniteSPQR(node vB, node sT, node tT)
int numberOfPNodes(node vB) const
Returns the number of P-nodes in the SPQR-tree for a given B-component of the BC-tree.
node spqrproper(edge eH) const
const Graph & spqrTree() const
Returns the SPQR-tree graph.
NodeArray< int > m_bNode_numP
The numbers of P-components.
node spqrParent(node vT) const
Returns the parent node of a node of the SPQR-tree Graph, or nullptr if vT is a root.
void createSPQR(node vB) const
Creates the SPQR-tree for a given B-component of the BC-tree.
EdgeArray< node > m_hEdge_tNode
The SPQR-tree-vertices which the real and virtual edges are belonging to.
NodeArray< node > m_tNode_owner
The owners of the SPQR-tree-vertices in the UNION/FIND structure.
TNodeType typeOfTNode(node vT) const
edge virtualEdge(node vT, node wT) const
Returns the virtual edge which leads from one vertex of an SPQR-tree to another one.
edge twinEdge(edge eH) const
Returns the twin edge of a given edge of m_H, if it is virtual, or nullptr, if it is real.
node newSPQRNode(node vB, const TNodeType spqrNodeType) const
Creates a new node in the SPQR-tree for a given B-component of the BC-tree.
SList< node > & findPathSPQR(node sH, node tH, node &rT) const
Finds the shortest path between the two sets of SPQR-tree-vertices which sH and tH are belonging to.
node findNCASPQR(node sT, node tT) const
edge spqrParentEdge(node vT) const
Returns the virtual edge leading to the parents of a SPQR-tree vertex, or nullptr if vT is a root.
NodeArray< edge > m_tNode_hRefEdge
The virtual edges leading to the parents of the SPQR-tree vertices.
NodeArray< node > m_htogc
Auxiliary array used by createSPQR().
edge newTwinEdge(edge eH, node vT) const
Creates a twin edge for eH, adds it to vT and returns it.
NodeArray< int > m_bNode_numR
The numbers of R-components.
DynamicSPQRForest(Graph &G, bool not_connected=false)
A constructor.
TNodeType
Enumeration type for characterizing the SPQR-tree-vertices.
EdgeArray< edge > m_hEdge_twinEdge
The partners of virtual edges (nullptr if real).
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
node newNode(int index=-1)
Creates a new node and returns it.
Definition Graph_d.h:1061
edge searchEdge(node v, node w, bool directed=false) const
Searches and returns an edge connecting nodes v and w in time O( min(deg(v ), deg(w ))).
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Class for the representation of nodes.
Definition Graph_d.h:241
Singly linked lists (maintaining the length of the list).
Definition SList.h:845
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
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.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:983