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
36
37#include <unordered_set>
38
39namespace ogdf {
40
41namespace planar_separator {
42
44
48public:
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
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
124 // find path
125 List<node> path;
126
127 auto firstIt = first.cycle.crbegin();
128 auto secondIt = second.cycle.cbegin();
129
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
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
215
224
233};
234
235}
236
237}
declaration and implementation of FaceArray class
Declaration of base class of all planar separator algorithms.
Class for adjacency list elements.
Definition Graph_d.h:79
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition Graph_d.h:112
node theNode() const
Returns the node whose adjacency list contains this element.
Definition Graph_d.h:103
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition Graph_d.h:149
Combinatorial embeddings of planar graphs with modification functionality.
Dynamic arrays indexed with faces of a combinatorial embedding.
Definition FaceArray.h:126
Faces in a combinatorial embedding.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
int size() const
Returns the number of elements in the list.
Definition List.h:1472
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1531
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition List.h:1518
E popBackRet()
Removes the last element from the list and returns it.
Definition List.h:1588
E popFrontRet()
Removes the first element from the list and returns it.
Definition List.h:1575
const_reference front() const
Returns a const reference to the first element.
Definition List.h:289
const_reference back() const
Returns a const reference to the last element.
Definition List.h:307
Class for the representation of nodes.
Definition Graph_d.h:177
Helper class for SeparatorDual and SeparatorDualFC.
CycleData process(face f, adjEntry adj)
Processes a face: One step of the recursion in the DFS.
List< std::pair< face, adjEntry > > getUnmarkedNeighbours(face f, adjEntry adj)
Finds all unmarked neighbours of a face.
CycleData dfs()
Recursive Depth First Search over the faces of the dual of the graph.
SeparatorDualHelper(std::shared_ptr< GraphCopy > pGraph, std::shared_ptr< BFSTree > pTree)
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
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, CycleData &first, CycleData &second)
Constructor.
CycleData()
Empty Constructor - only used to be able to throw empty CD in case of algorithm failure.
bool checkSize(int n) const
Checks the size of this cycle.
void removeTriangle(adjEntry adj)
Expands the cycle by removing a triangle.
bool isInCycle(node n)
Checks if a node lies on the cycle.
CycleData(const Graph &G, const face f, const adjEntry adj)
Constructor.
void addTriangle(adjEntry adj)
Expands the cycle by adding a triangle.
List< node > cycle
contains nodes on the cycle, starting with v, ending with u, where e = (u,v) is the initial edge