|
Boost Users : |
Subject: [Boost-users] request for help re: brandes_betweenness_centrality for weighted graph
From: allenem_at_[hidden]
Date: 2009-09-29 15:10:50
Hi-
I've just recently started to use the BGL and was wondering if someone
could provide an example (and/or just let me know where I am going
wrong) in trying to execute the brandes_betweenness_centrality algorithm
for a weighted graph.
Below are the relevant code snippets from my program.
I am able to compile and run the code, and have successfully iterated
over all elements (vertices, edges, and "interaction_weights" to verify
that the data are stored correctly) but the calculated betweenness
values are the same whether or not I use the edge weight map, which
suggests that they are not being considered in the calculation even when
passed as a parameter to the brandes_betweenness_centrality function.
What am I missing?
Thank you,
Emily
#include <boost/graph/graph_traits.hpp> // iterator functions
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/betweenness_centrality.hpp>
#include <map>
#include <vector>
using namespace std;
using namespace boost;
struct order_edges {
template <typename T>
bool operator() (const T& x, const T& y) const {
return x.get_property() < y.get_property();
}
};
/* =============================================================
Main
============================================================ */
int main(int argc, char **argv) {
// Define the Graph
typedef property < vertex_centrality_t, double > CentralityMap;
typedef adjacency_list<vecS, vecS, bidirectionalS, CentralityMap> Graph;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge;
typedef map<Edge, double, order_edges> edge_weight_map_t;
edge_weight_map_t base_map;
associative_property_map<edge_weight_map_t> interaction_weight(base_map);
Graph g; // instance of the graph
// determine vertices based upon input from a file
// add edges and assign values to associated interaction weights from
a file ....
brandes_betweenness_centrality(g, get(vertex_centrality,g),
interaction_weight);
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net