annotate DEPENDENCIES/generic/include/boost/graph/degree_centrality.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // (C) Copyright 2007-2009 Andrew Sutton
Chris@16 2 //
Chris@16 3 // Use, modification and distribution are subject to the
Chris@16 4 // Boost Software License, Version 1.0 (See accompanying file
Chris@16 5 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6
Chris@16 7 #ifndef BOOST_GRAPH_DEGREE_CENTRALITY_HPP
Chris@16 8 #define BOOST_GRAPH_DEGREE_CENTRALITY_HPP
Chris@16 9
Chris@16 10 #include <boost/graph/graph_concepts.hpp>
Chris@16 11 #include <boost/concept/assert.hpp>
Chris@16 12
Chris@16 13 namespace boost {
Chris@16 14
Chris@16 15 template <typename Graph>
Chris@16 16 struct degree_centrality_measure
Chris@16 17 {
Chris@16 18 typedef typename graph_traits<Graph>::degree_size_type degree_type;
Chris@16 19 typedef typename graph_traits<Graph>::vertex_descriptor vertex_type;
Chris@16 20 };
Chris@16 21
Chris@16 22 template <typename Graph>
Chris@16 23 struct influence_measure
Chris@16 24 : public degree_centrality_measure<Graph>
Chris@16 25 {
Chris@16 26 typedef degree_centrality_measure<Graph> base_type;
Chris@16 27 typedef typename base_type::degree_type degree_type;
Chris@16 28 typedef typename base_type::vertex_type vertex_type;
Chris@16 29
Chris@16 30 inline degree_type operator ()(vertex_type v, const Graph& g)
Chris@16 31 {
Chris@16 32 BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept<Graph> ));
Chris@16 33 return out_degree(v, g);
Chris@16 34 }
Chris@16 35 };
Chris@16 36
Chris@16 37 template <typename Graph>
Chris@16 38 inline influence_measure<Graph>
Chris@16 39 measure_influence(const Graph&)
Chris@16 40 { return influence_measure<Graph>(); }
Chris@16 41
Chris@16 42
Chris@16 43 template <typename Graph>
Chris@16 44 struct prestige_measure
Chris@16 45 : public degree_centrality_measure<Graph>
Chris@16 46 {
Chris@16 47 typedef degree_centrality_measure<Graph> base_type;
Chris@16 48 typedef typename base_type::degree_type degree_type;
Chris@16 49 typedef typename base_type::vertex_type vertex_type;
Chris@16 50
Chris@16 51 inline degree_type operator ()(vertex_type v, const Graph& g)
Chris@16 52 {
Chris@16 53 BOOST_CONCEPT_ASSERT(( BidirectionalGraphConcept<Graph> ));
Chris@16 54 return in_degree(v, g);
Chris@16 55 }
Chris@16 56 };
Chris@16 57
Chris@16 58 template <typename Graph>
Chris@16 59 inline prestige_measure<Graph>
Chris@16 60 measure_prestige(const Graph&)
Chris@16 61 { return prestige_measure<Graph>(); }
Chris@16 62
Chris@16 63
Chris@16 64 template <typename Graph, typename Vertex, typename Measure>
Chris@16 65 inline typename Measure::degree_type
Chris@16 66 degree_centrality(const Graph& g, Vertex v, Measure measure)
Chris@16 67 {
Chris@16 68 BOOST_CONCEPT_ASSERT(( DegreeMeasureConcept<Measure, Graph> ));
Chris@16 69 return measure(v, g);
Chris@16 70 }
Chris@16 71
Chris@16 72 template <typename Graph, typename Vertex>
Chris@16 73 inline typename graph_traits<Graph>::degree_size_type
Chris@16 74 degree_centrality(const Graph& g, Vertex v)
Chris@16 75 {
Chris@16 76 return degree_centrality(g, v, measure_influence(g));
Chris@16 77 }
Chris@16 78
Chris@16 79
Chris@16 80 // These are alias functions, intended to provide a more expressive interface.
Chris@16 81
Chris@16 82 template <typename Graph, typename Vertex>
Chris@16 83 inline typename graph_traits<Graph>::degree_size_type
Chris@16 84 influence(const Graph& g, Vertex v)
Chris@16 85 { return degree_centrality(g, v, measure_influence(g)); }
Chris@16 86
Chris@16 87
Chris@16 88 template <typename Graph, typename Vertex>
Chris@16 89 inline typename graph_traits<Graph>::degree_size_type
Chris@16 90 prestige(const Graph& g, Vertex v)
Chris@16 91 { return degree_centrality(g, v, measure_prestige(g)); }
Chris@16 92
Chris@16 93
Chris@16 94 template <typename Graph, typename CentralityMap, typename Measure>
Chris@16 95 inline void
Chris@16 96 all_degree_centralities(const Graph& g, CentralityMap cent, Measure measure)
Chris@16 97 {
Chris@16 98 BOOST_CONCEPT_ASSERT(( VertexListGraphConcept<Graph> ));
Chris@16 99 typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
Chris@16 100 typedef typename graph_traits<Graph>::vertex_iterator VertexIterator;
Chris@16 101 BOOST_CONCEPT_ASSERT(( WritablePropertyMapConcept<CentralityMap,Vertex> ));
Chris@16 102 typedef typename property_traits<CentralityMap>::value_type Centrality;
Chris@16 103
Chris@16 104 VertexIterator i, end;
Chris@16 105 for(boost::tie(i, end) = vertices(g); i != end; ++i) {
Chris@16 106 Centrality c = degree_centrality(g, *i, measure);
Chris@16 107 put(cent, *i, c);
Chris@16 108 }
Chris@16 109 }
Chris@16 110
Chris@16 111 template <typename Graph, typename CentralityMap>
Chris@16 112 inline void all_degree_centralities(const Graph& g, CentralityMap cent)
Chris@16 113 { all_degree_centralities(g, cent, measure_influence(g)); }
Chris@16 114
Chris@16 115 // More helper functions for computing influence and prestige.
Chris@16 116 // I hate the names of these functions, but influence and prestige
Chris@16 117 // don't pluralize too well.
Chris@16 118
Chris@16 119 template <typename Graph, typename CentralityMap>
Chris@16 120 inline void all_influence_values(const Graph& g, CentralityMap cent)
Chris@16 121 { all_degree_centralities(g, cent, measure_influence(g)); }
Chris@16 122
Chris@16 123 template <typename Graph, typename CentralityMap>
Chris@16 124 inline void all_prestige_values(const Graph& g, CentralityMap cent)
Chris@16 125 { all_degree_centralities(g, cent, measure_prestige(g)); }
Chris@16 126
Chris@16 127 } /* namespace boost */
Chris@16 128
Chris@16 129 #endif
Chris@16 130
Chris@16 131