Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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