Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

SpringEmbedderBase.h
Go to the documentation of this file.
1 
32 #pragma once
33 
38 #include <ogdf/basic/GraphCopy.h>
39 
40 namespace ogdf {
41 namespace spring_embedder {
42 
45 public:
47  enum class Scaling {
48  input,
52  };
53 
56  // default parameters
57  m_iterations = 400;
58  m_iterationsImprove = 200;
59  m_coolDownFactor = 0.999;
60  m_forceLimitStep = 0.25;
61 
62  m_boundingBox = DRect(0, 0, 250, 250);
63  m_noise = true;
64 
67 
70 
72  m_scaleFactor = 4.0;
73 
74  m_userBoundingBox = DRect(0, 0, 100, 100);
75 
77  m_pageRatio = 1.0;
78 
80 
81  double def_nw = LayoutStandards::defaultNodeWidth();
82  double def_nh = LayoutStandards::defaultNodeHeight();
83  m_idealEdgeLength = LayoutStandards::defaultNodeSeparation() + sqrt(def_nw*def_nw + def_nh*def_nh);
84  }
85 
86  virtual void call(GraphAttributes &GA) override {
87  const Graph &G = GA.constGraph();
88  if(G.empty())
89  return;
90 
91  // all edges straight-line
92  GA.clearAllBends();
93 
94  GraphCopy GC;
95  GC.createEmpty(G);
96 
97  // compute connected component of G
98  NodeArray<int> component(G);
99  int numCC = connectedComponents(G,component);
100 
101  // intialize the array of lists of nodes contained in a CC
102  Array<List<node> > nodesInCC(numCC);
103 
104  for(node v : G.nodes)
105  nodesInCC[component[v]].pushBack(v);
106 
107  EdgeArray<edge> auxCopy(G);
108  Array<DPoint> boundingBox(numCC);
109 
110  for(int i = 0; i < numCC; ++i)
111  {
112  GC.initByNodes(nodesInCC[i],auxCopy);
114 
115  const int n = GC.numberOfNodes();
116 
117  // special case: just one node
118  if(n == 1) {
119  node vOrig = GC.original(GC.firstNode());
120  GA.x(vOrig) = GA.y(vOrig) = 0;
121  boundingBox[i] = DPoint(0,0);
122  continue;
123  }
124 
125  callMaster(GC, GA, boundingBox[i]);
126  //std::cout << "avg. force: " << master.avgDisplacement() << std::endl;
127  //std::cout << "max. force: " << master.maxDisplacement() << std::endl;
128  }
129 
130  Array<DPoint> offset(numCC);
131  TileToRowsCCPacker packer;
132  packer.call(boundingBox,offset,m_pageRatio);
133 
134  // The arrangement is given by offset to the origin of the coordinate
135  // system. We still have to shift each node and edge by the offset
136  // of its connected component.
137 
138  for(int i = 0; i < numCC; ++i)
139  {
140  const List<node> &nodes = nodesInCC[i];
141 
142  const double dx = offset[i].m_x;
143  const double dy = offset[i].m_y;
144 
145  // iterate over all nodes in ith CC
147  for(node v : nodes) {
148  GA.x(v) += dx;
149  GA.y(v) += dy;
150  }
151  }
152  }
153 
156  return m_forceModel;
157  }
158 
161  m_forceModel = fm;
162  }
163 
166  return m_forceModelImprove;
167  }
168 
171  m_forceModelImprove = fm;
172  }
173 
175 
180  double avgConvergenceFactor() const {
181  return m_avgConvergenceFactor;
182  }
183 
185  void avgConvergenceFactor(double f) {
186  if(f >= 0)
188  }
189 
191 
196  double maxConvergenceFactor() const {
197  return m_maxConvergenceFactor;
198  }
199 
201  void maxConvergenceFactor(double f) {
202  if(f >= 0)
204  }
205 
207 
211  int iterations() const {
212  return m_iterations;
213  }
214 
216  void iterations(int i) {
217  if (i >= 0)
218  m_iterations = i;
219  }
220 
222  int iterationsImprove() const {
223  return m_iterationsImprove;
224  }
225 
227  void iterationsImprove(int i) {
228  if (i >= 0)
230  }
231 
232  double coolDownFactor() const {
233  return m_coolDownFactor;
234  }
235 
236  double forceLimitStep() const {
237  return m_forceLimitStep;
238  }
239 
241  double idealEdgeLength() const {
242  return m_idealEdgeLength;
243  }
244 
246 
250  void idealEdgeLength(double len) {
251  m_idealEdgeLength = len;
252  }
253 
255  bool noise() const {
256  return m_noise;
257  }
258 
260  void noise(bool on) {
261  m_noise = on;
262  }
263 
265  double minDistCC() const { return m_minDistCC; }
266 
268  void minDistCC(double x) { m_minDistCC = x; }
269 
271  double pageRatio() { return m_pageRatio; }
272 
274  void pageRatio(double x) { m_pageRatio = x; }
275 
277  Scaling scaling() const {
278  return m_scaling;
279  }
280 
282  void scaling(Scaling sc) {
283  m_scaling = sc;
284  }
285 
287  double scaleFunctionFactor() const {
288  return m_scaleFactor;
289  }
290 
292  void scaleFunctionFactor(double f) {
293  m_scaleFactor = f;
294  }
295 
297  void userBoundingBox(double xmin, double ymin, double xmax, double ymax) {
298  m_userBoundingBox = DRect(xmin, ymin, xmax, ymax);
299  }
300 
303  return m_userBoundingBox;
304  }
305 
307  unsigned int maxThreads() const { return m_maxThreads; }
308 
310  void maxThreads(unsigned int n) { m_maxThreads = n; }
311 
312 protected:
313  virtual void callMaster(const GraphCopy& copy, GraphAttributes& attr, DPoint& box) = 0;
314 
320 
322 
325  bool m_noise;
326 
328  double m_scaleFactor;
329 
331 
332  double m_minDistCC;
333  double m_pageRatio;
334 
337 
338  unsigned int m_maxThreads;
339 };
340 
341 }}
static double defaultNodeWidth()
Returns the global default width for nodes.
double m_idealEdgeLength
The ideal edge length.
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:200
Common base class for ogdf::SpringEmbedderBase and ogdf::SpringEmbedderGridVariant.
void initByNodes(const List< node > &origNodes, EdgeArray< edge > &eCopy)
Initializes the graph copy for the nodes in a component.
double m_scaleFactor
The factor used if scaling type is scScaleFunction.
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
GenericPoint< double > DPoint
Representing two-dimensional point with real coordinates.
Definition: geometry.h:244
void maxThreads(unsigned int n)
Sets the maximal number of used threads to n.
virtual void call(Array< DPoint > &box, Array< DPoint > &offset, double pageRatio=1.0) override
Arranges the rectangles given by box.
int iterations() const
Returns the current setting of iterations.
SpringForceModel forceModelImprove() const
Returns the currently used force model for the improvement step.
static double defaultCCSeparation()
Returns the global default separation between connected components.
void maxConvergenceFactor(double f)
Sets the maximum convergence factor to f.
Rectangles with real coordinates.
Definition: geometry.h:815
node firstNode() const
Returns the first node in the list of all nodes.
Definition: Graph_d.h:618
void createEmpty(const Graph &G)
Associates the graph copy with G, but does not create any nodes or edges.
void iterations(int i)
Sets the number of iterations to i.
SpringForceModel m_forceModelImprove
The used force model.
virtual void callMaster(const GraphCopy &copy, GraphAttributes &attr, DPoint &box)=0
double maxConvergenceFactor() const
Returns the currently used maximum convergence factor.
void noise(bool on)
Sets the parameter noise to on.
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
int m_iterations
The number of iterations.
int connectedComponents(const Graph &G, NodeArray< int > &component, List< node > *isolated=nullptr)
Computes the connected components of G and optionally generates a list of isolated nodes...
void iterationsImprove(int i)
Sets the number of iterations for the improvement phase to i.
void makeSimpleUndirected(Graph &G)
Removes all self-loops and all but one edge of each bundle of undirected parallel edges...
void idealEdgeLength(double len)
Sets the ideal edge length to len.
void forceModelImprove(SpringForceModel fm)
Sets the used force model for the improvement step to fm.
void pageRatio(double x)
Sets the page ration to x.
The tile-to-rows algorithm for packing drawings of connected components.
void avgConvergenceFactor(double f)
Sets the average convergence factor to f.
double y(node v) const
Returns the y-coordinate of node v.
void forceModel(SpringForceModel fm)
Sets the used force model to fm.
double pageRatio()
Returns the page ratio.
void userBoundingBox(double xmin, double ymin, double xmax, double ymax)
Sets the user bounding box (used if scaling method is scUserBoundingBox).
static void copy(const T &from, T &to)
Definition: Alg.h:61
Stores additional attributes of a graph (like layout information).
double scaleFunctionFactor() const
Returns the current scale function factor.
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
int iterationsImprove() const
Returns the current setting of iterations for the improvement phase.
Declaration of graph copy classes.
void scaling(Scaling sc)
Sets the method for scaling the inital layout to sc.
unsigned int m_maxThreads
The maximal number of used threads.
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
double x(node v) const
Returns the x-coordinate of node v.
Declaration of interface for layout algorithms (class LayoutModule)
static int numberOfProcessors()
Returns the number of processors (cores) available on the current system.
Definition: System.h:276
Declaration of class TileToRowsCCPacker.
Class for the representation of nodes.
Definition: Graph_d.h:169
const Graph & constGraph() const
Returns a reference to the associated graph.
double m_avgConvergenceFactor
convergence if avg.
Encapsulates a pointer to a list element.
Definition: List.h:42
double m_maxConvergenceFactor
convergence if max.
use the given ideal edge length to scale the layout suitably.
Interface of general layout algorithms.
Definition: LayoutModule.h:44
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:286
the force model proposed by Fruchterman and Reingold.
SpringForceModel
The force model used for computing forces on nodes.
static double defaultNodeSeparation()
Returns the global default node separation.
virtual void call(GraphAttributes &GA) override
Computes a layout of graph GA.
int m_iterationsImprove
The number of iterations for the improvement phase.
Scaling
The scaling method used by the algorithm.
static double defaultNodeHeight()
Returns the global default height for nodes.
double idealEdgeLength() const
Returns the current setting of ideal edge length.
unsigned int maxThreads() const
Returns the maximal number of used threads.
Declaration of simple graph algorithms.
bounding box set by userBoundingBox() is used.
SpringForceModel forceModel() const
Returns the currently used force model.
The namespace for all OGDF objects.
void minDistCC(double x)
Sets the minimum distance between connected components to x.
void clearAllBends()
Removes all edge bends.
bool m_noise
The used force model for the improvement phase.
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition: Graph_d.h:598
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:565
double avgConvergenceFactor() const
Returns the currently used average convergence factor.
DRect userBoundingBox() const
Gets the user bounding box.
Declaration of SpringForceModel enumeration.
automatic scaling is used with parameter set by scaleFunctionFactor() (larger factor, larger b-box).
bool empty() const
Returns true iff the graph is empty, i.e., contains no nodes.
Definition: Graph_d.h:595
bool noise() const
Returns the current setting of noise.
Scaling scaling() const
Returns the current scaling method.
double m_minDistCC
The minimal distance between connected components.
double minDistCC() const
Returns the minimum distance between connected components.
void scaleFunctionFactor(double f)
Sets the scale function factor to f.