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

fix extended clustering when graph has parallel edges


git-svn-id: https://svn.forked.de/graph-tool/trunk@37 d4600afd-f417-0410-95de-beed9576f240
parent 8f495045
......@@ -42,10 +42,7 @@ struct single_vertex_filter
single_vertex_filter() {}
single_vertex_filter(Vertex v):_v(v) {}
bool operator()(Vertex v) const
{
return v != _v;
}
bool operator()(Vertex v) const { return v != _v; }
Vertex _v;
};
......@@ -101,9 +98,7 @@ public:
typename Container::iterator val;
val = _base_map->find(k);
if (val == _base_map->end())
{
val = _base_map->insert(make_pair(k, _default)).first;
}
return val->second;
}
......@@ -147,17 +142,23 @@ struct get_extended_clustering
typedef DescriptorHash<IndexMap> hasher_t;
typedef tr1::unordered_set<typename graph_traits<Graph>::vertex_descriptor,hasher_t> neighbour_set_t;
neighbour_set_t neighbours(0, hasher_t(vertex_index));
neighbour_set_t neighbours2(0, hasher_t(vertex_index));
neighbour_set_t targets(0, hasher_t(vertex_index));
// collect the neighbours
// collect the targets
typename graph_traits<Graph>::adjacency_iterator a, a_end;
for(tie(a, a_end) = adjacent_vertices(*v, g); a != a_end; ++a)
if (*a != *v) // no self-loops
neighbours.insert(*a);
size_t k = neighbours.size();
targets.insert(*a);
size_t k = targets.size();
// And now we setup and start the BFS bonanza
for(tie(a, a_end) = adjacent_vertices(*v, g); a != a_end; ++a)
{
if (neighbours.find(*a) != neighbours.end()) // avoid parallel edges
continue;
neighbours.insert(*a);
typedef tr1::unordered_map<typename graph_traits<Graph>::vertex_descriptor,size_t,DescriptorHash<IndexMap> > dmap_t;
dmap_t dmap(0, DescriptorHash<IndexMap>(vertex_index));
InitializedPropertyMap<dmap_t> distance_map(dmap, numeric_limits<size_t>::max());
......@@ -168,21 +169,23 @@ struct get_extended_clustering
try
{
bfs_max_depth_watcher<neighbour_set_t,InitializedPropertyMap<dmap_t> > watcher(neighbours, cmaps.size(), distance_map);
bfs_max_depth_watcher<neighbour_set_t,InitializedPropertyMap<dmap_t> > watcher(targets, cmaps.size(), distance_map);
breadth_first_visit(fg, *a, visitor(make_bfs_visitor(make_pair(record_distances(distance_map, boost::on_tree_edge()),watcher))).
color_map(color_map));
}
catch(bfs_stop_exception) {}
neighbours2.clear();
typename graph_traits<Graph>::adjacency_iterator a2;
for(a2 = adjacent_vertices(*v, g).first ; a2 != a_end ; ++a2)
{
if (*a2 == *v) // no self-loops
continue;
if (neighbours2.find(*a2) != neighbours2.end()) // avoid parallel edges
continue;
neighbours2.insert(*a2);
if (distance_map[*a2] < cmaps.size())
{
cmaps[distance_map[*a2]][*v] += 1.0/(k*(k-1));
}
}
}
}
......
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