Commit 36e6fe57 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Allow for community labels to be of arbitrary types in modularity()

parent 8123d30c
......@@ -88,7 +88,7 @@ double modularity(GraphInterface& g, boost::any weight, boost::any property)
run_action<graph_tool::detail::never_directed>()
(g, bind<void>(get_modularity(), _1, _2, _3, ref(modularity)),
edge_props_t(), vertex_scalar_properties())
edge_props_t(), vertex_properties())
(weight, property);
return modularity;
}
......
......@@ -502,6 +502,7 @@ struct get_modularity
double& modularity) const
{
typedef typename property_traits<WeightMap>::key_type weight_key_t;
typedef typename property_traits<CommunityMap>::value_type s_val_t;
modularity = 0.0;
size_t E = 0;
......@@ -514,10 +515,10 @@ struct get_modularity
W += get(weights, *e);
E++;
if (get(s, target(*e,g)) == get(s, source(*e,g)))
modularity += 2*get(weights, weight_key_t(*e));
modularity += 2 * get(weights, weight_key_t(*e));
}
unordered_map<size_t, size_t> Ks;
unordered_map<s_val_t, size_t> Ks;
typename graph_traits<Graph>::vertex_iterator v, v_end;
for (tie(v,v_end) = vertices(g); v != v_end; ++v)
......
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