Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ExtendedNestingGraph.h
Go to the documentation of this file.
1
34#pragma once
35
36#include <ogdf/basic/Array.h>
37#include <ogdf/basic/Graph.h>
38#include <ogdf/basic/List.h>
39#include <ogdf/basic/SList.h>
40#include <ogdf/basic/basic.h>
41#include <ogdf/basic/memory.h>
43
44#include <iosfwd>
45#include <limits>
46
47namespace ogdf {
48
51 m_cnClusters = 0;
52 m_cnEdges = 0;
53 }
54
55 RCCrossings(int cnClusters, int cnEdges) {
56 m_cnClusters = cnClusters;
57 m_cnEdges = cnEdges;
58 }
59
60 void incEdges(int cn) { m_cnEdges += cn; }
61
62 void incClusters() { ++m_cnClusters; }
63
65 m_cnClusters += cr.m_cnClusters;
66 m_cnEdges += cr.m_cnEdges;
67 return *this;
68 }
69
71 return RCCrossings(m_cnClusters + cr.m_cnClusters, m_cnEdges + cr.m_cnEdges);
72 }
73
75 return RCCrossings(m_cnClusters - cr.m_cnClusters, m_cnEdges - cr.m_cnEdges);
76 }
77
78 bool operator<=(const RCCrossings& cr) const {
79 if (m_cnClusters == cr.m_cnClusters) {
80 return m_cnEdges <= cr.m_cnEdges;
81 } else {
82 return m_cnClusters <= cr.m_cnClusters;
83 }
84 }
85
86 bool operator<(const RCCrossings& cr) const {
87 if (m_cnClusters == cr.m_cnClusters) {
88 return m_cnEdges < cr.m_cnEdges;
89 } else {
90 return m_cnClusters < cr.m_cnClusters;
91 }
92 }
93
94 bool isZero() const { return m_cnClusters == 0 && m_cnEdges == 0; }
95
97 m_cnClusters = m_cnEdges = std::numeric_limits<int>::max();
98 return *this;
99 }
100
101 static int compare(const RCCrossings& x, const RCCrossings& y) {
102 int dc = y.m_cnClusters - x.m_cnClusters;
103 if (dc != 0) {
104 return dc;
105 }
106 return y.m_cnEdges - x.m_cnEdges;
107 }
108
111};
112
113OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const RCCrossings& cr);
114
116public:
117 enum class Type { Compound, Node, AuxNode };
118
119 struct Adjacency {
121 m_u = nullptr;
122 m_v = nullptr;
123 m_weight = 0;
124 }
125
126 Adjacency(node u, LHTreeNode* vNode, int weight = 1) {
127 m_u = u;
128 m_v = vNode;
129 m_weight = weight;
130 }
131
135
137 };
138
141 m_uc = nullptr;
142 m_u = nullptr;
143 m_cNode = nullptr;
144 m_uNode = nullptr;
145 }
146
147 ClusterCrossing(node uc, LHTreeNode* cNode, node u, LHTreeNode* uNode, edge e) {
148 m_uc = uc;
149 m_u = u;
150 m_cNode = cNode;
151 m_uNode = uNode;
152
153 m_edge = e;
154 }
155
160
162 };
163
164 // Construction
166 m_parent = nullptr;
167 m_origCluster = c;
168 m_node = nullptr;
169 m_type = Type::Compound;
170 m_down = nullptr;
171
172 m_up = up;
173 if (up) {
174 up->m_down = this;
175 }
176 }
177
178 LHTreeNode(LHTreeNode* parent, node v, Type t = Type::Node) {
179 m_parent = parent;
180 m_origCluster = nullptr;
181 m_node = v;
182 m_type = t;
183 m_up = nullptr;
184 m_down = nullptr;
185 }
186
187 // Access functions
188 bool isCompound() const { return m_type == Type::Compound; }
189
190 int numberOfChildren() const { return m_child.size(); }
191
192 const LHTreeNode* parent() const { return m_parent; }
193
194 const LHTreeNode* child(int i) const { return m_child[i]; }
195
196 cluster originalCluster() const { return m_origCluster; }
197
198 node getNode() const { return m_node; }
199
200 const LHTreeNode* up() const { return m_up; }
201
202 const LHTreeNode* down() const { return m_down; }
203
204 int pos() const { return m_pos; }
205
206 // Modification functions
207 LHTreeNode* parent() { return m_parent; }
208
209 void setParent(LHTreeNode* p) { m_parent = p; }
210
211 LHTreeNode* child(int i) { return m_child[i]; }
212
213 void initChild(int n) { m_child.init(n); }
214
215 void setChild(int i, LHTreeNode* p) { m_child[i] = p; }
216
217 void setPos();
218
219 void store() { m_storedChild = m_child; }
220
221 void restore() { m_child = m_storedChild; }
222
223 void permute() { m_child.permute(); }
224
226
231
232private:
234
238
241
244 int m_pos;
245
247};
248
251public:
252 ENGLayer() { m_root = nullptr; }
253
255
256 const LHTreeNode* root() const { return m_root; }
257
258 LHTreeNode* root() { return m_root; }
259
260 void setRoot(LHTreeNode* r) { m_root = r; }
261
262 void store();
263 void restore();
264 void permute();
265
268
269private:
271
273};
274
276
278public:
281
282 void init(const ExtendedNestingGraph& H, const ClusterGraph& CG);
283
284 const ClusterGraph& getOriginalClusterGraph() const { return *m_pCG; }
285
286 cluster copy(cluster cOrig) const { return m_copy[cOrig]; }
287
288 cluster original(cluster cCopy) const { return m_original[cCopy]; }
289
291
292private:
294
297
300};
301
303public:
304 // the type of a node in this copy
305 enum class NodeType { Node, ClusterTop, ClusterBottom, Dummy, ClusterTopBottom };
306
308
309 const ClusterGraphCopy& getClusterGraph() const { return m_CGC; }
310
311 const ClusterGraph& getOriginalClusterGraph() const { return m_CGC.getOriginalClusterGraph(); }
312
313 node copy(node v) const { return m_copy[v]; }
314
315 node top(cluster cOrig) const { return m_topNode[cOrig]; }
316
317 node bottom(cluster cOrig) const { return m_bottomNode[cOrig]; }
318
319 int topRank(cluster c) const { return m_topRank[c]; }
320
321 int bottomRank(cluster c) const { return m_bottomRank[c]; }
322
323 NodeType type(node v) const { return m_type[v]; }
324
325 node origNode(node v) const { return m_origNode[v]; }
326
327 edge origEdge(edge e) const { return m_origEdge[e]; }
328
329 cluster originalCluster(node v) const { return m_CGC.original(m_CGC.clusterOf(v)); }
330
331 cluster parent(node v) const { return m_CGC.clusterOf(v); }
332
333 cluster parent(cluster c) const { return c->parent(); }
334
335 bool isVirtual(cluster c) const { return m_CGC.original(c) == nullptr; }
336
337 const List<edge>& chain(edge e) const { return m_copyEdge[e]; }
338
339 // is edge e reversed ?
340 bool isReversed(edge e) const { return e->source() != origNode(chain(e).front()->source()); }
341
342 bool isLongEdgeDummy(node v) const { return type(v) == NodeType::Dummy && v->outdeg() == 1; }
343
344 bool verticalSegment(edge e) const { return m_vertical[e]; }
345
346 int numberOfLayers() const { return m_numLayers; }
347
348 int rank(node v) const { return m_rank[v]; }
349
350 int pos(node v) const { return m_pos[v]; }
351
352 const LHTreeNode* layerHierarchyTree(int i) const { return m_layer[i].root(); }
353
354 const ENGLayer& layer(int i) const { return m_layer[i]; }
355
356 RCCrossings reduceCrossings(int i, bool dirTopDown);
359 void permute();
360
362
363 int aeLevel(node v) const { return m_aeLevel[v]; }
364
365protected:
366 cluster lca(node u, node v) const;
367 LHTreeNode* lca(LHTreeNode* uNode, LHTreeNode* vNode, LHTreeNode** uChild,
368 LHTreeNode** vChild) const;
369
370 edge addEdge(node u, node v, bool addAlways = false);
371 void assignAeLevel(cluster c, int& count);
372 bool reachable(node v, node u, SListPure<node>& successors);
373 void moveDown(node v, const SListPure<node>& successors, NodeArray<int>& level);
374 bool tryEdge(node u, node v, Graph& G, NodeArray<int>& level);
375
376 RCCrossings reduceCrossings(LHTreeNode* cNode, bool dirTopDown);
377 void assignPos(const LHTreeNode* vNode, int& count);
378
379private:
386
387#if 0
389 const ClusterGraph &m_CG;
390#else
393#endif
394
395 // mapping: nodes in CG <-> nodes in this copy
398
399 // mapping: clusters in CG <-> nodes in this copy
400 ClusterArray<node> m_topNode; // the node representing top-most part of cluster (min. rank)
401 ClusterArray<node> m_bottomNode; // the node representing bottom-most part of cluster (max. rank)
404
405 // the type of a node in this copy
407
408 // mapping: edges in CG <-> edges in this copy
411
412 // level of each node
415
416 // the layers
418 // positions within a layer
420
421 // can an edge segment be drawn vertically?
423
424 // temporary data for "addEdge()"
428
429 // temporary data for "lca()"
436};
437
438}
Declaration and implementation of Array class and Array algorithms.
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Declaration of singly linked lists and iterators.
Basic declarations, included by all source files.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
RegisteredArray for labeling the clusters of a ClusterGraph.
Representation of clusters in a clustered graph.
cluster parent()
Returns the parent of the cluster.
void createClusterTree(cluster cOrig)
const ClusterGraph * m_pCG
ClusterArray< cluster > m_original
ClusterArray< cluster > m_copy
ClusterGraphCopy(const ExtendedNestingGraph &H, const ClusterGraph &CG)
void setParent(node v, cluster c)
cluster original(cluster cCopy) const
const ExtendedNestingGraph * m_pH
const ClusterGraph & getOriginalClusterGraph() const
void init(const ExtendedNestingGraph &H, const ClusterGraph &CG)
cluster copy(cluster cOrig) const
Representation of clustered graphs.
Represents layer in an extended nesting graph.
void removeAuxNodes()
void simplifyAdjacencies(List< LHTreeNode::Adjacency > &adjs)
const LHTreeNode * root() const
void simplifyAdjacencies()
void setRoot(LHTreeNode *r)
Class for the representation of edges.
Definition Graph_d.h:364
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
void assignAeLevel(cluster c, int &count)
RCCrossings reduceCrossings(LHTreeNode *cNode, bool dirTopDown)
SListPure< cluster > m_markedClustersTree
const ClusterGraph & getOriginalClusterGraph() const
void assignPos(const LHTreeNode *vNode, int &count)
const LHTreeNode * layerHierarchyTree(int i) const
EdgeArray< List< edge > > m_copyEdge
ClusterArray< LHTreeNode * > m_markTree
ClusterArray< cluster > m_mark
bool isVirtual(cluster c) const
cluster parent(cluster c) const
const List< edge > & chain(edge e) const
bool reachable(node v, node u, SListPure< node > &successors)
const ENGLayer & layer(int i) const
LHTreeNode * lca(LHTreeNode *uNode, LHTreeNode *vNode, LHTreeNode **uChild, LHTreeNode **vChild) const
ClusterArray< node > m_bottomNode
const ClusterGraphCopy & getClusterGraph() const
edge addEdge(node u, node v, bool addAlways=false)
ClusterGraphCopy m_CGC
copy of original cluster graph
SListPure< cluster > m_markedClusters
ExtendedNestingGraph(const ClusterGraph &CG)
cluster originalCluster(node v) const
node bottom(cluster cOrig) const
bool tryEdge(node u, node v, Graph &G, NodeArray< int > &level)
node top(cluster cOrig) const
cluster lca(node u, node v) const
void moveDown(node v, const SListPure< node > &successors, NodeArray< int > &level)
void createVirtualClusters(cluster c, NodeArray< node > &vCopy, ClusterArray< node > &cCopy)
RCCrossings reduceCrossings(int i, bool dirTopDown)
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
List< ClusterCrossing > m_upperClusterCrossing
Array< LHTreeNode * > m_child
cluster originalCluster() const
void setChild(int i, LHTreeNode *p)
void removeAuxChildren()
List< Adjacency > m_upperAdj
void setParent(LHTreeNode *p)
LHTreeNode * child(int i)
const LHTreeNode * up() const
const LHTreeNode * parent() const
LHTreeNode(LHTreeNode *parent, node v, Type t=Type::Node)
const LHTreeNode * down() const
List< Adjacency > m_lowerAdj
const LHTreeNode * child(int i) const
Array< LHTreeNode * > m_storedChild
LHTreeNode(cluster c, LHTreeNode *up)
List< ClusterCrossing > m_lowerClusterCrossing
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Class for the representation of nodes.
Definition Graph_d.h:241
int outdeg() const
Returns the outdegree of the node.
Definition Graph_d.h:281
Singly linked lists.
Definition SList.h:191
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_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:85
Declaration of memory manager for allocating small pieces of memory.
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
Adjacency(node u, LHTreeNode *vNode, int weight=1)
ClusterCrossing(node uc, LHTreeNode *cNode, node u, LHTreeNode *uNode, edge e)
RCCrossings operator-(const RCCrossings &cr) const
RCCrossings operator+(const RCCrossings &cr) const
bool operator<=(const RCCrossings &cr) const
RCCrossings & setInfinity()
RCCrossings & operator+=(const RCCrossings &cr)
RCCrossings(int cnClusters, int cnEdges)
bool operator<(const RCCrossings &cr) const
static int compare(const RCCrossings &x, const RCCrossings &y)