Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 
44 class BFSTree;
45 } // namespace ogdf::planar_separators
46 
47 namespace ogdf {
48 class GraphCopy;
49 
50 namespace planar_separators {
51 
53 
57 public:
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 
108  CycleData() { }
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
172  void addTriangle(adjEntry adj) {
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 
223  CycleData dfs();
224 
232  CycleData process(face f, adjEntry adj);
233 
241  List<std::pair<face, adjEntry>> getUnmarkedNeighbours(face f, adjEntry adj);
242 };
243 
244 }
245 
246 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::planar_separators
Definition: SeparatorDualHelper.h:43
ogdf::planar_separators::SeparatorDualHelper::CycleData::popFront
void popFront()
Definition: SeparatorDualHelper.h:99
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::AdjElement::theNode
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:166
ogdf::List::popFrontRet
E popFrontRet()
Removes the first element from the list and returns it.
Definition: List.h:1591
ogdf::planar_separators::SeparatorDualHelper::CycleData::addTriangle
void addTriangle(adjEntry adj)
Expands the cycle by adding a triangle.
Definition: SeparatorDualHelper.h:172
ogdf::planar_separators::SeparatorDualHelper::CycleData::nodes
std::unordered_set< node > nodes
Definition: SeparatorDualHelper.h:70
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::planar_separators::SeparatorDualHelper::CycleData::checkSize
bool checkSize(int n) const
Checks the size of this cycle.
Definition: SeparatorDualHelper.h:208
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::planar_separators::SeparatorDualHelper::marked
FaceArray< bool > marked
Definition: SeparatorDualHelper.h:216
ogdf::planar_separators::SeparatorDualHelper
Helper class for SeparatorDual and SeparatorDualFC.
Definition: SeparatorDualHelper.h:56
ogdf::planar_separators::SeparatorDualHelper::CycleData::pushFront
void pushFront(node n)
Definition: SeparatorDualHelper.h:88
ogdf::planar_separators::SeparatorDualHelper::CycleData
Auxiliary lightweight data structure to represent cycles.
Definition: SeparatorDualHelper.h:64
ogdf::List::pushFront
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: List.h:1534
ogdf::planar_separators::BFSTree
Abstract description of a Breadth First Search tree.
Definition: PlanarSeparatorModule.h:58
ogdf::planar_separators::SeparatorDualHelper::graph
std::shared_ptr< GraphCopy > graph
Definition: SeparatorDualHelper.h:211
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: DfsMakeBiconnected.h:40
ogdf::planar_separators::SeparatorDualHelper::CycleData::isInCycle
bool isInCycle(node n)
Checks if a node lies on the cycle.
Definition: SeparatorDualHelper.h:78
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::planar_separators::SeparatorDualHelper::CycleData::inside
unsigned int inside
Definition: SeparatorDualHelper.h:65
ogdf::List::popBackRet
E popBackRet()
Removes the last element from the list and returns it.
Definition: List.h:1604
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::SeparatorDualHelper::CycleData::removeTriangle
void removeTriangle(adjEntry adj)
Expands the cycle by removing a triangle.
Definition: SeparatorDualHelper.h:187
ogdf::EdgeStandardType::tree
@ tree
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
ogdf::planar_separators::SeparatorDualHelper::SeparatorDualHelper
SeparatorDualHelper(std::shared_ptr< GraphCopy > pGraph, std::shared_ptr< BFSTree > pTree)
Definition: SeparatorDualHelper.h:58
ogdf::planar_separators::SeparatorDualHelper::CycleData::pushBack
void pushBack(node n)
Definition: SeparatorDualHelper.h:82
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
ogdf::planar_separators::SeparatorDualHelper::CycleData::CycleData
CycleData()
Empty Constructor - only used to be able to throw empty CD in case of algorithm failure.
Definition: SeparatorDualHelper.h:108
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:406
ogdf::planar_separators::SeparatorDualHelper::embedding
CombinatorialEmbedding embedding
Definition: SeparatorDualHelper.h:215
List.h
Declaration of doubly linked lists and iterators.
ogdf::List::size
int size() const
Returns the number of elements in the list.
Definition: List.h:1488
ogdf::planar_separators::SeparatorDualHelper::tree
std::shared_ptr< BFSTree > tree
Definition: SeparatorDualHelper.h:212
ogdf::planar_separators::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:68
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::planar_separators::SeparatorDualHelper::CycleData::popBack
void popBack()
Definition: SeparatorDualHelper.h:94
ogdf::planar_separators::SeparatorDualHelper::CycleData::CycleData
CycleData(const Graph &G, const face f, const adjEntry adj)
Constructor.
Definition: SeparatorDualHelper.h:118
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1547
ogdf::FaceElement
Faces in a combinatorial embedding.
Definition: CombinatorialEmbedding.h:118
ogdf::planar_separators::SeparatorDualHelper::CycleData::CycleData
CycleData(const Graph &G, CycleData &first, CycleData &second)
Constructor.
Definition: SeparatorDualHelper.h:132