Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
StressMinimization.h
Go to the documentation of this file.
1
36#pragma once
37
38#include <ogdf/basic/Graph.h>
40#include <ogdf/basic/basic.h>
41
42namespace ogdf {
43class GraphAttributes;
44
46
50public:
51 enum class TerminationCriterion { None, PositionDifference, Stress };
52
55 : m_hasEdgeCostsAttribute(false)
56 , m_hasInitialLayout(false)
57 , m_numberOfIterations(200)
58 , m_edgeCosts(100)
59 , m_avgEdgeCosts(-1)
60 , m_componentLayout(false)
61 , m_terminationCriterion(TerminationCriterion::None)
62 , m_fixXCoords(false)
63 , m_fixYCoords(false)
64 , m_fixZCoords(false)
65 , m_forcing2DLayout(false)
66 , m_use3D(false) { }
67
70
72 virtual void call(GraphAttributes& GA) override;
73
76 inline void hasInitialLayout(bool hasInitialLayout);
77
79 inline void fixXCoordinates(bool fix);
80
82 inline void fixYCoordinates(bool fix);
83
85 inline void fixZCoordinates(bool fix);
86
89 inline void layoutComponentsSeparately(bool separate);
90
93 inline void setEdgeCosts(double edgeCosts);
94
97 inline void setIterations(int numberOfIterations);
98
100 inline void convergenceCriterion(TerminationCriterion criterion);
101
103 inline void useEdgeCostsAttribute(bool useEdgeCostsAttribute);
104
107
112 inline void setForcing2DLayout(bool forcing2DLayout);
113
114private:
116 const static double EPSILON;
117
119 const static int DEFAULT_NUMBER_OF_PIVOTS;
120
124
127
130
133
137
140
143
146
149
152
156
159
161 double calcStress(const GraphAttributes& GA, NodeArray<NodeArray<double>>& shortestPathMatrix,
162 NodeArray<NodeArray<double>>& weightMatrix);
163
165 void call(GraphAttributes& GA, NodeArray<NodeArray<double>>& shortestPathMatrix,
166 NodeArray<NodeArray<double>>& weightMatrix);
167
169 void calcWeights(const Graph& G, NodeArray<NodeArray<double>>& shortestPathMatrix,
170 NodeArray<NodeArray<double>>& weightMatrix);
171
174
177
180 NodeArray<double>& newZ);
181
184 bool finished(GraphAttributes& GA, int numberOfPerformedIterations,
185 NodeArray<double>& prevXCoords, NodeArray<double>& prevYCoords, const double prevStress,
186 const double curStress);
187
189 void initMatrices(const Graph& G, NodeArray<NodeArray<double>>& shortestPathMatrix,
190 NodeArray<NodeArray<double>>& weightMatrix);
191
195 NodeArray<NodeArray<double>>& weightMatrix);
196
200 NodeArray<NodeArray<double>>& weightMatrix);
201
203 void replaceInfinityDistances(NodeArray<NodeArray<double>>& shortestPathMatrix, double newVal);
204};
205
207
209
213
215
216void StressMinimization::setEdgeCosts(double edgeCosts) {
217 m_edgeCosts = (edgeCosts > 0) ? edgeCosts : 100;
218}
219
220void StressMinimization::setIterations(int numberOfIterations) {
221 m_numberOfIterations = (numberOfIterations > 0) ? numberOfIterations : 100;
222}
223
227
231
232void StressMinimization::setForcing2DLayout(bool forcing2DLayout) {
233 m_forcing2DLayout = forcing2DLayout;
234}
235
236}
Includes declaration of graph class.
Declaration of interface for layout algorithms (class LayoutModule)
Basic declarations, included by all source files.
Stores additional attributes of a graph (like layout information).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Interface of general layout algorithms.
Energy-based layout using stress minimization.
void setForcing2DLayout(bool forcing2DLayout)
Sets whether a 2D-layout should be calculated even when GraphAttributes::threeD is set.
TerminationCriterion m_terminationCriterion
Indicates whether epsilon convergence is used or not.
virtual void call(GraphAttributes &GA) override
Calls the layout algorithm with uniform edge costs.
void initMatrices(const Graph &G, NodeArray< NodeArray< double > > &shortestPathMatrix, NodeArray< NodeArray< double > > &weightMatrix)
Convenience method to initialize the matrices.
bool m_fixYCoords
Indicates whether the y coordinates will be modified or not.
bool m_hasEdgeCostsAttribute
Tells whether the stress minimization is based on uniform edge costs or a edge costs attribute.
void convergenceCriterion(TerminationCriterion criterion)
Tells which TerminationCriterion should be used.
double calcStress(const GraphAttributes &GA, NodeArray< NodeArray< double > > &shortestPathMatrix, NodeArray< NodeArray< double > > &weightMatrix)
Calculates the stress for the given layout.
void call(GraphAttributes &GA, NodeArray< NodeArray< double > > &shortestPathMatrix, NodeArray< NodeArray< double > > &weightMatrix)
Runs the stress for a given Graph, shortest path and weight matrix.
bool m_forcing2DLayout
Indicates whether a 2D-layout is calculated even when GraphAttributes::threeD is set.
void hasInitialLayout(bool hasInitialLayout)
Tells whether the current layout should be used or the initial layout needs to be computed.
void fixYCoordinates(bool fix)
Tells whether the y coordinates are allowed to be modified or not.
static const int DEFAULT_NUMBER_OF_PIVOTS
Default number of pivots used for the initial Pivot-MDS layout.
bool m_use3D
Indicates whether a 3D-layout is computed.
bool finished(GraphAttributes &GA, int numberOfPerformedIterations, NodeArray< double > &prevXCoords, NodeArray< double > &prevYCoords, const double prevStress, const double curStress)
Checks for epsilon convergence and whether the performed number of iterations exceed the predefined m...
bool m_componentLayout
Indicates whether the components should be treated separately.
void computeInitialLayout(GraphAttributes &GA)
Calculates the intial layout of the graph if necessary.
void useEdgeCostsAttribute(bool useEdgeCostsAttribute)
Tells whether the edge costs are uniform or defined by some edge costs attribute.
bool m_fixZCoords
Indicates whether the z coordinates will be modified or not.
void nextIteration(GraphAttributes &GA, NodeArray< NodeArray< double > > &shortestPathMatrix, NodeArray< NodeArray< double > > &weightMatrix)
Runs the next iteration of the stress minimization process. Note that serial update is used.
int m_numberOfIterations
Number of iterations performed by the stress minimization.
void fixXCoordinates(bool fix)
Tells whether the x coordinates are allowed to be modified or not.
void layoutComponentsSeparately(bool separate)
Sets whether the graph's components should be layouted separately or a dummy distance should be used ...
void replaceInfinityDistances(NodeArray< NodeArray< double > > &shortestPathMatrix, double newVal)
Replaces infinite distances to the given value.
double m_edgeCosts
The weight of an edge.
static const double EPSILON
Convergence constant.
void setEdgeCosts(double edgeCosts)
Sets the desired distance between adjacent nodes. If the new value is smaller or equal 0 the default ...
void copyLayout(const GraphAttributes &GA, NodeArray< double > &newX, NodeArray< double > &newY)
Convenience method copying the layout of the graph in case of epsilon convergence.
void setIterations(int numberOfIterations)
Sets a fixed number of iterations for stress majorization. If the new value is smaller or equal 0 the...
bool m_hasInitialLayout
Tells whether an initial layout has to be computed or not.
void calcWeights(const Graph &G, NodeArray< NodeArray< double > > &shortestPathMatrix, NodeArray< NodeArray< double > > &weightMatrix)
Calculates the weight matrix of the shortest path matrix. This is done by w_ij = s_ij^{-2}.
double m_avgEdgeCosts
The average edge costs. Needed to define distances of nodes belonging to different graph components.
void fixZCoordinates(bool fix)
Tells whether the z coordinates are allowed to be modified or not.
bool m_fixXCoords
Indicates whether the x coordinates will be modified or not.
void copyLayout(const GraphAttributes &GA, NodeArray< double > &newX, NodeArray< double > &newY, NodeArray< double > &newZ)
Convenience method copying the layout of the graph in case of epsilon convergence for 3D.
void minimizeStress(GraphAttributes &GA, NodeArray< NodeArray< double > > &shortestPathMatrix, NodeArray< NodeArray< double > > &weightMatrix)
Minimizes the stress for each component separately given the shortest path matrix and the weight matr...
StressMinimization()
Constructor: Constructs instance of stress majorization.
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
The namespace for all OGDF objects.
@ None
Two geometric objects do not intersect.