Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
BlockOrder.h
Go to the documentation of this file.
1
32#pragma once
33
35#include <ogdf/basic/Graph.h>
39
40namespace ogdf {
41
43class ArrayLevel : public LevelBase {
44private:
46
47public:
48 explicit ArrayLevel(unsigned int size) : m_nodes(size) { }
49
50 explicit ArrayLevel(const Array<node>& nodes) : m_nodes(nodes) { }
51
52 const node& operator[](int i) const override { return m_nodes[i]; }
53
54 node& operator[](int i) override { return m_nodes[i]; }
55
56 int size() const override { return m_nodes.size(); }
57
58 int high() const override { return m_nodes.high(); }
59};
60
61
62class BlockOrder;
63
71 friend class BlockOrder;
72
73private:
74 int m_index = 0;
75
76 int m_upper = 0;
77
78 int m_lower = 0;
79
81
83
85
87
89
90 // exactly one of those below is non null!
91 node m_Node = nullptr;
92 edge m_Edge = nullptr;
93
96
97public:
98 ~Block() { }
99
100 bool isEdgeBlock() { return m_isEdgeBlock; }
101
102 bool isVertexBlock() { return m_isNodeBlock; }
103
105 explicit Block(node v);
106
108 explicit Block(edge e);
109};
110
123private:
124 enum class Direction { Plus, Minus };
125
127
129
130 // Block X -> pi(X)
134
135 // int i -> Block X s.t. pi(X) = i
137
140
141#if 0
142 unsigned int m_storedCrossings;
143 unsigned int m_currentCrossings;
144#endif
145
149
151
152#if 0
153 unsigned int m_blocksCount;
154#endif
156
158
159 void deconstruct();
160
162
164
167
169
170public:
173
175 const ArrayLevel& operator[](int i) const override { return *(m_levels[i]); }
176
178 int pos(node v) const override { return m_pos[v]; }
179
181 int size() const override { return m_levels.size(); }
182
183 const Hierarchy& hierarchy() const override { return m_hierarchy; }
184
186 const Array<node>& adjNodes(node v, TraversingDir dir) const override {
187 if (dir == TraversingDir::upward) {
188 return m_upperAdjNodes[v];
189 } else {
190 return m_lowerAdjNodes[v];
191 }
192 }
193
195
196 // destruction
197 ~BlockOrder() { deconstruct(); }
198
200 int blocksCount() { return m_Blocks.size(); }
201
202#if 0
203 BlockOrder(const Graph &G, const NodeArray<int> &rank);
204#endif
205
206 explicit BlockOrder(Hierarchy& hierarchy, bool longEdgesOnly = true);
207
209 void globalSifting(int rho = 1, int nRepeats = 10, int* pNumCrossings = nullptr);
210
211private:
213 void doInit(bool longEdgesOnly = true);
214#if 0
215 void doInit( bool longEdgesOnly = true, const NodeArray<int> &ranks);
216#endif
217
224
234
243
250
257
262
267
272
277 buildDummyNodesLists();
278 buildLevels();
279 buildAdjNodes();
280 m_storedCrossings = calculateCrossings();
281 }
282
285
289 int verticalSwap(Block* b, int level);
290
292 int localCountCrossings(const Array<int>& levels);
293
300
302
303public:
305
309 void gridSifting(int nRepeats = 10);
310
312};
313
314}
Declaration of interfaces used in Sugiyama framework.
Declaration and implementation of EdgeArray class.
Includes declaration of graph class.
Declaration of graph copy classes.
Declaration and implementation of NodeArray class.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
INDEX high() const
Returns the maximal array index.
Definition Array.h:294
INDEX size() const
Returns the size (number of elements) of the array.
Definition Array.h:297
The simple implementation of LevelBase interface.
Definition BlockOrder.h:43
node & operator[](int i) override
Returns the node at position i.
Definition BlockOrder.h:54
const node & operator[](int i) const override
Returns the node at position i.
Definition BlockOrder.h:52
ArrayLevel(const Array< node > &nodes)
Definition BlockOrder.h:50
Array< node > m_nodes
Definition BlockOrder.h:45
int high() const override
Returns the maximal array index (= size()-1).
Definition BlockOrder.h:58
ArrayLevel(unsigned int size)
Definition BlockOrder.h:48
int size() const override
Returns the number of nodes on this level.
Definition BlockOrder.h:56
Class representing idea of Blocks used in GlobalSifting and GridSifting algorithms.
Definition BlockOrder.h:70
bool isVertexBlock()
Definition BlockOrder.h:102
Block(edge e)
Creates new edge block for an edge e.
Array< node > m_nodes
Vertices from the proper hierarchy corresponding to this block.
Definition BlockOrder.h:80
Array< int > m_NeighboursOutgoing
Indices of neighbouring outgoing blocks.
Definition BlockOrder.h:86
Array< int > m_InvertedOutgoing
Positions of this block in m_NeighboursIncoming of neighbours.
Definition BlockOrder.h:88
bool isEdgeBlock()
Definition BlockOrder.h:100
bool m_isEdgeBlock
Definition BlockOrder.h:94
bool m_isNodeBlock
Definition BlockOrder.h:95
Array< int > m_NeighboursIncoming
Indices of neighbouring incoming blocks.
Definition BlockOrder.h:82
Array< int > m_InvertedIncoming
Positions of this block in m_NeighboursOutgoing of neighbours.
Definition BlockOrder.h:84
Block(node v)
Creates new vertex block for a node v.
Hierarchical graph representation used by GlobalSifting and GridSifting algorithms.
Definition BlockOrder.h:122
int m_bestCrossings
The lowest number of crossing found in the sifting step.
Definition BlockOrder.h:139
void buildLevels()
Builds levels of vertices from original graph.
int localCountCrossings(const Array< int > &levels)
Only used in verticalSwap().
Array< ArrayLevel * > m_levels
The array of all levels.
Definition BlockOrder.h:163
NodeArray< int > m_pos
The position of a node on its level.
Definition BlockOrder.h:161
NodeArray< Block * > m_NodeBlocks
The array of all vertex blocks.
Definition BlockOrder.h:147
const Hierarchy & hierarchy() const override
Definition BlockOrder.h:183
void globalSifting(int rho=1, int nRepeats=10, int *pNumCrossings=nullptr)
Calls the global sifting algorithm on graph (its hierarchy).
void doInit(bool longEdgesOnly=true)
Does some initialization.
Array< Block * > m_Blocks
The array of all blocks.
Definition BlockOrder.h:146
int pos(node v) const override
Returns the position of node v on its level.
Definition BlockOrder.h:178
void buildDummyNodesLists()
Builds list of dummy nodes laying inside edge blocks.
BlockOrder(Hierarchy &hierarchy, bool longEdgesOnly=true)
Hierarchy & m_hierarchy
The hierarchy on grid- and globalsifting operates.
Definition BlockOrder.h:157
const Array< node > & adjNodes(node v, TraversingDir dir) const override
Returns the adjacent nodes of v.
Definition BlockOrder.h:186
void verticalStep(Block *b)
Performs vertical step for block b.
Array< int > m_nNodesOnLvls
Definition BlockOrder.h:301
EdgeArray< Block * > m_EdgeBlocks
The array of all edge blocks.
Definition BlockOrder.h:148
const ArrayLevel & operator[](int i) const override
Returns the i-th level.
Definition BlockOrder.h:175
NodeArray< int > m_ranks
The rank (level) of a node.
Definition BlockOrder.h:128
Array< int > m_storedPerm
The permutation from which the sifting step starts.
Definition BlockOrder.h:131
EdgeArray< bool > m_isActiveEdge
Stores information about active edge blocks.
Definition BlockOrder.h:150
Array< int > m_bestPerm
The best found permutation in the sifting step.
Definition BlockOrder.h:133
void buildAdjNodes()
Builds lists of adjacent nodes (needed by HierarchyLevelsBase).
void deconstruct()
Deletes levels and blocks owned by this instance of BlockOrder.
void buildHierarchy()
Builds arrays that allow using BlockOrder as HierarchyLevelsBase implementation.
Definition BlockOrder.h:276
NodeArray< Array< node > > m_upperAdjNodes
(Sorted) adjacent nodes on upper level.
Definition BlockOrder.h:166
int uswap(Block *blockOfA, Block *blockOfB, Direction d, int level)
Calculates change of crossings made by a single swap.
int m_storedCrossings
Numebr of crossings stored in the sifting step.
Definition BlockOrder.h:138
NodeArray< int > m_nSet
(Only used by buildAdjNodes().)
Definition BlockOrder.h:168
int siftingSwap(Block *blockOfA, Block *blockOfB)
Swaps two consecutive blocks.
void updateAdjacencies(Block *blockOfA, Block *blockOfB, Direction d)
Updates adjacencies lists before swaping two blocks.
NodeArray< Array< node > > m_lowerAdjNodes
(Sorted) adjacent nodes on lower level.
Definition BlockOrder.h:165
int size() const override
Returns the number of levels.
Definition BlockOrder.h:181
int verticalSwap(Block *b, int level)
Moves block to next level.
GraphCopy m_GC
The graph copy representing the topology of the proper hierarchy.
Definition BlockOrder.h:126
int siftingStep(Block *blockOfA)
Performs sifting for a single block.
void gridSifting(int nRepeats=10)
Calls the grid sifting algorithm on a graph (its hierarchy).
int blocksCount()
Returns the number of blocks.
Definition BlockOrder.h:200
Array< int > m_currentPerm
The permutation modified in the sifting step.
Definition BlockOrder.h:132
Array< int > m_currentPermInv
Inversion of m_currenPerm.
Definition BlockOrder.h:136
void sortAdjacencies()
Creates sorted lists of neighbours for all blocks.
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:254
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Representation of proper hierarchies used by Sugiyama-layout.
Definition Hierarchy.h:43
Representation of levels in hierarchies.
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.