Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 protected:
44  // struct for a candidate aka belt item
45  struct Candidate {
46  Candidate() : stopper(nullptr) {};
47 
48  // the edges in the belt item
50 
51  // a possible stopper of the candidate
53  };
54 
55 public:
56  // computes the leftist canonical order. Requires that G is simple, triconnected and embedded.
57  // adj_v1n is the adjEntry at v_1 looking towards v_n, the outerface is choosen such that v_2 is the cyclic pred
58  // 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.
59  bool call(const Graph& G, adjEntry adj_v1n, List<List<node>>& result);
60 
61 private:
62  // the leftmost feasible candidate function from the paper
64 
65  // this is used to check a candidate for a singleton copy
66  bool isSingletonWith(const Candidate& c, node v) const;
67 
68  // update belt function from the paper
69  void updateBelt();
70 
71  // belt extension function from the paper
72  void beltExtension(List<Candidate>& extension);
73 
74  // returns true if v is forbidde
75  bool forbidden(node v) const {
76  // too many cut faces?
77  return m_cutFaces[v] > m_cutEdges[v] + 1;
78  }
79 
80  // returns true if v is singular
81  bool singular(node v) const {
82  // not more cutfaces then cut edges plus one ?
83  return m_cutFaces[v] > 2 && m_cutFaces[v] == m_cutEdges[v] + 1;
84  }
85 
86  // the belt
88 
89  // the curr candidate in the belt
91 
92  // number of cutfaces incident to a vertex
94 
95  // number of cutedges incident to a vertex
97 
98  // flag for marking directed edges
100 
101 public:
102  // this is a custom class to have a more convienent way to access a canonical ordering
103  // used somewhere
104  class Partitioning {
105  public:
107 
108  Partitioning(const Graph& G, const List<List<node>>& lco) { buildFromResult(G, lco); }
109 
110  void buildFromResult(const Graph& G, const List<List<node>>& lco);
111 
112  // returns the adjEntry to the left node in G_k-1
113  adjEntry left(int k) const {
114  if (m_ears[k][0]) {
115  return m_ears[k][0]->twin();
116  } else {
117  return nullptr;
118  }
119  }
120 
121  // returns the adjEntry to the left node in G_k-1
122  adjEntry right(int k) const { return m_ears[k][m_ears[k].size() - 1]; }
123 
124  // returns the edge from v_i to v_i+1 in the k-th partition
125  adjEntry getChainAdj(int k, int i) const { return m_ears[k][i + 1]; }
126 
127  adjEntry getPathAdj(int k, int i) const { return m_ears[k][i]; }
128 
129  node getNode(int k, int i) const { return m_ears[k][i + 1]->theNode(); }
130 
131  // returns the number of all partitions
132  int numPartitions() const { return m_ears.size(); }
133 
134  // returns the number of nodes in partition k
135  int numNodes(int k) const { return m_ears[k].size() - 1; }
136 
137  int pathLength(int k) const { return m_ears[k].size(); }
138 
139  bool isSingleton(int k) const { return numNodes(k) == 1; }
140 
141  private:
142  // keeps for every partition the path from left, v_1, ... v_k, right
144  };
145 
146  bool call(const Graph& G, adjEntry adj_v1n, Partitioning& partition) {
147  // the simple result
148  List<List<node>> result;
149  // compute it
150  if (!call(G, adj_v1n, result)) {
151  return false;
152  }
153 
154  // generate the comfortable partitioning
155  partition.buildFromResult(G, result);
156 
157  // success hopefully..
158  return true;
159  }
160 };
161 
162 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ShellingOrderModule.h
Declares the base class ShellingOrderModule for modules that compute a shelling order of a graph.
ogdf::LeftistOrdering::isSingletonWith
bool isSingletonWith(const Candidate &c, node v) const
ogdf::LeftistOrdering::leftmostFeasibleCandidate
bool leftmostFeasibleCandidate(List< node > &result)
ogdf::LeftistOrdering::Partitioning::getChainAdj
adjEntry getChainAdj(int k, int i) const
Definition: LeftistOrdering.h:125
ogdf::LeftistOrdering::beltExtension
void beltExtension(List< Candidate > &extension)
ogdf::LeftistOrdering::Partitioning::left
adjEntry left(int k) const
Definition: LeftistOrdering.h:113
ogdf::LeftistOrdering::Partitioning::pathLength
int pathLength(int k) const
Definition: LeftistOrdering.h:137
ogdf::LeftistOrdering::Candidate::Candidate
Candidate()
Definition: LeftistOrdering.h:46
ogdf::LeftistOrdering::call
bool call(const Graph &G, adjEntry adj_v1n, Partitioning &partition)
Definition: LeftistOrdering.h:146
ogdf::LeftistOrdering::m_belt
List< Candidate > m_belt
Definition: LeftistOrdering.h:87
ogdf::LeftistOrdering::Partitioning::right
adjEntry right(int k) const
Definition: LeftistOrdering.h:122
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::LeftistOrdering::Candidate
Definition: LeftistOrdering.h:45
ogdf::LeftistOrdering::Partitioning::numNodes
int numNodes(int k) const
Definition: LeftistOrdering.h:135
ogdf::LeftistOrdering::m_currCandidateIt
List< Candidate >::iterator m_currCandidateIt
Definition: LeftistOrdering.h:90
ogdf::LeftistOrdering::singular
bool singular(node v) const
Definition: LeftistOrdering.h:81
ogdf::LeftistOrdering::Candidate::chain
List< adjEntry > chain
Definition: LeftistOrdering.h:46
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:214
ogdf::LeftistOrdering::Partitioning::Partitioning
Partitioning()
Definition: LeftistOrdering.h:106
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::LeftistOrdering::Partitioning
Definition: LeftistOrdering.h:104
ogdf::LeftistOrdering
Definition: LeftistOrdering.h:42
ogdf::LeftistOrdering::forbidden
bool forbidden(node v) const
Definition: LeftistOrdering.h:75
ogdf::LeftistOrdering::Partitioning::buildFromResult
void buildFromResult(const Graph &G, const List< List< node >> &lco)
ogdf::LeftistOrdering::Partitioning::isSingleton
bool isSingleton(int k) const
Definition: LeftistOrdering.h:139
ogdf::LeftistOrdering::Partitioning::numPartitions
int numPartitions() const
Definition: LeftistOrdering.h:132
ogdf::LeftistOrdering::Partitioning::getPathAdj
adjEntry getPathAdj(int k, int i) const
Definition: LeftistOrdering.h:127
ogdf::LeftistOrdering::call
bool call(const Graph &G, adjEntry adj_v1n, List< List< node >> &result)
AdjEntryArray.h
Declaration and implementation of AdjEntryArray class.
ogdf::LeftistOrdering::Partitioning::m_ears
Array< Array< adjEntry > > m_ears
Definition: LeftistOrdering.h:143
ogdf::LeftistOrdering::updateBelt
void updateBelt()
ogdf::LeftistOrdering::Candidate::stopper
node stopper
Definition: LeftistOrdering.h:52
ogdf::LeftistOrdering::m_marked
AdjEntryArray< bool > m_marked
Definition: LeftistOrdering.h:99
ogdf::LeftistOrdering::Partitioning::Partitioning
Partitioning(const Graph &G, const List< List< node >> &lco)
Definition: LeftistOrdering.h:108
ogdf::LeftistOrdering::m_cutFaces
NodeArray< int > m_cutFaces
Definition: LeftistOrdering.h:93
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::LeftistOrdering::Partitioning::getNode
node getNode(int k, int i) const
Definition: LeftistOrdering.h:129
ogdf::LeftistOrdering::m_cutEdges
NodeArray< int > m_cutEdges
Definition: LeftistOrdering.h:96