Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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/List.h>
39 #include <ogdf/basic/SList.h>
40 
41 namespace ogdf {
42 
45  Undefined=0,
46  Selfloop=1,
47  Back=2,
48  Dfs=3,
49  DfsParallel=4,
50  BackDeleted=5
51 };
52 
54 class FindKuratowskis;
55 namespace boyer_myrvold {
56 class BoyerMyrvoldInit;
57 }
58 
61 {
62  friend class BoyerMyrvold;
64  friend class FindKuratowskis;
65  friend class ExtractKuratowskis;
66 
67 public:
69  const static int DirectionCCW;
70 
72  const static int DirectionCW;
73 
75  enum class EmbeddingGrade {
76  doNotEmbed=-3, // and not find any kuratowski subdivisions
77  doNotFind=-2, // but embed
78  doFindUnlimited=-1, // and embed
79  doFindZero=0 // and embed
80  };
81 
84  Graph& g,
85  bool bundles,
86  int embeddingGrade,
87  bool limitStructures,
89  double randomness,
90  bool avoidE2Minors,
91  bool extractSubgraph,
92  const EdgeArray<int> *edgeCosts = nullptr);
93 
96  Graph& g,
97  bool bundles,
98  EmbeddingGrade embeddingGrade,
99  bool limitStructures,
101  double randomness,
102  bool avoidE2Minors,
103  bool extractSubgraph,
104  const EdgeArray<int> *edgeCosts = nullptr)
105  : BoyerMyrvoldPlanar(g, bundles, static_cast<int>(embeddingGrade), limitStructures, output, randomness, avoidE2Minors, extractSubgraph, edgeCosts)
106  {}
107 
109  bool start();
110 
112 
118  void flipBicomp(
119  int c,
120  int marker,
121  NodeArray<int>& visited,
122  bool wholeGraph,
123  bool deleteFlipFlags);
124 
125  // avoid automatic creation of assignment operator
127  BoyerMyrvoldPlanar &operator=(const BoyerMyrvoldPlanar &);
128 
129 
133  void seed(const std::minstd_rand rand) {
134  m_rand = rand;
135  }
136 
137 protected:
140 
142  inline bool pertinent(node w) const {
143  OGDF_ASSERT(w!=nullptr);
144  return m_dfi[w] > 0 && (!m_backedgeFlags[w].empty() || !m_pertinentRoots[w].empty());
145  }
146 
148  inline bool internallyActive(node w, int v) const {
149  OGDF_ASSERT(w!=nullptr);
150  return m_dfi[w] > 0 && pertinent(w) && !externallyActive(w, v);
151  }
152 
154  inline bool externallyActive(node w, int v) const {
155  OGDF_ASSERT(w!=nullptr);
156  if (m_dfi[w] <= 0) return false;
157  if (m_leastAncestor[w] < v) return true;
158  return !m_separatedDFSChildList[w].empty() && m_lowPoint[m_separatedDFSChildList[w].front()] < v;
159  }
160 
162  inline bool inactive(node w, int v) {
163  OGDF_ASSERT(w!=nullptr);
164  if (m_dfi[w] <= 0) return true;
165  if (!m_backedgeFlags[w].empty() || !m_pertinentRoots[w].empty()
166  || m_leastAncestor[w] < v) return false;
167  return m_separatedDFSChildList[w].empty() || m_lowPoint[m_separatedDFSChildList[w].front()] >= v;
168  }
169 
171 
178  inline int infoAboutNode(node w, int v) const {
179  OGDF_ASSERT(w!=nullptr);
180  if (m_dfi[w] <= 0) return 0;
181  if (!m_pertinentRoots[w].empty() || !m_backedgeFlags[w].empty()) {
182  // pertinent
183  if (m_leastAncestor[w] < v) return 2;
184  if (m_separatedDFSChildList[w].empty()) return 1;
185  return m_lowPoint[m_separatedDFSChildList[w].front()] < v ? 2 : 1;
186  } else {
187  // not pertinent
188  if (m_leastAncestor[w] < v) return 3;
189  if (m_separatedDFSChildList[w].empty()) return 0;
190  return m_lowPoint[m_separatedDFSChildList[w].front()] < v ? 3 : 0;
191  }
192  }
193 
195 
200  inline node successorOnExternalFace(node w, int& direction) const {
201  OGDF_ASSERT(w!=nullptr);
202  OGDF_ASSERT(w->degree()>0);
203  OGDF_ASSERT(m_link[BoyerMyrvoldPlanar::DirectionCW][w]!=nullptr);
204  OGDF_ASSERT(m_link[BoyerMyrvoldPlanar::DirectionCCW][w]!=nullptr);
205  adjEntry adj = m_link[direction][w];
206  OGDF_ASSERT(adj->theNode()!=nullptr);
207 
208  if (w->degree() > 1) direction =
209  adj==beforeShortCircuitEdge(adj->theNode(),BoyerMyrvoldPlanar::DirectionCCW)->twin();
210  OGDF_ASSERT(direction || adj==beforeShortCircuitEdge(adj->theNode(),BoyerMyrvoldPlanar::DirectionCW)->twin());
211  return adj->theNode();
212  }
213 
215  inline node successorWithoutShortCircuit(node w, int& direction) {
216  OGDF_ASSERT(w!=nullptr);
217  OGDF_ASSERT(w->degree()>0);
218  OGDF_ASSERT(m_link[BoyerMyrvoldPlanar::DirectionCW][w]!=nullptr);
219  OGDF_ASSERT(m_link[BoyerMyrvoldPlanar::DirectionCCW][w]!=nullptr);
220  adjEntry adj = beforeShortCircuitEdge(w,direction);
221  OGDF_ASSERT(adj->theNode()!=nullptr);
222 
223  if (w->degree() > 1) direction =
224  adj==beforeShortCircuitEdge(adj->theNode(),BoyerMyrvoldPlanar::DirectionCCW)->twin();
225  OGDF_ASSERT(direction || adj==beforeShortCircuitEdge(adj->theNode(),BoyerMyrvoldPlanar::DirectionCW)->twin());
226  return adj->theNode();
227  }
228 
230 
232  inline node constSuccessorOnExternalFace(node v, int direction) {
233  OGDF_ASSERT(v!=nullptr);
234  OGDF_ASSERT(v->degree()>0);
235  return m_link[direction][v]->theNode();
236  }
237 
239 
241  inline node constSuccessorWithoutShortCircuit(node v, int direction) const {
242  OGDF_ASSERT(v!=nullptr);
243  OGDF_ASSERT(v->degree()>0);
244  return beforeShortCircuitEdge(v,direction)->theNode();
245  }
246 
248 
251  inline adjEntry beforeShortCircuitEdge(node v, int direction) const {
252  OGDF_ASSERT(v!=nullptr);
253  return (m_beforeSCE[direction][v]==nullptr) ? m_link[direction][v] : m_beforeSCE[direction][v];
254  }
255 
257 
259  node activeSuccessor(node w, int& direction, int v, int& info) const;
260 
262 
264  inline node constActiveSuccessor(node w, int direction, int v, int& info) const {
265  return activeSuccessor(w,direction,v,info);
266  }
267 
269 
271  inline bool wNodesExist(node root, node stopx, node stopy) const {
272  OGDF_ASSERT(root != stopx);
273  OGDF_ASSERT(root != stopy);
274  OGDF_ASSERT(stopx != stopy);
276  bool between = false;
277  while (root != nullptr) {
278  root = successorOnExternalFace(root,dir);
279  if (between && pertinent(root)) {
280  return true;
281  }
282  if (root == stopx || root == stopy) {
283  if (between) {
284  return false;
285  }
286  between = true;
287  }
288  }
289  return false;
290  }
291 
293  inline void printNodeInfo(node v) {
294  std::cout
295  << "\nprintNodeInfo(" << m_dfi[v] << "): "
296  << "CCW=" << m_dfi[constSuccessorOnExternalFace(v, BoyerMyrvoldPlanar::DirectionCCW)]
297  << ",CW=" << m_dfi[constSuccessorOnExternalFace(v, BoyerMyrvoldPlanar::DirectionCW)]
298  << "\tCCWBefore=" << m_dfi[constSuccessorWithoutShortCircuit(v, BoyerMyrvoldPlanar::DirectionCCW)]
299  << ",CWBefore=" << m_dfi[constSuccessorWithoutShortCircuit(v, BoyerMyrvoldPlanar::DirectionCW)]
300  << "\tadjList: ";
301  adjEntry adj;
302  for (adj = v->firstAdj(); adj; adj = adj->succ()) {
303  std::cout << adj->twinNode() << " ";
304  }
305  }
306 
309  void mergeBiconnectedComponent(ArrayBuffer<int>& stack);
310 
313  void embedBackedges(const node v, const int v_dir, const node w, const int w_dir);
314 
316  void createShortCircuitEdge(const node v, const int v_dir,
317  const node w, const int w_dir);
318 
320 
323  node walkup(const node v, const node w, const int marker, const edge back);
324 
326 
332  int walkdown(const int i, const node v, FindKuratowskis* findKuratowskis);
333 
335  void mergeUnprocessedNodes();
336 
338 
340  void postProcessEmbedding();
341 
343 
345  bool embed();
346 
348 
351 
354  const bool m_bundles;
355  const int m_embeddingGrade;
356  const bool m_limitStructures;
357  const double m_randomness;
358  const bool m_avoidE2Minors;
360  std::minstd_rand m_rand;
362 
364  bool m_extractSubgraph = true;
365 
368 
371 
373 
376 
379 
382 
384 
387 
389 
393  NodeArray<adjEntry> m_beforeSCE[2];
394 
397 
399 
402 
405 
408 
411 
413 
416 
418 
421 
425 
428 
431 
438 
445 
447 
452 
454 
458 
461 
464 
466 };
467 
469  return lhs > static_cast<int>(rhs);
470 }
471 
473  return lhs == static_cast<int>(rhs);
474 }
475 
477  return lhs != static_cast<int>(rhs);
478 }
479 
481  return lhs <= static_cast<int>(rhs);
482 }
483 
484 }
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:492
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
EmbeddingGrade
Denotes the different embedding options.
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:210
NodeArray< int > m_numUnembeddedBackedgesInBicomp
Stores for each (virtual) bicomp root how many backedges to its bicomp still have to be embedded...
bool externallyActive(node w, int v) const
Checks whether real node w is externally active while embedding node with DFI v.
A Kuratowski Structure is a special graph structure containing severals subdivisions.
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.
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 internallyActive(node w, int v) const
Checks whether real node w is internally active while embedding node with DFI v.
bool operator>(int lhs, BoyerMyrvoldPlanar::EmbeddingGrade rhs)
int infoAboutNode(node w, int v) const
Checks all dynamic information about a node w while embedding node with DFI v.
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.
node constSuccessorWithoutShortCircuit(node v, int direction) const
Walks upon external face in direction avoiding short circuit edges.
NodeArray< edge > m_visitedWithBackedge
Stores for each (real) non-root vertex v with which backedge it was visited during the walkup...
adjEntry beforeShortCircuitEdge(node v, int direction) const
Returns underlying former adjEntry, if a short circuit edge in direction of v exists.
Graph & m_g
Input graph, which can be altered.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:108
Class for the representation of edges.
Definition: Graph_d.h:292
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:169
Declaration and implementation of NodeArray class.
const EdgeArray< int > * m_edgeCosts
node successorOnExternalFace(node w, int &direction) const
Walks upon external face in the given direction starting at w.
NodeArray< SListPure< adjEntry > > m_backedgeFlags
Holds information, if node is the source of a backedge.
bool wNodesExist(node root, node stopx, node stopy) const
Checks, if one ore more wNodes exist between the two stopping vertices stopx and stopy.
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.
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:148
static const int DirectionCW
Direction for clockwise traversal.
bool pertinent(node w) const
Checks whether node w is pertinent. w has to be non-virtual.
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:213
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition: tuples.h:76
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:100
bool operator!=(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Inequality operator for 2-tuples.
Definition: tuples.h:83
Class for adjacency list elements.
Definition: Graph_d.h:79
node constActiveSuccessor(node w, int direction, int v, int &info) const
Walks upon external face in the given direction (without changing it) until an active vertex is reach...
#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.
SListPure< KuratowskiStructure > & m_output
Data structure for the Kuratowski subdivisions, which will be returned.