Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
SeparatorDualHelper.h
Go to the documentation of this file.
1
32#pragma once
33
35#include <ogdf/basic/Graph.h>
36#include <ogdf/basic/List.h>
37#include <ogdf/basic/basic.h>
38
39#include <memory>
40#include <unordered_set>
41#include <utility>
42
44class BFSTree;
45} // namespace ogdf::planar_separators
46
47namespace ogdf {
48class GraphCopy;
49
50namespace planar_separators {
51
53
57public:
58 SeparatorDualHelper(std::shared_ptr<GraphCopy> pGraph, std::shared_ptr<BFSTree> pTree)
59 : graph {pGraph}, tree {pTree} { }
60
64 struct CycleData {
65 unsigned int inside; // contains number of nodes on the inside
66
69
70 std::unordered_set<node> nodes;
71
78 bool isInCycle(node n) { return nodes.find(n) != nodes.end(); }
79
80 /* Methods to add and remove nodes from the cycle. */
81
82 void pushBack(node n) {
83 OGDF_ASSERT(!isInCycle(n));
84 cycle.pushBack(n);
85 nodes.insert(n);
86 }
87
88 void pushFront(node n) {
89 OGDF_ASSERT(!isInCycle(n));
90 cycle.pushFront(n);
91 nodes.insert(n);
92 }
93
94 void popBack() {
95 node x = cycle.popBackRet();
96 nodes.erase(x);
97 }
98
99 void popFront() {
100 node x = cycle.popFrontRet();
101 nodes.erase(x);
102 }
103
109
110 // case 1
118 CycleData(const Graph& G, const face f, const adjEntry adj) : inside {0} {
119 pushBack(adj->twinNode());
120 pushBack(adj->faceCycleSucc()->twinNode());
121 pushBack(adj->theNode());
122 }
123
124 // case 4
132 CycleData(const Graph& G, CycleData& first, CycleData& second) {
133 // find path
134 List<node> path;
135
136 auto firstIt = first.cycle.crbegin();
137 auto secondIt = second.cycle.cbegin();
138
139 OGDF_ASSERT(*firstIt == *secondIt);
140
141 while (firstIt != first.cycle.crend() && secondIt != second.cycle.cend()
142 && *firstIt == *secondIt) {
143 path.pushBack(*firstIt);
144 ++firstIt;
145 ++secondIt;
146 }
147 node x = path.back();
148
149 // number of nodes on the inside
150 inside = first.inside + second.inside + path.size() - 1;
151
152 // join cycles
153 for (auto it = first.cycle.cbegin(); *it != x; ++it) {
154 pushBack(*it);
155 }
156
157 auto it = second.cycle.cbegin();
158 while (*it != x) {
159 ++it;
160 }
161 for (; it != second.cycle.cend(); ++it) {
162 pushBack(*it);
163 }
164 }
165
166 // case 2
173 OGDF_ASSERT(!(isInCycle(adj->theNode()) && isInCycle(adj->twinNode())));
174 if (isInCycle(adj->theNode())) {
175 pushFront(adj->twinNode());
176 } else {
177 pushBack(adj->theNode());
178 }
179 }
180
181 // case 3
188 // two different scenarios, depending on which adjacent triangle contains the cycle
189 OGDF_ASSERT(isInCycle(adj->theNode()) && isInCycle(adj->twinNode()));
190
191 if (cycle.back() == adj->theNode()) {
192 popFront();
193 } else if (cycle.front() == adj->twinNode()) {
194 popBack();
195 } else {
196 OGDF_ASSERT(false); // Removing triangle was impossible because graph layout was illegitimate.
197 }
198
199 inside++;
200 }
201
208 bool checkSize(int n) const { return inside + cycle.size() > 1.0 / 3.0 * n; }
209 };
210
211 std::shared_ptr<GraphCopy> graph;
212 std::shared_ptr<BFSTree> tree;
213
214 // components needed for DFS
217
224
233
242};
243
244}
245
246}
Declaration of CombinatorialEmbedding and face.
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
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
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition Graph_d.h:213
Combinatorial embeddings of planar graphs with modification functionality.
RegisteredArray for labeling the faces of a CombinatorialEmbedding.
Faces in a combinatorial embedding.
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
int size() const
Returns the number of elements in the list.
Definition List.h:1488
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1547
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition List.h:1534
E popBackRet()
Removes the last element from the list and returns it.
Definition List.h:1604
E popFrontRet()
Removes the first element from the list and returns it.
Definition List.h:1591
const_reference front() const
Returns a const reference to the first element.
Definition List.h:305
const_reference back() const
Returns a const reference to the last element.
Definition List.h:323
Class for the representation of nodes.
Definition Graph_d.h:241
Abstract description of a Breadth First Search tree.
Helper class for SeparatorDual and SeparatorDualFC.
CycleData dfs()
Recursive Depth First Search over the faces of the dual of the graph.
List< std::pair< face, adjEntry > > getUnmarkedNeighbours(face f, adjEntry adj)
Finds all unmarked neighbours of a face.
SeparatorDualHelper(std::shared_ptr< GraphCopy > pGraph, std::shared_ptr< BFSTree > pTree)
CycleData process(face f, adjEntry adj)
Processes a face: One step of the recursion in the DFS.
#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.
@ tree
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
Auxiliary lightweight data structure to represent cycles.
CycleData(const Graph &G, const face f, const adjEntry adj)
Constructor.
bool isInCycle(node n)
Checks if a node lies on the cycle.
List< node > cycle
contains nodes on the cycle, starting with v, ending with u, where e = (u,v) is the initial edge
void removeTriangle(adjEntry adj)
Expands the cycle by removing a triangle.
CycleData(const Graph &G, CycleData &first, CycleData &second)
Constructor.
bool checkSize(int n) const
Checks the size of this cycle.
void addTriangle(adjEntry adj)
Expands the cycle by adding a triangle.
CycleData()
Empty Constructor - only used to be able to throw empty CD in case of algorithm failure.