has no member "类型”-6ren"> has no member "类型”-一段时间以来,我一直在努力使用 Boost 框架来实现 Djikstra 的算法,但我似乎无法弄清楚我遗漏了什么。 使用在以下位置找到的示例:https://www.boost.org/doc/lib-6ren">
gpt4 book ai didi

c++ - Boost Djikstra 类 "boost::property_map> has no member "类型”

转载 作者:太空宇宙 更新时间:2023-11-04 12:45:03 26 4
gpt4 key购买 nike

一段时间以来,我一直在努力使用 Boost 框架来实现 Djikstra 的算法,但我似乎无法弄清楚我遗漏了什么。

使用在以下位置找到的示例:https://www.boost.org/doc/libs/1_67_0/libs/graph/doc/dijkstra_shortest_paths.html ,

第 36 行出现错误

property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g);

class "boost::property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_weight_t, int, boost::no_property>, boost::no_property, boost::listS>, boost::edge_weight_t, void>" has no member "type"

我找不到其他人遇到同样的问题,而且我似乎无法弄清楚问题出在哪里。对此问题的任何帮助将不胜感激。

提前致谢

最佳答案

问题很可能是您未能在图上定义边权重属性。例如:

Live On Coliru

using graph_t = boost::adjacency_list</*boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::no_property*/>;

boost::property_map<graph_t, boost::edge_weight_t>::type weightmap = boost::get(boost::edge_weight, g);

不编译。你应该添加一个:

Live On Coliru

#include <boost/graph/adjacency_list.hpp>

using graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
boost::no_property,
boost::property<boost::edge_weight_t, double> >;

int main() {
graph_t g(5);
boost::property_map<graph_t, boost::edge_weight_t>::type weightmap = boost::get(boost::edge_weight, g);
}

你或许可以稍微简化一下:

auto weightmap = get(boost::edge_weight, g);

或者考虑使用捆绑属性:

Live On Coliru

#include <boost/graph/adjacency_list.hpp>

struct EdgeProps {
double weight = 0.0;
};

using graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, EdgeProps>;

int main() {
graph_t g(5);
auto weightmap = get(&EdgeProps::weight, g);
}

关于c++ - Boost Djikstra 类 "boost::property_map> has no member "类型”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52099598/

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