问题描述
我正在尝试使用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;
}
解决方法
好吧,那很尴尬,结果证明代码是正确的,我的图形有某种错误,我重新生成了它,并且它起作用了。
编辑1
看到加载图所需的时间和内存量后,我 能够找到问题,在节点上进行了一些操作之后, 将它们插入同一张图中,而不是一张新图中。
编辑2
调用权重之间的函数的方法是错误的,正确的方法是:
boost::brandes_betweenness_centrality(
graph,centrality_map(vertex_property_map)
.vertex_index_map(v_index)
.weight_map(get(&TravelEdge::travel_time,graph))
);
我希望有人觉得这很有用p