gpt4 book ai didi

C++ Boost 图形库 - Dijkstra 示例

转载 作者:搜寻专家 更新时间:2023-10-31 01:16:38 25 4
gpt4 key购买 nike

我在使用来自 boost graph library Dijkstra example 的代码时遇到一些问题.我更改了它,以便我的版本不使用枚举和字母,而只使用整数。它提示 for 循环和 tie 函数,以及除第一个之外的其他 tie 调用。

声明:

  typedef std::pair<int, int> Edge;

const int num_edges = num_edge;
Edge edge_array[num_edges];
int weights[num_edges];

int size = 0;
for(itora = edges.begin(); itora != edges.end(); ++itora){
int u = *itora;
++itora;
int v = *itora;
++itora;

weights[size] = *itora;
edge_array[size] = Edge(u,v);

size++;
}


graph_traits<graph_t>::vertex_iterator i, iend;
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
graph_t g(vertices.size());
property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g);

std::vector<vertex_descriptor> msvc_vertices;
for (boost::tie(i, iend) = vertices(g); i != iend; ++i){
msvc_vertices.push_back(*i);
}

for (std::size_t j = 0; j < num_edges; ++j) {
edge_descriptor e; bool inserted;
boost::tie(e, inserted) = add_edge(msvc_vertices[edge_array[j].first],
msvc_vertices[edge_array[j].second], g);
weightmap[e] = weights[j];
}

不断裂:

for (boost::tie(i, iend) = vertices(g); i != iend; ++i){
msvc_vertices.push_back(*i);
}

这部分中断:

graph_traits<graph_t>::vertex_iterator xi, xiend;
for (boost::tie(xi, xiend) = vertices(g); xi != xiend; ++xi) {
indexmap[*xi] = c;
name[*xi] = '0' + c;
c++;
}

这里是错误:

x.cc: In function 'int main(int, char**)':
x.cc:141: error: no match for call to '(std::vector<int, std::allocator<int> >) (main(int, char**)::graph_t&)'
gmake: *** [x.o] Error 1

任何帮助将不胜感激,我真的不知道错误在提示什么...

最佳答案

您是否创建了局部变量 std::vector<int> vertices在未引用代码的某处?

关于C++ Boost 图形库 - Dijkstra 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8903516/

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