Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

LeftistOrdering.h
Go to the documentation of this file.
1 
34 #pragma once
35 
38 
39 namespace ogdf {
40 
41 // context class for the leftist canonical ordering algorithm
43 {
44 protected:
45 
46  // struct for a candidate aka belt item
47  struct Candidate
48  {
49  Candidate() : stopper(nullptr) {};
50 
51  // the edges in the belt item
53 
54  // a possible stopper of the candidate
56  };
57 
58 public:
59  // computes the leftist canonical order. Requires that G is simple, triconnected and embedded.
60  // adj_v1n is the adjEntry at v_1 looking towards v_n, the outerface is choosen such that v_2 is the cyclic pred
61  // of v_n. the result is saved in result, a list of list of nodes, first set is v_1, v_2, last one is v_n.
62  bool call(const Graph& G, adjEntry adj_v1n, List<List<node> >& result);
63 
64 private:
65  // the leftmost feasible candidate function from the paper
67 
68  // this is used to check a candidate for a singleton copy
69  bool isSingletonWith(const Candidate& c,node v) const;
70 
71  // update belt function from the paper
72  void updateBelt();
73 
74  // belt extension function from the paper
75  void beltExtension(List<Candidate>& extension);
76 
77  // returns true if v is forbidde
78  bool forbidden(node v) const
79  {
80  // too many cut faces?
81  return m_cutFaces[v] > m_cutEdges[v] + 1;
82  }
83 
84  // returns true if v is singular
85  bool singular(node v) const
86  {
87  // not more cutfaces then cut edges plus one ?
88  return m_cutFaces[v] > 2 && m_cutFaces[v] == m_cutEdges[v] + 1;
89  }
90 
91  // the belt
93 
94  // the curr candidate in the belt
96 
97  // number of cutfaces incident to a vertex
99 
100  // number of cutedges incident to a vertex
102 
103  // flag for marking directed edges
105 
106 public:
107  // this is a custom class to have a more convienent way to access a canonical ordering
108  // used somewhere
110  {
111  public:
113  Partitioning(const Graph& G, const List<List<node> >& lco) { buildFromResult(G, lco); }
114 
115  void buildFromResult(const Graph& G, const List<List<node> >& lco);
116 
117  // returns the adjEntry to the left node in G_k-1
118  adjEntry left(int k) const
119  {
120  if (m_ears[k][0])
121  return m_ears[k][0]->twin();
122  else
123  return nullptr;
124  }
125 
126  // returns the adjEntry to the left node in G_k-1
127  adjEntry right(int k) const
128  {
129  return m_ears[k][m_ears[k].size()-1];
130  }
131 
132  // returns the edge from v_i to v_i+1 in the k-th partition
133  adjEntry getChainAdj(int k, int i) const
134  {
135  return m_ears[k][i+1];
136  }
137 
138  adjEntry getPathAdj(int k, int i) const
139  {
140  return m_ears[k][i];
141  }
142 
143  node getNode(int k, int i) const
144  {
145  return m_ears[k][i+1]->theNode();
146  }
147 
148  // returns the number of all partitions
149  int numPartitions() const
150  {
151  return m_ears.size();
152  }
153 
154  // returns the number of nodes in partition k
155  int numNodes(int k) const
156  {
157  return m_ears[k].size() - 1;
158  }
159 
160  int pathLength(int k) const
161  {
162  return m_ears[k].size();
163  }
164 
165  bool isSingleton(int k) const
166  {
167  return numNodes(k)==1;
168  }
169 
170  private:
171  // keeps for every partition the path from left, v_1, ... v_k, right
173  };
174 
175  bool call(const Graph& G, adjEntry adj_v1n, Partitioning& partition)
176  {
177  // the simple result
178  List<List<node> > result;
179  // compute it
180  if (!call(G, adj_v1n, result))
181  return false;
182 
183  // generate the comfortable partitioning
184  partition.buildFromResult(G, result);
185 
186  // success hopefully..
187  return true;
188  }
189 };
190 
191 }
Array< Array< adjEntry > > m_ears
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:200
void buildFromResult(const Graph &G, const List< List< node > > &lco)
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
Declaration and implementation of AdjEntryArray class.
List< Candidate > m_belt
bool leftmostFeasibleCandidate(List< node > &result)
void beltExtension(List< Candidate > &extension)
AdjEntryArray< bool > m_marked
Partitioning(const Graph &G, const List< List< node > > &lco)
bool forbidden(node v) const
List< Candidate >::iterator m_currCandidateIt
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:105
Declares the base class ShellingOrderModule for modules that compute a shelling order of a graph...
adjEntry getPathAdj(int k, int i) const
Class for the representation of nodes.
Definition: Graph_d.h:169
Encapsulates a pointer to a list element.
Definition: List.h:42
bool call(const Graph &G, adjEntry adj_v1n, List< List< node > > &result)
node getNode(int k, int i) const
NodeArray< int > m_cutEdges
NodeArray< int > m_cutFaces
adjEntry getChainAdj(int k, int i) const
The namespace for all OGDF objects.
bool call(const Graph &G, adjEntry adj_v1n, Partitioning &partition)
bool isSingletonWith(const Candidate &c, node v) const
Class for adjacency list elements.
Definition: Graph_d.h:79
bool singular(node v) const