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/DualGraph.h>
36 
37 namespace ogdf {
38 
39 namespace planar_separators {
40 
47 public:
54  BFSTreeHP(GraphCopy& G, node rootNode) : ArrayBFSTree(G, rootNode) { construct(); }
55 
59  void construct();
60 
66  void reconstruct(const Cycle& cycle);
67 
71  void calculateDescendants();
72 };
73 
74 struct Ring; // see below
75 
76 }
77 
78 using namespace planar_separators;
79 
81 
90  friend struct planar_separators::Ring;
91 
92 public:
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 
102 protected:
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 
140  edge findSeparatorEdge() const;
141 
148  void createDual(Graph& Dual, EdgeArray<edge>& oldEdge) const;
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 
195  void walkAlongSeparator(node startNode, node endNode, EdgeArray<bool>& regionBorder,
196  List<node>& region) const;
197 
207  void walkAlongRing(const Ring& ring, bool firstSection, bool invert,
208  EdgeArray<bool>& regionBorder, List<node>& region) const;
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 
261 private:
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 
282 namespace planar_separators {
283 
288 struct 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 
324  Ring(node startNode, node endNode, adjEntry outPointer, const SeparatorHarPeled& separator) {
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]) {
336  adjEntry outP = outPointer;
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) {
353  adjEntry candidate =
354  nextEntry->twin()->cyclicSucc(); // start checking at the entry via which we entered
355  while (separator.ringOut[next].search(candidate) == separator.ringOut[next].end()) {
356  candidate = candidate->cyclicSucc();
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 
385  List<adjEntry> getSectionInSeparator(bool firstSection) const {
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 }
ogdf::SeparatorHarPeled::psi
node psi
Definition: SeparatorHarPeled.h:263
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::planar_separators::Ring::faces
int faces
Definition: SeparatorHarPeled.h:297
ogdf::AdjElement::theNode
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:159
ogdf::planar_separators::Ring::getFaces
int getFaces() const
Definition: SeparatorHarPeled.h:372
ogdf::SeparatorHarPeled
Computes planar separators according to Har-Peled.
Definition: SeparatorHarPeled.h:88
ogdf::SeparatorHarPeled::isMultiNode
NodeArray< bool > isMultiNode
Definition: SeparatorHarPeled.h:275
ogdf::SeparatorHarPeled::border
EdgeArray< int > border
Definition: SeparatorHarPeled.h:266
ogdf::planar_separators::Ring::entries
List< adjEntry > entries
Definition: SeparatorHarPeled.h:291
backward::Color::reset
@ reset
Definition: backward.hpp:1719
ogdf::planar_separators::ArrayBFSTree
Abstract BFSTree that is realized via NodeArrays.
Definition: PlanarSeparatorModule.h:123
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:384
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:385
ogdf::planar_separators::Ring::Ring
Ring(node startNode, node endNode, adjEntry outPointer, const SeparatorHarPeled &separator)
Constructor for a full ring.
Definition: SeparatorHarPeled.h:324
ogdf::matching_blossom::Cycle
Definition: Cycle.h:43
ogdf::planar_separators::Ring
A closed ring of nodes.
Definition: SeparatorHarPeled.h:288
ogdf::SeparatorHarPeled::faceFrontiers
List< List< face > > faceFrontiers
Definition: SeparatorHarPeled.h:267
ogdf::SeparatorHarPeled::tree
std::shared_ptr< BFSTreeHP > tree
A special tree that can be reconstructed, see above.
Definition: SeparatorHarPeled.h:122
ogdf::planar_separators::BFSTreeHP
Specialised tree representation for Har-Peled.
Definition: SeparatorHarPeled.h:46
ogdf::SeparatorHarPeled::ringOut
NodeArray< List< adjEntry > > ringOut
Definition: SeparatorHarPeled.h:274
ogdf::AdjElement::twin
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:165
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::planar_separators::Ring::Ring
Ring(node n)
Constructor for degenerate rings.
Definition: SeparatorHarPeled.h:312
ogdf::SeparatorHarPeled::SeparatorHarPeled
SeparatorHarPeled()
Constructor.
Definition: SeparatorHarPeled.h:96
ogdf::SeparatorHarPeled::rings
Array< Ring, int > rings
Definition: SeparatorHarPeled.h:277
ogdf::planar_separators::Ring::nodes
List< node > nodes
Nodes and adjEntries that form the border of the ring.
Definition: SeparatorHarPeled.h:290
ogdf::PlanarSeparatorModule
Abstract description of all planar separator algorithms.
Definition: PlanarSeparatorModule.h:916
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:214
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:294
DualGraph.h
Includes declaration of dual graph class.
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:273
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::SeparatorHarPeled::E
ConstCombinatorialEmbedding E
Definition: SeparatorHarPeled.h:262
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::FaceArrayBase
RegisteredArray for labeling the faces of a CombinatorialEmbedding.
Definition: CombinatorialEmbedding.h:172
ogdf::AdjElement::twinNode
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:168
ogdf::planar_separators::Ring::Ring
Ring()
Constructor.
Definition: SeparatorHarPeled.h:305
ogdf::AdjElement::cyclicSucc
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
Definition: Graph_d.h:347
ogdf::ConstCombinatorialEmbedding
Combinatorial embeddings of planar graphs.
Definition: CombinatorialEmbedding.h:207
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::planar_separators::Cycle
Auxiliary data structure to represent Cycles in planar graphs.
Definition: PlanarSeparatorModule.h:526
ogdf::planar_separators::Ring::getSize
int getSize() const
Definition: SeparatorHarPeled.h:377
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
ogdf::SeparatorHarPeled::mainSeparator
NodeArray< adjEntry > mainSeparator
Definition: SeparatorHarPeled.h:279
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:100
ogdf::planar_separators::BFSTreeHP::BFSTreeHP
BFSTreeHP(GraphCopy &G, node rootNode)
Constructor.
Definition: SeparatorHarPeled.h:54
ogdf::List::size
int size() const
Returns the number of elements in the list.
Definition: List.h:1478
ogdf::SeparatorHarPeled::faceLevels
FaceArray< int > faceLevels
Definition: SeparatorHarPeled.h:265
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
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:98
ogdf::planar_separators::Ring::out
node out
Definition: SeparatorHarPeled.h:295
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1537
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
PlanarSeparatorModule.h
Declaration of base class of all planar separator algorithms.