【发布时间】:2021-02-18 20:40:54
【问题描述】:
我正在尝试使用 Edge length 属性作为权重来计算城市街道网络的中介中心性,但它似乎不起作用。
当我在没有重量的情况下跑步时,它会给出以下结果:
min: 0
mean: -nan(ind)
max: inf
stddev: -nan(ind)
还有权重:
min: 0
mean: 0
max: 0
stddev: 0
任何帮助将不胜感激
我的实现(在较小的图表中有效):
struct TravelEdge {
float length = 0.0f;
};
struct TravelNode {
float xcoord = 0.0f;
float ycoord = 0.0f;
std::string osmid;
};
typedef boost::adjacency_list<
boost::vecS, boost::vecS, boost::directedS,
TravelNode, TravelEdge
> GraphMap;
typedef boost::property_map<GraphMap, boost::vertex_index_t>::type VertexIndexMap;
int main(){
GraphMap graph;
// ... loads from graphml file
std::vector<double> centrality_vector(boost::num_vertices(graph), 0.0);
VertexIndexMap v_index = get(boost::vertex_index, graph);
boost::iterator_property_map<std::vector<double>::iterator, VertexIndexMap>
vertex_property_map = make_iterator_property_map(centrality_vector.begin(), v_index);
auto weight_map = make_transform_value_property_map([](TravelEdge& e) { return e.length; }, get(boost::edge_bundle, graph));
// without weights
//boost::brandes_betweenness_centrality(graph, vertex_property_map);
// with weights
boost::brandes_betweenness_centrality(graph, boost::predecessor_map(vertex_property_map).weight_map(weight_map));
boost::accumulators::accumulator_set<
double,
boost::accumulators::features<
boost::accumulators::tag::min,
boost::accumulators::tag::max,
boost::accumulators::tag::mean,
boost::accumulators::tag::variance
>
> acc;
std::for_each(centrality_vector.begin(), centrality_vector.end(), std::ref(acc));
return 0;
}
【问题讨论】:
标签: c++ boost boost-graph