Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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 class FaceSetPure;
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 }; // class GraphCopySimple
212 
213 
250 class OGDF_EXPORT GraphCopy : public Graph {
251 protected:
252 
253  const Graph *m_pGraph;
257 
260 
261 public:
263 
266  explicit GraphCopy(const Graph &G);
267 
269  GraphCopy() : Graph(), m_pGraph(nullptr) { }
270 
272 
276  GraphCopy(const GraphCopy &GC);
277 
278  virtual ~GraphCopy() { }
279 
280 
285 
287  const Graph &original() const { return *m_pGraph; }
288 
295  node original(node v) const { return m_vOrig[v]; }
296 
303  edge original(edge e) const { return m_eOrig[e]; }
304 
319  edge e = adj->theEdge();
320  edge f = m_eOrig[e];
321 
322  if (adj->isSource()) {
323  OGDF_ASSERT(m_eCopy[f].front() == e);
324  return f->adjSource();
325  } else {
326  OGDF_ASSERT(m_eCopy[f].back() == e);
327  return f->adjTarget();
328  }
329  }
330 
336  node copy(node v) const { return m_vCopy[v]; }
337 
343  const List<edge> &chain(edge e) const { return m_eCopy[e]; }
344 
345  // returns first edge in chain(e)
352  edge copy(edge e) const { return (m_eCopy[e].empty() ? nullptr : m_eCopy[e].front()); }
353 
364  adjEntry copy(adjEntry adj) const {
365  edge e = adj->theEdge();
366 
367  if (adj->isSource()) {
368  return m_eCopy[e].front()->adjSource();
369  } else {
370  return m_eCopy[e].back()->adjTarget();
371  }
372  }
373 
378  bool isDummy(node v) const { return m_vOrig[v] == nullptr; }
379 
384  bool isDummy(edge e) const { return m_eOrig[e] == nullptr; }
385 
390  bool isReversed (edge e) const {
391  return e->source() != original(copy(e)->source());
392  }
393 
400  bool isReversedCopyEdge (edge e) const;
401 
402 
407 
413  node newNode(node vOrig) {
414  OGDF_ASSERT(vOrig != nullptr);
415  OGDF_ASSERT(vOrig->graphOf() == m_pGraph);
416  node v = Graph::newNode();
417  m_vCopy[m_vOrig[v] = vOrig] = v;
418  return v;
419  }
420 
421  using Graph::newNode;
422 
429  virtual void delNode(node v) override;
430 
437  virtual void delEdge(edge e) override;
438 
439 
440  virtual void clear() override;
441 
447  virtual edge split(edge e) override;
448 
449 
458  void unsplit(edge eIn, edge eOut) override;
459 
461  edge newEdge(edge eOrig);
462 
463  using Graph::newEdge;
464 
466 
470  void setEdge(edge eOrig, edge eCopy);
471 
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  FaceSetPure &newFaces);
588 
589 
591 
595 
597  bool consistencyCheck() const;
598 
600 
607  void init(const Graph &G);
608 
610 
639  void createEmpty(const Graph &G);
640 
642 
647  void initByCC(const CCsInfo &info, int cc, EdgeArray<edge> &eCopy);
648 
650 
666  void initByNodes(const List<node> &origNodes, EdgeArray<edge> &eCopy);
667 
669 
681  void initByActiveNodes(const List<node> &nodeList,
682  const NodeArray<bool> &activeNodes, EdgeArray<edge> &eCopy);
683 
685 
689 
691 
699  GraphCopy &operator=(const GraphCopy &GC);
700 
701 
703 
704 protected:
705  void removeUnnecessaryCrossing(
706  adjEntry adjA1,
707  adjEntry adjA2,
708  adjEntry adjB1,
709  adjEntry adjB2);
710 
711 private:
712  void initGC(const GraphCopy &GC,
713  NodeArray<node> &vCopy, EdgeArray<edge> &eCopy);
714 
715 }; // class GraphCopy
716 
717 
718 } // end namespace ogdf
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:327
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:381
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:95
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:336
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:413
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
#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:330
node original(node v) const
Returns the node in the original graph corresponding to v.
Definition: GraphCopy.h:295
NodeArray< node > m_vOrig
The corresponding node in the original graph.
Definition: GraphCopy.h:254
edge original(edge e) const
Returns the edge in the original graph corresponding to e.
Definition: GraphCopy.h:303
Declaration of CombinatorialEmbedding and face.
EdgeArray< List< edge > > m_eCopy
The corresponding list of edges in the graph copy.
Definition: GraphCopy.h:259
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
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:777
edge copy(edge e) const
Returns the first edge in the list of edges coresponding to edge e.
Definition: GraphCopy.h:352
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
Declaration and implementation of EdgeArray class.
bool isReversed(edge e) const
Returns true iff edge e has been reversed.
Definition: GraphCopy.h:390
EdgeArray< edge > m_eOrig
The corresponding edge in the original graph.
Definition: GraphCopy.h:255
GraphCopy()
Default constructor (does nothing!).
Definition: GraphCopy.h:269
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:343
Class for the representation of edges.
Definition: Graph_d.h:291
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:250
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:318
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:167
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:287
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:1286
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:258
virtual ~GraphCopy()
Definition: GraphCopy.h:278
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:253
EdgeArray< edge > m_eCopy
The corresponding edge in the graph copy.
Definition: GraphCopy.h:66
EdgeArray< ListIterator< edge > > m_eIterator
The position of copy edge in the list.
Definition: GraphCopy.h:256
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:325
Face sets.
Definition: FaceSet.h:138
adjEntry copy(adjEntry adj) const
Returns the adjacency entry in the copy graph corresponding to adj.
Definition: GraphCopy.h:364
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:378
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:384
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:332
Class for adjacency list elements.
Definition: Graph_d.h:78
#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