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/EdgeArray.h>
35 #include <ogdf/basic/GraphCopy.h>
37 #include <ogdf/layered/Hierarchy.h>
38 #include <ogdf/layered/Level.h>
39 
40 namespace ogdf {
41 
43 
47 public:
48  friend class Level;
49  friend class LayerBasedUPRLayout;
50 
51 private:
52  const Hierarchy& m_H;
53 
56 
59 
61 
63 
64 public:
65  explicit HierarchyLevels(const Hierarchy& H);
66  ~HierarchyLevels();
67 
68  const Hierarchy& hierarchy() const override { return m_H; }
69 
71  TraversingDir direction() const { return m_direction; }
72 
74  void direction(TraversingDir dir) { m_direction = dir; }
75 
77  int size() const override { return m_pLevel.size(); }
78 
80  int high() const override { return m_pLevel.high(); }
81 
83  int pos(node v) const override { return m_pos[v]; }
84 
86  const Array<node>& adjNodes(node v) const {
87  return (m_direction == TraversingDir::downward) ? m_lowerAdjNodes[v] : m_upperAdjNodes[v];
88  }
89 
91  const Array<node>& adjNodes(node v, TraversingDir dir) const override {
92  return (dir == TraversingDir::downward) ? m_lowerAdjNodes[v] : m_upperAdjNodes[v];
93  }
94 
96  const Level& adjLevel(int i) const {
97  return (m_direction == TraversingDir::downward) ? *m_pLevel[i - 1] : *m_pLevel[i + 1];
98  }
99 
101  const Level& operator[](int i) const override { return *m_pLevel[i]; }
102 
104  Level& operator[](int i) { return *m_pLevel[i]; }
105 
107  int calculateCrossingsSimDraw(int i, const EdgeArray<uint32_t>* edgeSubGraphs) const;
109  int calculateCrossingsSimDraw(const EdgeArray<uint32_t>* edgeSubGraphs) const;
110 
112  void storePos(NodeArray<int>& oldPos) const;
114  void restorePos(const NodeArray<int>& newPos);
115 
117  void permute();
118 
119  template<class RNG>
120  void permute(RNG& rng);
121 
123  void separateCCs(int numCC, const NodeArray<int>& component);
124 
125  bool transpose(node v);
126 
127  void print(std::ostream& os) const;
128 
129  void buildAdjNodes(int i);
130  void buildAdjNodes();
131 
132  void check() const;
133 
134 private:
135  int transposePart(const Array<node>& adjV, const Array<node>& adjW);
136 
138 };
139 
140 template<class RNG>
141 void HierarchyLevels::permute(RNG& rng) {
142  for (int i = 0; i < m_pLevel.high(); ++i) {
143  Level& level = *m_pLevel[i];
144  level.m_nodes.permute(rng);
145  for (int j = 0; j <= level.high(); ++j) {
146  m_pos[level[j]] = j;
147  }
148  }
149 
150  buildAdjNodes();
151 }
152 
153 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::HierarchyLevels::operator[]
Level & operator[](int i)
Returns the i-th level.
Definition: HierarchyLevels.h:104
ogdf::HierarchyLevels::size
int size() const override
Returns the number of levels.
Definition: HierarchyLevels.h:77
ogdf::HierarchyLevels::direction
TraversingDir direction() const
Returns the current direction of layer-by-layer sweep.
Definition: HierarchyLevels.h:71
ogdf::Level::high
int high() const override
Returns the maximal array index (= size()-1).
Definition: Level.h:92
ogdf::Array::high
INDEX high() const
Returns the maximal array index.
Definition: Array.h:294
ogdf::Hierarchy
Representation of proper hierarchies used by Sugiyama-layout.
Definition: Hierarchy.h:43
ogdf::HierarchyLevelsBase
Definition: CrossingMinInterfaces.h:61
ogdf::HierarchyLevels::adjLevel
const Level & adjLevel(int i) const
Returns the adjacent level of level i (according to direction()).
Definition: HierarchyLevels.h:96
ogdf::HierarchyLevels::direction
void direction(TraversingDir dir)
Sets the current direction of layer-by-layer sweep.
Definition: HierarchyLevels.h:74
ogdf::Array::permute
void permute(INDEX l, INDEX r)
Randomly permutes the subarray with index set [l..r].
Definition: Array.h:516
ogdf::HierarchyLevelsBase::TraversingDir
TraversingDir
Definition: CrossingMinInterfaces.h:71
ogdf::HierarchyLevels::m_upperAdjNodes
NodeArray< Array< node > > m_upperAdjNodes
(Sorted) adjacent nodes on upper level.
Definition: HierarchyLevels.h:58
ogdf::HierarchyLevels::m_direction
TraversingDir m_direction
The current direction of layer-by-layer sweep.
Definition: HierarchyLevels.h:62
ogdf::HierarchyLevels::operator[]
const Level & operator[](int i) const override
Returns the i-th level.
Definition: HierarchyLevels.h:101
ogdf::LayerBasedUPRLayout
Definition: LayerBasedUPRLayout.h:101
OGDF_MALLOC_NEW_DELETE
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:91
ogdf::HierarchyLevels::pos
int pos(node v) const override
Returns the position of node v on its level.
Definition: HierarchyLevels.h:83
ogdf::Level::m_nodes
Array< node > m_nodes
The nodes on this level.
Definition: Level.h:65
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:214
EdgeArray.h
Declaration and implementation of EdgeArray class.
ogdf::HierarchyLevels::m_pos
NodeArray< int > m_pos
The position of a node on its level.
Definition: HierarchyLevels.h:55
ogdf::HierarchyLevels::adjNodes
const Array< node > & adjNodes(node v) const
Returns the adjacent nodes of v (according to direction()).
Definition: HierarchyLevels.h:86
ogdf::HierarchyLevels::m_pLevel
Array< Level * > m_pLevel
The array of all levels.
Definition: HierarchyLevels.h:54
GraphCopy.h
Declaration of graph copy classes.
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::HierarchyLevels::buildAdjNodes
void buildAdjNodes()
ogdf::HierarchyLevels::m_nSet
NodeArray< int > m_nSet
(Only used by buildAdjNodes().)
Definition: HierarchyLevels.h:60
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:68
ogdf::HierarchyLevels::adjNodes
const Array< node > & adjNodes(node v, TraversingDir dir) const override
Returns the adjacent nodes of v.
Definition: HierarchyLevels.h:91
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:52
ogdf::HierarchyLevels::m_lowerAdjNodes
NodeArray< Array< node > > m_lowerAdjNodes
(Sorted) adjacent nodes on lower level.
Definition: HierarchyLevels.h:57
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:967
Hierarchy.h
Declaration of Hierarchy class.
ogdf::Array::size
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:297
ogdf::Level
Representation of levels in hierarchies.
Definition: Level.h:60
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:80
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::HierarchyLevels
Representation of proper hierarchies used by Sugiyama-layout.
Definition: HierarchyLevels.h:46
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709