influence_prestige.cpp 2.2 KB

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