Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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