Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
CombinatorialEmbedding.h
Go to the documentation of this file.
1
34#pragma once
35
36#include <ogdf/basic/Graph.h>
38#include <ogdf/basic/basic.h>
39#include <ogdf/basic/comparer.h>
40#include <ogdf/basic/internal/config_autogen.h>
42#include <ogdf/basic/memory.h>
43
44#include <functional>
45#include <iosfwd>
46
47namespace ogdf {
48
50
52OGDF_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
56namespace internal {
57
62
63public:
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
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
102
103 explicit FaceAdjContainer(adjEntry adjFirst) : m_adjFirst(adjFirst) { }
104
105public:
107
108 iterator begin() const { return iterator(m_adjFirst); }
109
110 iterator end() const { return iterator(); }
111};
112
113}
114
121 friend class internal::GraphList<FaceElement>;
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
133 FaceElement(const ConstCombinatorialEmbedding* pEmbedding, adjEntry adjFirst, int id)
134 : m_id(id), m_size(0), m_pEmbedding(pEmbedding), entries(adjFirst) { }
135#else
137 FaceElement(adjEntry adjFirst, int id) : m_id(id), m_size(0), entries(adjFirst) { }
138#endif
139
140public:
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
180template<class Value, bool WithDefault>
181class FaceArrayBase : public RegisteredArray<ConstCombinatorialEmbedding, Value, WithDefault> {
183
184public:
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
217protected:
219
221
224
225public:
228
231
234
236
241
244
247
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
297 std::function<bool(face)> includeFace = [](face) { return true; },
298 bool isFastTest = true) const;
299
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
330
331#ifdef OGDF_DEBUG
333 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
388protected:
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)
416
417public:
422
429 explicit CombinatorialEmbedding(Graph& G) : ConstCombinatorialEmbedding(G) { m_pGraph = &G; }
430
432
436
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
457
464 void init(Graph& G) {
465 ConstCombinatorialEmbedding::init(G);
466 m_pGraph = &G;
467 }
468
472 void clear();
473
474
476
480
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
550
560
567
574
577
579 void moveBridge(adjEntry adjBridge, adjEntry adjBefore);
580
583
585 void updateMerger(edge e, face fRight, face fLeft);
586
587
590private:
600};
601
602}
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
#define OGDF_DECL_REG_ARRAY(NAME)
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition Graph_d.h:173
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition Graph_d.h:213
Combinatorial embeddings of planar graphs with modification functionality.
void updateMerger(edge e, face fRight, face fLeft)
Update face information after inserting a merger in a copy graph.
node splitNode(adjEntry adjStartLeft, adjEntry adjStartRight)
Splits a node while preserving the order of adjacency entries.
void removeDeg1(node v)
Removes degree-1 node v.
CombinatorialEmbedding()
Creates a combinatorial embedding associated with no graph.
void init(Graph &G)
Initializes the embedding for graph G.
Graph * m_pGraph
The associated graph.
node contract(edge e, bool keepSelfLoops=false)
Contracts edge e while preserving the order of adjacency entries.
face joinFaces(edge e)
Removes edge e and joins the two faces adjacent to e.
CombinatorialEmbedding(const CombinatorialEmbedding &)=delete
void moveBridge(adjEntry adjBridge, adjEntry adjBefore)
Moves a bridge in the graph.
void reverseEdge(edge e)
Reverses edges e and updates embedding.
face joinFaces(adjEntry adj)
Removes edge e corresponding to adj and joins the two faces adjacent to e.
CombinatorialEmbedding & operator=(const CombinatorialEmbedding &)=delete
CombinatorialEmbedding(Graph &G)
Creates a combinatorial embedding of graph G.
edge addEdgeToIsolatedNode(node v, adjEntry adjTgt)
Inserts a new edge similarly to splitFace without having to call computeFaces again.
edge addEdgeToIsolatedNode(adjEntry adjSrc, node v)
Inserts a new edge similarly to splitFace without having to call computeFaces again.
edge split(edge e)
Splits edge e=(v,w) into e=(v,u) and e'=(u,w) creating a new node u.
void clear()
Removes all nodes, edges, and faces from the graph and the embedding.
edge addEdgeToIsolatedNode(adjEntry adj, node v, bool adjSrc)
Inserts a new edge similarly to splitFace without having to call computeFaces again.
const Graph & getGraph() const
Returns the associated graph.
void unsplit(edge eIn, edge eOut)
Undoes a split operation.
edge splitFace(adjEntry adjSrc, adjEntry adjTgt, bool sourceAfter=false)
Splits a face by inserting a new edge.
Combinatorial embeddings of planar graphs.
const Graph * m_cpGraph
The associated graph.
adjEntry findCommonFace(const node v, const node w, adjEntry &adjW, bool left=true) const
Identifies a common face of two nodes and returns the respective adjacency entry.
face rightFace(adjEntry adj) const
Returns the face to the right of adj, i.e., the face containing adj.
ConstCombinatorialEmbedding(const Graph &G)
Creates a combinatorial embedding of graph G.
face chooseFace(std::function< bool(face)> includeFace=[](face) { return true;}, bool isFastTest=true) const
Returns a random face.
face firstFace() const
Returns the first face in the list of all faces.
face maximalFace() const
Returns a face of maximal size.
bool valid() const
Returns whether the embedding is associated with a graph.
face externalFace() const
Returns the external face.
void computeFaces()
Computes the list of faces.
face createFaceElement(adjEntry adjFirst)
Create a new face.
virtual ~ConstCombinatorialEmbedding()
Destructor.
void init(const Graph &G)
Initializes the embedding for graph G.
face lastFace() const
Returns the last face in the list of all faces.
int maxFaceIndex() const
Returns the largest used face index.
void setExternalFace(face f)
Sets the external face to f.
const Graph & getGraph() const
Returns the associated graph of the combinatorial embedding.
ConstCombinatorialEmbedding()
Creates a combinatorial embedding associated with no graph.
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
ConstCombinatorialEmbedding(const ConstCombinatorialEmbedding &C)
Copy constructor.
void consistencyCheck() const
Asserts that this embedding is consistent.
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.
AdjEntryArray< face > m_rightFace
The face to which an adjacency entry belongs.
int m_faceIdCount
The index assigned to the next created face.
int numberOfFaces() const
Returns the number of faces.
internal::GraphObjectContainer< FaceElement > faces
The container containing all face objects.
ConstCombinatorialEmbedding & operator=(const ConstCombinatorialEmbedding &C)
Assignment operator.
Class for the representation of edges.
Definition Graph_d.h:364
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition Graph_d.h:408
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition Graph_d.h:411
RegisteredArray for labeling the faces of a CombinatorialEmbedding.
ConstCombinatorialEmbedding * embeddingOf() const
Returns a pointer to the associated combinatorial embedding.
Faces in a combinatorial embedding.
face pred() const
Returns the predecessor in the list of all faces.
int size() const
Returns the size of the face, i.e., the number of edges in the face.
FaceElement(const ConstCombinatorialEmbedding *pEmbedding, adjEntry adjFirst, int id)
Creates a face with given first adjacency element adjFirst, face index id and keeps track of the owne...
static int compare(const FaceElement &x, const FaceElement &y)
Standard Comparer.
int m_size
The size of the face.
adjEntry nextFaceEdge(adjEntry adj) const
Returns the successor of adj in the list of all adjacency elements in the face.
const ConstCombinatorialEmbedding * embeddingOf() const
face succ() const
Returns the successor in the list of all faces.
internal::FaceAdjContainer entries
Container maintaining the adjacency entries in the face.
adjEntry firstAdj() const
Returns the first adjacency element in the face.
const ConstCombinatorialEmbedding * m_pEmbedding
int index() const
Returns the index of the face.
int m_id
The index of the face.
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Class for the representation of nodes.
Definition Graph_d.h:241
Dynamic arrays indexed with arbitrary keys.
typename std::conditional< WithDefault, internal::RegisteredArrayWithDefault< ConstCombinatorialEmbedding, Value >, internal::RegisteredArrayWithoutDefault< ConstCombinatorialEmbedding, Value > >::type RA
Abstract base class for registries.
Container for the adjacency entries in a face.
Forward iterator for adjacency entries in a face.
bool operator!=(const FaceAdjIterator &other) const
FaceAdjIterator & operator=(const FaceAdjIterator &)=default
bool operator==(const FaceAdjIterator &other) const
FaceAdjIterator(const FaceAdjIterator &)=default
FaceAdjIterator(adjEntry adjFirst, adjEntry adj)
The base class for objects used by (hyper)graphs.
Definition GraphList.h:60
Lists of graph objects (like nodes, edges, etc.).
Definition GraphList.h:301
T * head() const
Returns the first element in the list.
Definition GraphList.h:324
T * tail() const
Returns the last element in the list.
Definition GraphList.h:327
iterator begin() const
Returns an iterator to the first element in the container.
Definition GraphList.h:385
iterator end() const
Returns an iterator to the one-past-last element in the container.
Definition GraphList.h:388
int size() const
Returns the size of the list.
Definition GraphList.h:89
Public read-only interface for lists of graph objects.
Definition GraphList.h:410
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
Declarations for Comparer objects.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
Decralation of graph iterators.
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
Definition comparer.h:183
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:85
Declaration of memory manager for allocating small pieces of memory.
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:983
int calculateTableSize(int actualCount)
The default growth function for registered arrays.