1 // (C) Copyright 2007-2009 Andrew Sutton
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0 (See accompanying file
5 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/graph/undirected_graph.hpp>
10 #include <boost/graph/directed_graph.hpp>
11 #include <boost/graph/degree_centrality.hpp>
12 #include <boost/graph/exterior_property.hpp>
15 using namespace boost
;
18 // number of vertices in the graph
19 static const unsigned N
= 5;
21 template <typename Graph
>
22 void build_graph(Graph
& g
,
23 vector
<typename graph_traits
<Graph
>::vertex_descriptor
>& v
)
26 for(size_t i
= 0; i
< N
; ++i
) {
31 add_edge(v
[0], v
[1], g
);
32 add_edge(v
[1], v
[2], g
);
33 add_edge(v
[2], v
[0], g
);
34 add_edge(v
[3], v
[4], g
);
35 add_edge(v
[4], v
[0], g
);
38 template <typename Graph
>
39 void test_undirected()
41 typedef typename graph_traits
<Graph
>::vertex_descriptor Vertex
;
43 typedef exterior_vertex_property
<Graph
, unsigned> CentralityProperty
;
44 typedef typename
CentralityProperty::container_type CentralityContainer
;
45 typedef typename
CentralityProperty::map_type CentralityMap
;
51 CentralityContainer
cents(num_vertices(g
));
52 CentralityMap
cm(cents
, g
);
53 all_degree_centralities(g
, cm
);
55 BOOST_ASSERT(cm
[v
[0]] == 3);
56 BOOST_ASSERT(cm
[v
[1]] == 2);
57 BOOST_ASSERT(cm
[v
[2]] == 2);
58 BOOST_ASSERT(cm
[v
[3]] == 1);
59 BOOST_ASSERT(cm
[v
[4]] == 2);
62 template <typename Graph
>
65 typedef typename graph_traits
<Graph
>::vertex_descriptor Vertex
;
67 typedef exterior_vertex_property
<Graph
, unsigned> CentralityProperty
;
68 typedef typename
CentralityProperty::container_type CentralityContainer
;
69 typedef typename
CentralityProperty::map_type CentralityMap
;
76 CentralityContainer
cents(num_vertices(g
));
77 CentralityMap
cm(cents
, g
);
78 all_influence_values(g
, cm
);
80 BOOST_ASSERT(cm
[v
[0]] == 1);
81 BOOST_ASSERT(cm
[v
[1]] == 1);
82 BOOST_ASSERT(cm
[v
[2]] == 1);
83 BOOST_ASSERT(cm
[v
[3]] == 1);
84 BOOST_ASSERT(cm
[v
[4]] == 1);
87 template <typename Graph
>
90 typedef typename graph_traits
<Graph
>::vertex_descriptor Vertex
;
92 typedef exterior_vertex_property
<Graph
, unsigned> CentralityProperty
;
93 typedef typename
CentralityProperty::container_type CentralityContainer
;
94 typedef typename
CentralityProperty::map_type CentralityMap
;
101 CentralityContainer
cents(num_vertices(g
));
102 CentralityMap
cm(cents
, g
);
103 all_prestige_values(g
, cm
);
105 BOOST_ASSERT(cm
[v
[0]] == 2);
106 BOOST_ASSERT(cm
[v
[1]] == 1);
107 BOOST_ASSERT(cm
[v
[2]] == 1);
108 BOOST_ASSERT(cm
[v
[3]] == 0);
109 BOOST_ASSERT(cm
[v
[4]] == 1);
115 typedef undirected_graph
<> Graph
;
116 typedef directed_graph
<> Digraph
;
118 test_undirected
<Graph
>();
119 test_influence
<Digraph
>();
120 test_prestige
<Digraph
>();