Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

GraphCopy.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/DualGraph.h>
35 #include <ogdf/basic/EdgeArray.h>
36 #include <ogdf/basic/NodeArray.h>
37 #include <ogdf/basic/SList.h>
38 
39 namespace ogdf {
40 
41 template<bool>
42 class FaceSet;
43 
45 protected:
46  const Graph* m_pGraph = nullptr;
50  bool m_linkCopiesOnInsert =
51  true;
52 
53 public:
55  GraphCopyBase() = default;
56 
57  GraphCopyBase(const GraphCopyBase& other) = delete;
58 
59  GraphCopyBase(GraphCopyBase&& other) noexcept = delete;
60 
61  GraphCopyBase& operator=(const GraphCopyBase& other) = delete;
62 
63  GraphCopyBase& operator=(GraphCopyBase&& other) noexcept = delete;
64 
66  void init(const Graph& G) {
67  Graph::clear();
68  setOriginalGraph(&G);
69  insert(G);
70  }
71 
73  void init(const Graph* G) {
74  Graph::clear();
75  setOriginalGraph(G);
76  if (G != nullptr) {
77  insert(*G);
78  }
79  }
80 
82  OGDF_DEPRECATED("setOriginalGraph() should be used instead.")
83 
84  void createEmpty(const Graph& G) { setOriginalGraph(&G); }
85 
87  virtual void setOriginalGraph(const Graph* G) = 0;
88 
90  void setOriginalGraph(const Graph& G) { setOriginalGraph(&G); };
91 
92  const Graph* getOriginalGraph() const { return m_pGraph; }
93 
95  void clear() override = 0;
96 
98  const Graph& original() const {
99  OGDF_ASSERT(m_pGraph != nullptr);
100  return *m_pGraph;
101  }
102 
109  node original(node v) const { return m_vOrig[v]; }
110 
117  edge original(edge e) const { return m_eOrig[e]; }
118 
130  edge f = m_eOrig[adj->theEdge()];
131  return adj->isSource() ? f->adjSource() : f->adjTarget();
132  }
133 
140  node copy(node v) const { return m_vCopy[v]; }
141 
150  virtual edge copy(edge e) const = 0;
151 
160  virtual adjEntry copy(adjEntry adj) const = 0;
161 
166  bool isDummy(node v) const { return m_vOrig[v] == nullptr; }
167 
172  bool isDummy(edge e) const { return m_eOrig[e] == nullptr; }
173 
178  bool isDummy(adjEntry adj) const { return isDummy(adj->theEdge()); }
179 
185  node newNode(node vOrig) {
186  OGDF_ASSERT(vOrig != nullptr);
187  OGDF_ASSERT(vOrig->graphOf() == m_pGraph);
188  node v = Graph::newNode();
189  m_vCopy[m_vOrig[v] = vOrig] = v;
190  return v;
191  }
192 
193  using Graph::newNode;
194 
200  void delNode(node v) override {
201  node vOrig = m_vOrig[v];
202  Graph::delNode(v);
203  if (vOrig != nullptr) {
204  m_vCopy[vOrig] = nullptr;
205  }
206  }
207 
209 
213  virtual void setOriginalEmbedding() = 0;
214 
215  bool getLinkCopiesOnInsert() const { return m_linkCopiesOnInsert; }
216 
218 
227  void setLinkCopiesOnInsert(bool linkCopiesOnInsert) {
228  m_linkCopiesOnInsert = linkCopiesOnInsert;
229  }
230 
231 protected:
232  void* preInsert(bool copyEmbedding, bool copyIDs, bool notifyObservers, bool edgeFilter,
233  NodeArray<node>& nodeMap, EdgeArray<edge>& edgeMap, int* newNodes,
234  int* newEdges) override;
235 
236  void nodeInserted(void* userData, node original, node copy) override;
237 };
238 
255 public:
257 
258  explicit GraphCopySimple() : GraphCopySimple(nullptr) { }
259 
260  explicit GraphCopySimple(const Graph& G) : GraphCopySimple(&G) { }
261 
262  explicit GraphCopySimple(const Graph* G) : GraphCopyBase() {
263  if (G) {
264  init(*G);
265  }
266  }
267 
268  GraphCopySimple(const GraphCopySimple& other) : GraphCopyBase() { *this = other; }
269 
270  GraphCopySimple& operator=(const GraphCopySimple& other);
271 
273 
275  void setOriginalGraph(const Graph* G) override;
276 
278  void clear() override;
279 
280  using GraphCopyBase::copy;
281 
288  edge copy(edge e) const override { return m_eCopy[e]; }
289 
301  adjEntry copy(adjEntry adj) const override {
302  edge f = m_eCopy[adj->theEdge()];
303  if (f == nullptr) {
304  return nullptr;
305  }
306  return adj->isSource() ? f->adjSource() : f->adjTarget();
307  }
308 
314  edge newEdge(edge eOrig) {
315  OGDF_ASSERT(eOrig != nullptr);
316  OGDF_ASSERT(eOrig->graphOf() == m_pGraph);
317 
318  edge e = Graph::newEdge(m_vCopy[eOrig->source()], m_vCopy[eOrig->target()]);
319  m_eCopy[m_eOrig[e] = eOrig] = e;
320 
321  return e;
322  }
323 
324  using Graph::newEdge;
325 
331  void delEdge(edge e) override;
332 
333  void setOriginalEmbedding() override;
334 
342  void copyEmbeddingToOriginal(Graph& orig) const;
343 
344 protected:
345  void edgeInserted(void* userData, edge original, edge copy) override;
346 };
347 
385 protected:
388 
389 public:
390  explicit GraphCopy() : GraphCopy(nullptr) { }
391 
392  explicit GraphCopy(const Graph& G) : GraphCopy(&G) { }
393 
394  explicit GraphCopy(const Graph* G) : GraphCopyBase() {
395  if (G) {
396  init(*G);
397  }
398  }
399 
400  GraphCopy(const GraphCopy& other) : GraphCopyBase() { *this = other; }
401 
402  GraphCopy& operator=(const GraphCopy& other);
403 
405 
407 
432  void setOriginalGraph(const Graph* G) override;
433 
435  void clear() override;
436 
440 
447  const List<edge>& chain(edge e) const { return m_eCopy[e]; }
448 
449  using GraphCopyBase::copy;
450 
457  edge copy(edge e) const override { return m_eCopy[e].empty() ? nullptr : m_eCopy[e].front(); }
458 
469  adjEntry copy(adjEntry adj) const override {
470  auto& el = m_eCopy[adj->theEdge()];
471  if (el.empty()) {
472  return nullptr;
473  } else if (adj->isSource()) {
474  return el.front()->adjSource();
475  } else {
476  return el.back()->adjTarget();
477  }
478  }
479 
484  bool isReversed(edge e) const { return e->source() != original(copy(e)->source()); }
485 
492  bool isReversedCopyEdge(edge e) const;
494 
498 
506  void delEdge(edge e) override;
507 
513  edge split(edge e) override;
514 
523  void unsplit(edge eIn, edge eOut) override;
524 
526  edge newEdge(edge eOrig);
527 
528  using Graph::newEdge;
529 
531 
535  void setEdge(edge eOrig, edge eCopy);
536 
537  void setOriginalEmbedding() override;
538 
540  void removePseudoCrossings();
541 
544  bool hasSameEdgesCrossings() const;
545 
548  bool hasAdjacentEdgesCrossings() const;
549 
552 
559  inline bool hasNonSimpleCrossings() const {
560  return hasAdjacentEdgesCrossings() || hasSameEdgesCrossings();
561  };
562 
574  void removeNonSimpleCrossings(SListPure<edge>& edgesToCheck,
575  DynamicDualGraph* dualGraph = nullptr);
576 
586  inline void removeNonSimpleCrossings(DynamicDualGraph* dualGraph = nullptr) {
587  SListPure<edge> edgesToCheck;
588  m_pGraph->allEdges(edgesToCheck);
589  removeNonSimpleCrossings(edgesToCheck, dualGraph);
590  };
591 
603  inline void removeNonSimpleCrossings(node origNode, DynamicDualGraph* dualGraph = nullptr) {
604  SListPure<edge> edgesToCheck;
605  for (adjEntry adj : origNode->adjEntries) {
606  edgesToCheck.pushBack(adj->theEdge());
607  }
608  removeNonSimpleCrossings(edgesToCheck, dualGraph);
609  }
610 
612 
621  void insertEdgePath(edge eOrig, const SList<adjEntry>& crossedEdges);
622 
624  void insertEdgePath(node srcOrig, node tgtOrig, const SList<adjEntry>& crossedEdges);
625 
627 
630  void removeEdgePath(edge eOrig);
631 
633 
649  edge insertCrossing(edge& crossingEdge, edge crossedEdge, bool rightToLeft);
651 
655 
658 
672  edge newEdge(node v, adjEntry adj, edge eOrig, CombinatorialEmbedding& E);
673 
675 
694  void insertEdgePathEmbedded(edge eOrig, CombinatorialEmbedding& E,
695  const SList<adjEntry>& crossedEdges);
696 
697  void insertEdgePathEmbedded(edge eOrig, CombinatorialEmbedding& E, DynamicDualGraph& dual,
698  const SList<adjEntry>& crossedEdges);
699 
701 
711  void removeEdgePathEmbedded(CombinatorialEmbedding& E, edge eOrig, FaceSet<false>& newFaces);
712 
713  void removeEdgePathEmbedded(CombinatorialEmbedding& E, DynamicDualGraph& dual, edge eOrig);
714 
716 
719 
721 #ifdef OGDF_DEBUG
722  void consistencyCheck() const;
724 #endif
725 
727 
728 protected:
729  void edgeInserted(void* userData, edge original, edge copy) override;
730 
731 
732  void removeUnnecessaryCrossing(adjEntry adjA1, adjEntry adjA2, adjEntry adjB1, adjEntry adjB2);
733 
743  void removeUnnecessaryCrossing(adjEntry adj, DynamicDualGraph* dualGraph);
744 
752  void removeAdjacentEdgesCrossing(adjEntry adj1, adjEntry adj2, DynamicDualGraph* dualGraph);
753 
763  void removeSameEdgesCrossing(adjEntry adjFirstCrossing1, adjEntry adjFirstCrossing2,
764  adjEntry adjSecondCrossing1, adjEntry adjSecondCrossing2, DynamicDualGraph* dualGraph);
765 
774  void swapOriginalEdgesAtCrossing(adjEntry adjCopy1, adjEntry adjCopy2,
775  DynamicDualGraph* dual = nullptr);
776 
783  void swapOriginalEdgesBetweenCrossings(adjEntry adjFirstCrossing1, adjEntry adjFirstCrossing2,
784  adjEntry adjSecondCrossing1, adjEntry adjSecondCrossing2,
785  DynamicDualGraph* dual = nullptr);
786 
791  void setOriginalEdgeAlongCrossings(adjEntry adjCopy1, adjEntry adjCopy2, node vCopy,
792  edge eOrig1, edge eOrig2);
793 };
794 
795 OGDF_EXPORT void copyEmbedding(const Graph& from, Graph& to,
796  std::function<adjEntry(adjEntry)> adjMapFromTo);
797 
798 }
ogdf::GraphCopy::removeNonSimpleCrossings
void removeNonSimpleCrossings(DynamicDualGraph *dualGraph=nullptr)
Removes all non-simple cossings (see hasNonSimpleCrossings() for a definition of non-simple crossings...
Definition: GraphCopy.h:586
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::GraphCopyBase::original
node original(node v) const
Returns the node in the original graph corresponding to v.
Definition: GraphCopy.h:109
ogdf::GraphCopyBase::getOriginalGraph
const Graph * getOriginalGraph() const
Definition: GraphCopy.h:92
ogdf::GraphCopyBase::original
edge original(edge e) const
Returns the edge in the original graph corresponding to e.
Definition: GraphCopy.h:117
ogdf::GraphCopySimple::copy
edge copy(edge e) const override
Returns the edge in the graph copy corresponding to e.
Definition: GraphCopy.h:288
ogdf::GraphCopy::isReversed
bool isReversed(edge e) const
Returns true iff edge e has been reversed.
Definition: GraphCopy.h:484
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::Graph::delNode
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
ogdf::GraphCopyBase::m_vOrig
NodeArray< node > m_vOrig
The corresponding node in the original graph.
Definition: GraphCopy.h:47
OGDF_DEPRECATED
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition: config.h:120
ogdf::DualGraphBase
A dual graph including its combinatorial embedding of an embedded graph.
Definition: DualGraph.h:42
ogdf::GraphCopySimple::GraphCopySimple
GraphCopySimple(const Graph &G)
Definition: GraphCopy.h:260
ogdf::GraphCopy::hasNonSimpleCrossings
bool hasNonSimpleCrossings() const
Returns whether the GraphCopy contains crossings that will result in a non-simple drawing.
Definition: GraphCopy.h:559
ogdf::GraphCopyBase::isDummy
bool isDummy(node v) const
Returns true iff v has no corresponding node in the original graph.
Definition: GraphCopy.h:166
ogdf::sync_plan::split
std::pair< node, node > split(Graph &G, sync_plan::PipeBij &bij, const EdgeArray< edge > *new_edges=nullptr, const EdgeArray< bool > *reverse_edges=nullptr, node src=nullptr, node tgt=nullptr)
ogdf::SList
Singly linked lists (maintaining the length of the list).
Definition: SList.h:833
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:384
ogdf::GraphCopyBase::setOriginalGraph
virtual void setOriginalGraph(const Graph *G)=0
Re-initializes the copy using G (which might be null), but does not create any nodes or edges.
ogdf::GraphCopySimple
Copies of graphs with mapping between nodes and edges.
Definition: GraphCopy.h:254
ogdf::GraphCopyBase::isDummy
bool isDummy(adjEntry adj) const
Returns true iff adj->theEdge() has no corresponding edge in the original graph.
Definition: GraphCopy.h:178
ogdf::GraphCopySimple::copy
adjEntry copy(adjEntry adj) const override
Returns the adjacency entry in the graph copy corresponding to adj.
Definition: GraphCopy.h:301
ogdf::adjEntry
AdjElement * adjEntry
The type of adjacency entries.
Definition: Graph_d.h:71
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::AdjElement::isSource
bool isSource() const
Returns true iff this is the source adjacency entry of the corresponding edge.
Definition: Graph_d.h:472
ogdf::GraphCopyBase::getLinkCopiesOnInsert
bool getLinkCopiesOnInsert() const
Definition: GraphCopy.h:215
ogdf::GraphCopy::copy
adjEntry copy(adjEntry adj) const override
Returns the adjacency entry in the copy graph corresponding to adj.
Definition: GraphCopy.h:469
ogdf::GraphCopyBase::m_vCopy
NodeArray< node > m_vCopy
The corresponding node in the graph copy.
Definition: GraphCopy.h:49
ogdf::GraphCopy::GraphCopy
GraphCopy(const GraphCopy &other)
Definition: GraphCopy.h:400
ogdf::GraphCopyBase::init
void init(const Graph &G)
Re-initializes the copy using G, creating copies for all nodes and edges in G.
Definition: GraphCopy.h:66
ogdf::GraphCopyBase::original
adjEntry original(adjEntry adj) const
Returns the adjacency entry in the original graph corresponding to adj.
Definition: GraphCopy.h:129
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:153
ogdf::Graph::clear
virtual void clear()
Removes all nodes and all edges from the graph.
ogdf::GraphCopy::removeNonSimpleCrossings
void removeNonSimpleCrossings(node origNode, DynamicDualGraph *dualGraph=nullptr)
Removes all non-simple cossings involving edges incident to origNode (see hasNonSimpleCrossings() for...
Definition: GraphCopy.h:603
Minisat::Internal::copy
static void copy(const T &from, T &to)
Definition: Alg.h:61
ogdf::EdgeElement::graphOf
const Graph * graphOf() const
Returns the graph containing this node (debug only).
Definition: Graph_d.h:433
ogdf::GraphCopyBase::setLinkCopiesOnInsert
void setLinkCopiesOnInsert(bool linkCopiesOnInsert)
Whether insert(getOriginalGraph()) will automatically set copy and original.
Definition: GraphCopy.h:227
SList.h
Declaration of singly linked lists and iterators.
ogdf::GraphCopy::GraphCopy
GraphCopy(const Graph &G)
Definition: GraphCopy.h:392
ogdf::NodeElement::adjEntries
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:264
ogdf::GraphCopySimple::GraphCopySimple
GraphCopySimple()
Definition: GraphCopy.h:258
EdgeArray.h
Declaration and implementation of EdgeArray class.
ogdf::GraphCopy::chain
const List< edge > & chain(edge e) const
Returns the list of edges coresponding to edge e.
Definition: GraphCopy.h:447
ogdf::FaceSet< false >
DualGraph.h
Includes declaration of dual graph class.
ogdf::SListPure
Singly linked lists.
Definition: SList.h:39
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:391
ogdf::GraphCopyBase::newNode
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
Definition: GraphCopy.h:185
ogdf::List< edge >
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::GraphCopyBase::init
void init(const Graph *G)
Re-initializes the copy using G (which might be null), creating copies for all nodes and edges in G.
Definition: GraphCopy.h:73
ogdf::GraphCopy::m_eCopy
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition: GraphCopy.h:387
ogdf::EdgeElement::adjSource
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:400
ogdf::GraphCopyBase::delNode
void delNode(node v) override
Removes node v.
Definition: GraphCopy.h:200
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::GraphCopyBase
Definition: GraphCopy.h:44
ogdf::GraphCopy::copy
edge copy(edge e) const override
Returns the first edge in the list of edges corresponding to edge e.
Definition: GraphCopy.h:457
NodeArray.h
Declaration and implementation of NodeArray class.
ogdf::GraphCopySimple::GraphCopySimple
GraphCopySimple(const Graph *G)
Definition: GraphCopy.h:262
ogdf::EdgeElement::adjTarget
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:403
ogdf::graphics::init
void init()
Definition: graphics.h:446
ogdf::GraphCopyBase::isDummy
bool isDummy(edge e) const
Returns true iff e has no corresponding edge in the original graph.
Definition: GraphCopy.h:172
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::GraphCopyBase::setOriginalGraph
void setOriginalGraph(const Graph &G)
Re-initializes the copy using G, but does not create any nodes or edges.
Definition: GraphCopy.h:90
ogdf::Graph::newNode
node newNode(int index=-1)
Creates a new node and returns it.
Definition: Graph_d.h:1056
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:397
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
ogdf::NodeElement::graphOf
const Graph * graphOf() const
Returns the graph containing this node (debug only).
Definition: Graph_d.h:337
ogdf::GraphCopySimple::m_eCopy
EdgeArray< edge > m_eCopy
The corresponding edge in the graph copy.
Definition: GraphCopy.h:256
ogdf::SListPure::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:469
ogdf::GraphCopy::GraphCopy
GraphCopy()
Definition: GraphCopy.h:390
ogdf::GraphCopy::m_eIterator
EdgeArray< ListIterator< edge > > m_eIterator
The position of copy edge in the list.
Definition: GraphCopy.h:386
ogdf::EdgeElement::target
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:394
ogdf::GraphCopySimple::GraphCopySimple
GraphCopySimple(const GraphCopySimple &other)
Definition: GraphCopy.h:268
ogdf::Graph::newEdge
edge newEdge(node v, node w, int index=-1)
Creates a new edge (v,w) and returns it.
Definition: Graph_d.h:1075
ogdf::copyEmbedding
void copyEmbedding(const Graph &from, Graph &to, std::function< adjEntry(adjEntry)> adjMapFromTo)
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::GraphCopySimple::newEdge
edge newEdge(edge eOrig)
Creates a new edge in the graph copy with original edge eOrig.
Definition: GraphCopy.h:314
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:98
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::GraphCopy::GraphCopy
GraphCopy(const Graph *G)
Definition: GraphCopy.h:394
ogdf::GraphCopyBase::copy
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:140
ogdf::GraphCopyBase::m_eOrig
EdgeArray< edge > m_eOrig
The corresponding edge in the original graph.
Definition: GraphCopy.h:48