From 818cabc378ca9eb3432be6694e2b37db396e0b74 Mon Sep 17 00:00:00 2001 From: Javier Dehesa Date: Mon, 19 May 2014 12:15:46 +0200 Subject: [PATCH 1/4] Fix to make it compatible with boostorg/graph PR #6 Pull request #6 in boostorg/graph changes some internal structs used by graph-parallel, and so some fixes have been made so it still compiles. Note that support for multiplicities has not been added yet. --- .../distributed/betweenness_centrality.hpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/include/boost/graph/distributed/betweenness_centrality.hpp b/include/boost/graph/distributed/betweenness_centrality.hpp index b56367c0..e3a5a765 100644 --- a/include/boost/graph/distributed/betweenness_centrality.hpp +++ b/include/boost/graph/distributed/betweenness_centrality.hpp @@ -1450,7 +1450,17 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, VertexIndexMap vertex_index, Buffer sources) { - detail::graph::brandes_unweighted_shortest_paths shortest_paths; + // default constant multiplicity of one + typedef typename graph_traits::edge_descriptor edge_descriptor; + typedef typename property_traits::value_type multiplicity_type; + typedef static_property_map MultiplicityMap; + + MultiplicityMap multiplicity_map = + detail::graph::make_static_one_property(g); + + typedef detail::graph::make_shortest_paths make; + typedef typename make::type ShortestPaths; + ShortestPaths shortest_paths = make()(dummy_property_map(), multiplicity_map); graph::parallel::detail::non_distributed_brandes_betweenness_centrality_impl(pg, g, centrality, edge_centrality_map, @@ -1478,7 +1488,17 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, WeightMap weight_map, Buffer sources) { - detail::graph::brandes_dijkstra_shortest_paths shortest_paths(weight_map); + // default constant multiplicity of one + typedef typename graph_traits::edge_descriptor edge_descriptor; + typedef typename property_traits::value_type multiplicity_type; + typedef static_property_map MultiplicityMap; + + MultiplicityMap multiplicity_map = + detail::graph::make_static_one_property(g); + + typedef detail::graph::make_shortest_paths make; + typedef typename make::type ShortestPaths; + ShortestPaths shortest_paths = make()(weight_map, multiplicity_map); graph::parallel::detail::non_distributed_brandes_betweenness_centrality_impl(pg, g, centrality, edge_centrality_map, From dccfcb048397f6ed433b8ea767eb9368f2131050 Mon Sep 17 00:00:00 2001 From: Javier Dehesa Date: Mon, 19 May 2014 13:35:18 +0200 Subject: [PATCH 2/4] Changes according to graph --- .../distributed/betweenness_centrality.hpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/boost/graph/distributed/betweenness_centrality.hpp b/include/boost/graph/distributed/betweenness_centrality.hpp index e3a5a765..3948c1db 100644 --- a/include/boost/graph/distributed/betweenness_centrality.hpp +++ b/include/boost/graph/distributed/betweenness_centrality.hpp @@ -1237,6 +1237,12 @@ brandes_betweenness_centrality(const Graph& g, typename property_traits::value_type delta BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph,distributed_graph_tag)) { + + // default constant multiplicity of one + typedef typename property_traits::value_type multiplicity_type; + typedef static_property_map MultiplicityMap; + MultiplicityMap multiplicity_map(detail::graph::one()); + typedef typename property_traits::value_type distance_type; typedef static_property_map WeightMap; @@ -1451,12 +1457,9 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, Buffer sources) { // default constant multiplicity of one - typedef typename graph_traits::edge_descriptor edge_descriptor; typedef typename property_traits::value_type multiplicity_type; - typedef static_property_map MultiplicityMap; - - MultiplicityMap multiplicity_map = - detail::graph::make_static_one_property(g); + typedef static_property_map MultiplicityMap; + MultiplicityMap multiplicity_map(detail::graph::one()); typedef detail::graph::make_shortest_paths make; typedef typename make::type ShortestPaths; @@ -1489,12 +1492,9 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, Buffer sources) { // default constant multiplicity of one - typedef typename graph_traits::edge_descriptor edge_descriptor; typedef typename property_traits::value_type multiplicity_type; - typedef static_property_map MultiplicityMap; - - MultiplicityMap multiplicity_map = - detail::graph::make_static_one_property(g); + typedef static_property_map MultiplicityMap; + MultiplicityMap multiplicity_map(detail::graph::one()); typedef detail::graph::make_shortest_paths make; typedef typename make::type ShortestPaths; From 4d579f9afe618c8f6473a34e0d4beed8204be1e4 Mon Sep 17 00:00:00 2001 From: Javier Dehesa Date: Wed, 21 May 2014 10:42:52 +0200 Subject: [PATCH 3/4] Some other simplification. --- include/boost/graph/distributed/betweenness_centrality.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/graph/distributed/betweenness_centrality.hpp b/include/boost/graph/distributed/betweenness_centrality.hpp index 3948c1db..bc6c0557 100644 --- a/include/boost/graph/distributed/betweenness_centrality.hpp +++ b/include/boost/graph/distributed/betweenness_centrality.hpp @@ -1241,7 +1241,7 @@ brandes_betweenness_centrality(const Graph& g, // default constant multiplicity of one typedef typename property_traits::value_type multiplicity_type; typedef static_property_map MultiplicityMap; - MultiplicityMap multiplicity_map(detail::graph::one()); + MultiplicityMap multiplicity_map(multiplicity_type(1)); typedef typename property_traits::value_type distance_type; typedef static_property_map WeightMap; @@ -1459,7 +1459,7 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, // default constant multiplicity of one typedef typename property_traits::value_type multiplicity_type; typedef static_property_map MultiplicityMap; - MultiplicityMap multiplicity_map(detail::graph::one()); + MultiplicityMap multiplicity_map(multiplicity_type(1)); typedef detail::graph::make_shortest_paths make; typedef typename make::type ShortestPaths; @@ -1494,7 +1494,7 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, // default constant multiplicity of one typedef typename property_traits::value_type multiplicity_type; typedef static_property_map MultiplicityMap; - MultiplicityMap multiplicity_map(detail::graph::one()); + MultiplicityMap multiplicity_map(multiplicity_type(1)); typedef detail::graph::make_shortest_paths make; typedef typename make::type ShortestPaths; From 619a2cdaf5f13959e4a85c01e777616770a9f030 Mon Sep 17 00:00:00 2001 From: Javier Dehesa Date: Fri, 23 May 2014 11:51:13 +0200 Subject: [PATCH 4/4] Added multiplicity_map parameter to non_distributed_betweenness_centrality Added the possibility to include edge multiplicities in non_distributed_betweenness_centrality. --- ...on_distributed_betweenness_centrality.html | 21 ++++ ...non_distributed_betweenness_centrality.rst | 22 ++++ .../distributed/betweenness_centrality.hpp | 108 +++++++++++++++--- 3 files changed, 135 insertions(+), 16 deletions(-) diff --git a/doc/html/non_distributed_betweenness_centrality.html b/doc/html/non_distributed_betweenness_centrality.html index 6079d5db..f7b63171 100644 --- a/doc/html/non_distributed_betweenness_centrality.html +++ b/doc/html/non_distributed_betweenness_centrality.html @@ -70,6 +70,24 @@

Parameters

A model of Readable Property Map whose key type is the edge descriptor type of the graph g. If not supplied the betweenness centrality calculation will be unweighted.
+
IN: MultiplicityMap multiplicity_map
+
A model of Readable Property Map whose key type is the edge +descriptor type of the graph g.
IN: Buffer sources

A model of Buffer containing the starting vertices for the algorithm. If sources is empty a complete betweenness diff --git a/doc/non_distributed_betweenness_centrality.rst b/doc/non_distributed_betweenness_centrality.rst index 264dd81b..d4063816 100644 --- a/doc/non_distributed_betweenness_centrality.rst +++ b/doc/non_distributed_betweenness_centrality.rst @@ -63,6 +63,24 @@ WeightMap weight_map, Buffer sources); + template + void + non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, + const Graph& g, + CentralityMap centrality, + EdgeCentralityMap edge_centrality_map, + IncomingMap incoming, + DistanceMap distance, + DependencyMap dependency, + PathCountMap path_count, + VertexIndexMap vertex_index, + WeightMap weight_map, + MultiplicityMap multiplicity_map, + Buffer sources); + // helper functions template typename property_traits::value_type @@ -161,6 +179,10 @@ IN: ``WeightMap weight_map`` descriptor type of the graph ``g``. If not supplied the betweenness centrality calculation will be unweighted. +IN: ``MultiplicityMap multiplicity_map`` + A model of `Readable Property Map`_ whose key type is the edge + descriptor type of the graph ``g``. + IN: ``Buffer sources`` A model of Buffer_ containing the starting vertices for the algorithm. If ``sources`` is empty a complete betweenness diff --git a/include/boost/graph/distributed/betweenness_centrality.hpp b/include/boost/graph/distributed/betweenness_centrality.hpp index bc6c0557..64aeeeb3 100644 --- a/include/boost/graph/distributed/betweenness_centrality.hpp +++ b/include/boost/graph/distributed/betweenness_centrality.hpp @@ -1038,7 +1038,7 @@ namespace boost { template + typename MultiplicityMap, typename Stack> void do_sequential_brandes_sssp(const Graph& g, CentralityMap centrality, @@ -1049,6 +1049,7 @@ namespace boost { PathCountMap path_count, VertexIndexMap vertex_index, ShortestPaths shortest_paths, + MultiplicityMap multiplicity_map, Stack& ordered_vertices, typename graph_traits::vertex_descriptor v) { @@ -1087,6 +1088,7 @@ namespace boost { vertex_descriptor v = source(*vw, g); dependency_type factor = dependency_type(get(path_count, v)) / dependency_type(get(path_count, w)); + factor *= dependency_type(get(multiplicity_map, *vw)); factor *= (dependency_type(1) + get(dependency, w)); put(dependency, v, get(dependency, v) + factor); update_centrality(edge_centrality_map, *vw, factor); @@ -1106,7 +1108,7 @@ namespace boost { typename IncomingMap, typename DistanceMap, typename DependencyMap, typename PathCountMap, typename VertexIndexMap, typename ShortestPaths, - typename Buffer> + typename MultiplicityMap, typename Buffer> void non_distributed_brandes_betweenness_centrality_impl(const ProcessGroup& pg, const Graph& g, @@ -1118,6 +1120,7 @@ namespace boost { PathCountMap path_count, // sigma VertexIndexMap vertex_index, ShortestPaths shortest_paths, + MultiplicityMap multiplicity_map, Buffer sources) { using boost::detail::graph::init_centrality_map; @@ -1151,7 +1154,8 @@ namespace boost { for(size_t i = 0; i < local_sources.size(); ++i) do_sequential_brandes_sssp(g, centrality, edge_centrality_map, incoming, distance, dependency, path_count, vertex_index, - shortest_paths, ordered_vertices, local_sources[i]); + shortest_paths, multiplicity_map, + ordered_vertices, local_sources[i]); } else { // Exact Betweenness Centrality typedef typename graph_traits::vertices_size_type vertices_size_type; @@ -1162,7 +1166,8 @@ namespace boost { do_sequential_brandes_sssp(g, centrality, edge_centrality_map, incoming, distance, dependency, path_count, vertex_index, - shortest_paths, ordered_vertices, v); + shortest_paths, multiplicity_map, + ordered_vertices, v); } } @@ -1471,6 +1476,7 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, dependency, path_count, vertex_index, shortest_paths, + multiplicity_map, sources); } @@ -1496,6 +1502,31 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, typedef static_property_map MultiplicityMap; MultiplicityMap multiplicity_map(multiplicity_type(1)); + non_distributed_brandes_betweenness_centrality(pg, g, centrality, edge_centrality_map, + incoming, distance, dependency, + path_count, vertex_index, + weight_map, multiplicity_map, + sources); +} + +template +void +non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, + const Graph& g, + CentralityMap centrality, + EdgeCentralityMap edge_centrality_map, + IncomingMap incoming, + DistanceMap distance, + DependencyMap dependency, + PathCountMap path_count, + VertexIndexMap vertex_index, + WeightMap weight_map, + MultiplicityMap multiplicity_map, + Buffer sources) +{ typedef detail::graph::make_shortest_paths make; typedef typename make::type ShortestPaths; ShortestPaths shortest_paths = make()(weight_map, multiplicity_map); @@ -1506,19 +1537,21 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, dependency, path_count, vertex_index, shortest_paths, + multiplicity_map, sources); } namespace detail { namespace graph { template + typename EdgeCentralityMap, typename WeightMap, typename MultiplicityMap, + typename VertexIndexMap, typename Buffer> void non_distributed_brandes_betweenness_centrality_dispatch2(const ProcessGroup& pg, const Graph& g, CentralityMap centrality, EdgeCentralityMap edge_centrality_map, WeightMap weight_map, + MultiplicityMap multiplicity_map, VertexIndexMap vertex_index, Buffer sources) { @@ -1544,7 +1577,7 @@ namespace detail { namespace graph { make_iterator_property_map(distance.begin(), vertex_index), make_iterator_property_map(dependency.begin(), vertex_index), make_iterator_property_map(path_count.begin(), vertex_index), - vertex_index, weight_map, unwrap_ref(sources)); + vertex_index, weight_map, multiplicity_map, unwrap_ref(sources)); } @@ -1583,7 +1616,7 @@ namespace detail { namespace graph { vertex_index, unwrap_ref(sources)); } - template + template struct non_distributed_brandes_betweenness_centrality_dispatch1 { template + struct non_distributed_brandes_betweenness_centrality_dispatch1 + { + template + static void + run(const ProcessGroup& pg, const Graph& g, CentralityMap centrality, + EdgeCentralityMap edge_centrality_map, VertexIndexMap vertex_index, + Buffer sources, WeightMap weight_map, param_not_found) + { + // default constant multiplicity of one + typedef typename mpl::if_, + EdgeCentralityMap, CentralityMap>::type + a_centrality_map; + typedef typename property_traits::value_type multiplicity_type; + typedef static_property_map MultiplicityMap; + MultiplicityMap multiplicity_map(multiplicity_type(1)); + + non_distributed_brandes_betweenness_centrality_dispatch2(pg, g, centrality, edge_centrality_map, + weight_map, multiplicity_map, + vertex_index, sources); + } + }; + + template + struct non_distributed_brandes_betweenness_centrality_dispatch1 + { + template + static void + run(const ProcessGroup& pg, const Graph& g, CentralityMap centrality, + EdgeCentralityMap edge_centrality_map, VertexIndexMap vertex_index, + Buffer sources, param_not_found, MultiplicityMap multiplicity_map) { + // default weight to dummy property map non_distributed_brandes_betweenness_centrality_dispatch2(pg, g, centrality, edge_centrality_map, - weight_map, vertex_index, sources); + dummy_property_map(), multiplicity_map, + vertex_index, sources); } }; template<> - struct non_distributed_brandes_betweenness_centrality_dispatch1 + struct non_distributed_brandes_betweenness_centrality_dispatch1 { template static void run(const ProcessGroup& pg, const Graph& g, CentralityMap centrality, EdgeCentralityMap edge_centrality_map, VertexIndexMap vertex_index, - Buffer sources, param_not_found) + Buffer sources, param_not_found, param_not_found) { non_distributed_brandes_betweenness_centrality_dispatch2(pg, g, centrality, edge_centrality_map, vertex_index, sources); @@ -1625,9 +1700,9 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, const Gra typedef queue queue_t; queue_t q; - typedef typename get_param_type::type ew_param; - typedef typename detail::choose_impl_result::type ew; - detail::graph::non_distributed_brandes_betweenness_centrality_dispatch1::run( + typedef typename get_param_type::type ew; + typedef typename get_param_type::type em; + detail::graph::non_distributed_brandes_betweenness_centrality_dispatch1::run( pg, g, choose_param(get_param(params, vertex_centrality), dummy_property_map()), @@ -1635,7 +1710,8 @@ non_distributed_brandes_betweenness_centrality(const ProcessGroup& pg, const Gra dummy_property_map()), choose_const_pmap(get_param(params, vertex_index), g, vertex_index), choose_param(get_param(params, buffer_param_t()), boost::ref(q)), - choose_const_pmap(get_param(params, edge_weight), g, edge_weight)); + get_param(params, edge_weight), + get_param(params, edge_multiplicity_t())); } template