Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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