Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 
45 namespace ogdf {
46 class GraphCopy;
47 
48 namespace planar_separators {
49 
56 public:
63  BFSTreeHP(GraphCopy& G, node rootNode) : ArrayBFSTree(G, rootNode) { construct(); }
64 
68  void construct();
69 
75  void reconstruct(const Cycle& cycle);
76 
80  void calculateDescendants();
81 };
82 
83 struct Ring; // see below
84 
85 }
86 
87 using namespace planar_separators;
88 
90 
99  friend struct planar_separators::Ring;
100 
101 public:
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 
111 protected:
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 
149  edge findSeparatorEdge() const;
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 
270 private:
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 
291 namespace planar_separators {
292 
297 struct 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 }
ogdf::SeparatorHarPeled::psi
node psi
Definition: SeparatorHarPeled.h:272
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::planar_separators::Ring::faces
int faces
Definition: SeparatorHarPeled.h:306
ogdf::AdjElement::theNode
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:166
ogdf::planar_separators::Ring::getFaces
int getFaces() const
Definition: SeparatorHarPeled.h:381
ogdf::SeparatorHarPeled
Computes planar separators according to Har-Peled.
Definition: SeparatorHarPeled.h:97
ogdf::SeparatorHarPeled::isMultiNode
NodeArray< bool > isMultiNode
Definition: SeparatorHarPeled.h:284
ogdf::SeparatorHarPeled::border
EdgeArray< int > border
Definition: SeparatorHarPeled.h:275
ogdf::planar_separators::Ring::entries
List< adjEntry > entries
Definition: SeparatorHarPeled.h:300
backward::Color::reset
@ reset
Definition: backward.hpp:1719
ogdf::planar_separators::ArrayBFSTree
Abstract BFSTree that is realized via NodeArrays.
Definition: PlanarSeparatorModule.h:132
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::planar_separators::Ring::getSectionInSeparator
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...
Definition: SeparatorHarPeled.h:394
ogdf::planar_separators::Ring::Ring
Ring(node startNode, node endNode, adjEntry outPointer, const SeparatorHarPeled &separator)
Constructor for a full ring.
Definition: SeparatorHarPeled.h:333
ogdf::matching_blossom::Cycle
Definition: Cycle.h:44
ogdf::planar_separators::Ring
A closed ring of nodes.
Definition: SeparatorHarPeled.h:297
ogdf::SeparatorHarPeled::faceFrontiers
List< List< face > > faceFrontiers
Definition: SeparatorHarPeled.h:276
ogdf::SeparatorHarPeled::tree
std::shared_ptr< BFSTreeHP > tree
A special tree that can be reconstructed, see above.
Definition: SeparatorHarPeled.h:131
ogdf::planar_separators::BFSTreeHP
Specialised tree representation for Har-Peled.
Definition: SeparatorHarPeled.h:55
ogdf::SeparatorHarPeled::ringOut
NodeArray< List< adjEntry > > ringOut
Definition: SeparatorHarPeled.h:283
ogdf::AdjElement::twin
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:172
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::planar_separators::Ring::Ring
Ring(node n)
Constructor for degenerate rings.
Definition: SeparatorHarPeled.h:321
ogdf::SeparatorHarPeled::SeparatorHarPeled
SeparatorHarPeled()
Constructor.
Definition: SeparatorHarPeled.h:105
ogdf::SeparatorHarPeled::rings
Array< Ring, int > rings
Definition: SeparatorHarPeled.h:286
ogdf::planar_separators::Ring::nodes
List< node > nodes
Nodes and adjEntries that form the border of the ring.
Definition: SeparatorHarPeled.h:299
ogdf::PlanarSeparatorModule
Abstract description of all planar separator algorithms.
Definition: PlanarSeparatorModule.h:925
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:219
ogdf::planar_separators::Ring::in
node in
Crossing points with the main separator S: in is where S enters, out is where S leaves.
Definition: SeparatorHarPeled.h:303
ogdf::SeparatorHarPeled::ringIn
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...
Definition: SeparatorHarPeled.h:282
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: DfsMakeBiconnected.h:40
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::SeparatorHarPeled::E
ConstCombinatorialEmbedding E
Definition: SeparatorHarPeled.h:271
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::AdjElement::twinNode
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:175
ogdf::planar_separators::Ring::Ring
Ring()
Constructor.
Definition: SeparatorHarPeled.h:314
ogdf::AdjElement::cyclicSucc
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
Definition: Graph_d.h:354
ogdf::ConstCombinatorialEmbedding
Combinatorial embeddings of planar graphs.
Definition: CombinatorialEmbedding.h:216
basic.h
Basic declarations, included by all source files.
CombinatorialEmbedding.h
Declaration of CombinatorialEmbedding and face.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::planar_separators::Cycle
Auxiliary data structure to represent Cycles in planar graphs.
Definition: PlanarSeparatorModule.h:535
ogdf::planar_separators::Ring::getSize
int getSize() const
Definition: SeparatorHarPeled.h:386
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
List.h
Declaration of doubly linked lists and iterators.
ogdf::SeparatorHarPeled::mainSeparator
NodeArray< adjEntry > mainSeparator
Definition: SeparatorHarPeled.h:288
ogdf::SeparatorHarPeled::getSpecificName
virtual std::string getSpecificName() const override
Returns the unique name of the core algorithm, to be combined with postprocessors later.
Definition: SeparatorHarPeled.h:109
ogdf::planar_separators::BFSTreeHP::BFSTreeHP
BFSTreeHP(GraphCopy &G, node rootNode)
Constructor.
Definition: SeparatorHarPeled.h:63
ogdf::List::size
int size() const
Returns the number of elements in the list.
Definition: List.h:1488
ogdf::SeparatorHarPeled::faceLevels
FaceArray< int > faceLevels
Definition: SeparatorHarPeled.h:274
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::SeparatorHarPeled::getMaxSeparatorSize
virtual double getMaxSeparatorSize(int n) const override
Provides the maximal separator size that this algorithm guarantees as a function of the number of nod...
Definition: SeparatorHarPeled.h:107
ogdf::planar_separators::Ring::out
node out
Definition: SeparatorHarPeled.h:304
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1547
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
PlanarSeparatorModule.h
Declaration of base class of all planar separator algorithms.