• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // (C) Copyright Andrew Sutton 2007
2 //
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)
6 
7 //[influence_prestige_example
8 #include <iostream>
9 #include <iomanip>
10 
11 #include <boost/graph/directed_graph.hpp>
12 #include <boost/graph/exterior_property.hpp>
13 #include <boost/graph/degree_centrality.hpp>
14 
15 #include "helper.hpp"
16 
17 using namespace std;
18 using namespace boost;
19 
20 // The Actor type stores the name of each vertex in the graph.
21 struct Actor
22 {
23     string name;
24 };
25 
26 // Declare the graph type and its vertex and edge types.
27 typedef directed_graph< Actor > Graph;
28 typedef graph_traits< Graph >::vertex_descriptor Vertex;
29 typedef graph_traits< Graph >::edge_descriptor Edge;
30 
31 // The name map provides an abstract accessor for the names of
32 // each vertex. This is used during graph creation.
33 typedef property_map< Graph, string Actor::* >::type NameMap;
34 
35 // Declare a container type for influence and prestige (both
36 // of which are degree centralities) and its corresponding
37 // property map.
38 typedef exterior_vertex_property< Graph, unsigned > CentralityProperty;
39 typedef CentralityProperty::container_type CentralityContainer;
40 typedef CentralityProperty::map_type CentralityMap;
41 
main(int argc,char * argv[])42 int main(int argc, char* argv[])
43 {
44     // Create the graph and a property map that provides
45     // access to the actor names.
46     Graph g;
47     NameMap nm(get(&Actor::name, g));
48 
49     // Read the graph from standard input.
50     read_graph(g, nm, cin);
51 
52     // Compute the influence for the graph.
53     CentralityContainer influence(num_vertices(g));
54     CentralityMap im(influence, g);
55     all_influence_values(g, im);
56 
57     // Compute the influence for the graph.
58     CentralityContainer prestige(num_vertices(g));
59     CentralityMap pm(prestige, g);
60     all_prestige_values(g, pm);
61 
62     // Print the degree centrality of each vertex
63     graph_traits< Graph >::vertex_iterator i, end;
64     for (boost::tie(i, end) = vertices(g); i != end; ++i)
65     {
66         Vertex v = *i;
67         cout << setiosflags(ios::left) << setw(12) << g[v].name << "\t" << im[v]
68              << "\t" << pm[v] << endl;
69     }
70 
71     return 0;
72 }
73 //]
74