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
34#include <ogdf/basic/Array.h>
35#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/basic.h>
39
40namespace ogdf {
41class Hierarchy;
42
44class ArrayLevel : public LevelBase {
45private:
47
48public:
49 explicit ArrayLevel(unsigned int size) : m_nodes(size) { }
50
51 explicit ArrayLevel(const Array<node>& nodes) : m_nodes(nodes) { }
52
53 const node& operator[](int i) const override { return m_nodes[i]; }
54
55 node& operator[](int i) override { return m_nodes[i]; }
56
57 int size() const override { return m_nodes.size(); }
58
59 int high() const override { return m_nodes.high(); }
60};
61
69 friend class BlockOrder;
70
71private:
72 int m_index = 0;
73
74 int m_upper = 0;
75
76 int m_lower = 0;
77
79
81
83
85
87
88 // exactly one of those below is non null!
89 node m_Node = nullptr;
90 edge m_Edge = nullptr;
91
94
95public:
96 ~Block() { }
97
98 bool isEdgeBlock() { return m_isEdgeBlock; }
99
100 bool isVertexBlock() { return m_isNodeBlock; }
101
103 explicit Block(node v);
104
106 explicit Block(edge e);
107};
108
121private:
122 enum class Direction { Plus, Minus };
123
125
127
128 // Block X -> pi(X)
132
133 // int i -> Block X s.t. pi(X) = i
135
138
139#if 0
140 unsigned int m_storedCrossings;
141 unsigned int m_currentCrossings;
142#endif
143
147
149
150#if 0
151 unsigned int m_blocksCount;
152#endif
154
156
157 void deconstruct();
158
160
162
165
167
168public:
171
173 const ArrayLevel& operator[](int i) const override { return *(m_levels[i]); }
174
176 int pos(node v) const override { return m_pos[v]; }
177
179 int size() const override { return m_levels.size(); }
180
181 const Hierarchy& hierarchy() const override { return m_hierarchy; }
182
184 const Array<node>& adjNodes(node v, TraversingDir dir) const override {
185 if (dir == TraversingDir::upward) {
186 return m_upperAdjNodes[v];
187 } else {
188 return m_lowerAdjNodes[v];
189 }
190 }
191
193
194 // destruction
195 ~BlockOrder() { deconstruct(); }
196
198 int blocksCount() { return m_Blocks.size(); }
199
200#if 0
201 BlockOrder(const Graph &G, const NodeArray<int> &rank);
202#endif
203
204 explicit BlockOrder(Hierarchy& hierarchy, bool longEdgesOnly = true);
205
207 void globalSifting(int rho = 1, int nRepeats = 10, int* pNumCrossings = nullptr);
208
209private:
211 void doInit(bool longEdgesOnly = true);
212#if 0
213 void doInit( bool longEdgesOnly = true, const NodeArray<int> &ranks);
214#endif
215
222
231 void updateAdjacencies(Block* blockOfA, Block* blockOfB, Direction d);
232
240 int uswap(Block* blockOfA, Block* blockOfB, Direction d, int level);
241
247 int siftingSwap(Block* blockOfA, Block* blockOfB);
248
254 int siftingStep(Block* blockOfA);
255
260
265
270
275 buildDummyNodesLists();
276 buildLevels();
277 buildAdjNodes();
278 m_storedCrossings = calculateCrossings();
279 }
280
283
287 int verticalSwap(Block* b, int level);
288
290 int localCountCrossings(const Array<int>& levels);
291
298
300
301public:
303
307 void gridSifting(int nRepeats = 10);
308
310};
311
312}
Declaration and implementation of Array class and Array algorithms.
Declaration of interfaces used in Sugiyama framework.
Includes declaration of graph class.
Declaration of graph copy classes.
Basic declarations, included by all source files.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
INDEX high() const
Returns the maximal array index.
Definition Array.h:299
INDEX size() const
Returns the size (number of elements) of the array.
Definition Array.h:302
The simple implementation of LevelBase interface.
Definition BlockOrder.h:44
node & operator[](int i) override
Returns the node at position i.
Definition BlockOrder.h:55
const node & operator[](int i) const override
Returns the node at position i.
Definition BlockOrder.h:53
ArrayLevel(const Array< node > &nodes)
Definition BlockOrder.h:51
Array< node > m_nodes
Definition BlockOrder.h:46
int high() const override
Returns the maximal array index (= size()-1).
Definition BlockOrder.h:59
ArrayLevel(unsigned int size)
Definition BlockOrder.h:49
int size() const override
Returns the number of nodes on this level.
Definition BlockOrder.h:57
Class representing idea of Blocks used in GlobalSifting and GridSifting algorithms.
Definition BlockOrder.h:68
bool isVertexBlock()
Definition BlockOrder.h:100
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:78
Array< int > m_NeighboursOutgoing
Indices of neighbouring outgoing blocks.
Definition BlockOrder.h:84
Array< int > m_InvertedOutgoing
Positions of this block in m_NeighboursIncoming of neighbours.
Definition BlockOrder.h:86
bool isEdgeBlock()
Definition BlockOrder.h:98
bool m_isEdgeBlock
Definition BlockOrder.h:92
bool m_isNodeBlock
Definition BlockOrder.h:93
Array< int > m_NeighboursIncoming
Indices of neighbouring incoming blocks.
Definition BlockOrder.h:80
Array< int > m_InvertedIncoming
Positions of this block in m_NeighboursOutgoing of neighbours.
Definition BlockOrder.h:82
Block(node v)
Creates new vertex block for a node v.
Hierarchical graph representation used by GlobalSifting and GridSifting algorithms.
Definition BlockOrder.h:120
int m_bestCrossings
The lowest number of crossing found in the sifting step.
Definition BlockOrder.h:137
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:161
NodeArray< int > m_pos
The position of a node on its level.
Definition BlockOrder.h:159
NodeArray< Block * > m_NodeBlocks
The array of all vertex blocks.
Definition BlockOrder.h:145
const Hierarchy & hierarchy() const override
Definition BlockOrder.h:181
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:144
int pos(node v) const override
Returns the position of node v on its level.
Definition BlockOrder.h:176
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:155
const Array< node > & adjNodes(node v, TraversingDir dir) const override
Returns the adjacent nodes of v.
Definition BlockOrder.h:184
void verticalStep(Block *b)
Performs vertical step for block b.
Array< int > m_nNodesOnLvls
Definition BlockOrder.h:299
EdgeArray< Block * > m_EdgeBlocks
The array of all edge blocks.
Definition BlockOrder.h:146
const ArrayLevel & operator[](int i) const override
Returns the i-th level.
Definition BlockOrder.h:173
NodeArray< int > m_ranks
The rank (level) of a node.
Definition BlockOrder.h:126
Array< int > m_storedPerm
The permutation from which the sifting step starts.
Definition BlockOrder.h:129
EdgeArray< bool > m_isActiveEdge
Stores information about active edge blocks.
Definition BlockOrder.h:148
Array< int > m_bestPerm
The best found permutation in the sifting step.
Definition BlockOrder.h:131
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:274
NodeArray< Array< node > > m_upperAdjNodes
(Sorted) adjacent nodes on upper level.
Definition BlockOrder.h:164
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:136
NodeArray< int > m_nSet
(Only used by buildAdjNodes().)
Definition BlockOrder.h:166
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:163
int size() const override
Returns the number of levels.
Definition BlockOrder.h:179
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:124
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:198
Array< int > m_currentPerm
The permutation modified in the sifting step.
Definition BlockOrder.h:130
Array< int > m_currentPermInv
Inversion of m_currenPerm.
Definition BlockOrder.h:134
void sortAdjacencies()
Creates sorted lists of neighbours for all blocks.
Class for the representation of edges.
Definition Graph_d.h:364
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Representation of proper hierarchies used by Sugiyama-layout.
Definition Hierarchy.h:47
Representation of levels in hierarchies.
Class for the representation of nodes.
Definition Graph_d.h:241
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
The namespace for all OGDF objects.