Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

MasterBase.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Array.h>
35 #include <ogdf/basic/Barrier.h>
36 #include <ogdf/basic/Graph.h>
37 #include <ogdf/basic/GraphCopy.h>
38 #include <ogdf/basic/geometry.h>
40 
41 #include <cmath>
42 #include <limits>
43 
44 namespace ogdf {
45 class GraphAttributes;
46 
47 namespace spring_embedder {
48 
50 template<typename NodeInfo, typename ForceModelBase>
51 class MasterBase {
52 protected:
54  const GraphCopy& m_gc;
57 
62 
63  ForceModelBase* m_forceModel;
64  ForceModelBase* m_forceModelImprove;
65 
67 
69 
70  double m_tNull;
71  double m_cF;
72  double m_t;
74 
77  double m_scaleFactor;
78 
79 public:
80  MasterBase(const SpringEmbedderBase& spring, const GraphCopy& gc, GraphAttributes& ga,
81  DPoint& boundingBox)
82  : m_spring(spring)
83  , m_gc(gc)
84  , m_ga(ga)
85  , m_boundingBox(boundingBox)
86  , m_index(gc)
87  , m_vInfo(gc.numberOfNodes())
88  , m_disp(gc.numberOfNodes())
89  , m_adjLists(2 * gc.numberOfEdges())
90  , m_forceModel(nullptr)
91  , m_forceModelImprove(nullptr)
92  , m_barrier(nullptr)
93  , m_avgDisplacement(std::numeric_limits<double>::max())
94  , m_maxDisplacement(std::numeric_limits<double>::max()) { }
95 
97  delete m_barrier;
98  delete m_forceModel;
99  delete m_forceModelImprove;
100  }
101 
102  int numberOfNodes() const { return m_vInfo.size(); }
103 
104  int numberOfIterations() const { return m_spring.iterations(); }
105 
107 
109  // cool down
110  m_t = m_tNull = 0.25 * m_idealEdgeLength * sqrt(numberOfNodes());
111  m_cF = 2.0;
113 
114  // convergence
115  m_avgDisplacement = std::numeric_limits<double>::max();
116  m_maxDisplacement = std::numeric_limits<double>::max();
117  }
118 
120  // cool down
121  m_t = m_tNull;
122  m_cF = 2.0;
124 
125  // convergence
126  m_avgDisplacement = std::numeric_limits<double>::max();
127  m_maxDisplacement = std::numeric_limits<double>::max();
128  }
129 
130  void coolDown() {
132  m_t = m_tNull / std::log2(m_cF);
133 
135  }
136 
137  double maxForceLength() const { return m_t; }
138 
139  double coolingFactor() const { return m_coolingFactor; }
140 
141  double idealEdgeLength() const { return m_idealEdgeLength; }
142 
143  bool noise() const { return m_spring.noise(); }
144 
145  const GraphCopy& getGraph() const { return m_gc; }
146 
148 
149  const NodeArray<int>& index() const { return m_index; }
150 
152 
153  Array<DPoint>& disp() { return m_disp; }
154 
156 
157  const ForceModelBase& forceModel() const { return *m_forceModel; }
158 
159  const ForceModelBase& forceModelImprove() const { return *m_forceModelImprove; }
160 
161  void syncThreads() {
162  if (m_barrier) {
164  }
165  }
166 
167  double scaleFactor() const { return m_scaleFactor; }
168 
169  bool hasConverged() const {
172  }
173 
174  double avgDisplacement() const { return m_avgDisplacement; }
175 
176  double maxDisplacement() const { return m_maxDisplacement; }
177 };
178 
179 }
180 }
ogdf::spring_embedder::SpringEmbedderBase::coolDownFactor
double coolDownFactor() const
Definition: SpringEmbedderBase.h:235
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:72
ogdf::spring_embedder::SpringEmbedderBase::noise
bool noise() const
Returns the current setting of noise.
Definition: SpringEmbedderBase.h:250
Graph.h
Includes declaration of graph class.
ogdf::GenericPoint
Parameterized base class for points.
Definition: geometry.h:81
ogdf::spring_embedder::MasterBase::disp
Array< DPoint > & disp()
Definition: MasterBase.h:153
ogdf::spring_embedder::MasterBase::avgDisplacement
double avgDisplacement() const
Definition: MasterBase.h:174
geometry.h
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
ogdf::spring_embedder::MasterBase::initImprovementPhase
void initImprovementPhase()
Definition: MasterBase.h:119
ogdf::spring_embedder::MasterBase::m_idealEdgeLength
double m_idealEdgeLength
Definition: MasterBase.h:68
ogdf::spring_embedder::MasterBase::hasConverged
bool hasConverged() const
Definition: MasterBase.h:169
ogdf::spring_embedder::MasterBase::m_spring
const SpringEmbedderBase & m_spring
Definition: MasterBase.h:53
ogdf::spring_embedder::MasterBase::getGraph
const GraphCopy & getGraph() const
Definition: MasterBase.h:145
ogdf::spring_embedder::MasterBase::m_index
NodeArray< int > m_index
Definition: MasterBase.h:58
ogdf::spring_embedder::SpringEmbedderBase::maxConvergenceFactor
double maxConvergenceFactor() const
Returns the currently used maximum convergence factor.
Definition: SpringEmbedderBase.h:202
ogdf::spring_embedder::MasterBase::coolDown
void coolDown()
Definition: MasterBase.h:130
ogdf::spring_embedder::MasterBase::coolingFactor
double coolingFactor() const
Definition: MasterBase.h:139
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::spring_embedder::MasterBase::getAttributes
GraphAttributes & getAttributes()
Definition: MasterBase.h:147
ogdf::spring_embedder::MasterBase::maxForceLength
double maxForceLength() const
Definition: MasterBase.h:137
ogdf::spring_embedder::MasterBase::m_scaleFactor
double m_scaleFactor
Definition: MasterBase.h:77
ogdf::spring_embedder::SpringEmbedderBase
Common base class for ogdf::SpringEmbedderBase and ogdf::SpringEmbedderGridVariant.
Definition: SpringEmbedderBase.h:54
ogdf::spring_embedder::MasterBase::m_tNull
double m_tNull
Definition: MasterBase.h:70
ogdf::spring_embedder::SpringEmbedderBase::avgConvergenceFactor
double avgConvergenceFactor() const
Returns the currently used average convergence factor.
Definition: SpringEmbedderBase.h:187
ogdf::spring_embedder::MasterBase::MasterBase
MasterBase(const SpringEmbedderBase &spring, const GraphCopy &gc, GraphAttributes &ga, DPoint &boundingBox)
Definition: MasterBase.h:80
ogdf::spring_embedder::MasterBase::maxDisplacement
double maxDisplacement() const
Definition: MasterBase.h:176
ogdf::spring_embedder::MasterBase::vInfo
Array< NodeInfo > & vInfo()
Definition: MasterBase.h:151
ogdf::spring_embedder::MasterBase::m_forceModel
ForceModelBase * m_forceModel
Definition: MasterBase.h:63
ogdf::spring_embedder::MasterBase::forceModelImprove
const ForceModelBase & forceModelImprove() const
Definition: MasterBase.h:159
ogdf::spring_embedder::MasterBase::m_forceModelImprove
ForceModelBase * m_forceModelImprove
Definition: MasterBase.h:64
ogdf::spring_embedder::MasterBase::m_barrier
Barrier * m_barrier
Definition: MasterBase.h:66
Barrier.h
Implementation of a thread barrier.
ogdf::spring_embedder::MasterBase::m_avgDisplacement
double m_avgDisplacement
Definition: MasterBase.h:75
ogdf::Array< NodeInfo >
ogdf::spring_embedder::MasterBase::adjLists
Array< int > & adjLists()
Definition: MasterBase.h:155
ogdf::spring_embedder::MasterBase::noise
bool noise() const
Definition: MasterBase.h:143
ogdf::spring_embedder::MasterBase::m_cF
double m_cF
Definition: MasterBase.h:71
ogdf::spring_embedder::MasterBase::numberOfIterationsImprove
int numberOfIterationsImprove() const
Definition: MasterBase.h:106
ogdf::spring_embedder::MasterBase
Base class for ogdf::SpringEmbedderGridVariant::Master.
Definition: MasterBase.h:51
GraphCopy.h
Declaration of graph copy classes.
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::spring_embedder::MasterBase::initUnfoldPhase
void initUnfoldPhase()
Definition: MasterBase.h:108
ogdf::Barrier::threadSync
void threadSync()
Synchronizes the threads in the group.
Definition: Barrier.h:68
ogdf::spring_embedder::MasterBase::m_gc
const GraphCopy & m_gc
Definition: MasterBase.h:54
ogdf::Barrier
Representation of a barrier.
Definition: Barrier.h:48
ogdf::spring_embedder::MasterBase::idealEdgeLength
double idealEdgeLength() const
Definition: MasterBase.h:141
ogdf::spring_embedder::SpringEmbedderBase::iterationsImprove
int iterationsImprove() const
Returns the current setting of iterations for the improvement phase.
Definition: SpringEmbedderBase.h:226
ogdf::spring_embedder::MasterBase::m_ga
GraphAttributes & m_ga
Definition: MasterBase.h:55
ogdf::spring_embedder::MasterBase::m_maxDisplacement
double m_maxDisplacement
Definition: MasterBase.h:76
std
Definition: GML.h:111
ogdf::Math::log2
T log2(T x)
Returns the logarithm of x to the base 2.
Definition: Math.h:111
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::spring_embedder::MasterBase::m_disp
Array< DPoint > m_disp
Definition: MasterBase.h:60
ogdf::spring_embedder::SpringEmbedderBase::forceLimitStep
double forceLimitStep() const
Definition: SpringEmbedderBase.h:237
ogdf::Array::size
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:302
ogdf::spring_embedder::MasterBase::scaleFactor
double scaleFactor() const
Definition: MasterBase.h:167
ogdf::spring_embedder::MasterBase::m_adjLists
Array< int > m_adjLists
Definition: MasterBase.h:61
ogdf::spring_embedder::MasterBase::numberOfIterations
int numberOfIterations() const
Definition: MasterBase.h:104
ogdf::spring_embedder::MasterBase::m_coolingFactor
double m_coolingFactor
Definition: MasterBase.h:73
ogdf::spring_embedder::MasterBase::m_t
double m_t
Definition: MasterBase.h:72
ogdf::spring_embedder::SpringEmbedderBase::iterations
int iterations() const
Returns the current setting of iterations.
Definition: SpringEmbedderBase.h:216
ogdf::spring_embedder::MasterBase::m_boundingBox
DPoint & m_boundingBox
Definition: MasterBase.h:56
SpringEmbedderBase.h
Declaration and definition of ogdf::SpringEmbedderBase.
ogdf::spring_embedder::MasterBase::syncThreads
void syncThreads()
Definition: MasterBase.h:161
ogdf::spring_embedder::MasterBase::index
const NodeArray< int > & index() const
Definition: MasterBase.h:149
ogdf::spring_embedder::MasterBase::numberOfNodes
int numberOfNodes() const
Definition: MasterBase.h:102
ogdf::spring_embedder::MasterBase::~MasterBase
~MasterBase()
Definition: MasterBase.h:96
ogdf::spring_embedder::MasterBase::m_vInfo
Array< NodeInfo > m_vInfo
Definition: MasterBase.h:59
ogdf::spring_embedder::MasterBase::forceModel
const ForceModelBase & forceModel() const
Definition: MasterBase.h:157