Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

SeparatorDualHelper.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/FaceArray.h>
36 
37 #include <unordered_set>
38 
39 namespace ogdf {
40 
41 namespace planar_separator {
42 
44 
48 public:
49  SeparatorDualHelper(std::shared_ptr<GraphCopy> pGraph, std::shared_ptr<BFSTree> pTree)
50  : graph {pGraph}, tree {pTree} { }
51 
55  struct CycleData {
56  unsigned int inside; // contains number of nodes on the inside
57 
60 
61  std::unordered_set<node> nodes;
62 
69  bool isInCycle(node n) { return nodes.find(n) != nodes.end(); }
70 
71  /* Methods to add and remove nodes from the cycle. */
72 
73  void pushBack(node n) {
74  OGDF_ASSERT(!isInCycle(n));
75  cycle.pushBack(n);
76  nodes.insert(n);
77  }
78 
79  void pushFront(node n) {
80  OGDF_ASSERT(!isInCycle(n));
81  cycle.pushFront(n);
82  nodes.insert(n);
83  }
84 
85  void popBack() {
86  node x = cycle.popBackRet();
87  nodes.erase(x);
88  }
89 
90  void popFront() {
91  node x = cycle.popFrontRet();
92  nodes.erase(x);
93  }
94 
99  CycleData() { }
100 
101  // case 1
109  CycleData(const Graph& G, const face f, const adjEntry adj) : inside {0} {
110  pushBack(adj->twinNode());
111  pushBack(adj->faceCycleSucc()->twinNode());
112  pushBack(adj->theNode());
113  }
114 
115  // case 4
123  CycleData(const Graph& G, CycleData& first, CycleData& second) {
124  // find path
125  List<node> path;
126 
127  auto firstIt = first.cycle.crbegin();
128  auto secondIt = second.cycle.cbegin();
129 
130  OGDF_ASSERT(*firstIt == *secondIt);
131 
132  while (firstIt != first.cycle.crend() && secondIt != second.cycle.cend()
133  && *firstIt == *secondIt) {
134  path.pushBack(*firstIt);
135  ++firstIt;
136  ++secondIt;
137  }
138  node x = path.back();
139 
140  // number of nodes on the inside
141  inside = first.inside + second.inside + path.size() - 1;
142 
143  // join cycles
144  for (auto it = first.cycle.cbegin(); *it != x; ++it) {
145  pushBack(*it);
146  }
147 
148  auto it = second.cycle.cbegin();
149  while (*it != x) {
150  ++it;
151  }
152  for (; it != second.cycle.cend(); ++it) {
153  pushBack(*it);
154  }
155  }
156 
157  // case 2
163  void addTriangle(adjEntry adj) {
164  OGDF_ASSERT(!(isInCycle(adj->theNode()) && isInCycle(adj->twinNode())));
165  if (isInCycle(adj->theNode())) {
166  pushFront(adj->twinNode());
167  } else {
168  pushBack(adj->theNode());
169  }
170  }
171 
172  // case 3
179  // two different scenarios, depending on which adjacent triangle contains the cycle
180  OGDF_ASSERT(isInCycle(adj->theNode()) && isInCycle(adj->twinNode()));
181 
182  if (cycle.back() == adj->theNode()) {
183  popFront();
184  } else if (cycle.front() == adj->twinNode()) {
185  popBack();
186  } else {
187  OGDF_ASSERT(false); // Removing triangle was impossible because graph layout was illegitimate.
188  }
189 
190  inside++;
191  }
192 
199  bool checkSize(int n) const { return inside + cycle.size() > 1.0 / 3.0 * n; }
200  };
201 
202  std::shared_ptr<GraphCopy> graph;
203  std::shared_ptr<BFSTree> tree;
204 
205  // components needed for DFS
208 
214  CycleData dfs();
215 
223  CycleData process(face f, adjEntry adj);
224 
232  List<std::pair<face, adjEntry>> getUnmarkedNeighbours(face f, adjEntry adj);
233 };
234 
235 }
236 
237 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::planar_separator::SeparatorDualHelper::CycleData::pushBack
void pushBack(node n)
Definition: SeparatorDualHelper.h:73
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::planar_separator::SeparatorDualHelper::tree
std::shared_ptr< BFSTree > tree
Definition: SeparatorDualHelper.h:203
ogdf::AdjElement::theNode
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:159
ogdf::planar_separator::SeparatorDualHelper
Helper class for SeparatorDual and SeparatorDualFC.
Definition: SeparatorDualHelper.h:47
ogdf::List::popFrontRet
E popFrontRet()
Removes the first element from the list and returns it.
Definition: List.h:1581
ogdf::planar_separator::SeparatorDualHelper::embedding
CombinatorialEmbedding embedding
Definition: SeparatorDualHelper.h:206
ogdf::planar_separator::SeparatorDualHelper::CycleData::popBack
void popBack()
Definition: SeparatorDualHelper.h:85
ogdf::planar_separator::SeparatorDualHelper::CycleData::isInCycle
bool isInCycle(node n)
Checks if a node lies on the cycle.
Definition: SeparatorDualHelper.h:69
FaceArray.h
declaration and implementation of FaceArray class
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::planar_separator::SeparatorDualHelper::CycleData::CycleData
CycleData()
Empty Constructor - only used to be able to throw empty CD in case of algorithm failure.
Definition: SeparatorDualHelper.h:99
ogdf::List::pushFront
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: List.h:1524
ogdf::planar_separator::SeparatorDualHelper::CycleData::checkSize
bool checkSize(int n) const
Checks the size of this cycle.
Definition: SeparatorDualHelper.h:199
ogdf::planar_separator::SeparatorDualHelper::SeparatorDualHelper
SeparatorDualHelper(std::shared_ptr< GraphCopy > pGraph, std::shared_ptr< BFSTree > pTree)
Definition: SeparatorDualHelper.h:49
ogdf::planar_separator::SeparatorDualHelper::CycleData::addTriangle
void addTriangle(adjEntry adj)
Expands the cycle by adding a triangle.
Definition: SeparatorDualHelper.h:163
ogdf::planar_separator::SeparatorDualHelper::CycleData::CycleData
CycleData(const Graph &G, CycleData &first, CycleData &second)
Constructor.
Definition: SeparatorDualHelper.h:123
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
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::List::popBackRet
E popBackRet()
Removes the last element from the list and returns it.
Definition: List.h:1594
ogdf::planar_separator::SeparatorDualHelper::CycleData::inside
unsigned int inside
Definition: SeparatorDualHelper.h:56
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::EdgeStandardType::tree
@ tree
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
ogdf::planar_separator::SeparatorDualHelper::marked
FaceArray< bool > marked
Definition: SeparatorDualHelper.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_separator::SeparatorDualHelper::CycleData::cycle
List< node > cycle
contains nodes on the cycle, starting with v, ending with u, where e = (u,v) is the initial edge
Definition: SeparatorDualHelper.h:59
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:397
ogdf::planar_separator::SeparatorDualHelper::CycleData
Auxiliary lightweight data structure to represent cycles.
Definition: SeparatorDualHelper.h:55
ogdf::List::size
int size() const
Returns the number of elements in the list.
Definition: List.h:1478
ogdf::planar_separator::SeparatorDualHelper::CycleData::nodes
std::unordered_set< node > nodes
Definition: SeparatorDualHelper.h:61
ogdf::planar_separator::SeparatorDualHelper::CycleData::removeTriangle
void removeTriangle(adjEntry adj)
Expands the cycle by removing a triangle.
Definition: SeparatorDualHelper.h:178
ogdf::planar_separator::SeparatorDualHelper::CycleData::popFront
void popFront()
Definition: SeparatorDualHelper.h:90
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::planar_separator::SeparatorDualHelper::CycleData::pushFront
void pushFront(node n)
Definition: SeparatorDualHelper.h:79
ogdf::planar_separator::SeparatorDualHelper::graph
std::shared_ptr< GraphCopy > graph
Definition: SeparatorDualHelper.h:202
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1537
PlanarSeparatorModule.h
Declaration of base class of all planar separator algorithms.
ogdf::planar_separator::SeparatorDualHelper::CycleData::CycleData
CycleData(const Graph &G, const face f, const adjEntry adj)
Constructor.
Definition: SeparatorDualHelper.h:109
ogdf::FaceElement
Faces in a combinatorial embedding.
Definition: CombinatorialEmbedding.h:109