108 for (
node v = G.firstNode(); v; v = v->succ()) {
109 GA.
x(v) = coords[v].coords[0];
110 GA.
y(v) = coords[v].coords[1];
131 for (
node v = G.firstNode(); v; v = v->succ()) {
132 GA.
x(v) = coords[v].coords[0];
133 GA.
y(v) = coords[v].coords[1];
134 GA.
z(v) = coords[v].coords[2];
141 using namespace energybased::dtree;
142 using Embedder = DTreeEmbedder<Dim>;
145 resultCoords.
init(graph);
151 GalaxyLevel levelBegin(graph);
154 GalaxyLevel* pLevelEnd = levelBegin.buildLevelsUntil(m_levelMaxNumNodes);
160 double currNumIterations = m_numIterationsFinestLevel;
161 double currThreshold = m_thresholdFinestLevel;
164 for (GalaxyLevel* pCurrLevel = &levelBegin; pCurrLevel !=
nullptr;
165 pCurrLevel = pCurrLevel->nextCoarser()) {
166 currNumIterations *= m_numIterationsFactorPerLevel;
167 currThreshold *= m_thresholdFactorPerLevel;
171 for (GalaxyLevel* pCurrLevel = pLevelEnd; pCurrLevel; pCurrLevel = pCurrLevel->nextFiner()) {
172 currNumIterations /= m_numIterationsFactorPerLevel;
173 currThreshold /= m_thresholdFactorPerLevel;
176 Embedder embedder(pCurrLevel->graph());
179 if (pCurrLevel->isCoarsestLevel()) {
181 for (
node v = pCurrLevel->graph().firstNode(); v; v = v->
succ()) {
183 for (
int d = 0; d < Dim; d++) {
190 for (
node v = pCurrLevel->graph().firstNode(); v; v = v->
succ()) {
192 node v_parent = pCurrLevel->parent(v);
195 for (
int d = 0; d < Dim; d++) {
197 double offset = parentPosition[v_parent].coords[d] * m_scaleFactorPerLevel;
200 embedder.setPosition(v, d, offset +
randomDouble(-1.0, 1.0));
206 if (m_useMultilevelWeights) {
208 for (
node v = pCurrLevel->graph().firstNode(); v; v = v->
succ()) {
209 embedder.setMass(v, pCurrLevel->weight(v));
212 for (
edge e = pCurrLevel->graph().firstEdge(); e; e = e->
succ()) {
213 embedder.setEdgeWeight(e, pCurrLevel->edgeWeight(e));
217 const int numIterationsMaybe =
218 pCurrLevel->isCoarsestLevel() ? m_numIterationsCoarsestLevel : currNumIterations;
219 const int numIterations = std::min(std::max(m_minIterationsPerLevel, numIterationsMaybe),
220 m_maxIterationsPerLevel);
222 embedder.scaleNodes(3.0);
223 embedder.doIterationsNewton(numIterations, currThreshold, RepForceFunctionNewton<Dim, 1>,
224 AttrForceFunctionPow<Dim, 2>);
225 embedder.scaleNodes(1.0 / 3.0);
226 embedder.doIterationsNewton(numIterations, currThreshold, RepForceFunctionNewton<Dim, 2>,
227 AttrForceFunctionPow<Dim, 2>);
231 parentPosition.
init(pCurrLevel->graph());
234 for (
node v = pCurrLevel->graph().firstNode(); v; v = v->
succ()) {
236 for (
int d = 0; d < Dim; d++) {
237 parentPosition[v].coords[d] = embedder.position(v, d);