Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

HierarchyLevels.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/basic.h>
37 #include <ogdf/basic/memory.h>
39 #include <ogdf/layered/Level.h>
40 
41 #include <cstdint>
42 #include <iosfwd>
43 
44 namespace ogdf {
45 class Hierarchy;
46 
48 
52 public:
53  friend class Level;
54  friend class LayerBasedUPRLayout;
55 
56 private:
57  const Hierarchy& m_H;
58 
61 
64 
66 
68 
69 public:
70  explicit HierarchyLevels(const Hierarchy& H);
71  ~HierarchyLevels();
72 
73  const Hierarchy& hierarchy() const override { return m_H; }
74 
76  TraversingDir direction() const { return m_direction; }
77 
79  void direction(TraversingDir dir) { m_direction = dir; }
80 
82  int size() const override { return m_pLevel.size(); }
83 
85  int high() const override { return m_pLevel.high(); }
86 
88  int pos(node v) const override { return m_pos[v]; }
89 
91  const Array<node>& adjNodes(node v) const {
92  return (m_direction == TraversingDir::downward) ? m_lowerAdjNodes[v] : m_upperAdjNodes[v];
93  }
94 
96  const Array<node>& adjNodes(node v, TraversingDir dir) const override {
97  return (dir == TraversingDir::downward) ? m_lowerAdjNodes[v] : m_upperAdjNodes[v];
98  }
99 
101  const Level& adjLevel(int i) const {
102  return (m_direction == TraversingDir::downward) ? *m_pLevel[i - 1] : *m_pLevel[i + 1];
103  }
104 
106  const Level& operator[](int i) const override { return *m_pLevel[i]; }
107 
109  Level& operator[](int i) { return *m_pLevel[i]; }
110 
112  int calculateCrossingsSimDraw(int i, const EdgeArray<uint32_t>* edgeSubGraphs) const;
114  int calculateCrossingsSimDraw(const EdgeArray<uint32_t>* edgeSubGraphs) const;
115 
117  void storePos(NodeArray<int>& oldPos) const;
119  void restorePos(const NodeArray<int>& newPos);
120 
122  void permute();
123 
124  template<class RNG>
125  void permute(RNG& rng);
126 
128  void separateCCs(int numCC, const NodeArray<int>& component);
129 
130  bool transpose(node v);
131 
132  void print(std::ostream& os) const;
133 
134  void buildAdjNodes(int i);
135  void buildAdjNodes();
136 
137  void check() const;
138 
139 private:
140  int transposePart(const Array<node>& adjV, const Array<node>& adjW);
141 
143 };
144 
145 template<class RNG>
146 void HierarchyLevels::permute(RNG& rng) {
147  for (int i = 0; i < m_pLevel.high(); ++i) {
148  Level& level = *m_pLevel[i];
149  level.m_nodes.permute(rng);
150  for (int j = 0; j <= level.high(); ++j) {
151  m_pos[level[j]] = j;
152  }
153  }
154 
155  buildAdjNodes();
156 }
157 
158 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::HierarchyLevels::operator[]
Level & operator[](int i)
Returns the i-th level.
Definition: HierarchyLevels.h:109
ogdf::HierarchyLevels::size
int size() const override
Returns the number of levels.
Definition: HierarchyLevels.h:82
ogdf::HierarchyLevels::direction
TraversingDir direction() const
Returns the current direction of layer-by-layer sweep.
Definition: HierarchyLevels.h:76
ogdf::Level::high
int high() const override
Returns the maximal array index (= size()-1).
Definition: Level.h:98
ogdf::Array::high
INDEX high() const
Returns the maximal array index.
Definition: Array.h:299
ogdf::Hierarchy
Representation of proper hierarchies used by Sugiyama-layout.
Definition: Hierarchy.h:47
ogdf::HierarchyLevelsBase
Definition: CrossingMinInterfaces.h:63
ogdf::HierarchyLevels::adjLevel
const Level & adjLevel(int i) const
Returns the adjacent level of level i (according to direction()).
Definition: HierarchyLevels.h:101
ogdf::HierarchyLevels::direction
void direction(TraversingDir dir)
Sets the current direction of layer-by-layer sweep.
Definition: HierarchyLevels.h:79
ogdf::Array::permute
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
Definition: Array.h:521
ogdf::HierarchyLevelsBase::TraversingDir
TraversingDir
Definition: CrossingMinInterfaces.h:73
ogdf::HierarchyLevels::m_upperAdjNodes
NodeArray< Array< node > > m_upperAdjNodes
(Sorted) adjacent nodes on upper level.
Definition: HierarchyLevels.h:63
ogdf::HierarchyLevels::m_direction
TraversingDir m_direction
The current direction of layer-by-layer sweep.
Definition: HierarchyLevels.h:67
ogdf::HierarchyLevels::operator[]
const Level & operator[](int i) const override
Returns the i-th level.
Definition: HierarchyLevels.h:106
ogdf::LayerBasedUPRLayout
Definition: LayerBasedUPRLayout.h:109
OGDF_MALLOC_NEW_DELETE
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:92
ogdf::HierarchyLevels::pos
int pos(node v) const override
Returns the position of node v on its level.
Definition: HierarchyLevels.h:88
ogdf::Level::m_nodes
Array< node > m_nodes
The nodes on this level.
Definition: Level.h:71
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:219
ogdf::HierarchyLevels::m_pos
NodeArray< int > m_pos
The position of a node on its level.
Definition: HierarchyLevels.h:60
ogdf::HierarchyLevels::adjNodes
const Array< node > & adjNodes(node v) const
Returns the adjacent nodes of v (according to direction()).
Definition: HierarchyLevels.h:91
ogdf::HierarchyLevels::m_pLevel
Array< Level * > m_pLevel
The array of all levels.
Definition: HierarchyLevels.h:59
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::HierarchyLevels::buildAdjNodes
void buildAdjNodes()
ogdf::HierarchyLevels::m_nSet
NodeArray< int > m_nSet
(Only used by buildAdjNodes().)
Definition: HierarchyLevels.h:65
ogdf::HierarchyLevels::permute
void permute()
Permutes the order of nodes on each level.
CrossingMinInterfaces.h
Declaration of interfaces used in Sugiyama framework.
ogdf::HierarchyLevels::hierarchy
const Hierarchy & hierarchy() const override
Definition: HierarchyLevels.h:73
ogdf::HierarchyLevels::adjNodes
const Array< node > & adjNodes(node v, TraversingDir dir) const override
Returns the adjacent nodes of v.
Definition: HierarchyLevels.h:96
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::HierarchyLevels::m_H
const Hierarchy & m_H
Definition: HierarchyLevels.h:57
ogdf::HierarchyLevels::m_lowerAdjNodes
NodeArray< Array< node > > m_lowerAdjNodes
(Sorted) adjacent nodes on lower level.
Definition: HierarchyLevels.h:62
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::print
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
Definition: Array.h:972
ogdf::Array::size
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:302
ogdf::Level
Representation of levels in hierarchies.
Definition: Level.h:66
Level.h
Declaration and implementation of Level class.
ogdf::HierarchyLevels::high
int high() const override
Returns the maximal array index of a level (= size()-1).
Definition: HierarchyLevels.h:85
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::HierarchyLevels
Representation of proper hierarchies used by Sugiyama-layout.
Definition: HierarchyLevels.h:51
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716