Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

CombinatorialEmbedding.h
Go to the documentation of this file.
1 
34 #pragma once
35 
36 #include <ogdf/basic/Graph.h>
37 #include <ogdf/basic/GraphList.h>
38 #include <ogdf/basic/basic.h>
39 #include <ogdf/basic/comparer.h>
42 #include <ogdf/basic/memory.h>
43 
44 #include <functional>
45 #include <iosfwd>
46 
47 namespace ogdf {
48 
49 using face = FaceElement*;
50 
52 OGDF_EXPORT std::ostream& operator<<(std::ostream& os, ogdf::face f);
53 
54 // Definition of iterator and container types for adjacency entries in a face
55 // These declarations are just internal representations
56 namespace internal {
57 
62 
63 public:
64  FaceAdjIterator() : m_adj(nullptr), m_adjFirst(nullptr) { }
65 
66  explicit FaceAdjIterator(adjEntry adj) : m_adj(adj), m_adjFirst(adj) { }
67 
68  FaceAdjIterator(adjEntry adjFirst, adjEntry adj) : m_adj(adj), m_adjFirst(adjFirst) { }
69 
70  FaceAdjIterator(const FaceAdjIterator&) = default;
71  FaceAdjIterator& operator=(const FaceAdjIterator&) = default;
72 
73  bool operator==(const FaceAdjIterator& other) const { return m_adj == other.m_adj; }
74 
75  bool operator!=(const FaceAdjIterator& other) const { return m_adj != other.m_adj; }
76 
77  adjEntry operator*() const { return m_adj; }
78 
80  OGDF_ASSERT(m_adj != nullptr);
82  if (m_adj == m_adjFirst) {
83  m_adj = nullptr;
84  }
85  return *this;
86  }
87 };
88 
90 
95  friend class ogdf::FaceElement;
98 
100 
101  FaceAdjContainer() : m_adjFirst(nullptr) { }
102 
103  explicit FaceAdjContainer(adjEntry adjFirst) : m_adjFirst(adjFirst) { }
104 
105 public:
107 
108  iterator begin() const { return iterator(m_adjFirst); }
109 
110  iterator end() const { return iterator(); }
111 };
112 
113 }
114 
122 
123  //adjEntry m_adjFirst; //!< The first adjacency element in the face.
124  int m_id;
125  int m_size;
126 
127 #ifdef OGDF_DEBUG
129 #endif
130 
131 #ifdef OGDF_DEBUG
132  FaceElement(const ConstCombinatorialEmbedding* pEmbedding, adjEntry adjFirst, int id)
134  : m_id(id), m_size(0), m_pEmbedding(pEmbedding), entries(adjFirst) { }
135 #else
136  FaceElement(adjEntry adjFirst, int id) : m_id(id), m_size(0), entries(adjFirst) { }
138 #endif
139 
140 public:
143 
145  int index() const { return m_id; }
146 
148  adjEntry firstAdj() const { return entries.m_adjFirst; }
149 
151  int size() const { return m_size; }
152 
154  face succ() const { return static_cast<face>(m_next); }
155 
157  face pred() const { return static_cast<face>(m_prev); }
158 
161  adj = adj->faceCycleSucc();
162  return (adj != entries.m_adjFirst) ? adj : nullptr;
163  }
164 
165 #ifdef OGDF_DEBUG
166  const ConstCombinatorialEmbedding* embeddingOf() const { return m_pEmbedding; }
167 #endif
168 
170  static int compare(const FaceElement& x, const FaceElement& y) { return x.m_id - y.m_id; }
172 
174 };
175 
178 
180 template<class Value, bool WithDefault>
181 class FaceArrayBase : public RegisteredArray<ConstCombinatorialEmbedding, Value, WithDefault> {
183 
184 public:
185  using RA::RA;
186 
188  ConstCombinatorialEmbedding* embeddingOf() const { return RA::registeredAt(); }
189 };
190 
191 #define OGDF_DECL_REG_ARRAY_TYPE(v, c) FaceArrayBase<v, c>
193 #undef OGDF_DECL_REG_ARRAY_TYPE
194 
217 protected:
218  const Graph* m_cpGraph;
219 
221 
224 
225 public:
228 
231 
234 
236 
240  explicit ConstCombinatorialEmbedding(const Graph& G);
241 
244 
247 
249  virtual ~ConstCombinatorialEmbedding();
250 
252  bool valid() const { return m_cpGraph != nullptr; }
253 
255 
258  const Graph& getGraph() const {
259  OGDF_ASSERT(valid());
260  return *m_cpGraph;
261  }
262 
264  operator const Graph&() const { return getGraph(); }
265 
267  face firstFace() const { return faces.head(); }
268 
270  face lastFace() const { return faces.tail(); }
271 
273  int numberOfFaces() const { return faces.size(); }
274 
276 
279  face rightFace(adjEntry adj) const { return m_rightFace[adj]; }
280 
285  face leftFace(adjEntry adj) const { return m_rightFace[adj->twin()]; }
286 
288  int maxFaceIndex() const { return m_faceIdCount - 1; }
289 
296  face chooseFace(
297  std::function<bool(face)> includeFace = [](face) { return true; },
298  bool isFastTest = true) const;
299 
301  face maximalFace() const;
302 
304  face externalFace() const { return m_externalFace; }
305 
311  OGDF_ASSERT(f->embeddingOf() == this);
312  m_externalFace = f;
313  }
314 
315  bool isBridge(edge e) const {
316  return m_rightFace[e->adjSource()] == m_rightFace[e->adjTarget()];
317  }
318 
320 
324  void init(const Graph& G);
325 
326  void init();
327 
329  void computeFaces();
330 
331 #ifdef OGDF_DEBUG
332  void consistencyCheck() const;
334 #endif
335 
336  static inline int keyToIndex(face key) { return key->index(); }
337 
338  bool isKeyAssociated(face key) const {
339  if (key == nullptr) {
340  return false;
341  }
342 #ifdef OGDF_DEBUG
343  if (key->embeddingOf() == this) {
344  OGDF_ASSERT(keyToIndex(key) < this->getArraySize());
345  return true;
346  } else {
347  return false;
348  }
349 #else
350  return true;
351 #endif
352  }
353 
354  int calculateArraySize(int add) const { return calculateTableSize(m_faceIdCount + add); }
355 
356  int maxKeyIndex() const { return (m_faceIdCount)-1; }
357 
358  face_iterator begin() const { return faces.begin(); }
359 
360  face_iterator end() const { return faces.end(); }
361 
371  adjEntry findCommonFace(const node v, const node w, bool left = true) const {
372  adjEntry adj;
373  return findCommonFace(v, w, adj, left);
374  }
375 
386  adjEntry findCommonFace(const node v, const node w, adjEntry& adjW, bool left = true) const;
387 
388 protected:
390  face createFaceElement(adjEntry adjFirst);
391 };
392 
407  friend class GraphCopy;
408 
410 
411  // the following methods are explicitly deleted
412  // It is not clear which meaning copying of a comb. embedding should
413  // have since we only store a pointer to the topology (Graph)
415  CombinatorialEmbedding& operator=(const CombinatorialEmbedding&) = delete;
416 
417 public:
422 
429  explicit CombinatorialEmbedding(Graph& G) : ConstCombinatorialEmbedding(G) { m_pGraph = &G; }
430 
432 
435 
438  const Graph& getGraph() const {
439  OGDF_ASSERT(valid());
440  return *m_cpGraph;
441  }
442 
444  OGDF_ASSERT(valid());
445  return *m_pGraph;
446  }
447 
448  operator const Graph&() const { return getGraph(); }
449 
450  operator Graph&() { return getGraph(); }
451 
453 
456 
464  void init(Graph& G) {
466  m_pGraph = &G;
467  }
468 
472  void clear();
473 
474 
476 
479 
486  edge split(edge e);
487 
493  void unsplit(edge eIn, edge eOut);
494 
513  node splitNode(adjEntry adjStartLeft, adjEntry adjStartRight);
514 
518  node contract(edge e, bool keepSelfLoops = false);
519 
539  edge splitFace(adjEntry adjSrc, adjEntry adjTgt, bool sourceAfter = false);
540 
549  edge addEdgeToIsolatedNode(node v, adjEntry adjTgt);
550 
559  edge addEdgeToIsolatedNode(adjEntry adjSrc, node v);
560 
566  face joinFaces(edge e);
567 
569  void reverseEdge(edge e);
570 
572  void moveBridge(adjEntry adjBridge, adjEntry adjBefore);
573 
575  void removeDeg1(node v);
576 
578  void updateMerger(edge e, face fRight, face fLeft);
579 
580 
583 private:
592  edge addEdgeToIsolatedNode(adjEntry adj, node v, bool adjSrc);
593 };
594 
595 }
ogdf::RegistryBase
Abstract base class for registries.
Definition: RegisteredArray.h:104
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::ConstCombinatorialEmbedding::valid
bool valid() const
Returns whether the embedding is associated with a graph.
Definition: CombinatorialEmbedding.h:252
ogdf::RegisteredArray
Dynamic arrays indexed with arbitrary keys.
Definition: RegisteredArray.h:817
OGDF_DECL_REG_ARRAY
#define OGDF_DECL_REG_ARRAY(NAME)
Definition: RegisteredArray.h:969
ogdf::internal::GraphList< GraphObject >::size
int size() const
Returns the size of the list.
Definition: GraphList.h:89
ogdf::internal::FaceAdjIterator::m_adjFirst
adjEntry m_adjFirst
Definition: CombinatorialEmbedding.h:61
ogdf::internal::FaceAdjContainer::begin
iterator begin() const
Definition: CombinatorialEmbedding.h:108
Graph.h
Includes declaration of graph class.
ogdf::internal::FaceAdjIterator::FaceAdjIterator
FaceAdjIterator(adjEntry adjFirst, adjEntry adj)
Definition: CombinatorialEmbedding.h:68
ogdf::internal::FaceAdjContainer::FaceAdjContainer
FaceAdjContainer()
Definition: CombinatorialEmbedding.h:101
ogdf::internal::FaceAdjContainer
Container for the adjacency entries in a face.
Definition: CombinatorialEmbedding.h:94
ogdf::internal::GraphList< GraphObject >::tail
GraphObject * tail() const
Returns the last element in the list.
Definition: GraphList.h:327
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::FaceElement::embeddingOf
const ConstCombinatorialEmbedding * embeddingOf() const
Definition: CombinatorialEmbedding.h:166
ogdf::internal::GraphIteratorBase
Definition: graph_iterators.h:45
ogdf::FaceElement::m_size
int m_size
The size of the face.
Definition: CombinatorialEmbedding.h:125
ogdf::ConstCombinatorialEmbedding::findCommonFace
adjEntry findCommonFace(const node v, const node w, bool left=true) const
Identifies a common face of two nodes and returns the respective adjacency entry.
Definition: CombinatorialEmbedding.h:371
ogdf::RegisteredArray< ConstCombinatorialEmbedding, Value, WithDefault >::RA
typename std::conditional< WithDefault, internal::RegisteredArrayWithDefault< ConstCombinatorialEmbedding, Value >, internal::RegisteredArrayWithoutDefault< ConstCombinatorialEmbedding, Value > >::type RA
Definition: RegisteredArray.h:822
ogdf::internal::FaceAdjContainer::end
iterator end() const
Definition: CombinatorialEmbedding.h:110
ogdf::internal::GraphElement
The base class for objects used by (hyper)graphs.
Definition: GraphList.h:60
ogdf::ConstCombinatorialEmbedding::leftFace
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
Definition: CombinatorialEmbedding.h:285
ogdf::ConstCombinatorialEmbedding::m_faceIdCount
int m_faceIdCount
The index assigned to the next created face.
Definition: CombinatorialEmbedding.h:220
OGDF_AUGMENT_COMPARER
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
Definition: comparer.h:183
ogdf::CombinatorialEmbedding::getGraph
Graph & getGraph()
Definition: CombinatorialEmbedding.h:443
ogdf::FaceArrayBase::embeddingOf
ConstCombinatorialEmbedding * embeddingOf() const
Returns a pointer to the associated combinatorial embedding.
Definition: CombinatorialEmbedding.h:188
ogdf::FaceElement::entries
internal::FaceAdjContainer entries
Container maintaining the adjacency entries in the face.
Definition: CombinatorialEmbedding.h:142
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::ConstCombinatorialEmbedding::maxKeyIndex
int maxKeyIndex() const
Definition: CombinatorialEmbedding.h:356
ogdf::ConstCombinatorialEmbedding::rightFace
face rightFace(adjEntry adj) const
Returns the face to the right of adj, i.e., the face containing adj.
Definition: CombinatorialEmbedding.h:279
ogdf::internal::FaceAdjIterator::operator++
FaceAdjIterator & operator++()
Definition: CombinatorialEmbedding.h:79
ogdf::ConstCombinatorialEmbedding::numberOfFaces
int numberOfFaces() const
Returns the number of faces.
Definition: CombinatorialEmbedding.h:273
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::ConstCombinatorialEmbedding::lastFace
face lastFace() const
Returns the last face in the list of all faces.
Definition: CombinatorialEmbedding.h:270
ogdf::ConstCombinatorialEmbedding::end
face_iterator end() const
Definition: CombinatorialEmbedding.h:360
ogdf::internal::FaceAdjIterator::FaceAdjIterator
FaceAdjIterator(adjEntry adj)
Definition: CombinatorialEmbedding.h:66
ogdf::internal::GraphObjectContainer
Public read-only interface for lists of graph objects.
Definition: GraphList.h:410
ogdf::ConstCombinatorialEmbedding::maxFaceIndex
int maxFaceIndex() const
Returns the largest used face index.
Definition: CombinatorialEmbedding.h:288
ogdf::AdjElement::twin
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:172
OGDF_NEW_DELETE
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition: memory.h:85
ogdf::ConstCombinatorialEmbedding::begin
face_iterator begin() const
Definition: CombinatorialEmbedding.h:358
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::FaceElement::firstAdj
adjEntry firstAdj() const
Returns the first adjacency element in the face.
Definition: CombinatorialEmbedding.h:148
ogdf::ConstCombinatorialEmbedding::setExternalFace
void setExternalFace(face f)
Sets the external face to f.
Definition: CombinatorialEmbedding.h:310
ogdf::ConstCombinatorialEmbedding::init
void init()
ogdf::CombinatorialEmbeddingRegistry
RegistryBase< face, ConstCombinatorialEmbedding, internal::GraphIterator< face > > CombinatorialEmbeddingRegistry
Definition: CombinatorialEmbedding.h:177
ogdf::FaceElement::compare
static int compare(const FaceElement &x, const FaceElement &y)
Standard Comparer.
Definition: CombinatorialEmbedding.h:170
ogdf::internal::FaceAdjIterator::operator*
adjEntry operator*() const
Definition: CombinatorialEmbedding.h:77
ogdf::ConstCombinatorialEmbedding::faces
internal::GraphObjectContainer< FaceElement > faces
The container containing all face objects.
Definition: CombinatorialEmbedding.h:230
ogdf::ConstCombinatorialEmbedding::isKeyAssociated
bool isKeyAssociated(face key) const
Definition: CombinatorialEmbedding.h:338
ogdf::internal::FaceAdjIterator::m_adj
adjEntry m_adj
Definition: CombinatorialEmbedding.h:60
ogdf::CombinatorialEmbedding::init
void init(Graph &G)
Initializes the embedding for graph G.
Definition: CombinatorialEmbedding.h:464
ogdf::ConstCombinatorialEmbedding::keyToIndex
static int keyToIndex(face key)
Definition: CombinatorialEmbedding.h:336
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::calculateTableSize
int calculateTableSize(int actualCount)
The default growth function for registered arrays.
Definition: RegisteredArray.h:67
ogdf::ConstCombinatorialEmbedding::m_rightFace
AdjEntryArray< face > m_rightFace
The face to which an adjacency entry belongs.
Definition: CombinatorialEmbedding.h:222
ogdf::FaceElement::m_id
int m_id
The index of the face.
Definition: CombinatorialEmbedding.h:124
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:983
config_autogen.h
ogdf::ConstCombinatorialEmbedding::m_cpGraph
const Graph * m_cpGraph
The associated graph.
Definition: CombinatorialEmbedding.h:218
ogdf::ConstCombinatorialEmbedding::getGraph
const Graph & getGraph() const
Returns the associated graph of the combinatorial embedding.
Definition: CombinatorialEmbedding.h:258
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::EdgeElement::adjSource
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:407
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::FaceArrayBase
RegisteredArray for labeling the faces of a CombinatorialEmbedding.
Definition: CombinatorialEmbedding.h:181
ogdf::internal::GraphList
Lists of graph objects (like nodes, edges, etc.).
Definition: GraphList.h:301
ogdf::ConstCombinatorialEmbedding::firstFace
face firstFace() const
Returns the first face in the list of all faces.
Definition: CombinatorialEmbedding.h:267
ogdf::CombinatorialEmbedding::m_pGraph
Graph * m_pGraph
The associated graph.
Definition: CombinatorialEmbedding.h:409
ogdf::FaceElement::size
int size() const
Returns the size of the face, i.e., the number of edges in the face.
Definition: CombinatorialEmbedding.h:151
graph_iterators.h
Decralation of graph iterators.
ogdf::internal::FaceAdjIterator
Forward iterator for adjacency entries in a face.
Definition: CombinatorialEmbedding.h:59
ogdf::ConstCombinatorialEmbedding::externalFace
face externalFace() const
Returns the external face.
Definition: CombinatorialEmbedding.h:304
ogdf::ConstCombinatorialEmbedding
Combinatorial embeddings of planar graphs.
Definition: CombinatorialEmbedding.h:216
ogdf::FaceElement::pred
face pred() const
Returns the predecessor in the list of all faces.
Definition: CombinatorialEmbedding.h:157
ogdf::FaceElement::index
int index() const
Returns the index of the face.
Definition: CombinatorialEmbedding.h:145
ogdf::EdgeElement::adjTarget
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:410
ogdf::internal::FaceAdjContainer::iterator
FaceAdjIterator iterator
Definition: CombinatorialEmbedding.h:106
ogdf::ConstCombinatorialEmbedding::m_externalFace
face m_externalFace
Definition: CombinatorialEmbedding.h:223
ogdf::internal::GraphList< GraphObject >::begin
iterator begin() const
Returns an iterator to the first element in the container.
Definition: GraphList.h:385
ogdf::graphics::init
void init()
Definition: graphics.h:450
ogdf::internal::GraphList< GraphObject >::head
GraphObject * head() const
Returns the first element in the list.
Definition: GraphList.h:324
ogdf::face
FaceElement * face
Definition: CombinatorialEmbedding.h:49
ogdf::internal::FaceAdjContainer::FaceAdjContainer
FaceAdjContainer(adjEntry adjFirst)
Definition: CombinatorialEmbedding.h:103
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::internal::FaceAdjContainer::m_adjFirst
adjEntry m_adjFirst
Definition: CombinatorialEmbedding.h:99
ogdf::internal::GraphList< GraphObject >::end
iterator end() const
Returns an iterator to the one-past-last element in the container.
Definition: GraphList.h:388
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:406
ogdf::AdjElement::faceCycleSucc
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition: Graph_d.h:212
ogdf::internal::FaceAdjIterator::FaceAdjIterator
FaceAdjIterator()
Definition: CombinatorialEmbedding.h:64
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::CombinatorialEmbedding::getGraph
const Graph & getGraph() const
Returns the associated graph.
Definition: CombinatorialEmbedding.h:438
ogdf::ConstCombinatorialEmbedding::isBridge
bool isBridge(edge e) const
Definition: CombinatorialEmbedding.h:315
ogdf::ConstCombinatorialEmbedding::calculateArraySize
int calculateArraySize(int add) const
Definition: CombinatorialEmbedding.h:354
ogdf::internal::FaceAdjIterator::operator!=
bool operator!=(const FaceAdjIterator &other) const
Definition: CombinatorialEmbedding.h:75
ogdf::internal::FaceAdjIterator::operator=
FaceAdjIterator & operator=(const FaceAdjIterator &)=default
ogdf::FaceElement::nextFaceEdge
adjEntry nextFaceEdge(adjEntry adj) const
Returns the successor of adj in the list of all adjacency elements in the face.
Definition: CombinatorialEmbedding.h:160
ogdf::internal::FaceAdjIterator::operator==
bool operator==(const FaceAdjIterator &other) const
Definition: CombinatorialEmbedding.h:73
comparer.h
Declarations for Comparer objects.
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::FaceElement::m_pEmbedding
const ConstCombinatorialEmbedding * m_pEmbedding
Definition: CombinatorialEmbedding.h:128
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::CombinatorialEmbedding::CombinatorialEmbedding
CombinatorialEmbedding(Graph &G)
Creates a combinatorial embedding of graph G.
Definition: CombinatorialEmbedding.h:429
ogdf::FaceElement
Faces in a combinatorial embedding.
Definition: CombinatorialEmbedding.h:118
ogdf::FaceElement::succ
face succ() const
Returns the successor in the list of all faces.
Definition: CombinatorialEmbedding.h:154
ogdf::CombinatorialEmbedding::CombinatorialEmbedding
CombinatorialEmbedding()
Creates a combinatorial embedding associated with no graph.
Definition: CombinatorialEmbedding.h:421