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/Graph.h>
36 #include <ogdf/basic/GraphList.h>
37 #include <ogdf/basic/List.h>
38 #include <ogdf/basic/SList.h>
39 #include <ogdf/basic/basic.h>
42 
43 #include <functional>
44 
45 namespace ogdf {
46 
47 class CombinatorialEmbedding;
48 template<bool>
49 class FaceSet;
50 
52 protected:
53  const Graph* m_pGraph = nullptr;
57  bool m_linkCopiesOnInsert =
58  true;
59 
60 public:
62  GraphCopyBase() = default;
63 
64  GraphCopyBase(const GraphCopyBase& other) = delete;
65 
66  GraphCopyBase(GraphCopyBase&& other) noexcept = delete;
67 
68  GraphCopyBase& operator=(const GraphCopyBase& other) = delete;
69 
70  GraphCopyBase& operator=(GraphCopyBase&& other) noexcept = delete;
71 
73  void init(const Graph& G) {
74  Graph::clear();
75  setOriginalGraph(&G);
76  insert(G);
77  }
78 
80  void init(const Graph* G) {
81  Graph::clear();
82  setOriginalGraph(G);
83  if (G != nullptr) {
84  insert(*G);
85  }
86  }
87 
89  OGDF_DEPRECATED("setOriginalGraph() should be used instead.")
90 
91  void createEmpty(const Graph& G) { setOriginalGraph(&G); }
92 
94  virtual void setOriginalGraph(const Graph* G) = 0;
95 
97  void setOriginalGraph(const Graph& G) { setOriginalGraph(&G); };
98 
99  const Graph* getOriginalGraph() const { return m_pGraph; }
100 
102  void clear() override = 0;
103 
105  const Graph& original() const {
106  OGDF_ASSERT(m_pGraph != nullptr);
107  return *m_pGraph;
108  }
109 
116  node original(node v) const { return m_vOrig[v]; }
117 
124  edge original(edge e) const { return m_eOrig[e]; }
125 
137  edge f = m_eOrig[adj->theEdge()];
138  return adj->isSource() ? f->adjSource() : f->adjTarget();
139  }
140 
147  node copy(node v) const { return m_vCopy[v]; }
148 
157  virtual edge copy(edge e) const = 0;
158 
167  virtual adjEntry copy(adjEntry adj) const = 0;
168 
173  bool isDummy(node v) const { return m_vOrig[v] == nullptr; }
174 
179  bool isDummy(edge e) const { return m_eOrig[e] == nullptr; }
180 
185  bool isDummy(adjEntry adj) const { return isDummy(adj->theEdge()); }
186 
192  node newNode(node vOrig) {
193  OGDF_ASSERT(vOrig != nullptr);
194  OGDF_ASSERT(vOrig->graphOf() == m_pGraph);
195  node v = Graph::newNode();
196  m_vCopy[m_vOrig[v] = vOrig] = v;
197  return v;
198  }
199 
200  using Graph::newNode;
201 
207  void delNode(node v) override {
208  node vOrig = m_vOrig[v];
209  Graph::delNode(v);
210  if (vOrig != nullptr) {
211  m_vCopy[vOrig] = nullptr;
212  }
213  }
214 
216 
220  virtual void setOriginalEmbedding() = 0;
221 
222  bool getLinkCopiesOnInsert() const { return m_linkCopiesOnInsert; }
223 
225 
234  void setLinkCopiesOnInsert(bool linkCopiesOnInsert) {
235  m_linkCopiesOnInsert = linkCopiesOnInsert;
236  }
237 
238 protected:
239  void* preInsert(bool copyEmbedding, bool copyIDs, bool notifyObservers, bool edgeFilter,
240  NodeArray<node>& nodeMap, EdgeArray<edge>& edgeMap, int* newNodes,
241  int* newEdges) override;
242 
243  void nodeInserted(void* userData, node original, node copy) override;
244 };
245 
262 public:
264 
265  explicit GraphCopySimple() : GraphCopySimple(nullptr) { }
266 
267  explicit GraphCopySimple(const Graph& G) : GraphCopySimple(&G) { }
268 
269  explicit GraphCopySimple(const Graph* G) : GraphCopyBase() {
270  if (G) {
271  init(*G);
272  }
273  }
274 
275  GraphCopySimple(const GraphCopySimple& other) : GraphCopyBase() { *this = other; }
276 
277  GraphCopySimple& operator=(const GraphCopySimple& other);
278 
280 
282  void setOriginalGraph(const Graph* G) override;
283 
285  void clear() override;
286 
287  using GraphCopyBase::copy;
288 
295  edge copy(edge e) const override { return m_eCopy[e]; }
296 
308  adjEntry copy(adjEntry adj) const override {
309  edge f = m_eCopy[adj->theEdge()];
310  if (f == nullptr) {
311  return nullptr;
312  }
313  return adj->isSource() ? f->adjSource() : f->adjTarget();
314  }
315 
321  edge newEdge(edge eOrig) {
322  OGDF_ASSERT(eOrig != nullptr);
323  OGDF_ASSERT(eOrig->graphOf() == m_pGraph);
324 
325  edge e = Graph::newEdge(m_vCopy[eOrig->source()], m_vCopy[eOrig->target()]);
326  m_eCopy[m_eOrig[e] = eOrig] = e;
327 
328  return e;
329  }
330 
331  using Graph::newEdge;
332 
338  void delEdge(edge e) override;
339 
340  void setOriginalEmbedding() override;
341 
349  void copyEmbeddingToOriginal(Graph& orig) const;
350 
351 protected:
352  void edgeInserted(void* userData, edge original, edge copy) override;
353 };
354 
392 protected:
395 
396 public:
397  explicit GraphCopy() : GraphCopy(nullptr) { }
398 
399  explicit GraphCopy(const Graph& G) : GraphCopy(&G) { }
400 
401  explicit GraphCopy(const Graph* G) : GraphCopyBase() {
402  if (G) {
403  init(*G);
404  }
405  }
406 
407  GraphCopy(const GraphCopy& other) : GraphCopyBase() { *this = other; }
408 
409  GraphCopy& operator=(const GraphCopy& other);
410 
412 
414 
439  void setOriginalGraph(const Graph* G) override;
440 
442  void clear() override;
443 
447 
454  const List<edge>& chain(edge e) const { return m_eCopy[e]; }
455 
456  using GraphCopyBase::copy;
457 
464  edge copy(edge e) const override { return m_eCopy[e].empty() ? nullptr : m_eCopy[e].front(); }
465 
476  adjEntry copy(adjEntry adj) const override {
477  auto& el = m_eCopy[adj->theEdge()];
478  if (el.empty()) {
479  return nullptr;
480  } else if (adj->isSource()) {
481  return el.front()->adjSource();
482  } else {
483  return el.back()->adjTarget();
484  }
485  }
486 
491  bool isReversed(edge e) const { return e->source() != original(copy(e)->source()); }
492 
499  bool isReversedCopyEdge(edge e) const;
501 
505 
513  void delEdge(edge e) override;
514 
520  edge split(edge e) override;
521 
530  void unsplit(edge eIn, edge eOut) override;
531 
533  edge newEdge(edge eOrig);
534 
535  using Graph::newEdge;
536 
538 
542  void setEdge(edge eOrig, edge eCopy);
543 
544  void setOriginalEmbedding() override;
545 
547  void removePseudoCrossings();
548 
551  bool hasSameEdgesCrossings() const;
552 
555  bool hasAdjacentEdgesCrossings() const;
556 
559 
566  inline bool hasNonSimpleCrossings() const {
567  return hasAdjacentEdgesCrossings() || hasSameEdgesCrossings();
568  };
569 
581  void removeNonSimpleCrossings(SListPure<edge>& edgesToCheck,
582  DynamicDualGraph* dualGraph = nullptr);
583 
593  inline void removeNonSimpleCrossings(DynamicDualGraph* dualGraph = nullptr) {
594  SListPure<edge> edgesToCheck;
595  m_pGraph->allEdges(edgesToCheck);
596  removeNonSimpleCrossings(edgesToCheck, dualGraph);
597  };
598 
610  inline void removeNonSimpleCrossings(node origNode, DynamicDualGraph* dualGraph = nullptr) {
611  SListPure<edge> edgesToCheck;
612  for (adjEntry adj : origNode->adjEntries) {
613  edgesToCheck.pushBack(adj->theEdge());
614  }
615  removeNonSimpleCrossings(edgesToCheck, dualGraph);
616  }
617 
619 
628  void insertEdgePath(edge eOrig, const SList<adjEntry>& crossedEdges);
629 
631  void insertEdgePath(node srcOrig, node tgtOrig, const SList<adjEntry>& crossedEdges);
632 
634 
637  void removeEdgePath(edge eOrig);
638 
640 
656  edge insertCrossing(edge& crossingEdge, edge crossedEdge, bool rightToLeft);
658 
662 
665 
679  edge newEdge(node v, adjEntry adj, edge eOrig, CombinatorialEmbedding& E);
680 
682 
701  void insertEdgePathEmbedded(edge eOrig, CombinatorialEmbedding& E,
702  const SList<adjEntry>& crossedEdges);
703 
704  void insertEdgePathEmbedded(edge eOrig, CombinatorialEmbedding& E, DynamicDualGraph& dual,
705  const SList<adjEntry>& crossedEdges);
706 
708 
718  void removeEdgePathEmbedded(CombinatorialEmbedding& E, edge eOrig, FaceSet<false>& newFaces);
719 
720  void removeEdgePathEmbedded(CombinatorialEmbedding& E, DynamicDualGraph& dual, edge eOrig);
721 
723 
726 
728 #ifdef OGDF_DEBUG
729  void consistencyCheck() const;
731 #endif
732 
734 
735 protected:
736  void edgeInserted(void* userData, edge original, edge copy) override;
737 
738 
739  void removeUnnecessaryCrossing(adjEntry adjA1, adjEntry adjA2, adjEntry adjB1, adjEntry adjB2);
740 
750  void removeUnnecessaryCrossing(adjEntry adj, DynamicDualGraph* dualGraph);
751 
759  void removeAdjacentEdgesCrossing(adjEntry adj1, adjEntry adj2, DynamicDualGraph* dualGraph);
760 
770  void removeSameEdgesCrossing(adjEntry adjFirstCrossing1, adjEntry adjFirstCrossing2,
771  adjEntry adjSecondCrossing1, adjEntry adjSecondCrossing2, DynamicDualGraph* dualGraph);
772 
781  void swapOriginalEdgesAtCrossing(adjEntry adjCopy1, adjEntry adjCopy2,
782  DynamicDualGraph* dual = nullptr);
783 
790  void swapOriginalEdgesBetweenCrossings(adjEntry adjFirstCrossing1, adjEntry adjFirstCrossing2,
791  adjEntry adjSecondCrossing1, adjEntry adjSecondCrossing2,
792  DynamicDualGraph* dual = nullptr);
793 
798  void setOriginalEdgeAlongCrossings(adjEntry adjCopy1, adjEntry adjCopy2, node vCopy,
799  edge eOrig1, edge eOrig2);
800 };
801 
802 OGDF_EXPORT void copyEmbedding(const Graph& from, Graph& to,
803  std::function<adjEntry(adjEntry)> adjMapFromTo);
804 
805 }
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:593
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::GraphCopyBase::original
node original(node v) const
Returns the node in the original graph corresponding to v.
Definition: GraphCopy.h:116
ogdf::GraphCopyBase::getOriginalGraph
const Graph * getOriginalGraph() const
Definition: GraphCopy.h:99
Graph.h
Includes declaration of graph class.
ogdf::GraphCopyBase::original
edge original(edge e) const
Returns the edge in the original graph corresponding to e.
Definition: GraphCopy.h:124
ogdf::GraphCopySimple::copy
edge copy(edge e) const override
Returns the edge in the graph copy corresponding to e.
Definition: GraphCopy.h:295
ogdf::GraphCopy::isReversed
bool isReversed(edge e) const
Returns true iff edge e has been reversed.
Definition: GraphCopy.h:491
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
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:54
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:47
ogdf::GraphCopySimple::GraphCopySimple
GraphCopySimple(const Graph &G)
Definition: GraphCopy.h:267
ogdf::GraphCopy::hasNonSimpleCrossings
bool hasNonSimpleCrossings() const
Returns whether the GraphCopy contains crossings that will result in a non-simple drawing.
Definition: GraphCopy.h:566
ogdf::GraphCopyBase::isDummy
bool isDummy(node v) const
Returns true iff v has no corresponding node in the original graph.
Definition: GraphCopy.h:173
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:845
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
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:261
ogdf::GraphCopyBase::isDummy
bool isDummy(adjEntry adj) const
Returns true iff adj->theEdge() has no corresponding edge in the original graph.
Definition: GraphCopy.h:185
ogdf::GraphCopySimple::copy
adjEntry copy(adjEntry adj) const override
Returns the adjacency entry in the graph copy corresponding to adj.
Definition: GraphCopy.h:308
ogdf::adjEntry
AdjElement * adjEntry
The type of adjacency entries.
Definition: Graph_d.h:78
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::AdjElement::isSource
bool isSource() const
Returns true iff this is the source adjacency entry of the corresponding edge.
Definition: Graph_d.h:479
ogdf::GraphCopyBase::getLinkCopiesOnInsert
bool getLinkCopiesOnInsert() const
Definition: GraphCopy.h:222
ogdf::GraphCopy::copy
adjEntry copy(adjEntry adj) const override
Returns the adjacency entry in the copy graph corresponding to adj.
Definition: GraphCopy.h:476
ogdf::GraphCopyBase::m_vCopy
NodeArray< node > m_vCopy
The corresponding node in the graph copy.
Definition: GraphCopy.h:56
ogdf::GraphCopy::GraphCopy
GraphCopy(const GraphCopy &other)
Definition: GraphCopy.h:407
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:73
ogdf::GraphCopyBase::original
adjEntry original(adjEntry adj) const
Returns the adjacency entry in the original graph corresponding to adj.
Definition: GraphCopy.h:136
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:160
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:610
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:440
ogdf::GraphCopyBase::setLinkCopiesOnInsert
void setLinkCopiesOnInsert(bool linkCopiesOnInsert)
Whether insert(getOriginalGraph()) will automatically set copy and original.
Definition: GraphCopy.h:234
SList.h
Declaration of singly linked lists and iterators.
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::GraphCopy::GraphCopy
GraphCopy(const Graph &G)
Definition: GraphCopy.h:399
ogdf::NodeElement::adjEntries
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:271
ogdf::GraphCopySimple::GraphCopySimple
GraphCopySimple()
Definition: GraphCopy.h:265
ogdf::GraphCopy::chain
const List< edge > & chain(edge e) const
Returns the list of edges coresponding to edge e.
Definition: GraphCopy.h:454
ogdf::FaceSet< false >
DualGraph.h
Includes declaration of dual graph class.
ogdf::SListPure
Singly linked lists.
Definition: SList.h:52
config_autogen.h
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:398
ogdf::GraphCopyBase::newNode
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
Definition: GraphCopy.h:192
ogdf::List< edge >
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
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:80
ogdf::GraphCopy::m_eCopy
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition: GraphCopy.h:394
ogdf::EdgeElement::adjSource
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:407
ogdf::GraphCopyBase::delNode
void delNode(node v) override
Removes node v.
Definition: GraphCopy.h:207
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::GraphCopyBase
Definition: GraphCopy.h:51
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:464
graph_iterators.h
Decralation of graph iterators.
ogdf::GraphCopySimple::GraphCopySimple
GraphCopySimple(const Graph *G)
Definition: GraphCopy.h:269
ogdf::EdgeElement::adjTarget
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:410
ogdf::graphics::init
void init()
Definition: graphics.h:450
basic.h
Basic declarations, included by all source files.
ogdf::GraphCopyBase::isDummy
bool isDummy(edge e) const
Returns true iff e has no corresponding edge in the original graph.
Definition: GraphCopy.h:179
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:97
ogdf::Graph::newNode
node newNode(int index=-1)
Creates a new node and returns it.
Definition: Graph_d.h:1064
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:406
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
List.h
Declaration of doubly linked lists and iterators.
ogdf::NodeElement::graphOf
const Graph * graphOf() const
Returns the graph containing this node (debug only).
Definition: Graph_d.h:344
ogdf::GraphCopySimple::m_eCopy
EdgeArray< edge > m_eCopy
The corresponding edge in the graph copy.
Definition: GraphCopy.h:263
ogdf::SListPure::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:481
ogdf::GraphCopy::GraphCopy
GraphCopy()
Definition: GraphCopy.h:397
ogdf::GraphCopy::m_eIterator
EdgeArray< ListIterator< edge > > m_eIterator
The position of copy edge in the list.
Definition: GraphCopy.h:393
ogdf::EdgeElement::target
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:401
ogdf::GraphCopySimple::GraphCopySimple
GraphCopySimple(const GraphCopySimple &other)
Definition: GraphCopy.h:275
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:1083
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:240
ogdf::GraphCopySimple::newEdge
edge newEdge(edge eOrig)
Creates a new edge in the graph copy with original edge eOrig.
Definition: GraphCopy.h:321
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:105
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::GraphCopy::GraphCopy
GraphCopy(const Graph *G)
Definition: GraphCopy.h:401
ogdf::GraphCopyBase::copy
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:147
ogdf::GraphCopyBase::m_eOrig
EdgeArray< edge > m_eOrig
The corresponding edge in the original graph.
Definition: GraphCopy.h:55