Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
40namespace ogdf {
41
42// context class for the leftist canonical ordering algorithm
44protected:
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
56public:
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
62private:
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
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
102public:
103 // this is a custom class to have a more convienent way to access a canonical ordering
104 // used somewhere
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}
Declaration and implementation of Array class and Array algorithms.
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Class for adjacency list elements.
Definition Graph_d.h:143
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition Graph_d.h:173
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
void buildFromResult(const Graph &G, const List< List< node > > &lco)
adjEntry getPathAdj(int k, int i) const
Partitioning(const Graph &G, const List< List< node > > &lco)
adjEntry getChainAdj(int k, int i) const
Array< Array< adjEntry > > m_ears
bool call(const Graph &G, adjEntry adj_v1n, List< List< node > > &result)
bool call(const Graph &G, adjEntry adj_v1n, Partitioning &partition)
NodeArray< int > m_cutFaces
List< Candidate >::iterator m_currCandidateIt
AdjEntryArray< bool > m_marked
void beltExtension(List< Candidate > &extension)
NodeArray< int > m_cutEdges
List< Candidate > m_belt
bool leftmostFeasibleCandidate(List< node > &result)
bool singular(node v) const
bool isSingletonWith(const Candidate &c, node v) const
bool forbidden(node v) const
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Encapsulates a pointer to a list element.
Definition List.h:113
Class for the representation of nodes.
Definition Graph_d.h:241
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
The namespace for all OGDF objects.