Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

GraphCopy.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/NodeArray.h>
35 #include <ogdf/basic/EdgeArray.h>
36 #include <ogdf/basic/SList.h>
38 
39 
40 namespace ogdf {
41 
42 template<bool b> class FaceSet;
43 
44 
61 {
62  const Graph *m_pGraph;
67 
68 public:
70  explicit GraphCopySimple(const Graph &G);
71 
74 
75  virtual ~GraphCopySimple() { }
76 
78  void init(const Graph &G);
79 
81  const Graph &original() const { return *m_pGraph; }
82 
89  node original(node v) const { return m_vOrig[v]; }
90 
97  edge original(edge e) const { return m_eOrig[e]; }
98 
110  edge f = m_eOrig[adj->theEdge()];
111  return adj->isSource() ? f->adjSource() : f->adjTarget();
112  }
113 
120  node copy(node v) const { return m_vCopy[v]; }
121 
128  edge copy(edge e) const { return m_eCopy[e]; }
129 
141  adjEntry copy(adjEntry adj) const {
142  edge f = m_eCopy[adj->theEdge()];
143  if (f == nullptr) { return nullptr; }
144  return adj->isSource() ? f->adjSource() : f->adjTarget();
145  }
146 
151  bool isDummy(node v) const { return m_vOrig[v] == nullptr; }
152 
157  bool isDummy(edge e) const { return m_eOrig[e] == nullptr; }
158 
160  GraphCopySimple &operator=(const GraphCopySimple &GC);
161 
167  node newNode(node vOrig) {
168  OGDF_ASSERT(vOrig != nullptr);
169  OGDF_ASSERT(vOrig->graphOf() == m_pGraph);
170  node v = Graph::newNode();
171  m_vCopy[m_vOrig[v] = vOrig] = v;
172  return v;
173  }
174 
175  using Graph::newNode;
176 
182  edge newEdge(edge eOrig) {
183  OGDF_ASSERT(eOrig != nullptr);
184  OGDF_ASSERT(eOrig->graphOf() == m_pGraph);
185 
186  edge e = Graph::newEdge(m_vCopy[eOrig->source()], m_vCopy[eOrig->target()]);
187  m_eCopy[m_eOrig[e] = eOrig] = e;
188 
189  return e;
190  }
191 
192  using Graph::newEdge;
193 
199  virtual void delEdge(edge e) override;
200 
206  virtual void delNode(node v) override;
207 
208 private:
209  void initGC(const GraphCopySimple &GC, NodeArray<node> &vCopy,
210  EdgeArray<edge> &eCopy);
211 };
212 
249 class OGDF_EXPORT GraphCopy : public Graph {
250 protected:
251 
252  const Graph *m_pGraph;
256 
259 
260 public:
262 
265  explicit GraphCopy(const Graph &G);
266 
268  GraphCopy() : Graph(), m_pGraph(nullptr) { }
269 
271 
275  GraphCopy(const GraphCopy &GC);
276 
277  virtual ~GraphCopy() { }
278 
279 
284 
286  const Graph &original() const { return *m_pGraph; }
287 
294  node original(node v) const { return m_vOrig[v]; }
295 
302  edge original(edge e) const { return m_eOrig[e]; }
303 
318  edge e = adj->theEdge();
319  edge f = m_eOrig[e];
320 
321  if (adj->isSource()) {
322  OGDF_ASSERT(m_eCopy[f].front() == e);
323  return f->adjSource();
324  } else {
325  OGDF_ASSERT(m_eCopy[f].back() == e);
326  return f->adjTarget();
327  }
328  }
329 
335  node copy(node v) const { return m_vCopy[v]; }
336 
342  const List<edge> &chain(edge e) const { return m_eCopy[e]; }
343 
344  // returns first edge in chain(e)
351  edge copy(edge e) const { return m_eCopy[e].empty() ? nullptr : m_eCopy[e].front(); }
352 
363  adjEntry copy(adjEntry adj) const {
364  edge e = adj->theEdge();
365 
366  if (adj->isSource()) {
367  return m_eCopy[e].front()->adjSource();
368  } else {
369  return m_eCopy[e].back()->adjTarget();
370  }
371  }
372 
377  bool isDummy(node v) const { return m_vOrig[v] == nullptr; }
378 
383  bool isDummy(edge e) const { return m_eOrig[e] == nullptr; }
384 
389  bool isReversed (edge e) const {
390  return e->source() != original(copy(e)->source());
391  }
392 
399  bool isReversedCopyEdge (edge e) const;
400 
401 
406 
412  node newNode(node vOrig) {
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 
460  edge newEdge(edge eOrig);
461 
462  using Graph::newEdge;
463 
465 
469  void setEdge(edge eOrig, edge eCopy);
470 
472  OGDF_DEPRECATED("Use ogdf::planarEmbed() instead.")
473  bool embed();
474 
476  void removePseudoCrossings();
477 
479 
488  void insertEdgePath(edge eOrig, const SList<adjEntry> &crossedEdges);
489 
491  void insertEdgePath(node srcOrig, node tgtOrig, const SList<adjEntry> &crossedEdges);
492 
493 
495 
498  void removeEdgePath(edge eOrig);
499 
501 
517  edge insertCrossing(
518  edge& crossingEdge,
519  edge crossedEdge,
520  bool rightToLeft);
521 
522 
527 
529 
543  edge newEdge(node v, adjEntry adj, edge eOrig, CombinatorialEmbedding &E);
544 
550  void setOriginalEmbedding();
551 
553 
572  void insertEdgePathEmbedded(
573  edge eOrig,
575  const SList<adjEntry> &crossedEdges);
576 
578 
584  void removeEdgePathEmbedded(
586  edge eOrig,
587  FaceSet<false> &newFaces);
588 
589 
591 
595 
596 #ifdef OGDF_DEBUG
597  void consistencyCheck() const;
599 #endif
600 
602 
609  void init(const Graph &G);
610 
612 
641  void createEmpty(const Graph &G);
642 
644 
649  void initByCC(const CCsInfo &info, int cc, EdgeArray<edge> &eCopy);
650 
652 
668  void initByNodes(const List<node> &origNodes, EdgeArray<edge> &eCopy);
669 
671 
683  void initByActiveNodes(const List<node> &nodeList,
684  const NodeArray<bool> &activeNodes, EdgeArray<edge> &eCopy);
685 
687 
691 
693 
701  GraphCopy &operator=(const GraphCopy &GC);
702 
703 
705 
706 protected:
707  void removeUnnecessaryCrossing(
708  adjEntry adjA1,
709  adjEntry adjA2,
710  adjEntry adjB1,
711  adjEntry adjB2);
712 
713 private:
714  void initGC(const GraphCopy &GC,
715  NodeArray<node> &vCopy, EdgeArray<edge> &eCopy);
716 };
717 
718 }
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:328
Declaration of singly linked lists and iterators.
bool isSource() const
Returns true iff this is the source adjacency entry of the corresponding edge.
Definition: Graph_d.h:396
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:96
const Graph * m_pGraph
The original graph.
Definition: GraphCopy.h:62
NodeArray< node > m_vOrig
The corresponding node in the original graph.
Definition: GraphCopy.h:63
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:335
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:81
virtual ~GraphCopySimple()
Definition: GraphCopy.h:75
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
Definition: GraphCopy.h:412
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
adjEntry original(adjEntry adj) const
Returns the adjacency entry in the original graph corresponding to adj.
Definition: GraphCopy.h:109
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:333
node original(node v) const
Returns the node in the original graph corresponding to v.
Definition: GraphCopy.h:294
NodeArray< node > m_vOrig
The corresponding node in the original graph.
Definition: GraphCopy.h:253
edge original(edge e) const
Returns the edge in the original graph corresponding to e.
Definition: GraphCopy.h:302
Declaration of CombinatorialEmbedding and face.
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition: GraphCopy.h:258
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
void init()
Definition: graphics.h:472
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
Definition: GraphCopy.h:167
Singly linked lists (maintaining the length of the list).
Definition: SList.h:773
edge copy(edge e) const
Returns the first edge in the list of edges coresponding to edge e.
Definition: GraphCopy.h:351
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:438
bool empty() const
Returns true iff there are no elements in the array.
Definition: Array.h:285
Declaration and implementation of EdgeArray class.
bool isReversed(edge e) const
Returns true iff edge e has been reversed.
Definition: GraphCopy.h:389
EdgeArray< edge > m_eOrig
The corresponding edge in the original graph.
Definition: GraphCopy.h:254
GraphCopy()
Default constructor (does nothing!).
Definition: GraphCopy.h:268
static void copy(const T &from, T &to)
Definition: Alg.h:61
bool isDummy(edge e) const
Returns true iff e has no corresponding edge in the original graph.
Definition: GraphCopy.h:157
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
const List< edge > & chain(edge e) const
Returns the list of edges coresponding to edge e.
Definition: GraphCopy.h:342
Class for the representation of edges.
Definition: Graph_d.h:292
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
Copies of graphs with mapping between nodes and edges.
Definition: GraphCopy.h:60
adjEntry original(adjEntry adj) const
Returns the adjacency entry in the original graph corresponding to adj.
Definition: GraphCopy.h:317
EdgeArray< edge > m_eOrig
The corresponding edge in the original graph.
Definition: GraphCopy.h:65
Class for the representation of nodes.
Definition: Graph_d.h:169
Declaration and implementation of NodeArray class.
NodeArray< node > m_vCopy
The corresponding node in the graph copy.
Definition: GraphCopy.h:64
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:286
node original(node v) const
Returns the node in the original graph corresponding to v.
Definition: GraphCopy.h:89
Info structure for maintaining connected components.
Definition: Graph_d.h:1310
edge copy(edge e) const
Returns the edge in the graph copy corresponding to e.
Definition: GraphCopy.h:128
Edges are oriented from right to left.
NodeArray< node > m_vCopy
The corresponding node in the graph copy.
Definition: GraphCopy.h:257
virtual ~GraphCopy()
Definition: GraphCopy.h:277
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:120
edge newEdge(edge eOrig)
Creates a new edge in the graph copy with original edge eOrig.
Definition: GraphCopy.h:182
bool isDummy(node v) const
Returns true iff v has no corresponding node in the original graph.
Definition: GraphCopy.h:151
const Graph * m_pGraph
The original graph.
Definition: GraphCopy.h:252
EdgeArray< edge > m_eCopy
The corresponding edge in the graph copy.
Definition: GraphCopy.h:66
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition: config.h:118
EdgeArray< ListIterator< edge > > m_eIterator
The position of copy edge in the list.
Definition: GraphCopy.h:255
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:326
adjEntry copy(adjEntry adj) const
Returns the adjacency entry in the copy graph corresponding to adj.
Definition: GraphCopy.h:363
The namespace for all OGDF objects.
edge original(edge e) const
Returns the edge in the original graph corresponding to e.
Definition: GraphCopy.h:97
node newNode()
Creates a new node and returns it.
bool isDummy(node v) const
Returns true iff v has no corresponding node in the original graph.
Definition: GraphCopy.h:377
Combinatorial embeddings of planar graphs with modification functionality.
bool isDummy(edge e) const
Returns true iff e has no corresponding edge in the original graph.
Definition: GraphCopy.h:383
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:335
Class for adjacency list elements.
Definition: Graph_d.h:79
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
adjEntry copy(adjEntry adj) const
Returns the adjacency entry in the graph copy corresponding to adj.
Definition: GraphCopy.h:141