Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
GraphCopy.h
Go to the documentation of this file.
1
32#pragma once
33
37#include <ogdf/basic/SList.h>
38
39namespace ogdf {
40
41template<bool b>
42class FaceSet;
43
60 const Graph* m_pGraph;
65
66public:
69
71 explicit GraphCopySimple(const Graph& G);
72
75
76 virtual ~GraphCopySimple() { }
77
79 void init(const Graph& G);
80
82 void createEmpty(const Graph& G);
83
85 const Graph& original() const { return *m_pGraph; }
86
93 node original(node v) const { return m_vOrig[v]; }
94
101 edge original(edge e) const { return m_eOrig[e]; }
102
114 edge f = m_eOrig[adj->theEdge()];
115 return adj->isSource() ? f->adjSource() : f->adjTarget();
116 }
117
124 node copy(node v) const { return m_vCopy[v]; }
125
132 edge copy(edge e) const { return m_eCopy[e]; }
133
145 adjEntry copy(adjEntry adj) const {
146 edge f = m_eCopy[adj->theEdge()];
147 if (f == nullptr) {
148 return nullptr;
149 }
150 return adj->isSource() ? f->adjSource() : f->adjTarget();
151 }
152
157 bool isDummy(node v) const { return m_vOrig[v] == nullptr; }
158
163 bool isDummy(edge e) const { return m_eOrig[e] == nullptr; }
164
167
174 OGDF_ASSERT(vOrig != nullptr);
175 OGDF_ASSERT(vOrig->graphOf() == m_pGraph);
176 node v = Graph::newNode();
177 m_vCopy[m_vOrig[v] = vOrig] = v;
178 return v;
179 }
180
181 using Graph::newNode;
182
189 OGDF_ASSERT(eOrig != nullptr);
190 OGDF_ASSERT(eOrig->graphOf() == m_pGraph);
191
192 edge e = Graph::newEdge(m_vCopy[eOrig->source()], m_vCopy[eOrig->target()]);
193 m_eCopy[m_eOrig[e] = eOrig] = e;
194
195 return e;
196 }
197
198 using Graph::newEdge;
199
205 virtual void delEdge(edge e) override;
206
212 virtual void delNode(node v) override;
213
214private:
216};
217
255protected:
260
263
264public:
266
269 explicit GraphCopy(const Graph& G);
270
272 GraphCopy() : Graph(), m_pGraph(nullptr) { }
273
275
280
281 virtual ~GraphCopy() { }
282
287
289 const Graph& original() const { return *m_pGraph; }
290
297 node original(node v) const { return m_vOrig[v]; }
298
305 edge original(edge e) const { return m_eOrig[e]; }
306
321 edge e = adj->theEdge();
322 edge f = m_eOrig[e];
323
324 if (adj->isSource()) {
325 OGDF_ASSERT(m_eCopy[f].front() == e);
326 return f->adjSource();
327 } else {
328 OGDF_ASSERT(m_eCopy[f].back() == e);
329 return f->adjTarget();
330 }
331 }
332
338 node copy(node v) const { return m_vCopy[v]; }
339
345 const List<edge>& chain(edge e) const { return m_eCopy[e]; }
346
347 // returns first edge in chain(e)
354 edge copy(edge e) const { return m_eCopy[e].empty() ? nullptr : m_eCopy[e].front(); }
355
366 adjEntry copy(adjEntry adj) const {
367 edge e = adj->theEdge();
368
369 if (adj->isSource()) {
370 return m_eCopy[e].front()->adjSource();
371 } else {
372 return m_eCopy[e].back()->adjTarget();
373 }
374 }
375
380 bool isDummy(node v) const { return m_vOrig[v] == nullptr; }
381
386 bool isDummy(edge e) const { return m_eOrig[e] == nullptr; }
387
392 bool isReversed(edge e) const { return e->source() != original(copy(e)->source()); }
393
401
406
413 OGDF_ASSERT(vOrig != nullptr);
414 OGDF_ASSERT(vOrig->graphOf() == m_pGraph);
415 node v = Graph::newNode();
416 m_vCopy[m_vOrig[v] = vOrig] = v;
417 return v;
418 }
419
420 using Graph::newNode;
421
428 virtual void delNode(node v) override;
429
436 virtual void delEdge(edge e) override;
437
438
439 virtual void clear() override;
440
446 virtual edge split(edge e) override;
447
448
457 void unsplit(edge eIn, edge eOut) override;
458
461
462 using Graph::newEdge;
463
465
470
472 OGDF_DEPRECATED("Use ogdf::planarEmbed() instead.")
473 bool embed();
474
476 void removePseudoCrossings();
477
480 bool hasSameEdgesCrossings() const;
481
484 bool hasAdjacentEdgesCrossings() const;
485
488
495 inline bool hasNonSimpleCrossings() const {
496 return hasAdjacentEdgesCrossings() || hasSameEdgesCrossings();
497 };
498
511 DynamicDualGraph* dualGraph = nullptr);
512
524 m_pGraph->allEdges(edgesToCheck);
525 removeNonSimpleCrossings(edgesToCheck, dualGraph);
526 };
527
539 inline void removeNonSimpleCrossings(node origNode, DynamicDualGraph* dualGraph = nullptr) {
541 for (adjEntry adj : origNode->adjEntries) {
542 edgesToCheck.pushBack(adj->theEdge());
543 }
544 removeNonSimpleCrossings(edgesToCheck, dualGraph);
545 }
546
548
558
561
562
564
568
570
587
588
593
595
610
617
619
640
643
645
656
658
659
661
665
666#ifdef OGDF_DEBUG
668 void consistencyCheck() const;
669#endif
670
672
679 void init(const Graph& G);
680
682
711 void createEmpty(const Graph& G);
712
714
719 void initByCC(const CCsInfo& info, int cc, EdgeArray<edge>& eCopy);
720
722
739
741
755
757
761
763
772
773
775
776protected:
778
789
798
810
820 DynamicDualGraph* dual = nullptr);
821
830 DynamicDualGraph* dual = nullptr);
831
838
839private:
841};
842
843}
Includes declaration of dual graph class.
Declaration and implementation of EdgeArray class.
Declaration and implementation of NodeArray class.
Declaration of singly linked lists and iterators.
Class for adjacency list elements.
Definition Graph_d.h:79
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition Graph_d.h:97
bool isSource() const
Returns true iff this is the source adjacency entry of the corresponding edge.
Definition Graph_d.h:416
bool empty() const
Returns true iff there are no elements in the array.
Definition Array.h:300
Combinatorial embeddings of planar graphs with modification functionality.
A dual graph including its combinatorial embedding of an embedded graph.
Definition DualGraph.h:56
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
node source() const
Returns the source node of the edge.
Definition Graph_d.h:335
Face sets.
Definition FaceSet.h:53
Info structure for maintaining connected components.
Definition Graph_d.h:1339
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:254
void removeNonSimpleCrossings(SListPure< edge > &edgesToCheck, DynamicDualGraph *dualGraph=nullptr)
Removes all non-simple cossings involving edges from edgesToCheck (see hasNonSimpleCrossings() for a ...
const List< edge > & chain(edge e) const
Returns the list of edges coresponding to edge e.
Definition GraphCopy.h:345
NodeArray< node > m_vCopy
The corresponding node in the graph copy.
Definition GraphCopy.h:261
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
Definition GraphCopy.h:412
GraphCopy(const GraphCopy &GC)
Copy constructor.
void setEdge(edge eOrig, edge eCopy)
sets eOrig to be the corresponding original edge of eCopy and vice versa
void setOriginalEmbedding()
Sets the embedding of the graph copy to the embedding of the original graph.
GraphCopy & operator=(const GraphCopy &GC)
Assignment operator.
void insertEdgePath(edge eOrig, const SList< adjEntry > &crossedEdges)
Re-inserts edge eOrig by "crossing" the edges in crossedEdges.
void removeEdgePath(edge eOrig)
Removes the complete edge path for edge eOrig.
void removeSameEdgesCrossing(adjEntry adjFirstCrossing1, adjEntry adjFirstCrossing2, adjEntry adjSecondCrossing1, adjEntry adjSecondCrossing2, DynamicDualGraph *dualGraph)
Removes the two crossings given by the adjEntries, assuming that both crossings stem from the same tw...
void init(const Graph &G)
Re-initializes the copy using the graph G.
GraphCopy()
Default constructor (does nothing!).
Definition GraphCopy.h:272
EdgeArray< edge > m_eOrig
The corresponding edge in the original graph.
Definition GraphCopy.h:258
virtual void delEdge(edge e) override
Removes edge e and clears the list of edges corresponding to e's original edge.
adjEntry copy(adjEntry adj) const
Returns the adjacency entry in the copy graph corresponding to adj.
Definition GraphCopy.h:366
node original(node v) const
Returns the node in the original graph corresponding to v.
Definition GraphCopy.h:297
bool isDummy(edge e) const
Returns true iff e has no corresponding edge in the original graph.
Definition GraphCopy.h:386
void insertEdgePathEmbedded(edge eOrig, CombinatorialEmbedding &E, const SList< adjEntry > &crossedEdges)
Re-inserts edge eOrig by "crossing" the edges in crossedEdges in embedding E.
EdgeArray< ListIterator< edge > > m_eIterator
The position of copy edge in the list.
Definition GraphCopy.h:259
edge copy(edge e) const
Returns the first edge in the list of edges coresponding to edge e.
Definition GraphCopy.h:354
void insertEdgePath(node srcOrig, node tgtOrig, const SList< adjEntry > &crossedEdges)
Special version (for FixedEmbeddingUpwardEdgeInserter only).
void unsplit(edge eIn, edge eOut) override
Undoes a previous split operation.
edge insertCrossing(edge &crossingEdge, edge crossedEdge, bool rightToLeft)
Inserts crossings between two copy edges.
void insertEdgePathEmbedded(edge eOrig, CombinatorialEmbedding &E, DynamicDualGraph &dual, const SList< adjEntry > &crossedEdges)
const Graph * m_pGraph
The original graph.
Definition GraphCopy.h:256
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition GraphCopy.h:262
void removeAdjacentEdgesCrossing(adjEntry adj1, adjEntry adj2, DynamicDualGraph *dualGraph)
Removes the crossing of the two adjacent edges adj1->theEdge() and adj2->theEdge().
void swapOriginalEdgesBetweenCrossings(adjEntry adjFirstCrossing1, adjEntry adjFirstCrossing2, adjEntry adjSecondCrossing1, adjEntry adjSecondCrossing2, DynamicDualGraph *dual=nullptr)
Swaps the original edges from adjFirstCrossing1 up to adjSecondCrossing1->theNode() with the original...
void initByNodes(const List< node > &origNodes, EdgeArray< edge > &eCopy)
Initializes the graph copy for the nodes in a component.
bool isDummy(node v) const
Returns true iff v has no corresponding node in the original graph.
Definition GraphCopy.h:380
NodeArray< node > m_vOrig
The corresponding node in the original graph.
Definition GraphCopy.h:257
void removeEdgePathEmbedded(CombinatorialEmbedding &E, DynamicDualGraph &dual, edge eOrig)
virtual void delNode(node v) override
Removes node v and all its adjacent edges cleaning-up their corresponding lists of original edges.
GraphCopy(const Graph &G)
Creates a graph copy of G.
void removeUnnecessaryCrossing(adjEntry adjA1, adjEntry adjA2, adjEntry adjB1, adjEntry adjB2)
void removeNonSimpleCrossings(DynamicDualGraph *dualGraph=nullptr)
Removes all non-simple cossings (see hasNonSimpleCrossings() for a definition of non-simple crossings...
Definition GraphCopy.h:522
void removeUnnecessaryCrossing(adjEntry adj, DynamicDualGraph *dualGraph)
Removes the pseudo crossing that adj belongs to.
virtual ~GraphCopy()
Definition GraphCopy.h:281
edge original(edge e) const
Returns the edge in the original graph corresponding to e.
Definition GraphCopy.h:305
void swapOriginalEdgesAtCrossing(adjEntry adjCopy1, adjEntry adjCopy2, DynamicDualGraph *dual=nullptr)
Swaps the original edges from adjCopy1 up to the common node of {adjCopy1, adjCopy2} with the origina...
void initByActiveNodes(const List< node > &nodeList, const NodeArray< bool > &activeNodes, EdgeArray< edge > &eCopy)
Initializes the graph copy for the nodes in nodeList.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition GraphCopy.h:338
const Graph & original() const
Returns a reference to the original graph.
Definition GraphCopy.h:289
virtual void clear() override
Removes all nodes and all edges from the graph.
void setOriginalEdgeAlongCrossings(adjEntry adjCopy1, adjEntry adjCopy2, node vCopy, edge eOrig1, edge eOrig2)
Sets the original edges from adjCopy1 up to vCopy to eOrig2, and the original edges from adjCopy2 up ...
edge newEdge(node v, adjEntry adj, edge eOrig, CombinatorialEmbedding &E)
Creates a new edge with original edge eOrig in an embedding E.
bool isReversed(edge e) const
Returns true iff edge e has been reversed.
Definition GraphCopy.h:392
void removeNonSimpleCrossings(node origNode, DynamicDualGraph *dualGraph=nullptr)
Removes all non-simple cossings involving edges incident to origNode (see hasNonSimpleCrossings() for...
Definition GraphCopy.h:539
void createEmpty(const Graph &G)
Associates the graph copy with G, but does not create any nodes or edges.
void removeEdgePathEmbedded(CombinatorialEmbedding &E, edge eOrig, FaceSet< false > &newFaces)
Removes the complete edge path for edge eOrig while preserving the embedding.
bool isReversedCopyEdge(edge e) const
Returns true iff e is reversed w.r.t.
void initGC(const GraphCopy &GC, NodeArray< node > &vCopy, EdgeArray< edge > &eCopy)
adjEntry original(adjEntry adj) const
Returns the adjacency entry in the original graph corresponding to adj.
Definition GraphCopy.h:320
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
virtual edge split(edge e) override
Splits edge e.
void initByCC(const CCsInfo &info, int cc, EdgeArray< edge > &eCopy)
Initializes the graph copy for the nodes in component cc.
Copies of graphs with mapping between nodes and edges.
Definition GraphCopy.h:59
edge newEdge(edge eOrig)
Creates a new edge in the graph copy with original edge eOrig.
Definition GraphCopy.h:188
GraphCopySimple & operator=(const GraphCopySimple &GC)
Assignment operator.
edge original(edge e) const
Returns the edge in the original graph corresponding to e.
Definition GraphCopy.h:101
virtual void delEdge(edge e) override
Removes edge e.
adjEntry copy(adjEntry adj) const
Returns the adjacency entry in the graph copy corresponding to adj.
Definition GraphCopy.h:145
GraphCopySimple()
Constructs a GraphCopySimple associated with no graph.
GraphCopySimple(const GraphCopySimple &GC)
Copy constructor.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition GraphCopy.h:124
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
Definition GraphCopy.h:173
GraphCopySimple(const Graph &G)
Constructs a copy of graph G.
void initGC(const GraphCopySimple &GC, NodeArray< node > &vCopy, EdgeArray< edge > &eCopy)
bool isDummy(edge e) const
Returns true iff e has no corresponding edge in the original graph.
Definition GraphCopy.h:163
void init(const Graph &G)
Re-initializes the copy using G.
bool isDummy(node v) const
Returns true iff v has no corresponding node in the original graph.
Definition GraphCopy.h:157
NodeArray< node > m_vCopy
The corresponding node in the graph copy.
Definition GraphCopy.h:62
const Graph & original() const
Returns a reference to the original graph.
Definition GraphCopy.h:85
adjEntry original(adjEntry adj) const
Returns the adjacency entry in the original graph corresponding to adj.
Definition GraphCopy.h:113
virtual ~GraphCopySimple()
Definition GraphCopy.h:76
virtual void delNode(node v) override
Removes node v.
edge copy(edge e) const
Returns the edge in the graph copy corresponding to e.
Definition GraphCopy.h:132
node original(node v) const
Returns the node in the original graph corresponding to v.
Definition GraphCopy.h:93
void createEmpty(const Graph &G)
Re-initializes the copy using G, but does not create any nodes or edges.
EdgeArray< edge > m_eCopy
The corresponding edge in the graph copy.
Definition GraphCopy.h:64
NodeArray< node > m_vOrig
The corresponding node in the original graph.
Definition GraphCopy.h:61
const Graph * m_pGraph
The original graph.
Definition GraphCopy.h:60
EdgeArray< edge > m_eOrig
The corresponding edge in the original graph.
Definition GraphCopy.h:63
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
void allEdges(CONTAINER &edgeContainer) const
Returns a container with all edges of the graph.
Definition Graph_d.h:695
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:208
Singly linked lists (maintaining the length of the list).
Definition SList.h:833
Singly linked lists.
Definition SList.h:179
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition SList.h:469
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition config.h:120
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.