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
34#include <ogdf/basic/Array.h>
36#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/List.h>
38#include <ogdf/basic/basic.h>
40
41#include <cmath>
42#include <memory>
43#include <string>
44
45namespace ogdf {
46class GraphCopy;
47
48namespace planar_separators {
49
56public:
63 BFSTreeHP(GraphCopy& G, node rootNode) : ArrayBFSTree(G, rootNode) { construct(); }
64
68 void construct();
69
75 void reconstruct(const Cycle& cycle);
76
81};
82
83struct Ring; // see below
84
85}
86
87using namespace planar_separators;
88
90
100
101public:
106
107 virtual double getMaxSeparatorSize(int n) const override { return sqrt(8) * sqrt(n); }
108
109 virtual std::string getSpecificName() const override { return "HPN"; } // Har-Peled and Nayyeri
110
111protected:
112#ifdef OGDF_DEBUG
113
114 void verifyRing(const Ring& ring) const;
115
116#endif
117
127 virtual bool doSeparate(const Graph& G, List<node>& separator, List<node>& first,
128 List<node>& second) override;
129
131 std::shared_ptr<BFSTreeHP> tree;
132
136 virtual void reset() override;
137
141 virtual void makeTree();
142
150
157 void createDual(Graph& Dual, EdgeArray<edge>& oldEdge) const;
158
165 void findFaceLevels(const node root);
166
173 void buildRings(const Cycle& cycle);
174
182 int find_i0(int delta) const;
183
194 bool findRegions(List<node>& region, const Cycle& cycle, const Ring& inner, int outerIdx) const;
195
204 void walkAlongSeparator(node startNode, node endNode, EdgeArray<bool>& regionBorder,
205 List<node>& region) const;
206
216 void walkAlongRing(const Ring& ring, bool firstSection, bool invert,
217 EdgeArray<bool>& regionBorder, List<node>& region) const;
218
228 bool testRegionSize(node startNode, const EdgeArray<bool>& regionBorder, bool inside,
229 int regionSize) const;
230
241 bool findRegion(List<node>& region, const Cycle& cycle, const Ring& inner, const Ring& outer,
242 bool inside) const;
243
253 bool constructK(List<node>& region, const Cycle& cycle, const Ring& inner,
254 const Ring& outer) const;
255
267 bool finalize(std::string exit, const List<node>& region, List<node>& separator,
268 List<node>& first, List<node>& second);
269
270private:
272 node psi; // the deeper of the two endpoints of tree-separator u,v
273
274 FaceArray<int> faceLevels; // holds for each face which level it inhabits
275 EdgeArray<int> border; // holds for every edge for which value i it lies on the border of region P<=i
276 List<List<face>> faceFrontiers; // for each level of the expansion, holds the list of faces that form the inner lining of the ring
277
284 NodeArray<bool> isMultiNode; // holds whether this node has more than 2 connecting edges
285
286 Array<Ring, int> rings; // the concentric rings of nodes around the root
287
288 NodeArray<adjEntry> mainSeparator; // represents the big separator in a way that allows immediate access
289};
290
291namespace planar_separators {
292
297struct Ring {
301
305
306 int faces; // number of faces inside this ring
307
309 bool isDegenerate = false;
310
314 Ring() { } // to be able to store them in arrays
315
321 Ring(node n) : in {n}, out {n}, isDegenerate {true} { }
322
333 Ring(node startNode, node endNode, adjEntry outPointer, const SeparatorHarPeled& separator) {
334 OGDF_ASSERT(outPointer->theNode() == startNode);
335
336 nodes.pushBack(startNode);
337 in = startNode;
338 out = endNode;
339
340 node next; // the next node in the ring
341 adjEntry nextEntry; // the adjEntry that points to the next node
342
343 // handling edge case of a multinode as startnode
344 if (separator.isMultiNode[startNode]) {
345 adjEntry outP = outPointer;
346 while (separator.ringOut[startNode].search(outP) == separator.ringOut[startNode].end()) {
347 outP = outP->cyclicSucc();
348 }
349 nextEntry = outP;
350 } else {
351 nextEntry = separator.ringOut[startNode].front();
352 }
353 next = nextEntry->twinNode();
354
355 // walk along ring until we arrive back at startNode
356 while (next != startNode) {
357 nodes.pushBack(next);
358 entries.pushBack(nextEntry);
359
360 // find next nextEntry
361 if (separator.ringOut[next].size() > 1) {
362 adjEntry candidate =
363 nextEntry->twin()->cyclicSucc(); // start checking at the entry via which we entered
364 while (separator.ringOut[next].search(candidate) == separator.ringOut[next].end()) {
365 candidate = candidate->cyclicSucc();
366 }
367 nextEntry = candidate;
368 } else if (separator.ringOut[next].size() == 1) {
369 nextEntry = separator.ringOut[next].front();
370 } else {
371 OGDF_ASSERT(false); // this should not happen, only the root is not part of a ring
372 }
373 next = nextEntry->twinNode();
374 }
375 entries.pushBack(nextEntry); // to close the ring, point back to first node
376 }
377
381 int getFaces() const { return faces; }
382
386 int getSize() const { return nodes.size(); }
387
394 List<adjEntry> getSectionInSeparator(bool firstSection) const {
395 List<adjEntry> list;
396
397 if (isDegenerate) {
398 return list; // degenerate ring is empty
399 }
400
401 auto adjIt = entries.cbegin();
402
403 if (firstSection) {
404 // go start to end
405 while (adjIt != entries.cend() && (*adjIt)->theNode() != out) {
406 list.pushBack(*adjIt);
407 ++adjIt;
408 }
409 } else {
410 // go end to start
411 while ((*adjIt)->theNode() != out && adjIt != entries.cend()) {
412 adjIt++;
413 }
414 while (adjIt != entries.cend()) {
415 list.pushBack(*adjIt);
416 ++adjIt;
417 }
418 }
419 return list;
420 }
421};
422
423}
424}
Declaration and implementation of Array class and Array algorithms.
Declaration of CombinatorialEmbedding and face.
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Declaration of base class of all planar separator algorithms.
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 cyclicSucc() const
Returns the cyclic successor in the adjacency list.
Definition Graph_d.h:355
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition Graph_d.h:176
node theNode() const
Returns the node whose adjacency list contains this element.
Definition Graph_d.h:167
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
Combinatorial embeddings of planar graphs.
Class for the representation of edges.
Definition Graph_d.h:364
RegisteredArray for labeling the faces of a CombinatorialEmbedding.
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1547
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition List.h:403
Class for the representation of nodes.
Definition Graph_d.h:241
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.
void verifyRing(const Ring &ring) const
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
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
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 dynamic library (shared object / DLL),...
Definition config.h:117
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
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.