Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

SpringEmbedderKK.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Array2D.h>
37 #include <ogdf/basic/tuples.h>
38 
39 namespace ogdf {
40 
42 
75 public:
77 
80  : m_tolerance(0.001)
81  , m_ltolerance(0.0001)
82  , m_computeMaxIt(true)
83  , m_K(5.0)
84  , m_prevEnergy(startVal)
85  , m_prevLEnergy(startVal)
86  , m_zeroLength(-1.0)
87  , m_desLength(0.0)
88  , m_distFactor(2.0)
89  , m_useLayout(true)
90  , m_gItBaseVal(50)
91  , m_gItFactor(16) {
92  m_maxLocalIt = m_maxGlobalIt = maxVal;
93  }
94 
98  virtual void call(GraphAttributes& GA) override;
99 
103  void call(GraphAttributes& GA, const EdgeArray<double>& eLength);
104 
107  void setStopTolerance(double s) { m_tolerance = s; }
108 
110  void setUseLayout(bool b) { m_useLayout = b; }
111 
112  bool useLayout() { return m_useLayout; }
113 
117  void setZeroLength(double d) { m_zeroLength = d; }
118 
119  double zeroLength() { return m_zeroLength; }
120 
122  void setDesLength(double d) { m_desLength = d; }
123 
127  int maxLocalIterations() const { return m_maxLocalIt; }
128 
130  if (i > 0) {
131  m_gItFactor = i;
132  }
133  }
134 
135  int maxGlobalIterations() const { return m_maxGlobalIt; }
136 
139  if (i > 0) {
140  m_maxGlobalIt = i;
141  }
142  }
143 
145  void setMaxLocalIterations(int i) {
146  if (i > 0) {
147  m_maxLocalIt = i;
148  }
149  }
150 
152  void computeMaxIterations(bool b) { m_computeMaxIt = b; }
153 #if 0
154  //We could add some noise to the computation
155 
157  bool noise() const {
158  return m_noise;
159  }
160 
162  void noise(bool on) {
163  m_noise = on;
164  }
165 #endif
166 
167 protected:
169  void doCall(GraphAttributes& GA, const EdgeArray<double>& eLength, bool simpleBFS);
170 
172  bool finished(double maxdelta) {
173  if (m_prevEnergy == startVal) // first step
174  {
175  m_prevEnergy = maxdelta;
176  return false;
177  }
178 
179 #if 0
180  double diff = m_prevEnergy - maxdelta; // energy difference
181  if (diff < 0.0) diff = -diff;
182 # ifdef OGDF_DEBUG
183  std::cout << "Finished(): maxdelta: " << maxdelta << " diff/prev: " << diff / m_prevEnergy << std::endl;
184 # endif
185 #endif
186  // check if we want to stop
187  bool done = (maxdelta < m_tolerance); // || (diff / m_prevEnergy) < m_tolerance);
188 
189  m_prevEnergy = maxdelta; // save previous energy level
190  m_prevLEnergy = startVal; // reset energy level for local node decision
191 
192  return done;
193  }
194 
196  bool finishedNode(double deltav) {
197  if (m_prevLEnergy == startVal) {
198  m_prevLEnergy = deltav;
199  return deltav == 0.0; // m_ltolerance; locally stable
200  }
201 #if 0
202 # ifdef OGDF_DEBUG
203  std::cout << "Local delta: " << deltav << "\n";
204 # endif
205 #endif
206  double diff = m_prevLEnergy - deltav;
207  // check if we want to stop
208  bool done = deltav == 0.0 || diff / m_prevLEnergy < m_ltolerance;
209 
210  m_prevLEnergy = deltav; // save previous energy level
211 
212  return done;
213  }
214 
217  void adaptLengths(const Graph& G, const GraphAttributes& GA, const EdgeArray<double>& eLengths,
218  EdgeArray<double>& adaptedLengths);
219 
221  void shufflePositions(GraphAttributes& GA);
222 
225  dpair computeParDer(node m, node u, GraphAttributes& GA, NodeArray<NodeArray<double>>& ss,
227 
229  dpair computeParDers(node v, GraphAttributes& GA, NodeArray<NodeArray<double>>& ss,
231 
233  void initialize(GraphAttributes& GA, NodeArray<dpair>& partialDer,
234  const EdgeArray<double>& eLength, NodeArray<NodeArray<double>>& oLength,
235  NodeArray<NodeArray<double>>& sstrength, bool simpleBFS);
236 
238  void mainStep(GraphAttributes& GA, NodeArray<dpair>& partialDer,
239  NodeArray<NodeArray<double>>& oLength, NodeArray<NodeArray<double>>& sstrength);
240 
243  void scale(GraphAttributes& GA);
244 
245 private:
248  double m_tolerance;
249  double m_ltolerance;
253  double m_K;
254  double m_prevEnergy;
255  double m_prevLEnergy;
256  double m_zeroLength;
257  double m_desLength;
258  double m_distFactor; //< introduces some distance for scaling in case BFS is used
259  bool m_useLayout;
262 
263  static const double startVal;
264  static const double minVal;
265  static const double desMinLength;
266  static const int maxVal;
267 
268  double allpairsspBFS(const Graph& G, NodeArray<NodeArray<double>>& distance);
269  double allpairssp(const Graph& G, const EdgeArray<double>& eLengths,
270  NodeArray<NodeArray<double>>& distance,
271  const double threshold = std::numeric_limits<double>::max());
272 };
273 
274 #if 0
275  //Things that potentially could be added
276 
278  double pageRatio() { return m_pageRatio; }
279 
281  void pageRatio(double x) { m_pageRatio = x; }
282 
284  Scaling scaling() const {
285  return m_scaling;
286  }
287 
289  void scaling(Scaling sc) {
290  m_scaling = sc;
291  }
292 
294  double scaleFunctionFactor() const {
295  return m_scaleFactor;
296  }
297 
299  void scaleFunctionFactor(double f) {
300  m_scaleFactor = f;
301  }
302 
304  void userBoundingBox(double xmin, double ymin, double xmax, double ymax) {
305  m_bbXmin = xmin;
306  m_bbYmin = ymin;
307  m_bbXmax = xmax;
308  m_bbYmax = ymax;
309  }
310 #endif
311 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:66
GraphAttributes.h
Declaration of class GraphAttributes which extends a Graph by additional attributes.
ogdf::SpringEmbedderKK::m_prevEnergy
double m_prevEnergy
Big K constant for strength computation.
Definition: SpringEmbedderKK.h:254
ogdf::SpringEmbedderKK::setUseLayout
void setUseLayout(bool b)
If set to true, the given layout is used for the initial positions.
Definition: SpringEmbedderKK.h:110
ogdf::SpringEmbedderKK::finishedNode
bool finishedNode(double deltav)
Checks if inner loop (current node) is finished.
Definition: SpringEmbedderKK.h:196
ogdf::SpringEmbedderKK::m_desLength
double m_desLength
Desirable edge length, used instead if > 0.
Definition: SpringEmbedderKK.h:257
ogdf::Tuple2
Tuples of two elements (2-tuples).
Definition: tuples.h:46
ogdf::SpringEmbedderKK::desMinLength
static const double desMinLength
Defines minimum desired edge length.
Definition: SpringEmbedderKK.h:265
ogdf::SpringEmbedderKK::setDesLength
void setDesLength(double d)
Sets desirable edge length directly.
Definition: SpringEmbedderKK.h:122
ogdf::SpringEmbedderKK::maxVal
static const int maxVal
defines infinite upper bound for iteration number
Definition: SpringEmbedderKK.h:266
ogdf::SpringEmbedderKK::startVal
static const double startVal
Definition: SpringEmbedderKK.h:263
ogdf::SpringEmbedderKK::setGlobalIterationFactor
void setGlobalIterationFactor(int i)
Definition: SpringEmbedderKK.h:129
ogdf::SpringEmbedderKK::m_useLayout
bool m_useLayout
use positions or allow to shuffle nodes to avoid degeneration
Definition: SpringEmbedderKK.h:259
LayoutModule.h
Declaration of interface for layout algorithms (class LayoutModule)
ogdf::SpringEmbedderKK::maxLocalIterations
int maxLocalIterations() const
It is possible to limit the number of iterations to a fixed value Returns the current setting of iter...
Definition: SpringEmbedderKK.h:127
ogdf::SpringEmbedderKK::m_gItFactor
int m_gItFactor
factor for global iterations: m_gItBaseVal+m_gItFactor*|V|
Definition: SpringEmbedderKK.h:261
ogdf::SpringEmbedderKK::m_distFactor
double m_distFactor
Definition: SpringEmbedderKK.h:258
ogdf::SpringEmbedderKK::useLayout
bool useLayout()
Definition: SpringEmbedderKK.h:112
ogdf::SpringEmbedderKK::m_maxGlobalIt
int m_maxGlobalIt
Maximum number of global iterations.
Definition: SpringEmbedderKK.h:250
ogdf::SpringEmbedderKK::SpringEmbedderKK
SpringEmbedderKK()
Constructor: Constructs instance of Kamada Kawai Layout.
Definition: SpringEmbedderKK.h:79
ogdf::SpringEmbedderKK::setZeroLength
void setZeroLength(double d)
If set != 0, value zerolength is used to determine the desirable edge length by L = zerolength / max ...
Definition: SpringEmbedderKK.h:117
ogdf::SpringEmbedderKK::m_K
double m_K
Definition: SpringEmbedderKK.h:253
ogdf::SpringEmbedderKK::m_computeMaxIt
bool m_computeMaxIt
If true, number of iterations is computed depending on number of nodes.
Definition: SpringEmbedderKK.h:252
ogdf::SpringEmbedderKK::setMaxGlobalIterations
void setMaxGlobalIterations(int i)
Sets the number of global iterations to i.
Definition: SpringEmbedderKK.h:138
ogdf::SpringEmbedderKK::maxGlobalIterations
int maxGlobalIterations() const
Definition: SpringEmbedderKK.h:135
ogdf::SpringEmbedderKK
The spring-embedder layout algorithm by Kamada and Kawai.
Definition: SpringEmbedderKK.h:74
ogdf::SpringEmbedderKK::m_gItBaseVal
int m_gItBaseVal
minimum number of global iterations
Definition: SpringEmbedderKK.h:260
ogdf::SpringEmbedderKK::setStopTolerance
void setStopTolerance(double s)
Sets the value for the stop tolerance, below which the system is regarded stable (balanced) and the o...
Definition: SpringEmbedderKK.h:107
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::SpringEmbedderKK::finished
bool finished(double maxdelta)
Checks if main loop is finished because local optimum reached.
Definition: SpringEmbedderKK.h:172
ogdf::SpringEmbedderKK::zeroLength
double zeroLength()
Definition: SpringEmbedderKK.h:119
ogdf::SpringEmbedderKK::minVal
static const double minVal
Definition: SpringEmbedderKK.h:264
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::SpringEmbedderKK::m_zeroLength
double m_zeroLength
Length of a side of the display area, used for edge length computation if > 0.
Definition: SpringEmbedderKK.h:256
ogdf::SpringEmbedderKK::computeMaxIterations
void computeMaxIterations(bool b)
If set to true, number of iterations is computed depending on G.
Definition: SpringEmbedderKK.h:152
ogdf::SpringEmbedderKK::m_maxLocalIt
int m_maxLocalIt
Maximum number of local iterations.
Definition: SpringEmbedderKK.h:251
ogdf::SpringEmbedderKK::m_ltolerance
double m_ltolerance
value for local stop criterion
Definition: SpringEmbedderKK.h:249
ogdf::SpringEmbedderKK::setMaxLocalIterations
void setMaxLocalIterations(int i)
Sets the number of local iterations to i.
Definition: SpringEmbedderKK.h:145
ogdf::SpringEmbedderKK::m_prevLEnergy
double m_prevLEnergy
local energy
Definition: SpringEmbedderKK.h:255
ogdf::SpringEmbedderKK::m_tolerance
double m_tolerance
The stop criterion when the forces of all strings are considered to be balanced.
Definition: SpringEmbedderKK.h:248
Array2D.h
Declaration and implementation of class Array2D which implements dynamic two dimensional arrays.
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::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::LayoutModule
Interface of general layout algorithms.
Definition: LayoutModule.h:44