Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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>
36 #include <ogdf/basic/GraphCopy.h>
37 #include <ogdf/basic/basic.h>
39 
40 namespace ogdf {
41 class Hierarchy;
42 
44 class ArrayLevel : public LevelBase {
45 private:
47 
48 public:
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 
71 private:
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 
95 public:
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 
121 private:
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 
168 public:
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 
209 private:
211  void doInit(bool longEdgesOnly = true);
212 #if 0
213  void doInit( bool longEdgesOnly = true, const NodeArray<int> &ranks);
214 #endif
215 
221  void sortAdjacencies();
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 
259  void buildLevels();
260 
264  void buildDummyNodesLists();
265 
269  void buildAdjNodes();
270 
274  void buildHierarchy() {
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 
297  void verticalStep(Block* b);
298 
300 
301 public:
303 
307  void gridSifting(int nRepeats = 10);
308 
310 };
311 
312 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::BlockOrder::m_hierarchy
Hierarchy & m_hierarchy
The hierarchy on grid- and globalsifting operates.
Definition: BlockOrder.h:155
ogdf::BlockOrder::m_Blocks
Array< Block * > m_Blocks
The array of all blocks.
Definition: BlockOrder.h:144
ogdf::Block::~Block
~Block()
Definition: BlockOrder.h:96
ogdf::BlockOrder::m_GC
GraphCopy m_GC
The graph copy representing the topology of the proper hierarchy.
Definition: BlockOrder.h:124
ogdf::Direction
Direction
Definition: basic.h:150
Graph.h
Includes declaration of graph class.
ogdf::Block::m_isNodeBlock
bool m_isNodeBlock
Definition: BlockOrder.h:93
ogdf::BlockOrder::m_storedCrossings
int m_storedCrossings
Numebr of crossings stored in the sifting step.
Definition: BlockOrder.h:136
ogdf::BlockOrder::m_NodeBlocks
NodeArray< Block * > m_NodeBlocks
The array of all vertex blocks.
Definition: BlockOrder.h:145
ogdf::BlockOrder::hierarchy
const Hierarchy & hierarchy() const override
Definition: BlockOrder.h:181
ogdf::Array::high
INDEX high() const
Returns the maximal array index.
Definition: Array.h:299
ogdf::Block
Class representing idea of Blocks used in GlobalSifting and GridSifting algorithms.
Definition: BlockOrder.h:68
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::Hierarchy
Representation of proper hierarchies used by Sugiyama-layout.
Definition: Hierarchy.h:47
ogdf::BlockOrder::m_lowerAdjNodes
NodeArray< Array< node > > m_lowerAdjNodes
(Sorted) adjacent nodes on lower level.
Definition: BlockOrder.h:163
ogdf::HierarchyLevelsBase
Definition: CrossingMinInterfaces.h:63
ogdf::BlockOrder::m_bestCrossings
int m_bestCrossings
The lowest number of crossing found in the sifting step.
Definition: BlockOrder.h:137
ogdf::ArrayLevel::operator[]
node & operator[](int i) override
Returns the node at position i.
Definition: BlockOrder.h:55
ogdf::Block::m_NeighboursOutgoing
Array< int > m_NeighboursOutgoing
Indices of neighbouring outgoing blocks.
Definition: BlockOrder.h:84
ogdf::BlockOrder::m_levels
Array< ArrayLevel * > m_levels
The array of all levels.
Definition: BlockOrder.h:161
ogdf::BlockOrder::m_nSet
NodeArray< int > m_nSet
(Only used by buildAdjNodes().)
Definition: BlockOrder.h:166
ogdf::BlockOrder::blocksCount
int blocksCount()
Returns the number of blocks.
Definition: BlockOrder.h:198
ogdf::BlockOrder::m_currentPerm
Array< int > m_currentPerm
The permutation modified in the sifting step.
Definition: BlockOrder.h:130
ogdf::BlockOrder::m_upperAdjNodes
NodeArray< Array< node > > m_upperAdjNodes
(Sorted) adjacent nodes on upper level.
Definition: BlockOrder.h:164
ogdf::Block::m_nodes
Array< node > m_nodes
Vertices from the proper hierarchy corresponding to this block.
Definition: BlockOrder.h:78
ogdf::HierarchyLevelsBase::TraversingDir
TraversingDir
Definition: CrossingMinInterfaces.h:73
ogdf::BlockOrder::m_bestPerm
Array< int > m_bestPerm
The best found permutation in the sifting step.
Definition: BlockOrder.h:131
ogdf::Block::m_InvertedIncoming
Array< int > m_InvertedIncoming
Positions of this block in m_NeighboursOutgoing of neighbours.
Definition: BlockOrder.h:82
ogdf::Block::isEdgeBlock
bool isEdgeBlock()
Definition: BlockOrder.h:98
ogdf::Array< node >
ogdf::ArrayLevel
The simple implementation of LevelBase interface.
Definition: BlockOrder.h:44
ogdf::BlockOrder::m_EdgeBlocks
EdgeArray< Block * > m_EdgeBlocks
The array of all edge blocks.
Definition: BlockOrder.h:146
ogdf::ArrayLevel::ArrayLevel
ArrayLevel(unsigned int size)
Definition: BlockOrder.h:49
GraphCopy.h
Declaration of graph copy classes.
ogdf::BlockOrder::m_currentPermInv
Array< int > m_currentPermInv
Inversion of m_currenPerm.
Definition: BlockOrder.h:134
ogdf::BlockOrder::adjNodes
const Array< node > & adjNodes(node v, TraversingDir dir) const override
Returns the adjacent nodes of v.
Definition: BlockOrder.h:184
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::Block::m_isEdgeBlock
bool m_isEdgeBlock
Definition: BlockOrder.h:92
CrossingMinInterfaces.h
Declaration of interfaces used in Sugiyama framework.
ogdf::Block::m_InvertedOutgoing
Array< int > m_InvertedOutgoing
Positions of this block in m_NeighboursIncoming of neighbours.
Definition: BlockOrder.h:86
ogdf::BlockOrder::m_storedPerm
Array< int > m_storedPerm
The permutation from which the sifting step starts.
Definition: BlockOrder.h:129
ogdf::BlockOrder::size
int size() const override
Returns the number of levels.
Definition: BlockOrder.h:179
ogdf::BlockOrder::pos
int pos(node v) const override
Returns the position of node v on its level.
Definition: BlockOrder.h:176
ogdf::BlockOrder::m_verticalStepsBound
int m_verticalStepsBound
Definition: BlockOrder.h:302
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::ArrayLevel::m_nodes
Array< node > m_nodes
Definition: BlockOrder.h:46
ogdf::BlockOrder::Direction
Direction
Definition: BlockOrder.h:122
ogdf::ArrayLevel::operator[]
const node & operator[](int i) const override
Returns the node at position i.
Definition: BlockOrder.h:53
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::BlockOrder::m_pos
NodeArray< int > m_pos
The position of a node on its level.
Definition: BlockOrder.h:159
ogdf::ArrayLevel::ArrayLevel
ArrayLevel(const Array< node > &nodes)
Definition: BlockOrder.h:51
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::BlockOrder::~BlockOrder
~BlockOrder()
Definition: BlockOrder.h:195
ogdf::Block::isVertexBlock
bool isVertexBlock()
Definition: BlockOrder.h:100
ogdf::BlockOrder
Hierarchical graph representation used by GlobalSifting and GridSifting algorithms.
Definition: BlockOrder.h:120
ogdf::Array::size
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:302
ogdf::BlockOrder::operator[]
const ArrayLevel & operator[](int i) const override
Returns the i-th level.
Definition: BlockOrder.h:173
ogdf::BlockOrder::m_activeBlocksCount
int m_activeBlocksCount
Definition: BlockOrder.h:153
ogdf::BlockOrder::m_isActiveEdge
EdgeArray< bool > m_isActiveEdge
Stores information about active edge blocks.
Definition: BlockOrder.h:148
ogdf::LevelBase
Representation of levels in hierarchies.
Definition: CrossingMinInterfaces.h:45
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::BlockOrder::m_ranks
NodeArray< int > m_ranks
The rank (level) of a node.
Definition: BlockOrder.h:126
ogdf::BlockOrder::m_nNodesOnLvls
Array< int > m_nNodesOnLvls
Definition: BlockOrder.h:299
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::Block::m_NeighboursIncoming
Array< int > m_NeighboursIncoming
Indices of neighbouring incoming blocks.
Definition: BlockOrder.h:80
ogdf::ArrayLevel::high
int high() const override
Returns the maximal array index (= size()-1).
Definition: BlockOrder.h:59
ogdf::ArrayLevel::size
int size() const override
Returns the number of nodes on this level.
Definition: BlockOrder.h:57
ogdf::BlockOrder::buildHierarchy
void buildHierarchy()
Builds arrays that allow using BlockOrder as HierarchyLevelsBase implementation.
Definition: BlockOrder.h:274