Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
SeparatorHarPeled.h
Go to the documentation of this file.
1
32#pragma once
33
36
37namespace ogdf {
38
39namespace planar_separators {
40
47public:
54 BFSTreeHP(GraphCopy& G, node rootNode) : ArrayBFSTree(G, rootNode) { construct(); }
55
59 void construct();
60
66 void reconstruct(const Cycle& cycle);
67
72};
73
74struct Ring; // see below
75
76}
77
78using namespace planar_separators;
79
81
91
92public:
97
98 virtual double getMaxSeparatorSize(int n) const override { return sqrt(8) * sqrt(n); }
99
100 virtual std::string getSpecificName() const override { return "HPN"; } // Har-Peled and Nayyeri
101
102protected:
103#ifdef OGDF_DEBUG
104
105 void verifyRing(const Ring& ring) const;
106
107#endif
108
118 virtual bool doSeparate(const Graph& G, List<node>& separator, List<node>& first,
119 List<node>& second) override;
120
122 std::shared_ptr<BFSTreeHP> tree;
123
127 virtual void reset() override;
128
132 virtual void makeTree();
133
141
149
156 void findFaceLevels(const node root);
157
164 void buildRings(const Cycle& cycle);
165
173 int find_i0(int delta) const;
174
185 bool findRegions(List<node>& region, const Cycle& cycle, const Ring& inner, int outerIdx) const;
186
196 List<node>& region) const;
197
207 void walkAlongRing(const Ring& ring, bool firstSection, bool invert,
209
219 bool testRegionSize(node startNode, const EdgeArray<bool>& regionBorder, bool inside,
220 int regionSize) const;
221
232 bool findRegion(List<node>& region, const Cycle& cycle, const Ring& inner, const Ring& outer,
233 bool inside) const;
234
244 bool constructK(List<node>& region, const Cycle& cycle, const Ring& inner,
245 const Ring& outer) const;
246
258 bool finalize(std::string exit, const List<node>& region, List<node>& separator,
259 List<node>& first, List<node>& second);
260
261private:
263 node psi; // the deeper of the two endpoints of tree-separator u,v
264
265 FaceArray<int> faceLevels; // holds for each face which level it inhabits
266 EdgeArray<int> border; // holds for every edge for which value i it lies on the border of region P<=i
267 List<List<face>> faceFrontiers; // for each level of the expansion, holds the list of faces that form the inner lining of the ring
268
275 NodeArray<bool> isMultiNode; // holds whether this node has more than 2 connecting edges
276
277 Array<Ring, int> rings; // the concentric rings of nodes around the root
278
279 NodeArray<adjEntry> mainSeparator; // represents the big separator in a way that allows immediate access
280};
281
282namespace planar_separators {
283
288struct Ring {
292
296
297 int faces; // number of faces inside this ring
298
300 bool isDegenerate = false;
301
305 Ring() { } // to be able to store them in arrays
306
312 Ring(node n) : in {n}, out {n}, isDegenerate {true} { }
313
325 OGDF_ASSERT(outPointer->theNode() == startNode);
326
327 nodes.pushBack(startNode);
328 in = startNode;
329 out = endNode;
330
331 node next; // the next node in the ring
332 adjEntry nextEntry; // the adjEntry that points to the next node
333
334 // handling edge case of a multinode as startnode
335 if (separator.isMultiNode[startNode]) {
337 while (separator.ringOut[startNode].search(outP) == separator.ringOut[startNode].end()) {
338 outP = outP->cyclicSucc();
339 }
340 nextEntry = outP;
341 } else {
342 nextEntry = separator.ringOut[startNode].front();
343 }
344 next = nextEntry->twinNode();
345
346 // walk along ring until we arrive back at startNode
347 while (next != startNode) {
348 nodes.pushBack(next);
349 entries.pushBack(nextEntry);
350
351 // find next nextEntry
352 if (separator.ringOut[next].size() > 1) {
354 nextEntry->twin()->cyclicSucc(); // start checking at the entry via which we entered
355 while (separator.ringOut[next].search(candidate) == separator.ringOut[next].end()) {
357 }
358 nextEntry = candidate;
359 } else if (separator.ringOut[next].size() == 1) {
360 nextEntry = separator.ringOut[next].front();
361 } else {
362 OGDF_ASSERT(false); // this should not happen, only the root is not part of a ring
363 }
364 next = nextEntry->twinNode();
365 }
366 entries.pushBack(nextEntry); // to close the ring, point back to first node
367 }
368
372 int getFaces() const { return faces; }
373
377 int getSize() const { return nodes.size(); }
378
386 List<adjEntry> list;
387
388 if (isDegenerate) {
389 return list; // degenerate ring is empty
390 }
391
392 auto adjIt = entries.cbegin();
393
394 if (firstSection) {
395 // go start to end
396 while (adjIt != entries.cend() && (*adjIt)->theNode() != out) {
397 list.pushBack(*adjIt);
398 ++adjIt;
399 }
400 } else {
401 // go end to start
402 while ((*adjIt)->theNode() != out && adjIt != entries.cend()) {
403 adjIt++;
404 }
405 while (adjIt != entries.cend()) {
406 list.pushBack(*adjIt);
407 ++adjIt;
408 }
409 }
410 return list;
411 }
412};
413
414}
415}
Includes declaration of dual graph class.
Declaration of base class of all planar separator algorithms.
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 cyclicSucc() const
Returns the cyclic successor in the adjacency list.
Definition Graph_d.h:291
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition Graph_d.h:112
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
Combinatorial embeddings of planar graphs.
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
Dynamic arrays indexed with faces of a combinatorial embedding.
Definition FaceArray.h:126
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:254
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1531
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition List.h:387
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
Abstract description of all planar separator algorithms.
Computes planar separators according to Har-Peled.
std::shared_ptr< BFSTreeHP > tree
A special tree that can be reconstructed, see above.
virtual void reset() override
Resets all fields, clears lists and re-initializes arrays to enable reuse of the module.
edge findSeparatorEdge() const
Finds a non-tree edge that, together with the tree, forms a (possibly too large) 2/3-separator.
virtual bool doSeparate(const Graph &G, List< node > &separator, List< node > &first, List< node > &second) override
Entry point for the core of the algorithm.
NodeArray< List< adjEntry > > ringIn
hold for every node the segment of the border between levels i-1 and i that runs through this node (t...
List< List< face > > faceFrontiers
virtual void makeTree()
Constructs the BFSTreeHP from a random node.
void findFaceLevels(const node root)
Performs a BFS over the faces of the embedding (more or less) to assign a level to each face and find...
void walkAlongRing(const Ring &ring, bool firstSection, bool invert, EdgeArray< bool > &regionBorder, List< node > &region) const
Used in region construction: Walks along a Ring and stores nodes and edges of the section.
virtual std::string getSpecificName() const override
Returns the unique name of the core algorithm, to be combined with postprocessors later.
void buildRings(const Cycle &cycle)
Constructs the array of concentric rings of nodes formed by the (potentially partial) borders of the ...
virtual double getMaxSeparatorSize(int n) const override
Provides the maximal separator size that this algorithm guarantees as a function of the number of nod...
NodeArray< List< adjEntry > > ringOut
bool constructK(List< node > &region, const Cycle &cycle, const Ring &inner, const Ring &outer) const
Builds the region K.
void createDual(Graph &Dual, EdgeArray< edge > &oldEdge) const
Creates the dual of the graph to help find a separator edge.
bool findRegions(List< node > &region, const Cycle &cycle, const Ring &inner, int outerIdx) const
Finds the regions R1 and R2 formed by the separator cycle and an inner and outer ring.
int find_i0(int delta) const
Finds i0, the first step of the first "ladder" of rings that is not larger than n / delta nodes.
bool finalize(std::string exit, const List< node > &region, List< node > &separator, List< node > &first, List< node > &second)
Takes a list of nodes of the GraphCopy and removes their counterparts from the original graph,...
NodeArray< bool > isMultiNode
bool findRegion(List< node > &region, const Cycle &cycle, const Ring &inner, const Ring &outer, bool inside) const
Builds the region R1 or R2.
void walkAlongSeparator(node startNode, node endNode, EdgeArray< bool > &regionBorder, List< node > &region) const
Used in region construction: Walks along the 2/3-separator from startNode to endNode.
bool testRegionSize(node startNode, const EdgeArray< bool > &regionBorder, bool inside, int regionSize) const
Checks whether the inside [outside] of the region defined by regionBorder is greater or smaller than ...
NodeArray< adjEntry > mainSeparator
ConstCombinatorialEmbedding E
Abstract BFSTree that is realized via NodeArrays.
Specialised tree representation for Har-Peled.
void construct()
Builds the tree by performing BFS search.
void reconstruct(const Cycle &cycle)
Reconstructs the tree, rooting it at root of cycle.
BFSTreeHP(GraphCopy &G, node rootNode)
Constructor.
void calculateDescendants()
Calculates the number of children of each node in the tree.
Auxiliary data structure to represent Cycles in planar graphs.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Ring(node startNode, node endNode, adjEntry outPointer, const SeparatorHarPeled &separator)
Constructor for a full ring.
Ring(node n)
Constructor for degenerate rings.
List< adjEntry > getSectionInSeparator(bool firstSection) const
Returns a section of this ring, either the first one from in to out, or the second one from out to in...
node in
Crossing points with the main separator S: in is where S enters, out is where S leaves.
List< node > nodes
Nodes and adjEntries that form the border of the ring.
bool isDegenerate
A degenerate ring contains only one node.