Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Level.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/SList.h>
36 #include <ogdf/basic/tuples.h>
38 
39 namespace ogdf {
40 
41 class HierarchyLevels;
42 class LayerBasedUPRLayout;
43 
44 template<class T = double>
47 
48 public:
49  explicit WeightComparer(const NodeArray<T>* pWeight) : m_pWeight(pWeight) { }
50 
51  bool less(node v, node w) const { return (*m_pWeight)[v] < (*m_pWeight)[w]; }
52 
53  bool operator()(node v, node w) const { return (*m_pWeight)[v] < (*m_pWeight)[w]; }
54 };
55 
57 
60 class OGDF_EXPORT Level : public LevelBase {
61  friend class HierarchyLevels;
62  friend class HierarchyLayoutModule;
63  friend class LayerBasedUPRLayout;
64 
67  int m_index;
68 
69 public:
71 
76  Level(HierarchyLevels* pLevels, int index, int num)
77  : m_nodes(num), m_pLevels(pLevels), m_index(index) { }
78 
79  // destruction
80  ~Level() { }
81 
83  const node& operator[](int i) const override { return m_nodes[i]; }
84 
86  node& operator[](int i) override { return m_nodes[i]; }
87 
89  int size() const override { return m_nodes.size(); }
90 
92  int high() const override { return m_nodes.high(); }
93 
95  int index() const { return m_index; }
96 
98  const Array<node>& adjNodes(node v) const;
99 
101  const HierarchyLevels& levels() const { return *m_pLevels; }
102 
104  void swap(int i, int j);
105 
107  void sort(NodeArray<double>& weight);
108 
110  void sort(NodeArray<int>& weight, int minBucket, int maxBucket);
111 
113  void sortByWeightOnly(NodeArray<double>& weight);
114 
116  template<class C>
117  void sortOrder(C& orderComparer) {
118  m_nodes.quicksort(orderComparer);
119  recalcPos();
120  }
121 
122  void recalcPos();
123 
124  friend std::ostream& operator<<(std::ostream& os, const Level& L) {
125  os << L.m_nodes;
126  return os;
127  }
128 
129 private:
130  void getIsolatedNodes(SListPure<Tuple2<node, int>>& isolated) const;
131  void setIsolatedNodes(SListPure<Tuple2<node, int>>& isolated);
132 
134 };
135 
136 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::Level::operator[]
node & operator[](int i) override
Returns the node at position i.
Definition: Level.h:86
Graph.h
Includes declaration of graph class.
ogdf::Level::operator<<
friend std::ostream & operator<<(std::ostream &os, const Level &L)
Definition: Level.h:124
ogdf::WeightComparer::WeightComparer
WeightComparer(const NodeArray< T > *pWeight)
Definition: Level.h:49
ogdf::Level::m_index
int m_index
The index of this level.
Definition: Level.h:67
ogdf::Tuple2
Tuples of two elements (2-tuples).
Definition: tuples.h:46
ogdf::HierarchyLayoutModule
Interface of hierarchy layout algorithms.
Definition: HierarchyLayoutModule.h:47
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::Level::~Level
~Level()
Definition: Level.h:80
ogdf::Level::operator[]
const node & operator[](int i) const override
Returns the node at position i.
Definition: Level.h:83
ogdf::Level::sortOrder
void sortOrder(C &orderComparer)
Sorts the nodes according to orderComparer.
Definition: Level.h:117
ogdf::WeightComparer
Definition: Level.h:45
ogdf::Level::Level
Level(HierarchyLevels *pLevels, int index, int num)
Creates a level with index index in hierarchy pLevels.
Definition: Level.h:76
Minisat::Internal::sort
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:57
ogdf::LayerBasedUPRLayout
Definition: LayerBasedUPRLayout.h:101
ogdf::Level::size
int size() const override
Returns the number of nodes on this level.
Definition: Level.h:89
OGDF_MALLOC_NEW_DELETE
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:91
ogdf::Level::m_nodes
Array< node > m_nodes
The nodes on this level.
Definition: Level.h:65
SList.h
Declaration of singly linked lists and iterators.
ogdf::Array< node >
ogdf::SListPure
Singly linked lists.
Definition: SList.h:39
ogdf::WeightComparer::less
bool less(node v, node w) const
Definition: Level.h:51
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::Level::levels
const HierarchyLevels & levels() const
Returns the hierarchy to which this level belongs.
Definition: Level.h:101
CrossingMinInterfaces.h
Declaration of interfaces used in Sugiyama framework.
ogdf::Level::index
int index() const
Returns the array index of this level in the hierarchy.
Definition: Level.h:95
ogdf::Level::m_pLevels
HierarchyLevels * m_pLevels
The hierarchy to which this level belongs.
Definition: Level.h:66
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::Array::quicksort
void quicksort()
Sorts array using Quicksort.
Definition: Array.h:634
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
ogdf::LevelBase
Representation of levels in hierarchies.
Definition: CrossingMinInterfaces.h:43
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
tuples.h
Declaration and implementation of class Tuple2, Tuple3 and Tuple4.
ogdf::WeightComparer::m_pWeight
const NodeArray< T > * m_pWeight
Definition: Level.h:46
ogdf::WeightComparer::operator()
bool operator()(node v, node w) const
Definition: Level.h:53
ogdf::HierarchyLevels
Representation of proper hierarchies used by Sugiyama-layout.
Definition: HierarchyLevels.h:46