Commit ca0d64e1 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

sfdp_layout(): Prevent Barnes-Hut tree from becoming unnecessarily dense

parent 65c9d1a9
Pipeline #94 failed with stage
...@@ -77,23 +77,41 @@ public: ...@@ -77,23 +77,41 @@ public:
return _dense_leafs; return _dense_leafs;
} }
size_t get_branch(Pos& p)
{
int i = p[0] > (_ll[0] + (_ur[0] - _ll[0]) / 2);
int j = p[1] > (_ll[1] + (_ur[1] - _ll[1]) / 2);
return i + 2 * j;
}
size_t put_pos(Pos& p, Weight w) size_t put_pos(Pos& p, Weight w)
{ {
_count += w; _count += w;
_cm[0] += p[0] * w; _cm[0] += p[0] * w;
_cm[1] += p[1] * w; _cm[1] += p[1] * w;
if (_max_level == 0) if (_max_level == 0 || _count == w)
{ {
_dense_leafs.push_back(std::make_tuple(p, w)); _dense_leafs.emplace_back(p, w);
return 1; return 1;
} }
else else
{ {
int i = p[0] > (_ll[0] + (_ur[0] - _ll[0]) / 2); if (!_dense_leafs.empty())
int j = p[1] > (_ll[1] + (_ur[1] - _ll[1]) / 2); {
// move dense leafs down
auto& leafs = get_leafs();
for (auto& leaf : _dense_leafs)
{
auto& lp = get<0>(leaf);
auto& lw = get<1>(leaf);
leafs[get_branch(lp)].put_pos(lp, lw);
}
_dense_leafs.clear();
}
size_t sc = (_max_level > 0 && _leafs.empty()) ? 4 : 0; size_t sc = (_max_level > 0 && _leafs.empty()) ? 4 : 0;
return sc + get_leafs()[i + 2 * j].put_pos(p, w); return sc + get_leafs()[get_branch(p)].put_pos(p, w);
} }
return 0; return 0;
} }
...@@ -214,7 +232,7 @@ struct get_sfdp_layout ...@@ -214,7 +232,7 @@ struct get_sfdp_layout
vector<vweight_t> group_size; vector<vweight_t> group_size;
vector<size_t> vertices; vector<size_t> vertices;
int HN=0; int HN = 0;
for (auto v : vertices_range(g)) for (auto v : vertices_range(g))
{ {
if (pin[v] == 0) if (pin[v] == 0)
...@@ -312,9 +330,9 @@ struct get_sfdp_layout ...@@ -312,9 +330,9 @@ struct get_sfdp_layout
auto& q = *Q.back(); auto& q = *Q.back();
Q.pop_back(); Q.pop_back();
if (q.max_level() == 0) auto& dleafs = q.get_dense_leafs();
if (!dleafs.empty())
{ {
auto& dleafs = q.get_dense_leafs();
for (auto& dleaf : dleafs) for (auto& dleaf : dleafs)
{ {
val_t d = get_diff(get<0>(dleaf), pos[v], diff); val_t d = get_diff(get<0>(dleaf), pos[v], diff);
......
...@@ -506,7 +506,7 @@ def coarse_graph_stack(g, c, coarse_stack, eweight=None, vweight=None, ...@@ -506,7 +506,7 @@ def coarse_graph_stack(g, c, coarse_stack, eweight=None, vweight=None,
def sfdp_layout(g, vweight=None, eweight=None, pin=None, groups=None, C=0.2, def sfdp_layout(g, vweight=None, eweight=None, pin=None, groups=None, C=0.2,
K=None, p=2., theta=0.6, max_level=11, gamma=1., mu=0., mu_p=1., K=None, p=2., theta=0.6, max_level=15, gamma=1., mu=0., mu_p=1.,
init_step=None, cooling_step=0.95, adaptive_cooling=True, init_step=None, cooling_step=0.95, adaptive_cooling=True,
epsilon=1e-2, max_iter=0, pos=None, multilevel=None, epsilon=1e-2, max_iter=0, pos=None, multilevel=None,
coarse_method="hybrid", mivs_thres=0.9, ec_thres=0.75, coarse_method="hybrid", mivs_thres=0.9, ec_thres=0.75,
...@@ -536,7 +536,7 @@ def sfdp_layout(g, vweight=None, eweight=None, pin=None, groups=None, C=0.2, ...@@ -536,7 +536,7 @@ def sfdp_layout(g, vweight=None, eweight=None, pin=None, groups=None, C=0.2,
Repulsive force exponent. Repulsive force exponent.
theta : float (optional, default: ``0.6``) theta : float (optional, default: ``0.6``)
Quadtree opening parameter, a.k.a. Barnes-Hut opening criterion. Quadtree opening parameter, a.k.a. Barnes-Hut opening criterion.
max_level : int (optional, default: ``11``) max_level : int (optional, default: ``15``)
Maximum quadtree level. Maximum quadtree level.
gamma : float (optional, default: ``1.0``) gamma : float (optional, default: ``1.0``)
Strength of the attractive force between connected components, or group Strength of the attractive force between connected components, or group
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment