Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

MultilevelGraph.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
36 #include <ogdf/basic/basic.h>
37 
38 #include <iosfwd>
39 #include <map>
40 #include <utility>
41 #include <vector>
42 
43 namespace ogdf {
44 
45 //Stores info on merging for a refinement level
46 struct NodeMerge {
47  // Node/Edge IDs instead of pointers as the nodes themselves may be nonexistent.
48  std::vector<int> m_deletedEdges;
49  std::vector<int> m_changedEdges;
50  std::map<int, double> m_doubleWeight; // for changed and deleted edges
51  std::map<int, int> m_source;
52  std::map<int, int> m_target;
53 
55  // optional information <target, distance>.
56  // mergedNode will be placed at average of relative distances to target.
57  std::vector<std::pair<int, double>> m_position;
58 
59  std::vector<int> m_changedNodes; // there may be placement strategies that use more than one reference-node.
60  std::map<int, double> m_radius; // for changed nodes and the merged node
61 
62  int m_level;
63 
64  explicit NodeMerge(int level) : m_mergedNode(-1), m_level(level) { }
65 
66  ~NodeMerge() { }
67 };
68 
70 private:
71  bool m_createdGraph; //used in destructor, TODO: check if it is needed
73  GraphAttributes* m_GA; //<! Keeps layout info in replacement of information below (todo: remove them)
74  std::vector<NodeMerge*> m_changes;
76  double m_avgRadius; //stores average node radius for scaling and random layout purposes
77 
79 
80  // Associations to index only as the node/edge may be nonexistent
83 
84  std::vector<node> m_reverseNodeIndex;
85  std::vector<int> m_reverseNodeMergeWeight; //<! Keeps number of vertices represented by vertex with given index
86  std::vector<edge> m_reverseEdgeIndex;
87 
88  MultilevelGraph* removeOneCC(std::vector<node>& componentSubArray);
89  void copyFromGraph(const Graph& G, NodeArray<int>& nodeAssociations,
90  EdgeArray<int>& edgeAssociations);
91  void prepareGraphAttributes(GraphAttributes& GA) const;
92 
93  void initReverseIndizes();
94  void initInternal();
95 
96 public:
97  ~MultilevelGraph();
99  explicit MultilevelGraph(Graph& G);
100  explicit MultilevelGraph(GraphAttributes& GA);
101  // if the Graph is available without const, no copy needs to be created.
103 
104  // creates MultilevelGraph directly from GML file.
105  explicit MultilevelGraph(std::istream& is);
106  explicit MultilevelGraph(const char* filename);
107 
108  NodeArray<double>& getRArray() { return m_radius; }
109 
110  EdgeArray<double>& getWArray() { return m_weight; }
111 
112  edge getEdge(unsigned int index);
113  node getNode(unsigned int index);
114 
115  double radius(node v) { return m_radius[v]; }
116 
117  void radius(node v, double r) { m_radius[v] = r; }
118 
119  double averageRadius() const { return m_avgRadius; }
120 
121  double x(node v) { return m_GA->x(v); }
122 
123  double y(node v) { return m_GA->y(v); }
124 
125  void x(node v, double x) { m_GA->x(v) = x; }
126 
127  void y(node v, double y) { m_GA->y(v) = y; }
128 
129  void weight(edge e, double weight) { m_weight[e] = weight; }
130 
131  double weight(edge e) { return m_weight[e]; }
132 
133  //returns the merge weight, i.e. the number of nodes represented by v on the current level
134  int mergeWeight(node v) { return m_reverseNodeMergeWeight[v->index()]; }
135 
136  void moveToZero();
137 
138  int getLevel();
139 
140  Graph& getGraph() { return *m_G; }
141 
143  GraphAttributes& getGraphAttributes() const { return *m_GA; }
144 
145  void exportAttributes(GraphAttributes& GA) const;
146  void exportAttributesSimple(GraphAttributes& GA) const;
147  void importAttributes(const GraphAttributes& GA);
148  void importAttributesSimple(const GraphAttributes& GA);
149  void reInsertGraph(MultilevelGraph& MLG);
150  void reInsertAll(std::vector<MultilevelGraph*>& components);
151  void copyNodeTo(node v, MultilevelGraph& MLG, std::map<node, node>& tempNodeAssociations,
152  bool associate, int index = -1);
153  void copyEdgeTo(edge e, MultilevelGraph& MLG, std::map<node, node>& tempNodeAssociations,
154  bool associate, int index = -1);
155  void writeGML(std::ostream& os);
156  void writeGML(const char* fileName);
157 
158  // the original graph will be cleared to save Memory
159  OGDF_DEPRECATED("Use ComponentSplitterLayout instead.")
160  std::vector<MultilevelGraph*> splitIntoComponents();
161 
162  bool postMerge(NodeMerge* NM, node merged);
163  //\a merged is the node now represented by \a theNode
164  bool changeNode(NodeMerge* NM, node theNode, double newRadius, node merged);
165  bool changeEdge(NodeMerge* NM, edge theEdge, double newWeight, node newSource, node newTarget);
166  bool deleteEdge(NodeMerge* NM, edge theEdge);
167  std::vector<edge> moveEdgesToParent(NodeMerge* NM, node theNode, node parent,
168  bool deleteDoubleEndges, int adjustEdgeLengths);
169  NodeMerge* getLastMerge();
170  node undoLastMerge();
171 
172  void updateReverseIndizes();
173  //sets the merge weights back to initial values
174  void updateMergeWeights();
175 };
176 
177 }
ogdf::MultilevelGraph::m_GA
GraphAttributes * m_GA
Definition: MultilevelGraph.h:73
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::MultilevelGraph::radius
void radius(node v, double r)
Definition: MultilevelGraph.h:117
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:72
GraphAttributes.h
Declaration of class GraphAttributes which extends a Graph by additional attributes.
ogdf::NodeMerge::m_position
std::vector< std::pair< int, double > > m_position
Definition: MultilevelGraph.h:57
Graph.h
Includes declaration of graph class.
OGDF_DEPRECATED
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition: config.h:120
ogdf::NodeMerge::m_mergedNode
int m_mergedNode
Definition: MultilevelGraph.h:54
ogdf::NodeElement::index
int index() const
Returns the (unique) node index.
Definition: Graph_d.h:274
ogdf::MultilevelGraph::m_changes
std::vector< NodeMerge * > m_changes
Definition: MultilevelGraph.h:74
ogdf::MultilevelGraph::getGraphAttributes
GraphAttributes & getGraphAttributes() const
Returns attributes of current level graph as GraphAttributes.
Definition: MultilevelGraph.h:143
ogdf::MultilevelGraph::getGraph
Graph & getGraph()
Definition: MultilevelGraph.h:140
ogdf::GraphAttributes::x
double x(node v) const
Returns the x-coordinate of node v.
Definition: GraphAttributes.h:247
ogdf::NodeMerge::m_level
int m_level
Definition: MultilevelGraph.h:62
ogdf::MultilevelGraph::averageRadius
double averageRadius() const
Definition: MultilevelGraph.h:119
ogdf::MultilevelGraph
Definition: MultilevelGraph.h:69
ogdf::NodeMerge::m_radius
std::map< int, double > m_radius
Definition: MultilevelGraph.h:60
ogdf::MultilevelGraph::m_nodeAssociations
NodeArray< int > m_nodeAssociations
Definition: MultilevelGraph.h:81
ogdf::MultilevelGraph::radius
double radius(node v)
Definition: MultilevelGraph.h:115
ogdf::NodeMerge::m_changedEdges
std::vector< int > m_changedEdges
Definition: MultilevelGraph.h:49
ogdf::GraphAttributes::y
double y(node v) const
Returns the y-coordinate of node v.
Definition: GraphAttributes.h:265
ogdf::NodeMerge::m_doubleWeight
std::map< int, double > m_doubleWeight
Definition: MultilevelGraph.h:50
ogdf::MultilevelGraph::getRArray
NodeArray< double > & getRArray()
Definition: MultilevelGraph.h:108
ogdf::NodeMerge
Definition: MultilevelGraph.h:46
r
int r[]
Definition: hierarchical-ranking.cpp:13
ogdf::MultilevelGraph::m_createdGraph
bool m_createdGraph
Definition: MultilevelGraph.h:71
ogdf::MultilevelGraph::m_reverseNodeIndex
std::vector< node > m_reverseNodeIndex
Definition: MultilevelGraph.h:84
ogdf::MultilevelGraph::m_avgRadius
double m_avgRadius
Definition: MultilevelGraph.h:76
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::NodeMerge::NodeMerge
NodeMerge(int level)
Definition: MultilevelGraph.h:64
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::MultilevelGraph::getWArray
EdgeArray< double > & getWArray()
Definition: MultilevelGraph.h:110
ogdf::MultilevelGraph::m_reverseNodeMergeWeight
std::vector< int > m_reverseNodeMergeWeight
Definition: MultilevelGraph.h:85
ogdf::MultilevelGraph::m_reverseEdgeIndex
std::vector< edge > m_reverseEdgeIndex
Definition: MultilevelGraph.h:86
ogdf::MultilevelGraph::x
void x(node v, double x)
Definition: MultilevelGraph.h:125
ogdf::MultilevelGraph::weight
void weight(edge e, double weight)
Definition: MultilevelGraph.h:129
basic.h
Basic declarations, included by all source files.
std
Definition: GML.h:111
ogdf::MultilevelGraph::y
double y(node v)
Definition: MultilevelGraph.h:123
ogdf::NodeMerge::m_source
std::map< int, int > m_source
Definition: MultilevelGraph.h:51
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::MultilevelGraph::m_radius
NodeArray< double > m_radius
Definition: MultilevelGraph.h:75
ogdf::MultilevelGraph::mergeWeight
int mergeWeight(node v)
Definition: MultilevelGraph.h:134
ogdf::MultilevelGraph::x
double x(node v)
Definition: MultilevelGraph.h:121
ogdf::NodeMerge::~NodeMerge
~NodeMerge()
Definition: MultilevelGraph.h:66
ogdf::MultilevelGraph::weight
double weight(edge e)
Definition: MultilevelGraph.h:131
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::NodeMerge::m_deletedEdges
std::vector< int > m_deletedEdges
Definition: MultilevelGraph.h:48
ogdf::MultilevelGraph::m_edgeAssociations
EdgeArray< int > m_edgeAssociations
Definition: MultilevelGraph.h:82
ogdf::MultilevelGraph::m_weight
EdgeArray< double > m_weight
Definition: MultilevelGraph.h:78
ogdf::MultilevelGraph::y
void y(node v, double y)
Definition: MultilevelGraph.h:127
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::NodeMerge::m_target
std::map< int, int > m_target
Definition: MultilevelGraph.h:52
ogdf::NodeMerge::m_changedNodes
std::vector< int > m_changedNodes
Definition: MultilevelGraph.h:59
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::MultilevelGraph::m_G
Graph * m_G
Definition: MultilevelGraph.h:72