Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

SpringEmbedderKK.h
Go to the documentation of this file.
1 
33 #pragma once
34 
36 #include <ogdf/basic/Array2D.h>
37 #include <ogdf/basic/tuples.h>
39 
40 namespace ogdf {
41 
43 
76 {
77 public:
79 
81  SpringEmbedderKK() : m_tolerance(0.001), m_ltolerance(0.0001), m_computeMaxIt(true),
82  m_K(5.0), m_desLength(0.0), m_distFactor(2.0), m_useLayout(true),
83  m_gItBaseVal(50), m_gItFactor(16)
84  {
85  m_maxLocalIt = m_maxGlobalIt = maxVal;
86  }
87 
90 
94  virtual void call(GraphAttributes& GA) override;
95 
99  void call(GraphAttributes& GA, const EdgeArray<double>& eLength);
100 
103  void setStopTolerance(double s) {m_tolerance = s;}
104 
106  void setUseLayout(bool b) {m_useLayout = b;}
107  bool useLayout() {return m_useLayout;}
108 
112  void setZeroLength(double d) {m_zeroLength = d;}
113  double zeroLength() {return m_zeroLength;}
114 
116  void setDesLength(double d) {m_desLength = d;}
117 
118 
122  int maxLocalIterations() const {
123  return m_maxLocalIt;
124  }
125  void setGlobalIterationFactor(int i) {if (i>0) m_gItFactor = i;}
126  int maxGlobalIterations() const {
127  return m_maxGlobalIt;
128  }
131  if (i>0)
132  m_maxGlobalIt = i;
133  }
135  void setMaxLocalIterations(int i) {
136  if (i>0)
137  m_maxLocalIt = i;
138  }
140  void computeMaxIterations(bool b)
141  {
142  m_computeMaxIt = b;
143  }
144 #if 0
145  //We could add some noise to the computation
146 
148  bool noise() const {
149  return m_noise;
150  }
151 
153  void noise(bool on) {
154  m_noise = on;
155  }
156 #endif
157 
158 protected:
160  void doCall(GraphAttributes& GA, const EdgeArray<double>& eLength, bool simpleBFS);
162  bool finished(double maxdelta)
163  {
164  if (m_prevEnergy == startVal) //first step
165  {
166  m_prevEnergy = maxdelta;
167  return false;
168  }
169 
170  double diff = m_prevEnergy - maxdelta; //energy difference
171  if (diff < 0.0) diff = -diff;
172 #if 0
173 #ifdef OGDF_DEBUG
174  cout << "Finished(): maxdelta: "<< maxdelta<<" diff/prev: "<<diff / m_prevEnergy<<"\n";
175 #endif
176 #endif
177  //check if we want to stop
178  bool done = (maxdelta < m_tolerance);// || (diff / m_prevEnergy) < m_tolerance);
179 
180  m_prevEnergy = maxdelta; //save previous energy level
181  m_prevLEnergy = startVal; //reset energy level for local node decision
182 
183  return done;
184  }//finished
186  bool finishedNode(double deltav)
187  {
188  if (m_prevLEnergy == startVal)
189  {
190  m_prevLEnergy = deltav;
191  return deltav == 0.0;//<m_ltolerance; //locally stable
192  }
193 #if 0
194 #ifdef OGDF_DEBUG
195  cout << "Local delta: "<<deltav<<"\n";
196 #endif
197 #endif
198  double diff = m_prevLEnergy - deltav;
199  //check if we want to stop
200  bool done = (deltav == 0.0 || (diff / m_prevLEnergy) < m_ltolerance);
201 
202  m_prevLEnergy = deltav; //save previous energy level
203 
204  return done;
205  }//finishedNode
208  void adaptLengths(const Graph& G,
209  const GraphAttributes& GA,
210  const EdgeArray<double>& eLengths,
211  EdgeArray<double>& adaptedLengths);
213  void shufflePositions(GraphAttributes& GA);
216  dpair computeParDer(node m,
217  node u,
218  GraphAttributes& GA,
220  NodeArray< NodeArray<double> >& dist);
222  dpair computeParDers(node v,
223  GraphAttributes& GA,
225  NodeArray< NodeArray<double> >& dist);
227  void initialize(GraphAttributes& GA,
228  NodeArray<dpair>& partialDer,
229  const EdgeArray<double>& eLength,
230  NodeArray< NodeArray<double> >& oLength,
231  NodeArray< NodeArray<double> >& sstrength,
232  bool simpleBFS);
234  void mainStep(GraphAttributes& GA,
235  NodeArray<dpair>& partialDer,
236  NodeArray< NodeArray<double> >& oLength,
237  NodeArray< NodeArray<double> >& sstrength);
240  void scale(GraphAttributes& GA);
241 
242 private:
245  double m_tolerance;
246  double m_ltolerance;
250  double m_K;
252  double m_prevEnergy;
254  double m_zeroLength;
255  double m_desLength;
257  double m_distFactor; //introduces some distance for scaling in case BFS is used
258 
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;
268 
269  double allpairsspBFS(const Graph& G, NodeArray< NodeArray<double> >& distance);
270  double allpairssp(const Graph& G, const EdgeArray<double>& eLengths,
271  NodeArray< NodeArray<double> >& distance, const double threshold = numeric_limits<double>::max());
272 };//SpringEmbedderKK
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 } // end namespace ogdf
void setZeroLength(double d)
If set != 0, value zerolength is used to determine the desirable edge length by L = zerolength / max ...
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
#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.
~SpringEmbedderKK()
Destructor.
static const double desMinLength
Defines minimum desired edge length.
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
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:423
Declaration of class GraphCopy Attributes which manages access on a copy of an attributed graph...
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:167
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...