Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

MasterBase.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/GraphCopy.h>
36 #include <ogdf/basic/Barrier.h>
38 
39 namespace ogdf {
40 namespace spring_embedder {
41 
43 template<typename NodeInfo, typename ForceModelBase>
44 class MasterBase {
45 protected:
47  const GraphCopy &m_gc;
50 
55 
56  ForceModelBase *m_forceModel;
57  ForceModelBase *m_forceModelImprove;
58 
60 
62 
63  double m_tNull;
64  double m_cF;
65  double m_t;
67 
70  double m_scaleFactor;
71 
72 public:
73  MasterBase(const SpringEmbedderBase &spring, const GraphCopy &gc, GraphAttributes &ga, DPoint &boundingBox)
74  : m_spring(spring)
75  , m_gc(gc)
76  , m_ga(ga)
77  , m_boundingBox(boundingBox)
78  , m_index(gc)
79  , m_vInfo(gc.numberOfNodes())
80  , m_disp(gc.numberOfNodes())
81  , m_adjLists(2*gc.numberOfEdges())
82  , m_forceModel(nullptr)
83  , m_forceModelImprove(nullptr)
84  , m_barrier(nullptr)
85  , m_avgDisplacement(std::numeric_limits<double>::max())
86  , m_maxDisplacement(std::numeric_limits<double>::max())
87  {
88  }
89 
91  {
92  delete m_barrier;
93  delete m_forceModel;
94  delete m_forceModelImprove;
95  }
96 
97  int numberOfNodes() const { return m_vInfo.size(); }
98  int numberOfIterations() const { return m_spring.iterations(); }
99  int numberOfIterationsImprove() const { return m_spring.iterationsImprove(); }
100 
102  {
103  // cool down
104  m_t = m_tNull = 0.25 * m_idealEdgeLength * sqrt(numberOfNodes());
105  m_cF = 2.0;
106  m_coolingFactor = m_spring.coolDownFactor();
107 
108  // convergence
109  m_avgDisplacement = std::numeric_limits<double>::max();
110  m_maxDisplacement = std::numeric_limits<double>::max();
111  }
112 
114  {
115  // cool down
116  m_t = m_tNull;
117  m_cF = 2.0;
118  m_coolingFactor = m_spring.coolDownFactor();
119 
120  // convergence
121  m_avgDisplacement = std::numeric_limits<double>::max();
122  m_maxDisplacement = std::numeric_limits<double>::max();
123  }
124 
125  void coolDown()
126  {
127  m_cF += m_spring.forceLimitStep();
128  m_t = m_tNull / std::log2(m_cF);
129 
130  m_coolingFactor *= m_spring.coolDownFactor();
131  }
132 
133  double maxForceLength() const { return m_t; }
134  double coolingFactor() const { return m_coolingFactor; }
135 
136  double idealEdgeLength() const { return m_idealEdgeLength; }
137  bool noise() const { return m_spring.noise(); }
138 
139  const GraphCopy &getGraph() const { return m_gc; }
141 
142  const NodeArray<int> &index() const { return m_index; }
144  Array<DPoint> &disp() { return m_disp; }
146 
147  const ForceModelBase &forceModel() const { return *m_forceModel; }
148  const ForceModelBase &forceModelImprove() const { return *m_forceModelImprove; }
149 
150  void syncThreads() {
151  if(m_barrier)
152  m_barrier->threadSync();
153  }
154 
155  double scaleFactor() const { return m_scaleFactor; }
156 
157  bool hasConverged() const {
158  return m_avgDisplacement <= m_spring.avgConvergenceFactor() * m_idealEdgeLength
159  && m_maxDisplacement <= m_spring.maxConvergenceFactor() * m_idealEdgeLength;
160  }
161 
162  double avgDisplacement() const { return m_avgDisplacement; }
163  double maxDisplacement() const { return m_maxDisplacement; }
164 };
165 
166 }
167 }
const ForceModelBase & forceModelImprove() const
Definition: MasterBase.h:148
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Common base class for ogdf::SpringEmbedderBase and ogdf::SpringEmbedderGridVariant.
Array< NodeInfo > & vInfo()
Definition: MasterBase.h:143
int iterations() const
Returns the current setting of iterations.
Definition: GML.h:110
double maxConvergenceFactor() const
Returns the currently used maximum convergence factor.
Representation of a barrier.
Definition: Barrier.h:50
void threadSync()
Synchronizes the threads in the group.
Definition: Barrier.h:72
const NodeArray< int > & index() const
Definition: MasterBase.h:142
Implementation of a thread barrier.
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:282
Stores additional attributes of a graph (like layout information).
T log2(T x)
Returns the logarithm of x to the base 2.
Definition: Math.h:110
int iterationsImprove() const
Returns the current setting of iterations for the improvement phase.
Declaration of graph copy classes.
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
const SpringEmbedderBase & m_spring
Definition: MasterBase.h:46
const GraphCopy & getGraph() const
Definition: MasterBase.h:139
const ForceModelBase & forceModel() const
Definition: MasterBase.h:147
MasterBase(const SpringEmbedderBase &spring, const GraphCopy &gc, GraphAttributes &ga, DPoint &boundingBox)
Definition: MasterBase.h:73
GraphAttributes & getAttributes()
Definition: MasterBase.h:140
The namespace for all OGDF objects.
Declaration and definition of ogdf::SpringEmbedderBase.
double avgConvergenceFactor() const
Returns the currently used average convergence factor.
ForceModelBase * m_forceModelImprove
Definition: MasterBase.h:57
bool noise() const
Returns the current setting of noise.
Base class for ogdf::SpringEmbedderGridVariant::Master.
Definition: MasterBase.h:44