Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

BoyerMyrvoldPlanar.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <random>
36 #include <ogdf/basic/NodeArray.h>
37 #include <ogdf/basic/EdgeArray.h>
38 #include <ogdf/basic/Stack.h>
39 #include <ogdf/basic/List.h>
40 #include <ogdf/basic/SList.h>
41 
42 namespace ogdf {
43 
46  Undefined=0,
47  Selfloop=1,
48  Back=2,
49  Dfs=3,
50  DfsParallel=4,
51  BackDeleted=5
52 };
53 
55 class FindKuratowskis;
56 namespace boyer_myrvold {
57 class BoyerMyrvoldInit;
58 }
59 
62 {
63  friend class BoyerMyrvold;
65  friend class FindKuratowskis;
66  friend class ExtractKuratowskis;
67 
68 public:
70  const static int DirectionCCW;
71 
73  const static int DirectionCW;
74 
76  enum class EmbeddingGrade {
77  doNotEmbed=-3, // and not find any kuratowski subdivisions
78  doNotFind=-2, // but embed
79  doFindUnlimited=-1, // and embed
80  doFindZero=0 // and embed
81  };
82 
85  Graph& g,
86  bool bundles,
87  int embeddingGrade,
88  bool limitStructures,
90  double randomness,
91  bool avoidE2Minors,
92  bool extractSubgraph,
93  const EdgeArray<int> *edgeCosts = nullptr);
94 
97  Graph& g,
98  bool bundles,
99  EmbeddingGrade embeddingGrade,
100  bool limitStructures,
102  double randomness,
103  bool avoidE2Minors,
104  bool extractSubgraph,
105  const EdgeArray<int> *edgeCosts = nullptr)
106  : BoyerMyrvoldPlanar(g, bundles, static_cast<int>(embeddingGrade), limitStructures, output, randomness, avoidE2Minors, extractSubgraph, edgeCosts)
107  {}
108 
110  bool start();
111 
113 
119  void flipBicomp(
120  int c,
121  int marker,
122  NodeArray<int>& visited,
123  bool wholeGraph,
124  bool deleteFlipFlags);
125 
126  // avoid automatic creation of assignment operator
128  BoyerMyrvoldPlanar &operator=(const BoyerMyrvoldPlanar &);
129 
130 
134  void seed(const std::minstd_rand rand) {
135  m_rand = rand;
136  }
137 
138 protected:
141 
143  inline bool pertinent(node w) {
144  OGDF_ASSERT(w!=nullptr);
145  return m_dfi[w] > 0 && (!m_backedgeFlags[w].empty() || !m_pertinentRoots[w].empty());
146  }
147 
149  inline bool internallyActive(node w, int v) {
150  OGDF_ASSERT(w!=nullptr);
151  return m_dfi[w] > 0 && pertinent(w) && !externallyActive(w, v);
152  }
153 
155  inline bool externallyActive(node w, int v) {
156  OGDF_ASSERT(w!=nullptr);
157  if (m_dfi[w] <= 0) return false;
158  if (m_leastAncestor[w] < v) return true;
159  return !m_separatedDFSChildList[w].empty() && m_lowPoint[m_separatedDFSChildList[w].front()] < v;
160  }
161 
163  inline bool inactive(node w, int v) {
164  OGDF_ASSERT(w!=nullptr);
165  if (m_dfi[w] <= 0) return true;
166  if (!m_backedgeFlags[w].empty() || !m_pertinentRoots[w].empty()
167  || m_leastAncestor[w] < v) return false;
168  return m_separatedDFSChildList[w].empty() || m_lowPoint[m_separatedDFSChildList[w].front()] >= v;
169  }
170 
172 
179  inline int infoAboutNode(node w, int v) {
180  OGDF_ASSERT(w!=nullptr);
181  if (m_dfi[w] <= 0) return 0;
182  if (!m_pertinentRoots[w].empty() || !m_backedgeFlags[w].empty()) {
183  // pertinent
184  if (m_leastAncestor[w] < v) return 2;
185  if (m_separatedDFSChildList[w].empty()) return 1;
186  return m_lowPoint[m_separatedDFSChildList[w].front()] < v ? 2 : 1;
187  } else {
188  // not pertinent
189  if (m_leastAncestor[w] < v) return 3;
190  if (m_separatedDFSChildList[w].empty()) return 0;
191  return m_lowPoint[m_separatedDFSChildList[w].front()] < v ? 3 : 0;
192  }
193  }
194 
196 
201  inline node successorOnExternalFace(node w, int& direction) {
202  OGDF_ASSERT(w!=nullptr);
203  OGDF_ASSERT(w->degree()>0);
204  OGDF_ASSERT(m_link[BoyerMyrvoldPlanar::DirectionCW][w]!=nullptr);
205  OGDF_ASSERT(m_link[BoyerMyrvoldPlanar::DirectionCCW][w]!=nullptr);
206  adjEntry adj = m_link[direction][w];
207  OGDF_ASSERT(adj->theNode()!=nullptr);
208 
209  if (w->degree() > 1) direction =
210  adj==beforeShortCircuitEdge(adj->theNode(),BoyerMyrvoldPlanar::DirectionCCW)->twin();
211  OGDF_ASSERT(direction || adj==beforeShortCircuitEdge(adj->theNode(),BoyerMyrvoldPlanar::DirectionCW)->twin());
212  return adj->theNode();
213  }
214 
216  inline node successorWithoutShortCircuit(node w, int& direction) {
217  OGDF_ASSERT(w!=nullptr);
218  OGDF_ASSERT(w->degree()>0);
219  OGDF_ASSERT(m_link[BoyerMyrvoldPlanar::DirectionCW][w]!=nullptr);
220  OGDF_ASSERT(m_link[BoyerMyrvoldPlanar::DirectionCCW][w]!=nullptr);
221  adjEntry adj = beforeShortCircuitEdge(w,direction);
222  OGDF_ASSERT(adj->theNode()!=nullptr);
223 
224  if (w->degree() > 1) direction =
225  adj==beforeShortCircuitEdge(adj->theNode(),BoyerMyrvoldPlanar::DirectionCCW)->twin();
226  OGDF_ASSERT(direction || adj==beforeShortCircuitEdge(adj->theNode(),BoyerMyrvoldPlanar::DirectionCW)->twin());
227  return adj->theNode();
228  }
229 
231 
233  inline node constSuccessorOnExternalFace(node v, int direction) {
234  OGDF_ASSERT(v!=nullptr);
235  OGDF_ASSERT(v->degree()>0);
236  return m_link[direction][v]->theNode();
237  }
238 
240 
242  inline node constSuccessorWithoutShortCircuit(node v, int direction) {
243  OGDF_ASSERT(v!=nullptr);
244  OGDF_ASSERT(v->degree()>0);
245  return beforeShortCircuitEdge(v,direction)->theNode();
246  }
247 
249 
252  inline adjEntry beforeShortCircuitEdge(node v, int direction) {
253  OGDF_ASSERT(v!=nullptr);
254  return (m_beforeSCE[direction][v]==nullptr) ? m_link[direction][v] : m_beforeSCE[direction][v];
255  }
256 
258 
260  node activeSuccessor(node w, int& direction, int v, int& info);
261 
263 
265  inline node constActiveSuccessor(node w, int direction, int v, int& info) {
266  return activeSuccessor(w,direction,v,info);
267  }
268 
270 
272  inline bool wNodesExist(node root, node stopx, node stopy) {
273  OGDF_ASSERT(root != stopx);
274  OGDF_ASSERT(root != stopy);
275  OGDF_ASSERT(stopx != stopy);
277  bool between = false;
278  while (root != nullptr) {
279  root = successorOnExternalFace(root,dir);
280  if (between && pertinent(root)) {
281  return true;
282  }
283  if (root == stopx || root == stopy) {
284  if (between) {
285  return false;
286  }
287  between = true;
288  }
289  }
290  return false;
291  }
292 
294  inline void printNodeInfo(node v) {
295  cout << "\nprintNodeInfo(" << m_dfi[v] << "): ";
296  cout << "CCW=" << m_dfi[constSuccessorOnExternalFace(v,BoyerMyrvoldPlanar::DirectionCCW)];
297  cout << ",CW=" << m_dfi[constSuccessorOnExternalFace(v,BoyerMyrvoldPlanar::DirectionCW)];
298  cout << "\tCCWBefore=" << m_dfi[constSuccessorWithoutShortCircuit(v,BoyerMyrvoldPlanar::DirectionCCW)];
299  cout << ",CWBefore=" << m_dfi[constSuccessorWithoutShortCircuit(v,BoyerMyrvoldPlanar::DirectionCW)];
300  cout << "\tadjList: ";
301  adjEntry adj;
302  for (adj = v->firstAdj(); adj; adj = adj->succ()) {
303  cout << adj->twinNode() << " ";
304  }
305  }
306 
308 
310  void mergeBiconnectedComponent(StackPure<int>& stack, const int j);
311 
313 
315  void mergeBiconnectedComponentOnlyPlanar(StackPure<int>& stack, const int j);
316 
318 
320  void embedBackedges(const node v, const int v_dir,
321  const node w, const int w_dir, const int i);
322 
324 
326  void embedBackedgesOnlyPlanar(const node v, const int v_dir,
327  const node w, const int w_dir, const int i);
328 
330  void createShortCircuitEdge(const node v, const int v_dir,
331  const node w, const int w_dir);
332 
334 
337  node walkup(const node v, const node w, const int marker, const edge back);
338 
340 
346  int walkdown(const int i, const node v, FindKuratowskis* findKuratowskis);
347 
349  void mergeUnprocessedNodes();
350 
352 
354  void postProcessEmbedding();
355 
357 
359  bool embed();
360 
362 
365 
368  const bool m_bundles;
369  const int m_embeddingGrade;
370  const bool m_limitStructures;
371  const double m_randomness;
372  const bool m_avoidE2Minors;
374  std::minstd_rand m_rand;
376 
378  bool m_extractSubgraph = true;
379 
382 
385 
387 
390 
393 
396 
398 
401 
403 
407  NodeArray<adjEntry> m_beforeSCE[2];
408 
411 
413 
416 
419 
422 
425 
427 
430 
432 
435 
439 
442 
445 
447 
450 
452 
457 
459 
463 
466 
469 
471 };
472 
474  return lhs > static_cast<int>(rhs);
475 }
476 
478  return lhs == static_cast<int>(rhs);
479 }
480 
482  return lhs != static_cast<int>(rhs);
483 }
484 
486  return lhs <= static_cast<int>(rhs);
487 }
488 
489 }
Declaration of singly linked lists and iterators.
Extracts multiple Kuratowski Subdivisions.
NodeArray< ListPure< node > > m_separatedDFSChildList
A list to all separated DFS-children of node.
Wrapper class used for preprocessing and valid invocation of the planarity test.
Definition: BoyerMyrvold.h:138
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
bool inactive(node w, int v)
Checks whether real node w is inactive while embedding node with DFI v.
NodeArray< node > m_realVertex
Link to non-virtual vertex of a virtual Vertex.
Array< node > m_nodeFromDFI
Returns appropriate node from given DFI.
Singly linked lists.
Definition: SList.h:38
NodeArray< int > m_visitedWithBackedge
Keeps track of all vertices that are visited by the walkup through a specific backedge.
EmbeddingGrade
Denotes the different embedding options.
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:208
node constActiveSuccessor(node w, int direction, int v, int &info)
Walks upon external face in the given direction (without changing it) until an active vertex is reach...
A Kuratowski Structure is a special graph structure containing severals subdivisions.
node successorOnExternalFace(node w, int &direction)
Walks upon external face in the given direction starting at w.
NodeArray< int > m_lowPoint
The lowpoint of each node.
NodeArray< int > m_leastAncestor
The DFI of the least ancestor node over all backedges.
node constSuccessorOnExternalFace(node v, int direction)
Returns the successornode on the external face in given direction.
int infoAboutNode(node w, int v)
Checks all dynamic information about a node w while embedding node with DFI v.
NodeArray< bool > m_flipped
Iff true, the node is the root of a bicomp which has to be flipped.
EdgeArray< BoyerMyrvoldEdgeType > m_edgeType
Contains the type of each edge.
bool operator>(int lhs, BoyerMyrvoldPlanar::EmbeddingGrade rhs)
adjEntry beforeShortCircuitEdge(node v, int direction)
Returns underlying former adjEntry, if a short circuit edge in direction of v exists.
void printNodeInfo(node v)
Prints informations about node v.
NodeArray< ListIterator< node > > m_pNodeInParent
Pointer to node contained in the DFSChildList of his parent, if exists.
This class is used in the Boyer-Myrvold planarity test for preprocessing purposes.
NodeArray< adjEntry > m_adjParent
The adjEntry which goes from DFS-parent to current vertex.
NodeArray< int > m_visited
This Array keeps track of all vertices that are visited by current walkup.
Declaration and implementation of EdgeArray class.
node successorWithoutShortCircuit(node w, int &direction)
Walks upon external face in given direction avoiding short circuit edges.
List-based stacks.
Definition: SList.h:39
bool externallyActive(node w, int v)
Checks whether real node w is externally active while embedding node with DFI v.
Graph & m_g
Input graph, which can be altered.
bool pertinent(node w)
Checks whether node w is pertinent. w has to be non-virtual.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:105
Class for the representation of edges.
Definition: Graph_d.h:291
NodeArray< SListPure< node > > m_pertinentRoots
List of virtual bicomp roots, that are pertinent to the current embedded node.
Class for the representation of nodes.
Definition: Graph_d.h:167
Declaration and implementation of NodeArray class.
const EdgeArray< int > * m_edgeCosts
NodeArray< SListPure< adjEntry > > m_backedgeFlags
Holds information, if node is the source of a backedge.
This class collects information about Kuratowski Subdivisions which is used for extraction later...
NodeArray< int > m_highestSubtreeDFI
The highest DFI in a subtree with node as root.
EdgeArray< node > m_pointsToRoot
Identifies the rootnode of the child bicomp the given backedge points to.
bool wNodesExist(node root, node stopx, node stopy)
Checks, if one ore more wNodes exist between the two stopping vertices stopx and stopy.
void seed(const std::minstd_rand rand)
Seeds the random generator for performing a random DFS. If this method is never called the random gen...
int m_flippedNodes
The whole number of bicomps, which have to be flipped.
This class implements the extended BoyerMyrvold planarity embedding algorithm.
static const int DirectionCCW
Direction for counterclockwise traversal.
BoyerMyrvoldPlanar(Graph &g, bool bundles, EmbeddingGrade embeddingGrade, bool limitStructures, SListPure< KuratowskiStructure > &output, double randomness, bool avoidE2Minors, bool extractSubgraph, const EdgeArray< int > *edgeCosts=nullptr)
Constructor, for parameters see BoyerMyrvold.
adjEntry succ() const
Returns the successor in the adjacency list.
Definition: Graph_d.h:145
static const int DirectionCW
Direction for clockwise traversal.
bool internallyActive(node w, int v)
Checks whether real node w is internally active while embedding node with DFI v.
node constSuccessorWithoutShortCircuit(node v, int direction)
Walks upon external face in direction avoiding short circuit edges.
NodeArray< int > m_dfi
The one and only DFI-NodeArray.
The namespace for all OGDF objects.
bool operator<=(int lhs, BoyerMyrvoldPlanar::EmbeddingGrade rhs)
BoyerMyrvoldEdgeType
Type of edge.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Graph_d.h:211
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition: tuples.h:75
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:99
bool operator!=(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Inequality operator for 2-tuples.
Definition: tuples.h:82
Class for adjacency list elements.
Definition: Graph_d.h:78
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
Declaration of doubly linked lists and iterators.
Declaration and implementation of list-based stacks (StackPure<E> and Stack<E>).
SListPure< KuratowskiStructure > & m_output
Data structure for the Kuratowski subdivisions, which will be returned.