gpt4 book ai didi

c++ - 如何计算权重之间的中间性

转载 作者:行者123 更新时间:2023-12-03 07:22:29 25 4
gpt4 key购买 nike

我正在尝试使用“边缘长度”属性作为权重来计算城市街道网络的居中性,但这似乎行不通。
当我没有重量运行时,将得到以下结果:

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))
);
我希望有人觉得这有用

关于c++ - 如何计算权重之间的中间性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64709107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com