Commit 29970a2f authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix issue in sfdp_layout() with vertices with self-loops

parent 7b263944
......@@ -99,17 +99,12 @@ struct do_propagate_pos
unordered_map<c_t, pos_t, boost::hash<c_t> >
cmap(num_vertices(*cg));
typename graph_traits<CoarseGraph>::vertex_iterator vi, vi_end;
for(tie(vi, vi_end) = vertices(*cg); vi != vi_end; ++vi)
{
typename graph_traits<CoarseGraph>::vertex_descriptor v = *vi;
for (auto v : vertices_range(*cg))
cmap[cvmap[v]] = cpos[v];
}
typename graph_traits<Graph>::vertex_iterator gvi, gvi_end;
for(tie(gvi, gvi_end) = vertices(g); gvi != gvi_end; ++gvi)
for (auto v : vertices_range(g))
{
typename graph_traits<Graph>::vertex_descriptor v = *gvi;
pos[v] = cmap[vmap[v]];
if (delta > 0)
......@@ -162,23 +157,21 @@ struct do_propagate_pos_mivs
uniform_real_distribution<val_t> noise(-delta, delta);
typename graph_traits<Graph>::vertex_iterator vi, vi_end;
for(tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
for (auto v : vertices_range(g))
{
typename graph_traits<Graph>::vertex_descriptor v = *vi;
if (mivs[v])
continue;
pos[v].resize(2);
pos[v][0] = pos[v][1] = 0;
size_t count = 0;
typename graph_traits<Graph>::adjacency_iterator a, a_end;
for(tie(a, a_end) = adjacent_vertices(v, g); a != a_end; ++a)
for (auto a : adjacent_vertices_range(v, g))
{
if (!mivs[*a])
if (!mivs[a])
continue;
pos[*a].resize(2, 0);
pos[a].resize(2, 0);
for (size_t j = 0; j < pos[v].size(); ++j)
pos[v][j] += pos[*a][j];
pos[v][j] += pos[a][j];
++count;
}
......@@ -232,14 +225,14 @@ struct do_avg_dist
vertex(i, g);
if (v == graph_traits<Graph>::null_vertex())
continue;
typename graph_traits<Graph>::adjacency_iterator a, a_end;
for(tie(a, a_end) = adjacent_vertices(v, g); a != a_end; ++a)
for (auto a : adjacent_vertices_range(v, g))
{
d += dist(pos[v], pos[*a]);
d += dist(pos[v], pos[a]);
count++;
}
}
d /= count;
if (count > 0)
d /= count;
ad = d;
}
};
......
......@@ -288,8 +288,7 @@ struct get_sfdp_layout
reduction(+:E, delta, nmoves) schedule(static) if (N > 100)
for (i = 0; i < N; ++i)
{
typename graph_traits<Graph>::vertex_descriptor v =
vertex(vertices[i], g);
auto v = vertex(vertices[i], g);
pos_t diff(2, 0), pos_u(2, 0), ftot(2, 0), cm(2, 0);
......@@ -298,13 +297,12 @@ struct get_sfdp_layout
Q.push_back(std::ref(qt));
while (!Q.empty())
{
QuadTree<pos_t, vweight_t>& q = Q.back();
auto& q = Q.back().get();
Q.pop_back();
if (q.max_level() == 0)
{
vector<std::tuple<pos_t,vweight_t> >& dleafs =
q.get_dense_leafs();
auto& dleafs = q.get_dense_leafs();
for(size_t j = 0; j < dleafs.size(); ++j)
{
val_t d = get_diff(get<0>(dleafs[j]), pos[v],
......@@ -326,7 +324,7 @@ struct get_sfdp_layout
{
for(size_t j = 0; j < 4; ++j)
{
QuadTree<pos_t, vweight_t>& leaf = q.get_leaf(j);
auto& leaf = q.get_leaf(j);
if (leaf.get_count() > 0)
Q.push_back(std::ref(leaf));
}
......@@ -345,21 +343,18 @@ struct get_sfdp_layout
}
// local attractive forces
typename graph_traits<Graph>::out_edge_iterator e, e_end;
for (tie(e,e_end) = out_edges(v, g); e != e_end; ++e)
for (auto e : out_edges_range(v, g))
{
typename graph_traits<Graph>::vertex_descriptor u =
target(*e, g);
auto u = target(e, g);
if (u == v)
continue;
#pragma omp critical
{
for (size_t l = 0; l < 2; ++l)
pos_u[l] = pos[u][l];
pos_u = pos[u];
}
get_diff(pos_u, pos[v], diff);
val_t f = f_a(K, pos_u, pos[v]);
f *= get(eweight, *e) * get(vweight, u) * get(vweight, v);
f *= get(eweight, e) * get(vweight, u) * get(vweight, v);
for (size_t l = 0; l < 2; ++l)
ftot[l] += f * diff[l];
}
......
......@@ -392,7 +392,7 @@ def _propagate_pos(g, cg, c, cc, cpos, delta, mivs):
def _avg_edge_distance(g, pos):
libgraph_tool_layout.sanitize_pos(g._Graph__graph, _prop("v", g, pos))
ad = libgraph_tool_layout.avg_dist(g._Graph__graph, _prop("v", g, pos))
if numpy.isnan(ad):
if numpy.isnan(ad) or ad == 0:
ad = 1.
return ad
......
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