Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Graph_d.h
Go to the documentation of this file.
1
35#pragma once
36
39
40#include <array>
41#include <mutex>
42
43#ifdef OGDF_DEBUG
44# include <set>
45#endif
46
47namespace ogdf {
48
49//
50// in embedded graphs, adjacency lists are given in clockwise order.
51//
52
53
54class OGDF_EXPORT Graph;
55class OGDF_EXPORT NodeElement;
56class OGDF_EXPORT EdgeElement;
57class OGDF_EXPORT AdjElement;
58class OGDF_EXPORT FaceElement;
59class OGDF_EXPORT ClusterElement;
60
61
65
69
73
75
80 friend class Graph;
82 friend class internal::GraphList<AdjElement>;
83
87 int m_id;
88
90 explicit AdjElement(node v) : m_twin(nullptr), m_edge(nullptr), m_node(v), m_id(0) { }
91
93 AdjElement(edge e, int id) : m_twin(nullptr), m_edge(e), m_node(nullptr), m_id(id) { }
94
95public:
97 edge theEdge() const { return m_edge; }
98
100 operator edge() const { return m_edge; }
101
103 node theNode() const { return m_node; }
104
106 operator node() const { return m_node; }
107
109 adjEntry twin() const { return m_twin; }
110
112 node twinNode() const { return m_twin->m_node; }
113
115 int index() const { return m_id; }
116
118 bool isSource() const;
119
130 bool isBetween(adjEntry adjBefore, adjEntry adjAfter) const;
131
132 // traversing faces in clockwise (resp. counter-clockwise) order
133 // (if face is an interior face)
134
136 adjEntry clockwiseFaceSucc() const { return m_twin->cyclicPred(); }
137
139 adjEntry clockwiseFacePred() const { return cyclicSucc()->m_twin; }
140
142 adjEntry counterClockwiseFaceSucc() const { return m_twin->cyclicSucc(); }
143
145 adjEntry counterClockwiseFacePred() const { return cyclicPred()->m_twin; }
146
147 // default is traversing faces in clockwise order
149 adjEntry faceCycleSucc() const { return clockwiseFaceSucc(); }
150
152 adjEntry faceCyclePred() const { return clockwiseFacePred(); }
153
155 adjEntry succ() const { return static_cast<adjEntry>(m_next); }
156
158 adjEntry pred() const { return static_cast<adjEntry>(m_prev); }
159
161 adjEntry cyclicSucc() const;
163 adjEntry cyclicPred() const;
164
165#ifdef OGDF_DEBUG
166 const Graph* graphOf() const;
167#endif
168
170 static int compare(const AdjElement& x, const AdjElement& y) { return x.m_id - y.m_id; }
172
174};
175
178 friend class Graph;
179 friend class internal::GraphList<NodeElement>;
180
181 //GraphList<AdjElement> m_adjEdges; //!< The adjacency list of the node.
184 int m_id;
185
186#ifdef OGDF_DEBUG
187 // we store the graph containing this node for debugging purposes
188 const Graph* m_pGraph;
189#endif
190
191
193#ifdef OGDF_DEBUG
199 NodeElement(const Graph* pGraph, int id)
200 : m_indeg(0), m_outdeg(0), m_id(id), m_pGraph(pGraph) { }
201#else
202 NodeElement(int id) : m_indeg(0), m_outdeg(0), m_id(id) { }
203#endif
204
205
206public:
209
211 int index() const { return m_id; }
212
214 int indeg() const { return m_indeg; }
215
217 int outdeg() const { return m_outdeg; }
218
220 int degree() const { return m_indeg + m_outdeg; }
221
223 adjEntry firstAdj() const { return adjEntries.head(); }
224
226 adjEntry lastAdj() const { return adjEntries.tail(); }
227
229 node succ() const { return static_cast<node>(m_next); }
230
232 node pred() const { return static_cast<node>(m_prev); }
233
235
239 template<class ADJLIST>
241 adjList.clear();
242 for (adjEntry adj : this->adjEntries) {
243 adjList.pushBack(adj);
244 }
245 }
246
248
255 template<class EDGELIST>
256 void adjEdges(EDGELIST& edgeList) const {
257 edgeList.clear();
258 for (adjEntry adj : this->adjEntries) {
259 edgeList.pushBack(adj->theEdge());
260 }
261 }
262
264
268 template<class EDGELIST>
269 void inEdges(EDGELIST& edgeList) const;
270
272
276 template<class EDGELIST>
277 void outEdges(EDGELIST& edgeList) const;
278
279#ifdef OGDF_DEBUG
281 const Graph* graphOf() const { return m_pGraph; }
282#endif
283
285 static int compare(const NodeElement& x, const NodeElement& y) { return x.m_id - y.m_id; }
287
289};
290
292 return (m_next) ? static_cast<adjEntry>(m_next) : m_node->firstAdj();
293}
294
296 return (m_prev) ? static_cast<adjEntry>(m_prev) : m_node->lastAdj();
297}
298
301 friend class Graph;
302 friend class internal::GraphList<EdgeElement>;
303
308 int m_id; // The (unique) index of the node.
309
311
319 : m_src(src), m_tgt(tgt), m_adjSrc(adjSrc), m_adjTgt(adjTgt), m_id(id) { }
320
322
327 EdgeElement(node src, node tgt, int id)
328 : m_src(src), m_tgt(tgt), m_adjSrc(nullptr), m_adjTgt(nullptr), m_id(id) { }
329
330public:
332 int index() const { return m_id; }
333
335 node source() const { return m_src; }
336
338 node target() const { return m_tgt; }
339
341 std::array<node, 2> nodes() const { return std::array<node, 2> {{m_src, m_tgt}}; }
342
344 adjEntry adjSource() const { return m_adjSrc; }
345
347 adjEntry adjTarget() const { return m_adjTgt; }
348
350 node opposite(node v) const {
351 OGDF_ASSERT(isIncident(v));
352 return v == m_src ? m_tgt : m_src;
353 }
354
356 bool isSelfLoop() const { return m_src == m_tgt; }
357
359 bool isInvertedDirected(edge e) const { return m_src == e->target() && m_tgt == e->source(); }
360
362 bool isParallelDirected(edge e) const { return m_src == e->source() && m_tgt == e->target(); }
363
366 return isParallelDirected(e) || isInvertedDirected(e);
367 }
368
370 edge succ() const { return static_cast<edge>(m_next); }
371
373 edge pred() const { return static_cast<edge>(m_prev); }
374
375#ifdef OGDF_DEBUG
377 const Graph* graphOf() const { return m_src->graphOf(); }
378#endif
379
381 bool isIncident(node v) const { return v == m_src || v == m_tgt; }
382
384 bool isAdjacent(edge e) const { return isIncident(e->m_src) || isIncident(e->m_tgt); }
385
388 return (m_src == e->m_src || m_src == e->m_tgt)
389 ? m_src
390 : ((m_tgt == e->m_src || m_tgt == e->m_tgt) ? m_tgt : nullptr);
391 }
392
396 OGDF_ASSERT(this->isIncident(v));
397 return v == m_src ? m_adjSrc : m_adjTgt;
398 }
399
401 static int compare(const EdgeElement& x, const EdgeElement& y) { return x.m_id - y.m_id; }
403
405
406#ifdef OGDF_DEBUG
407private:
408 bool m_hidden = false;
409#endif
410};
411
412#ifdef OGDF_DEBUG
413inline const Graph* AdjElement::graphOf() const { return m_node->graphOf(); }
414#endif
415
416inline bool AdjElement::isSource() const { return this == m_edge->adjSource(); }
417
419#ifdef OGDF_DEBUG
420 node v = this->theNode();
421 OGDF_ASSERT(adjBefore->theNode() == v);
422 OGDF_ASSERT(adjAfter->theNode() == v);
423#endif
424 bool result = this != adjBefore && this != adjAfter && adjBefore != adjAfter;
425
426 if (result) {
427 adjEntry adj = adjBefore;
428 for (; adj != this && adj != adjAfter; adj = adj->cyclicSucc()) {
429 ;
430 }
431 result = adj == this;
432 }
433
434 return result;
435}
436
437template<class EDGELIST>
438void NodeElement::inEdges(EDGELIST& edgeList) const {
439 edgeList.clear();
440 for (adjEntry adj : this->adjEntries) {
441 edge e = adj->theEdge();
442 if (adj == e->adjTarget()) {
443 edgeList.pushBack(e);
444 }
445 }
446}
447
448template<class EDGELIST>
449void NodeElement::outEdges(EDGELIST& edgeList) const {
450 edgeList.clear();
451 for (adjEntry adj : this->adjEntries) {
452 edge e = adj->theEdge();
453 if (adj == e->adjSource()) {
454 edgeList.pushBack(e);
455 }
456 }
457}
458
459class NodeArrayBase;
460class EdgeArrayBase;
462template<class T>
463class NodeArray;
464template<class T>
465class EdgeArray;
466template<class T>
467class AdjEntryArray;
469
470namespace internal {
471template<typename CONTAINER>
472inline void getAllNodes(const Graph& G, CONTAINER& nodes);
473template<typename CONTAINER>
474inline void getAllEdges(const Graph& G, CONTAINER& edges);
475}
476
478
522public:
523 class HiddenEdgeSet;
524
525private:
528
531
536
537#ifndef OGDF_MEMORY_POOL_NTS
538 mutable std::mutex m_mutexRegArrays;
539#endif
540
542
543public:
550
557
559
564
566 enum class EdgeType { association = 0, generalization = 1, dependency = 2 };
567
569 enum class NodeType {
570 vertex = 0,
571 dummy = 1,
572 generalizationMerger = 2,
573 generalizationExpander = 3,
574 highDegreeExpander = 4,
575 lowDegreeExpander = 5,
576 associationClass = 6
577 };
578
580
581
587
590
593
595
596
599
601
608 Graph(const Graph& G);
609
611 virtual ~Graph();
612
617
619 bool empty() const { return nodes.empty(); }
620
622 int numberOfNodes() const { return nodes.size(); }
623
625 int numberOfEdges() const { return edges.size(); }
626
628 int maxNodeIndex() const { return m_nodeIdCount - 1; }
629
631 int maxEdgeIndex() const { return m_edgeIdCount - 1; }
632
634 int maxAdjEntryIndex() const { return (m_edgeIdCount << 1) - 1; }
635
637 int nodeArrayTableSize() const { return m_nodeArrayTableSize; }
638
640 int edgeArrayTableSize() const { return m_edgeArrayTableSize; }
641
643 int adjEntryArrayTableSize() const { return m_edgeArrayTableSize << 1; }
644
646 node firstNode() const { return nodes.head(); }
647
649 node lastNode() const { return nodes.tail(); }
650
652 edge firstEdge() const { return edges.head(); }
653
655 edge lastEdge() const { return edges.tail(); }
656
665 std::function<bool(node)> includeNode = [](node) { return true; },
666 bool isFastTest = true) const;
667
676 std::function<bool(edge)> includeEdge = [](edge) { return true; },
677 bool isFastTest = true) const;
678
680
684 template<class CONTAINER>
686 internal::getAllNodes<CONTAINER>(*this, nodeContainer);
687 }
688
690
694 template<class CONTAINER>
696 internal::getAllEdges<CONTAINER>(*this, edgeContainer);
697 }
698
700
704
707
709
718 node newNode(int index);
719
721
727
729
740 edge newEdge(node v, node w, int index);
741
743
757
759
770
772
783
784
786
790
792 virtual void delNode(node v);
793
795 virtual void delEdge(edge e);
796
798 virtual void clear();
799
801
822 friend class Graph;
823 friend class EdgeElement;
824
825 public:
831 explicit HiddenEdgeSet(Graph& graph) : m_graph(&graph) {
832 m_it = m_graph->m_hiddenEdgeSets.pushFront(this);
833 }
834
839 if (m_graph) {
840 restore();
841 m_graph->m_hiddenEdgeSets.del(m_it);
842 }
843 }
844
851 void hide(edge e);
852
859 void restore(edge e);
860
867 void restore();
868
872 int size();
873
874 private:
878
879 // prevent copying
882 };
883
888
893 void insert(const Graph& G, NodeArray<node>& nodeMap);
894
896
899 void insert(const Graph& G);
900
902
911 virtual edge split(edge e);
912
914
923 void unsplit(node u);
924
926
937 virtual void unsplit(edge eIn, edge eOut);
938
940
962
964
972 node contract(edge e, bool keepSelfLoops = false);
973
975
990
992
998 void moveTarget(edge e, node w);
999
1001
1010
1012
1019
1021
1030
1032
1040 edge searchEdge(node v, node w, bool directed = false) const;
1041
1044
1047
1049
1055 template<class NODELIST>
1057 node v = nodesToCollapse.popFrontRet();
1058 while (!nodesToCollapse.empty()) {
1059 node w = nodesToCollapse.popFrontRet();
1060 adjEntry adj = w->firstAdj();
1061 while (adj != nullptr) {
1062 adjEntry succ = adj->succ();
1063 edge e = adj->theEdge();
1064 if (e->source() == v || e->target() == v) {
1065 delEdge(e);
1066 } else if (e->source() == w) {
1067 moveSource(e, v);
1068 } else {
1069 moveTarget(e, v);
1070 }
1071 adj = succ;
1072 }
1073 delNode(w);
1074 }
1075 }
1076
1078
1085 template<class ADJ_ENTRY_LIST>
1086 void sort(node v, const ADJ_ENTRY_LIST& newOrder) {
1087#ifdef OGDF_DEBUG
1088 std::set<int> entries;
1089 int counter = 0;
1090
1091 for (adjEntry adj : newOrder) {
1092 entries.insert(adj->index());
1093 OGDF_ASSERT(adj->theNode() == v);
1094 counter++;
1095 }
1096
1097 OGDF_ASSERT(counter == v->degree());
1098 OGDF_ASSERT(entries.size() == static_cast<unsigned int>(v->degree()));
1099#endif
1100 v->adjEntries.sort(newOrder);
1101 }
1102
1104
1107 void reverseAdjEdges(node v) { v->adjEntries.reverse(); }
1108
1110
1118 OGDF_ASSERT(adjMove != nullptr);
1119 OGDF_ASSERT(adjPos != nullptr);
1120 OGDF_ASSERT(adjMove->graphOf() == this);
1121 OGDF_ASSERT(adjPos->graphOf() == this);
1122 internal::GraphList<AdjElement>& adjList = adjMove->m_node->adjEntries;
1124 }
1125
1127
1134 OGDF_ASSERT(adjMove != nullptr);
1135 OGDF_ASSERT(adjAfter != nullptr);
1136 OGDF_ASSERT(adjMove->graphOf() == this);
1137 OGDF_ASSERT(adjAfter->graphOf() == this);
1138 adjMove->m_node->adjEntries.moveAfter(adjMove, adjAfter);
1139 }
1140
1142
1149 OGDF_ASSERT(adjMove != nullptr);
1150 OGDF_ASSERT(adjBefore != nullptr);
1151 OGDF_ASSERT(adjMove->graphOf() == this);
1152 OGDF_ASSERT(adjBefore->graphOf() == this);
1153 adjMove->m_node->adjEntries.moveBefore(adjMove, adjBefore);
1154 }
1155
1158
1160
1167 OGDF_ASSERT(adj1->theNode() == adj2->theNode());
1168 OGDF_ASSERT(adj1->graphOf() == this);
1169
1170 adj1->theNode()->adjEntries.swap(adj1, adj2);
1171 }
1172
1174
1178
1180
1190 int genus() const;
1191
1193
1196 bool representsCombEmbedding() const { return genus() == 0; }
1197
1198#ifdef OGDF_DEBUG
1200 void consistencyCheck() const;
1201#endif
1202
1204
1210
1212
1220
1222
1230
1232
1241
1243
1250
1252
1257
1259
1264
1266
1271
1273
1278
1280 template<class ArrayBase>
1282#ifndef OGDF_MEMORY_POOL_NTS
1283 std::lock_guard<std::mutex> guard(m_mutexRegArrays);
1284#endif
1285 *it = pArray;
1286 }
1287
1289
1314 void resetEdgeIdCount(int maxId);
1315
1316
1318
1323
1332
1334
1336
1337public:
1342
1347
1348 public:
1350 CCsInfo() : m_graph(nullptr), m_numCC(0) { }
1351
1353 explicit CCsInfo(const Graph& G);
1354
1356 const Graph& constGraph() const { return *m_graph; }
1357
1359 int numberOfCCs() const { return m_numCC; }
1360
1362 int numberOfNodes(int cc) const { return stopNode(cc) - startNode(cc); }
1363
1365 int numberOfEdges(int cc) const { return stopEdge(cc) - startEdge(cc); }
1366
1368 int startNode(int cc) const { return m_startNode[cc]; }
1369
1371 int stopNode(int cc) const { return m_startNode[cc + 1]; }
1372
1374 int startEdge(int cc) const { return m_startEdge[cc]; }
1375
1377 int stopEdge(int cc) const { return m_startEdge[cc + 1]; }
1378
1380 node v(int i) const { return m_nodes[i]; }
1381
1383 edge e(int i) const { return m_edges[i]; }
1384 };
1385
1386protected:
1388
1390
1392
1398
1401
1405
1406private:
1408 void copy(const Graph& G);
1409
1412
1413 // moves adjacency entry to node w
1414 void moveAdj(adjEntry adj, node w);
1415
1420
1425
1430};
1431
1432OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const Graph::EdgeType& et);
1433
1436public:
1438 int getBucket(const edge& e) override { return e->source()->index(); }
1439};
1440
1443public:
1445 int getBucket(const edge& e) override { return e->target()->index(); }
1446};
1447
1448namespace internal {
1449
1450template<typename CONTAINER>
1451inline void getAllNodes(const Graph& G, CONTAINER& nodes) {
1452 nodes.clear();
1453 for (node v : G.nodes) {
1454 nodes.pushBack(v);
1455 }
1456}
1457
1458template<>
1459inline void getAllNodes(const Graph& G, Array<node>& nodes) {
1460 nodes.init(G.numberOfNodes());
1461 int i = 0;
1462 for (node v : G.nodes) {
1463 nodes[i++] = v;
1464 }
1465}
1466
1467template<typename CONTAINER>
1468inline void getAllEdges(const Graph& G, CONTAINER& edges) {
1469 edges.clear();
1470 for (edge v : G.edges) {
1471 edges.pushBack(v);
1472 }
1473}
1474
1475template<>
1476inline void getAllEdges(const Graph& G, Array<edge>& edges) {
1477 edges.init(G.numberOfEdges());
1478 int i = 0;
1479 for (edge v : G.edges) {
1480 edges[i++] = v;
1481 }
1482}
1483
1484}
1485
1486struct NodePair {
1487 node source = nullptr;
1488 node target = nullptr;
1489 NodePair() = default;
1490
1491 NodePair(node src, node tgt) : source(src), target(tgt) { }
1492};
1493
1494inline std::ostream& operator<<(std::ostream& os, const NodePair& np) {
1495 os << "(" << np.source << "," << np.target << ")";
1496 return os;
1497}
1498
1499}
Decralation of GraphElement and GraphList classes.
Class for adjacency list elements.
Definition Graph_d.h:79
adjEntry faceCyclePred() const
Returns the cyclic predecessor in face.
Definition Graph_d.h:152
adjEntry pred() const
Returns the predecessor in the adjacency list.
Definition Graph_d.h:158
int index() const
Returns the index of this adjacency element.
Definition Graph_d.h:115
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition Graph_d.h:109
bool isBetween(adjEntry adjBefore, adjEntry adjAfter) const
Returns whether this adjacency entry lies between adjBefore and adjAfter in clockwise rotation.
Definition Graph_d.h:418
adjEntry clockwiseFaceSucc() const
Returns the clockwise successor in face. Use faceCycleSucc instead!
Definition Graph_d.h:136
AdjElement * m_twin
The corresponding adjacency entry (same edge)
Definition Graph_d.h:84
int m_id
The (unique) index of the adjacency entry.
Definition Graph_d.h:87
adjEntry counterClockwiseFaceSucc() const
Returns the counter-clockwise successor in face.
Definition Graph_d.h:142
static int compare(const AdjElement &x, const AdjElement &y)
Standard Comparer.
Definition Graph_d.h:170
edge m_edge
The associated edge.
Definition Graph_d.h:85
adjEntry counterClockwiseFacePred() const
Returns the counter-clockwise predecessor in face.
Definition Graph_d.h:145
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
Definition Graph_d.h:291
AdjElement(node v)
Constructs an adjacency element for a given node.
Definition Graph_d.h:90
adjEntry succ() const
Returns the successor in the adjacency list.
Definition Graph_d.h:155
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition Graph_d.h:97
adjEntry clockwiseFacePred() const
Returns the clockwise predecessor in face. Use faceCycleSucc instead!
Definition Graph_d.h:139
bool isSource() const
Returns true iff this is the source adjacency entry of the corresponding edge.
Definition Graph_d.h:416
node m_node
The node whose adjacency list contains this entry.
Definition Graph_d.h:86
adjEntry cyclicPred() const
Returns the cyclic predecessor in the adjacency list.
Definition Graph_d.h:295
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition Graph_d.h:112
node theNode() const
Returns the node whose adjacency list contains this element.
Definition Graph_d.h:103
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition Graph_d.h:149
AdjElement(edge e, int id)
Constructs an adjacency entry for a given edge and index.
Definition Graph_d.h:93
Abstract base class for adjacency entry arrays.
Dynamic arrays indexed with adjacency entries.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
void init()
Reinitializes the array to an array with empty index set.
Definition Array.h:367
Abstract base class for bucket functions.
Definition basic.h:241
Bucket function using the index of an edge's source node as bucket.
Definition Graph_d.h:1435
int getBucket(const edge &e) override
Returns source index of e.
Definition Graph_d.h:1438
Bucket function using the index of an edge's target node as bucket.
Definition Graph_d.h:1442
int getBucket(const edge &e) override
Returns target index of e.
Definition Graph_d.h:1445
Abstract base class for edge arrays.
Definition EdgeArray.h:44
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition Graph_d.h:344
bool isParallelDirected(edge e) const
Returns true iff edge e is parallel to this (directed) edge (or if it is the same edge)
Definition Graph_d.h:362
int index() const
Returns the index of the edge.
Definition Graph_d.h:332
EdgeElement(node src, node tgt, int id)
Constructs an edge element (src,tgt).
Definition Graph_d.h:327
node opposite(node v) const
Returns the adjacent node different from v.
Definition Graph_d.h:350
EdgeElement(node src, node tgt, AdjElement *adjSrc, AdjElement *adjTgt, int id)
Constructs an edge element (src,tgt).
Definition Graph_d.h:318
edge succ() const
Returns the successor in the list of all edges.
Definition Graph_d.h:370
AdjElement * m_adjSrc
Corresponding adjacancy entry at source node.
Definition Graph_d.h:306
std::array< node, 2 > nodes() const
Returns a list of adjacent nodes. If this edge is a self-loop, both entries will be the same node.
Definition Graph_d.h:341
bool isAdjacent(edge e) const
Returns true iff e is adjacent to the edge.
Definition Graph_d.h:384
AdjElement * m_adjTgt
Corresponding adjacancy entry at target node.
Definition Graph_d.h:307
bool isIncident(node v) const
Returns true iff v is incident to the edge.
Definition Graph_d.h:381
node m_tgt
The target node of the edge.
Definition Graph_d.h:305
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition Graph_d.h:347
node m_src
The source node of the edge.
Definition Graph_d.h:304
static int compare(const EdgeElement &x, const EdgeElement &y)
Standard Comparer.
Definition Graph_d.h:401
edge pred() const
Returns the predecessor in the list of all edges.
Definition Graph_d.h:373
node commonNode(edge e) const
Returns the common node of the edge and e. Returns nullptr if the two edges are not adjacent.
Definition Graph_d.h:387
bool isInvertedDirected(edge e) const
Returns true iff edge e is an inverted edge to this (directed) edge.
Definition Graph_d.h:359
bool isParallelUndirected(edge e) const
Returns true iff edge e is parallel to this (undirected) edge (or if it is the same edge)
Definition Graph_d.h:365
bool isSelfLoop() const
Returns true iff the edge is a self-loop (source node = target node).
Definition Graph_d.h:356
node target() const
Returns the target node of the edge.
Definition Graph_d.h:338
adjEntry getAdj(node v) const
Returns an adjacency entry of this edge at node v. If this is a self-loop the source adjacency entry ...
Definition Graph_d.h:395
node source() const
Returns the source node of the edge.
Definition Graph_d.h:335
Info structure for maintaining connected components.
Definition Graph_d.h:1339
int numberOfNodes(int cc) const
Returns the number of nodes in connected component cc.
Definition Graph_d.h:1362
int numberOfEdges(int cc) const
Returns the number of edges in connected component cc.
Definition Graph_d.h:1365
Array< node > m_nodes
array of all nodes.
Definition Graph_d.h:1343
edge e(int i) const
Returns the edge with index i.
Definition Graph_d.h:1383
CCsInfo()
Creates a info structure associated with no graph.
Definition Graph_d.h:1350
int m_numCC
the number of connected components.
Definition Graph_d.h:1341
int numberOfCCs() const
Returns the number of connected components.
Definition Graph_d.h:1359
CCsInfo(const Graph &G)
Creates a info structure associated with graph G.
const Graph & constGraph() const
Returns the associated graph.
Definition Graph_d.h:1356
node v(int i) const
Returns the node with index i.
Definition Graph_d.h:1380
Array< int > m_startEdge
start edge of each connected component in m_edges.
Definition Graph_d.h:1346
Array< int > m_startNode
start node of each connected component in m_nodes.
Definition Graph_d.h:1345
Array< edge > m_edges
array of all edges.
Definition Graph_d.h:1344
int stopNode(int cc) const
Returns the index of (one past) the last node in connected component cc.
Definition Graph_d.h:1371
int stopEdge(int cc) const
Returns the index of (one past) the last edge in connected component cc.
Definition Graph_d.h:1377
int startNode(int cc) const
Returns the index of the first node in connected component cc.
Definition Graph_d.h:1368
int startEdge(int cc) const
Returns the index of the first edge in connected component cc.
Definition Graph_d.h:1374
const Graph * m_graph
points to the associated graph.
Definition Graph_d.h:1340
Functionality for temporarily hiding edges in constant time.
Definition Graph_d.h:821
void hide(edge e)
Hides the given edge.
~HiddenEdgeSet()
Restores all hidden edges.
Definition Graph_d.h:838
HiddenEdgeSet & operator=(const HiddenEdgeSet &)
void restore(edge e)
Reveals the given edge.
ListIterator< HiddenEdgeSet * > m_it
Definition Graph_d.h:876
HiddenEdgeSet(const HiddenEdgeSet &)
HiddenEdgeSet(Graph &graph)
Creates a new set of hidden edges.
Definition Graph_d.h:831
int size()
Returns the number of edges contained in this set.
internal::GraphList< EdgeElement > m_edges
Definition Graph_d.h:875
void restore()
Restores all edges contained in this set.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
ListIterator< AdjEntryArrayBase * > registerArray(AdjEntryArrayBase *pAdjArray) const
Registers an adjEntry array.
void construct(const Graph &G, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge)
node contract(edge e, bool keepSelfLoops=false)
Contracts edge e while preserving the order of adjacency entries.
int maxNodeIndex() const
Returns the largest used node index.
Definition Graph_d.h:628
ListIterator< NodeArrayBase * > registerArray(NodeArrayBase *pNodeArray) const
Registers a node array.
node newNode(int index)
Creates a new node with predefined index and returns it.
virtual void unsplit(edge eIn, edge eOut)
Undoes a split operation.
int adjEntryArrayTableSize() const
Returns the table size of adjEntry arrays associated with this graph.
Definition Graph_d.h:643
void unsplit(node u)
Undoes a split operation.
void constructInitByCC(const CCsInfo &info, int cc, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge)
Constructs a copy of connected component cc in info.
node splitNode(adjEntry adjStartLeft, adjEntry adjStartRight)
Splits a node while preserving the order of adjacency entries.
node chooseNode(std::function< bool(node)> includeNode=[](node) { return true;}, bool isFastTest=true) const
Returns a random node.
ListPure< EdgeArrayBase * > m_regEdgeArrays
The registered edge arrays.
Definition Graph_d.h:533
node lastNode() const
Returns the last node in the list of all nodes.
Definition Graph_d.h:649
edge newEdge(node v, adjEntry adjTgt)
Creates a new edge at predefined positions in the adjacency lists.
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition Graph_d.h:622
ListPure< GraphObserver * > m_regStructures
The registered graph structures.
Definition Graph_d.h:535
ListPure< AdjEntryArrayBase * > m_regAdjArrays
The registered adjEntry arrays.
Definition Graph_d.h:534
void moveSource(edge e, node w)
Moves the source node of edge e to node w.
int m_nodeArrayTableSize
The current table size of node arrays associated with this graph.
Definition Graph_d.h:529
edge createEdgeElement(node v, node w, adjEntry adjSrc, adjEntry adjTgt)
void sort(node v, const ADJ_ENTRY_LIST &newOrder)
Sorts the adjacency list of node v according to newOrder.
Definition Graph_d.h:1086
void reinitArrays(bool doResetTableSizes=true)
Re-initializes registed arrays with respect to the current sizes. Calls resetTableSizes() if doResetT...
edge lastEdge() const
Returns the last edge in the list of all edges.
Definition Graph_d.h:655
void resetAdjEntryIndex(int newIndex, int oldIndex)
ListIterator< EdgeArrayBase * > registerArray(EdgeArrayBase *pEdgeArray) const
Registers an edge array.
void unregisterArray(ListIterator< AdjEntryArrayBase * > it) const
Unregisters an adjEntry array.
edge firstEdge() const
Returns the first edge in the list of all edges.
Definition Graph_d.h:652
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
void moveAdjBefore(adjEntry adjMove, adjEntry adjBefore)
Moves adjacency entry adjMove before adjBefore.
Definition Graph_d.h:1148
void collapse(NODELIST &nodesToCollapse)
Collapses all nodes in the list nodesToCollapse to the first node in the list.
Definition Graph_d.h:1056
void swapAdjEdges(adjEntry adj1, adjEntry adj2)
Exchanges two entries in an adjacency list.
Definition Graph_d.h:1166
virtual void clear()
Removes all nodes and all edges from the graph.
int maxEdgeIndex() const
Returns the largest used edge index.
Definition Graph_d.h:631
void moveTarget(edge e, node w)
Moves the target node of edge e to node w.
void allEdges(CONTAINER &edgeContainer) const
Returns a container with all edges of the graph.
Definition Graph_d.h:695
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
void move(edge e, adjEntry adjSrc, Direction dirSrc, adjEntry adjTgt, Direction dirTgt)
Moves edge e to a different adjacency list.
void moveRegisterArray(ListIterator< ArrayBase * > it, ArrayBase *pArray) const
Move the registration it of an graph element array to pArray (used with move semantics for graph elem...
Definition Graph_d.h:1281
int nodeArrayTableSize() const
Returns the table size of node arrays associated with this graph.
Definition Graph_d.h:637
int edgeArrayTableSize() const
Returns the table size of edge arrays associated with this graph.
Definition Graph_d.h:640
void reverseEdge(edge e)
Reverses the edge e, i.e., exchanges source and target node.
edge newEdge(adjEntry adjSrc, node w)
Creates a new edge at predefined positions in the adjacency lists.
int maxAdjEntryIndex() const
Returns the largest used adjEntry index.
Definition Graph_d.h:634
int m_edgeIdCount
The Index that will be assigned to the next created edge.
Definition Graph_d.h:527
int m_nodeIdCount
The Index that will be assigned to the next created node.
Definition Graph_d.h:526
int numberOfEdges() const
Returns the number of edges in the graph.
Definition Graph_d.h:625
bool representsCombEmbedding() const
Returns true iff the graph represents a combinatorial embedding.
Definition Graph_d.h:1196
void resetEdgeIdCount(int maxId)
Resets the edge id count to maxId.
void constructInitByNodes(const Graph &G, const List< node > &nodeList, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge)
Constructs a copy of the subgraph of G induced by nodeList.
List< HiddenEdgeSet * > m_hiddenEdgeSets
The list of hidden edges.
Definition Graph_d.h:541
edge newEdge(adjEntry adjSrc, adjEntry adjTgt, Direction dir=Direction::after)
Creates a new edge at predefined positions in the adjacency lists.
std::mutex m_mutexRegArrays
The critical section for protecting shared acces to register/unregister methods.
Definition Graph_d.h:538
void insert(const Graph &G)
Inserts Graph G as a subgraph into this Graph.
Graph(const Graph &G)
Constructs a graph that is a copy of G.
Graph & operator=(const Graph &G)
Assignment operator.
void reverseAdjEdges()
Reverses all adjacency lists.
void copy(const Graph &G, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge)
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition Graph_d.h:589
void constructInitByActiveNodes(const List< node > &nodeList, const NodeArray< bool > &activeNodes, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge)
void moveTarget(edge e, adjEntry adjTgt, Direction dir)
Moves the target node of edge e to a specific position in an adjacency list.
ListIterator< GraphObserver * > registerStructure(GraphObserver *pStructure) const
Registers a graph observer (e.g. a ClusterGraph).
void allNodes(CONTAINER &nodeContainer) const
Returns a container with all nodes of the graph.
Definition Graph_d.h:685
virtual void delEdge(edge e)
Removes edge e from the graph.
edge chooseEdge(std::function< bool(edge)> includeEdge=[](edge) { return true;}, bool isFastTest=true) const
Returns a random edge.
void assign(const Graph &G, NodeArray< node > &mapNode, EdgeArray< edge > &mapEdge)
void moveAdj(adjEntry adjMove, Direction dir, adjEntry adjPos)
Moves adjacency entry adjMove before or after adjPos.
Definition Graph_d.h:1117
node firstNode() const
Returns the first node in the list of all nodes.
Definition Graph_d.h:646
Graph()
Constructs an empty graph.
node pureNewNode()
void reverseAdjEdges(node v)
Reverses the adjacency list of v.
Definition Graph_d.h:1107
void unregisterArray(ListIterator< NodeArrayBase * > it) const
Unregisters a node array.
ListPure< NodeArrayBase * > m_regNodeArrays
The registered node arrays.
Definition Graph_d.h:532
NodeType
The type of nodes.
Definition Graph_d.h:569
virtual edge split(edge e)
Splits edge e into two edges introducing a new node.
void moveAdjAfter(adjEntry adjMove, adjEntry adjAfter)
Moves adjacency entry adjMove after adjAfter.
Definition Graph_d.h:1133
bool empty() const
Returns true iff the graph is empty, i.e., contains no nodes.
Definition Graph_d.h:619
void reverseAllEdges()
Reverses all edges in the graph.
EdgeType
The type of edges (only used in derived classes).
Definition Graph_d.h:566
void copy(const Graph &G)
virtual ~Graph()
Destructor.
void restoreAllEdges()
Used to restore all hidden edges upon deleting the graph.
void unregisterStructure(ListIterator< GraphObserver * > it) const
Unregisters a graph observer.
node newNode()
Creates a new node and returns it.
edge newEdge(node v, node w, int index)
Creates a new edge (v,w) with predefined index and returns it.
void insert(const Graph &G, NodeArray< node > &nodeMap)
Inserts Graph G as a subgraph into this Graph.
void moveSource(edge e, adjEntry adjSrc, Direction dir)
Moves the source node of edge e to a specific position in an adjacency list.
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 ))).
void moveAdj(adjEntry adj, node w)
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:592
int genus() const
Returns the genus of the graph's embedding.
int m_edgeArrayTableSize
The current table size of edge arrays associated with this graph.
Definition Graph_d.h:530
void unregisterArray(ListIterator< EdgeArrayBase * > it) const
Unregisters an edge array.
void resetTableSizes()
Sets the sizes of registered node and edge arrays to the next power of two that is no less than the c...
Abstract Base class for graph observers.
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
Encapsulates a pointer to a list element.
Definition List.h:103
Doubly linked lists.
Definition List.h:217
Abstract base class for node arrays.
Definition NodeArray.h:44
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
void allAdjEntries(ADJLIST &adjList) const
Returns a list with all adjacency entries of this node.
Definition Graph_d.h:240
void adjEdges(EDGELIST &edgeList) const
Returns a list with all edges incident to this node.
Definition Graph_d.h:256
void inEdges(EDGELIST &edgeList) const
Returns a list with all incoming edges of this node.
Definition Graph_d.h:438
int m_id
The (unique) index of the node.
Definition Graph_d.h:184
NodeElement(int id)
Constructs a node element with index id.
Definition Graph_d.h:202
int indeg() const
Returns the indegree of the node.
Definition Graph_d.h:214
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition Graph_d.h:220
void outEdges(EDGELIST &edgeList) const
Returns a list with all outgoing edges of this node.
Definition Graph_d.h:449
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:208
node succ() const
Returns the successor in the list of all nodes.
Definition Graph_d.h:229
int index() const
Returns the (unique) node index.
Definition Graph_d.h:211
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition Graph_d.h:223
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition Graph_d.h:226
node pred() const
Returns the predecessor in the list of all nodes.
Definition Graph_d.h:232
int m_indeg
The indegree of the node.
Definition Graph_d.h:182
static int compare(const NodeElement &x, const NodeElement &y)
Standard Comparer.
Definition Graph_d.h:285
int outdeg() const
Returns the outdegree of the node.
Definition Graph_d.h:217
int m_outdeg
The outdegree of the node.
Definition Graph_d.h:183
The base class for objects used by (hyper)graphs.
Definition GraphList.h:55
GraphElement * m_next
The successor in the list.
Definition GraphList.h:60
GraphElement * m_prev
The predecessor in the list.
Definition GraphList.h:61
Base class for GraphElement lists.
Definition GraphList.h:67
Lists of graph objects (like nodes, edges, etc.).
Definition GraphList.h:288
T * head() const
Returns the first element in the list.
Definition GraphList.h:304
void move(T *pX, GraphList< T > &L, T *pY, Direction dir)
Moves element pX to list L and inserts it before or after pY.
Definition GraphList.h:322
bool empty() const
Returns true iff the list is empty.
Definition GraphList.h:310
T * tail() const
Returns the last element in the list.
Definition GraphList.h:307
int size() const
Returns the size of the list.
Definition GraphList.h:301
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
Decralation of graph iterators.
#define OGDF_AUGMENT_STATICCOMPARER(type)
Add this macro to your class to turn it into a full static comparer.
Definition comparer.h:225
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition memory.h:91
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:84
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
void getAllNodes(const Graph &G, CONTAINER &nodes)
Definition Graph_d.h:1451
void getAllEdges(const Graph &G, CONTAINER &edges)
Definition Graph_d.h:1468
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:978
Direction
Definition basic.h:134
NodePair()=default
NodePair(node src, node tgt)
Definition Graph_d.h:1491