betweenness_centrality.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <!--
  4. Copyright (c) 2004 Trustees of Indiana University
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. -->
  9. <head>
  10. <title>Boost Graph Library: Brandes' Betweenness Centrality</title>
  11. </head>
  12. <body>
  13. <IMG SRC="../../../boost.png"
  14. ALT="C++ Boost" width="277" height="86">
  15. <h1><img src="figs/python.gif" alt="(Python)"/><tt>brandes_betweenness_centrality</tt></h1>
  16. <p>
  17. <pre>
  18. <em>// named parameter versions</em>
  19. template&lt;typename Graph, typename Param, typename Tag, typename Rest&gt;
  20. void
  21. brandes_betweenness_centrality(const Graph&amp; g,
  22. const bgl_named_params&lt;Param,Tag,Rest&gt;&amp; params);
  23. template&lt;typename Graph, typename CentralityMap&gt;
  24. void
  25. brandes_betweenness_centrality(const Graph&amp; g, CentralityMap centrality_map);
  26. template&lt;typename Graph, typename CentralityMap, typename EdgeCentralityMap&gt;
  27. void
  28. brandes_betweenness_centrality(const Graph&amp; g, CentralityMap centrality_map,
  29. EdgeCentralityMap edge_centrality);
  30. <em>// non-named parameter versions</em>
  31. template&lt;typename Graph, typename CentralityMap, typename EdgeCentralityMap,
  32. typename IncomingMap, typename DistanceMap, typename DependencyMap,
  33. typename PathCountMap, typename VertexIndexMap&gt;
  34. void
  35. brandes_betweenness_centrality(const Graph&amp; g, CentralityMap centrality_map,
  36. EdgeCentralityMap edge_centrality,
  37. IncomingMap incoming,
  38. DistanceMap distance, DependencyMap dependency,
  39. PathCountMap path_count,
  40. VertexIndexMap vertex_index);
  41. template&lt;typename Graph, typename CentralityMap, typename EdgeCentralityMap,
  42. typename IncomingMap, typename DistanceMap, typename DependencyMap,
  43. typename PathCountMap, typename VertexIndexMap, typename WeightMap&gt;
  44. void
  45. brandes_betweenness_centrality(const Graph&amp; g, CentralityMap centrality_map,
  46. EdgeCentralityMap edge_centrality,
  47. IncomingMap incoming,
  48. DistanceMap distance, DependencyMap dependency,
  49. PathCountMap path_count,
  50. VertexIndexMap vertex_index,
  51. WeightMap weight_map);
  52. <em>// helper functions</em>
  53. template&lt;typename Graph, typename CentralityMap&gt;
  54. void
  55. relative_betweenness_centrality(const Graph&amp; g, CentralityMap centrality_map);
  56. template&lt;typename Graph, typename CentralityMap&gt;
  57. typename property_traits&lt;CentralityMap&gt;::value_type
  58. central_point_dominance(const Graph&amp; g, CentralityMap centrality_map);
  59. </pre>
  60. <p>This algorithm&nbsp;[<a href="bibliography.html#brandes01">54</a>]
  61. computes the <em>betweenness centrality</em>&nbsp;[<a
  62. href="bibliography.html#freeman77">55</a>,<a
  63. href="bibliography.html#anthonisse71">56</a>] of each vertex or each
  64. edge in the graph. The betweenness centrality of a vertex <em>v</em>
  65. is defined by
  66. <p><img src="figs/betweenness_centrality.gif">,
  67. <p>where <img src="figs/sigma_st.gif"> is the number of shortest paths from
  68. vertex <em>s</em> to vertex <em>t</em> and <img src="figs/sigma_stv.gif">
  69. is the number of shortest paths from vertex <em>s</em> to vertex
  70. <em>t</em> that pass through vertex <em>v</em>.
  71. <!-- \sum_{s \neq v \neq t}\frac{\sigma_{st}(v)}{\sigma_{st}} -->
  72. <p>The edge betweenness centrality indicates for each edge the
  73. betweenness centrality that was contributed to the target(s) of the
  74. edge (plural for undirected graphs). Similar to (vertex) betweenness
  75. centrality, edge betweenness centrality can be used to determine the
  76. edges through which most shortest paths must pass. A single invocation
  77. of this algorithm can compute either the vertex or edge centrality (or
  78. both).</p>
  79. <p>This algorithm can operate either on weighted graphs (if a suitable
  80. edge weight map is supplied) or unweighted graphs (if no edge weight
  81. map is supplied). The result is the absolute betweenness centrality;
  82. to convert to the relative betweenness centrality, which scales each
  83. absolute centrality by <img src="figs/rel_betweenness_centrality.gif">
  84. (where <em>n</em> is the number of vertices in the graph), use
  85. <tt>relative_betweenness_centrality</tt>. Given the relative
  86. betweenness centrality, one can compute the <em>central point
  87. dominance</em>&nbsp;[<a href="bibliography.html#freeman77">55</a>], which is a measure of the maximum "betweenness" of any
  88. point in the graph: it will be 0 for complete graphs and
  89. 1 for "wheel" graphs (in which there is a central vertex that all
  90. paths include; see <a href="#Fig1">Fig. 1</a>). Let <img src="figs/v_star.gif"> be the vertex with the largest relative betweenness centrality; then, the central point dominance is defined as:
  91. <p><img src="figs/central_point_dominance.gif">
  92. <!-- C_B' = \frac{\sum_{v \in V} C_B(v^*) - C_B'(v)}{n-1} -->
  93. <p><a name="Fig1">
  94. <table border="1">
  95. <thead>
  96. <tr>
  97. <th>Fig. 1: A wheel graph, where every path travels through the central node. <br>The central point dominance of this graph is 1.</td>
  98. </tr>
  99. </thead>
  100. <tbody>
  101. <tr>
  102. <td align="center"><img src="figs/wheel_graph.gif"></td>
  103. </tr>
  104. </tbody>
  105. </table>
  106. <h3>Where Defined</h3>
  107. <a href="../../../boost/graph/betweenness_centrality.hpp"><tt>boost/graph/betweenness_centrality.hpp</tt></a>
  108. <h3>Parameters</h3>
  109. IN: <tt>const Graph&amp; g</tt>
  110. <blockquote>
  111. The graph object on which the algorithm will be applied. The type
  112. <tt>Graph</tt> must be a model of <a
  113. href="VertexListGraph.html">Vertex List Graph</a> and <a
  114. href="IncidenceGraph.html">Incidence Graph</a>. When an edge
  115. centrality map is supplied, it must also model <a
  116. href="EdgeListGraph.html">Edge List Graph</a>.<br>
  117. <b>Python</b>: The parameter is named <tt>graph</tt>.
  118. </blockquote>
  119. UTIL: <tt>IncomingMap incoming</tt>
  120. <blockquote>
  121. This property map records the set of edges incoming to each vertex that comprise a shortest path from a particular source vertex through this vertex, and is used internally by the algorithm.The <tt>IncomingMap</tt> type must be a <a
  122. href="../../property_map/doc/LvaluePropertyMap.html">Lvalue Property
  123. Map</a> whose key type is the same as the vertex descriptor type of
  124. the graph and whose value type is a Sequence (e.g., an
  125. <tt>std::vector</tt>) containing edge descriptors.<br>
  126. <b>Default:</b> <a
  127. href="../../property_map/doc/iterator_property_map.html">
  128. <tt>iterator_property_map</tt></a> created from a
  129. <tt>std::vector</tt> of <tt>std::vector&lt;Edge&gt;</tt>, where
  130. <tt>Edge</tt> is the edge descriptor type of the graph.<br>
  131. <b>Python</b>: Unsupported parameter.
  132. </blockquote>
  133. UTIL: <tt>DistanceMap distance_map</tt>
  134. <blockquote>
  135. The shortest path weight from each source vertex <tt>s</tt> to each
  136. vertex in the graph <tt>g</tt> is recorded in this property map, but
  137. the result is only used internally. The type <tt>DistanceMap</tt>
  138. must be a model of <a
  139. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  140. Property Map</a>. The vertex descriptor type of the graph needs to
  141. be usable as the key type of the distance map. The value type of the
  142. distance map is the element type of a <a
  143. href="./Monoid.html">Monoid</a>.<br>
  144. <b>Default:</b> <a
  145. href="../../property_map/doc/iterator_property_map.html">
  146. <tt>iterator_property_map</tt></a> created from a
  147. <tt>std::vector</tt> of the <tt>WeightMap</tt>'s value type (or the
  148. <tt>vertices_size_type</tt> of the graph when no weight map exists)
  149. of size <tt>num_vertices(g)</tt> and using the <tt>vertex_index</tt> for
  150. the index map.<br>
  151. <b>Python</b>: Unsupported parameter.
  152. </blockquote>
  153. UTIL: <tt>DependencyMap dependency</tt>
  154. <blockquote>
  155. Property map used internally to accumulate partial betweenness
  156. centrality results. The type <tt>DependencyMap</tt> must be a model
  157. of <a href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  158. Property Map</a>. The vertex descriptor type of the graph needs to
  159. be usable as the key type of the dependency map. The value type of
  160. the dependency map must be compatible with the value type of the
  161. centrality map.<br>
  162. <b>Default:</b> <a
  163. href="../../property_map/doc/iterator_property_map.html">
  164. <tt>iterator_property_map</tt></a> created from a
  165. <tt>std::vector</tt> of the <tt>CentralityMap</tt>'s value type of
  166. size <tt>num_vertices(g)</tt> and using the <tt>vertex_index</tt>
  167. for the index map.<br>
  168. <b>Python</b>: Unsupported parameter.
  169. </blockquote>
  170. UTIL: <tt>PathCountMap path_count</tt>
  171. <blockquote>
  172. Property map used internally to accumulate the number of paths that
  173. pass through each particular vertex. The type <tt>PathCountMap</tt>
  174. must be a model of <a
  175. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  176. Property Map</a>. The vertex descriptor type of the graph needs to
  177. be usable as the key type of the dependency map. The value type of
  178. the dependency map must be an integral type large enough to store
  179. the number of paths in the graph.<br>
  180. <b>Default:</b> <a
  181. href="../../property_map/doc/iterator_property_map.html">
  182. <tt>iterator_property_map</tt></a> created from a
  183. <tt>std::vector</tt> of the <tt>degree_size_type</tt> of the graph of
  184. size <tt>num_vertices(g)</tt> and using the <tt>vertex_index</tt>
  185. for the index map.<br>
  186. <b>Python</b>: Unsupported parameter.
  187. </blockquote>
  188. <h3>Named parameters</h3>
  189. OUT/UTIL: <tt>CentralityMap centrality_map</tt>
  190. <blockquote>
  191. This property map is used to accumulate the betweenness centrality
  192. of each vertex, and is the primary output of the algorithm. The type
  193. <tt>CentralityMap</tt> must be a model of <a
  194. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  195. Property Map</a>, with the graph's vertex descriptor type as its key
  196. type. The value type of this property map should be a floating-point
  197. or rational type.<br>
  198. <b>Default:</b> a <tt>dummy_property_map</tt>, which requires no
  199. work to compute and returns no answer.<br>
  200. <b>Python</b>: The color map must be a <tt>vertex_double_map</tt> for
  201. the graph.<br>
  202. <b>Python default</b>: <tt>graph.get_vertex_double_map("centrality")</tt>
  203. </blockquote>
  204. OUT/UTIL: <tt>EdgeCentralityMap edge_centrality_map</tt>
  205. <blockquote>
  206. This property map is used to accumulate the betweenness centrality
  207. of each edge, and is a secondary form of output for the
  208. algorithm. The type <tt>EdgeCentralityMap</tt> must be a model of <a
  209. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  210. Property Map</a>, with the graph's edge descriptor type as its key
  211. type. The value type of this property map should be the same as the
  212. value type of the <tt>CentralityMap</tt> property map.<br>
  213. <b>Default:</b> a <tt>dummy_property_map</tt>, which requires no
  214. work to compute and returns no answer.<br>
  215. <b>Python</b>: The color map must be a <tt>edge_double_map</tt> for
  216. the graph.<br>
  217. <b>Python default</b>: <tt>graph.get_edge_double_map("centrality")</tt>
  218. </blockquote>
  219. IN: <tt>vertex_index_map(VertexIndexMap vertex_index)</tt>
  220. <blockquote>
  221. This maps each vertex to an integer in the range <tt>[0,
  222. num_vertices(g))</tt>. This is necessary for efficient updates of the
  223. heap data structure when an edge is relaxed. The type
  224. <tt>VertexIndexMap</tt> must be a model of
  225. <a href="../../property_map/doc/ReadablePropertyMap.html">Readable Property Map</a>. The value type of the map must be an
  226. integer type. The vertex descriptor type of the graph needs to be
  227. usable as the key type of the map.<br>
  228. <b>Default:</b> <tt>get(vertex_index, g)</tt>.
  229. Note: if you use this default, make sure your graph has
  230. an internal <tt>vertex_index</tt> property. For example,
  231. <tt>adjacency_list</tt> with <tt>VertexList=listS</tt> does
  232. not have an internal <tt>vertex_index</tt> property.<br>
  233. <b>Python</b>: Unsupported parameter.
  234. </blockquote>
  235. IN: <tt>weight_map(WeightMap w_map)</tt>
  236. <blockquote>
  237. The weight or ``length'' of each edge in the graph. The weights
  238. must all be non-negative, and the algorithm will throw a
  239. <a href="./exception.html#negative_edge"><tt>negative_edge</tt></a>
  240. exception is one of the edges is negative.
  241. The type <tt>WeightMap</tt> must be a model of
  242. <a href="../../property_map/doc/ReadablePropertyMap.html">Readable Property Map</a>. The edge descriptor type of
  243. the graph needs to be usable as the key type for the weight
  244. map. The value type for this map must be
  245. the same as the value type of the distance map.<br>
  246. <b>Default:</b> All edge weights are assumed to be equivalent.
  247. <b>Python</b>: If supplied, must be an <tt>edge_double_map</tt> for the graph.
  248. </blockquote>
  249. <h3>Complexity</h3>
  250. The time complexity is <em>O(VE)</em> for unweighted graphs and
  251. <em>O(VE + V(V+E) log V)</em> for weighted graphs. The space complexity
  252. is <em>O(VE)</em>.
  253. <hr>
  254. <TABLE>
  255. <TR valign=top>
  256. <TD nowrap>Copyright &copy; 2004</TD><TD>
  257. <A HREF="http://www.boost.org/people/doug_gregor.html">Douglas Gregor</A>, Indiana University (dgregor@cs.indiana.edu</A>)<br>
  258. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  259. Indiana University (<A
  260. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
  261. </TD></TR></TABLE>
  262. <!-- Created: Fri Jun 4 16:42:50 EST 2004 -->
  263. <!-- hhmts start -->Last modified: Tue Mar 1 14:14:51 EST 2005 <!-- hhmts end -->
  264. </body>
  265. </html>