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
37
38namespace ogdf {
39
41
43OGDF_EXPORT std::ostream& operator<<(std::ostream& os, ogdf::face f);
44
45// Definition of iterator and container types for adjacency entries in a face
46// These declarations are just internal representations
47namespace internal {
48
53
54public:
56
57 explicit FaceAdjIterator(adjEntry adj) : m_adj(adj), m_adjFirst(adj) { }
58
60
63
64 bool operator==(const FaceAdjIterator& other) const { return m_adj == other.m_adj; }
65
66 bool operator!=(const FaceAdjIterator& other) const { return m_adj != other.m_adj; }
67
68 adjEntry operator*() const { return m_adj; }
69
71 OGDF_ASSERT(m_adj != nullptr);
73 if (m_adj == m_adjFirst) {
74 m_adj = nullptr;
75 }
76 return *this;
77 }
78};
79
81
103
104}
105
112 friend class internal::GraphList<FaceElement>;
113
114 //adjEntry m_adjFirst; //!< The first adjacency element in the face.
115 int m_id;
116 int m_size;
117
118#ifdef OGDF_DEBUG
119 const ConstCombinatorialEmbedding* m_pEmbedding;
120#endif
121
122#ifdef OGDF_DEBUG
125 : m_id(id), m_size(0), m_pEmbedding(pEmbedding), entries(adjFirst) { }
126#else
128 FaceElement(adjEntry adjFirst, int id) : m_id(id), m_size(0), entries(adjFirst) { }
129#endif
130
131public:
134
136 int index() const { return m_id; }
137
139 adjEntry firstAdj() const { return entries.m_adjFirst; }
140
142 int size() const { return m_size; }
143
145 face succ() const { return static_cast<face>(m_next); }
146
148 face pred() const { return static_cast<face>(m_prev); }
149
152 adj = adj->faceCycleSucc();
153 return (adj != entries.m_adjFirst) ? adj : nullptr;
154 }
155
156#ifdef OGDF_DEBUG
157 const ConstCombinatorialEmbedding* embeddingOf() const { return m_pEmbedding; }
158#endif
159
161 static int compare(const FaceElement& x, const FaceElement& y) { return x.m_id - y.m_id; }
163
165};
166
167class FaceArrayBase;
168template<class T>
169class FaceArray;
170
193protected:
195
198
201
203
204#ifndef OGDF_MEMORY_POOL_NTS
205 mutable std::mutex m_mutexRegArrays;
206#endif
207
208public:
211
214
219
227
228
231
234
237
239 bool valid() const { return m_cpGraph != nullptr; }
240
246 const Graph& getGraph() const {
247 OGDF_ASSERT(valid());
248 return *m_cpGraph;
249 }
250
252 operator const Graph&() const { return getGraph(); }
253
257 face firstFace() const { return faces.head(); }
258
260 face lastFace() const { return faces.tail(); }
261
263 int numberOfFaces() const { return faces.size(); }
264
269 face rightFace(adjEntry adj) const { return m_rightFace[adj]; }
270
275 face leftFace(adjEntry adj) const { return m_rightFace[adj->twin()]; }
276
280 int maxFaceIndex() const { return m_faceIdCount - 1; }
281
283 int faceArrayTableSize() const { return m_faceArrayTableSize; }
284
292 std::function<bool(face)> includeFace = [](face) { return true; },
293 bool isFastTest = true) const;
294
297
301 face externalFace() const { return m_externalFace; }
302
308 OGDF_ASSERT(f->embeddingOf() == this);
309 m_externalFace = f;
310 }
311
312 bool isBridge(edge e) const {
313 return m_rightFace[e->adjSource()] == m_rightFace[e->adjTarget()];
314 }
315
322 void init(const Graph& G);
323
324 void init();
325
328
329#ifdef OGDF_DEBUG
332 void consistencyCheck() const;
333#endif
334
335
342
349
352
362 adjEntry findCommonFace(const node v, const node w, bool left = true) const {
363 adjEntry adj;
364 return findCommonFace(v, w, adj, left);
365 }
366
377 adjEntry findCommonFace(const node v, const node w, adjEntry& adjW, bool left = true) const;
378
381protected:
384
387};
388
403 friend class GraphCopy;
404
406
407 // the following methods are explicitly deleted
408 // It is not clear which meaning copying of a comb. embedding should
409 // have since we only store a pointer to the topology (Graph)
412
413public:
418
425 explicit CombinatorialEmbedding(Graph& G) : ConstCombinatorialEmbedding(G) { m_pGraph = &G; }
426
428
432
434 const Graph& getGraph() const {
435 OGDF_ASSERT(valid());
436 return *m_cpGraph;
437 }
438
440 OGDF_ASSERT(valid());
441 return *m_pGraph;
442 }
443
444 operator const Graph&() const { return getGraph(); }
445
446 operator Graph&() { return getGraph(); }
447
449
453
460 void init(Graph& G) {
461 ConstCombinatorialEmbedding::init(G);
462 m_pGraph = &G;
463 }
464
468 void clear();
469
470
472
476
483
490
510
514 node contract(edge e, bool keepSelfLoops = false);
515
536
546
556
563
566
569
572
575
576
579private:
589};
590
591}
Declaration and implementation of AdjEntryArray class.
Class for adjacency list elements.
Definition Graph_d.h:79
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition Graph_d.h:109
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition Graph_d.h:149
Dynamic arrays indexed with adjacency entries.
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.
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.
std::mutex m_mutexRegArrays
The critical section for protecting shared acces to register/unregister methods.
face maximalFace() const
Returns a face of maximal size.
bool valid() const
Returns whether the embedding is associated with a graph.
int faceArrayTableSize() const
Returns the table size of face arrays associated with this embedding.
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 reinitArrays()
Reinitialize associated face arrays.
void moveRegisterArray(ListIterator< FaceArrayBase * > it, FaceArrayBase *pFaceArray) const
Move the registration it of a node array to pFaceArray (used with move semantics for face arrays).
void init(const Graph &G)
Initializes the embedding for graph G.
ListIterator< FaceArrayBase * > registerArray(FaceArrayBase *pFaceArray) const
Registers the face array pFaceArray.
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.
void unregisterArray(ListIterator< FaceArrayBase * > it) const
Unregisters the face array identified by it.
ConstCombinatorialEmbedding(const ConstCombinatorialEmbedding &C)
Copy constructor.
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_faceArrayTableSize
The current table size of face arrays.
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.
ListPure< FaceArrayBase * > m_regFaceArrays
The external face.
ConstCombinatorialEmbedding & operator=(const ConstCombinatorialEmbedding &C)
Assignment operator.
Class for the representation of edges.
Definition Graph_d.h:300
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition Graph_d.h:344
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition Graph_d.h:347
Abstract base class for face arrays.
Definition FaceArray.h:46
Faces in a combinatorial embedding.
FaceElement(adjEntry adjFirst, int id)
Creates a face with given first adjacency element adjFirst and face index id.
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.
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.
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.
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:254
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Encapsulates a pointer to a list element.
Definition List.h:103
Doubly linked lists.
Definition List.h:217
Class for the representation of nodes.
Definition Graph_d.h:177
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:55
Lists of graph objects (like nodes, edges, etc.).
Definition GraphList.h:288
T * head() const
Returns the first element in the list.
Definition GraphList.h:304
T * tail() const
Returns the last element in the list.
Definition GraphList.h:307
int size() const
Returns the size of the list.
Definition GraphList.h:301
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
Definition comparer.h:179
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:84
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
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:978