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