#include #include #include #include #include #include #include #include // Graph edge properties (bundled properties) struct EdgeProperties { int weight; }; typedef boost::property EdgeWeightProperty; typedef boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, boost::no_property, EdgeWeightProperty > Graph; typedef Graph::vertex_descriptor Vertex; typedef Graph::edge_descriptor Edge; void WriteGraph(const Graph& g, const std::string& filename); int addition(int a, int b); int betweenness(int*, int*, int); int main()//std::vector arr) { //provide array of connections from graph //from https://www.google.co.uk/search?q=between+centrality+calculation&client=firefox-b-ab&dcr=0&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjeg8W7tdvZAhXMBZoKHbEnCjkQ_AUICigB&biw=1376&bih=692#imgrc=H9wvPMTEbg6bKM: int arr [] = { 1,2, 1,3, 2,3, 3,4, 3,5, 2,5, 5,7, 5,6 }; //weights of the above connections int arr_weights[] = { 10,10,10,10,10,1,10,10}; int size_nodes = 8; int a; int out = 1; a = betweenness(arr, arr_weights, size_nodes);//works return 0; } int findMax(int array[], int arraySize) { int maxPosition = 0; //assume the first element is maximum for (int i = 1; i < arraySize; i++) if (array[i] > array[maxPosition]) //compare the current element with the known max maxPosition = i; //update maxPosition return array[maxPosition]; } int betweenness(int *param, int *weights, int size_nodes) { int ii = boost::lexical_cast("1"); double max_centrality = 14; //// Create a graph Graph g; int paramSize = size_nodes; static int Vert[50000000]; int biggest = findMax(param, 16); //create the vetrices for (int a1=0; a1 < biggest+1; a1++) { Vert[a1] = boost::add_vertex(g); } //create the edges (with the given weights included) for (int a2=0; a2 < paramSize; a2++) { //EdgeWeightProperty weight0 = 5; boost::add_edge(Vert[param[a2*2]],Vert[param[a2*2+1]], EdgeWeightProperty(weights[a2]), g); } // Define VertexCentralityMap typedef boost::property_map< Graph, boost::vertex_index_t>::type VertexIndexMap; VertexIndexMap v_index = get(boost::vertex_index, g); std::vector< double > v_centrality_vec(boost::num_vertices(g), 0.0); // Create the external property map boost::iterator_property_map< std::vector< double >::iterator, VertexIndexMap > v_centrality_map(v_centrality_vec.begin(), v_index); // Write to graphviz -> illustrate the graph via 'neato -Tps before.dot > before.ps' WriteGraph(g, "before.dot"); // Calculate the vertex and edge centralites // Can be used to get an initial impression about the edge centrality values for the graph //brandes_betweenness_centrality( g, v_centrality_map, e_centrality_map ); brandes_betweenness_centrality(g, v_centrality_map); //BGL_FORALL_VERTICES(vertex, g, Graph) for (int vertex=1;vertex