#include // for std::dataout #include // for std::pair #include // for boost::tie #include // for boost::graph_traits #include #include //for boost::brandes_betweenness_centrality #include using namespace boost; using namespace std; typedef adjacency_list < vecS, //Store out-edges vecS, //Store vertex set undirectedS, //the graph is undirected property > Graph; typedef graph_traits::vertex_descriptor Vertex; typedef graph_traits::vertex_iterator Vertex_Iter; typedef graph_traits::edge_descriptor Edge; typedef graph_traits::edge_iterator Edge_Iter; typedef property_map::type Name_Map_t; typedef property_map::type Edge_Map_t; int main(int,char*[]) { int n_vrtx = 5; //Builds graph with vertices, but no edges Graph g_star(n_vrtx); //Add edges. Graph g_star is a star add_edge(vertex(0, g_star), vertex(4, g_star), g_star); add_edge(vertex(1, g_star), vertex(4, g_star), g_star); add_edge(vertex(2, g_star), vertex(4, g_star), g_star); add_edge(vertex(3, g_star), vertex(4, g_star), g_star); Vertex_Iter vertex_iterator_begin, vertex_iterator_end; std::vector centrality(n_vrtx); brandes_betweenness_centrality(g_star, centrality_map(make_iterator_property_map(centrality.begin(), get(vertex_index, g_star),double())).vertex_index_map(get(vertex_index, g_star))); for ( tie(vertex_iterator_begin, vertex_iterator_end) = vertices(g_star); vertex_iterator_begin != vertex_iterator_end; ++vertex_iterator_begin) { cout << "Vertex: " << *vertex_iterator_begin <<"\tBC: "<< centrality[*vertex_iterator_begin] << endl; } }