// (C) Copyright 2007-2009 Andrew Sutton // // Use, modification and distribution are subject to the // Boost Software License, Version 1.0 (See accompanying file // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GRAPH_DEGREE_CENTRALITY_HPP #define BOOST_GRAPH_DEGREE_CENTRALITY_HPP #include #include namespace boost { template struct degree_centrality_measure { typedef typename graph_traits::degree_size_type degree_type; typedef typename graph_traits::vertex_descriptor vertex_type; }; template struct influence_measure : public degree_centrality_measure { typedef degree_centrality_measure base_type; typedef typename base_type::degree_type degree_type; typedef typename base_type::vertex_type vertex_type; inline degree_type operator ()(vertex_type v, const Graph& g) { BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept )); return out_degree(v, g); } }; template inline influence_measure measure_influence(const Graph&) { return influence_measure(); } template struct prestige_measure : public degree_centrality_measure { typedef degree_centrality_measure base_type; typedef typename base_type::degree_type degree_type; typedef typename base_type::vertex_type vertex_type; inline degree_type operator ()(vertex_type v, const Graph& g) { BOOST_CONCEPT_ASSERT(( BidirectionalGraphConcept )); return in_degree(v, g); } }; template inline prestige_measure measure_prestige(const Graph&) { return prestige_measure(); } template inline typename Measure::degree_type degree_centrality(const Graph& g, Vertex v, Measure measure) { BOOST_CONCEPT_ASSERT(( DegreeMeasureConcept )); return measure(v, g); } template inline typename graph_traits::degree_size_type degree_centrality(const Graph& g, Vertex v) { return degree_centrality(g, v, measure_influence(g)); } // These are alias functions, intended to provide a more expressive interface. template inline typename graph_traits::degree_size_type influence(const Graph& g, Vertex v) { return degree_centrality(g, v, measure_influence(g)); } template inline typename graph_traits::degree_size_type prestige(const Graph& g, Vertex v) { return degree_centrality(g, v, measure_prestige(g)); } template inline void all_degree_centralities(const Graph& g, CentralityMap cent, Measure measure) { BOOST_CONCEPT_ASSERT(( VertexListGraphConcept )); typedef typename graph_traits::vertex_descriptor Vertex; typedef typename graph_traits::vertex_iterator VertexIterator; BOOST_CONCEPT_ASSERT(( WritablePropertyMapConcept )); typedef typename property_traits::value_type Centrality; VertexIterator i, end; for(boost::tie(i, end) = vertices(g); i != end; ++i) { Centrality c = degree_centrality(g, *i, measure); put(cent, *i, c); } } template inline void all_degree_centralities(const Graph& g, CentralityMap cent) { all_degree_centralities(g, cent, measure_influence(g)); } // More helper functions for computing influence and prestige. // I hate the names of these functions, but influence and prestige // don't pluralize too well. template inline void all_influence_values(const Graph& g, CentralityMap cent) { all_degree_centralities(g, cent, measure_influence(g)); } template inline void all_prestige_values(const Graph& g, CentralityMap cent) { all_degree_centralities(g, cent, measure_prestige(g)); } } /* namespace boost */ #endif