Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
43namespace ogdf {
44
45//Stores info on merging for a refinement level
46struct 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
63
64 explicit NodeMerge(int level) : m_mergedNode(-1), m_level(level) { }
65
67};
68
70private:
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);
92
95
96public:
99 explicit MultilevelGraph(Graph& G);
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
137
138 int getLevel();
139
140 Graph& getGraph() { return *m_G; }
141
143 GraphAttributes& getGraphAttributes() const { return *m_GA; }
144
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}
Includes declaration of graph class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Basic declarations, included by all source files.
Class for the representation of edges.
Definition Graph_d.h:364
Stores additional attributes of a graph (like layout information).
double y(node v) const
Returns the y-coordinate of node v.
double x(node v) const
Returns the x-coordinate of node v.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
void writeGML(const char *fileName)
MultilevelGraph(const char *filename)
NodeArray< int > m_nodeAssociations
void reInsertGraph(MultilevelGraph &MLG)
double averageRadius() const
MultilevelGraph * removeOneCC(std::vector< node > &componentSubArray)
void weight(edge e, double weight)
std::vector< node > m_reverseNodeIndex
GraphAttributes * m_GA
std::vector< int > m_reverseNodeMergeWeight
std::vector< NodeMerge * > m_changes
void importAttributes(const GraphAttributes &GA)
void copyNodeTo(node v, MultilevelGraph &MLG, std::map< node, node > &tempNodeAssociations, bool associate, int index=-1)
void reInsertAll(std::vector< MultilevelGraph * > &components)
void y(node v, double y)
void exportAttributes(GraphAttributes &GA) const
EdgeArray< int > m_edgeAssociations
MultilevelGraph(GraphAttributes &GA)
NodeArray< double > m_radius
void x(node v, double x)
void radius(node v, double r)
MultilevelGraph(GraphAttributes &GA, Graph &G)
node getNode(unsigned int index)
MultilevelGraph(std::istream &is)
EdgeArray< double > & getWArray()
NodeArray< double > & getRArray()
EdgeArray< double > m_weight
GraphAttributes & getGraphAttributes() const
Returns attributes of current level graph as GraphAttributes.
void exportAttributesSimple(GraphAttributes &GA) const
void copyEdgeTo(edge e, MultilevelGraph &MLG, std::map< node, node > &tempNodeAssociations, bool associate, int index=-1)
edge getEdge(unsigned int index)
void copyFromGraph(const Graph &G, NodeArray< int > &nodeAssociations, EdgeArray< int > &edgeAssociations)
std::vector< edge > m_reverseEdgeIndex
void writeGML(std::ostream &os)
void importAttributesSimple(const GraphAttributes &GA)
void prepareGraphAttributes(GraphAttributes &GA) const
Class for the representation of nodes.
Definition Graph_d.h:241
int index() const
Returns the (unique) node index.
Definition Graph_d.h:275
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition config.h:206
The namespace for all OGDF objects.
Definition GML.h:111
std::vector< int > m_changedEdges
std::map< int, double > m_radius
std::map< int, int > m_target
std::vector< int > m_changedNodes
std::vector< int > m_deletedEdges
std::vector< std::pair< int, double > > m_position
std::map< int, double > m_doubleWeight
std::map< int, int > m_source
NodeMerge(int level)