您好我正在学习如何向Boost图库的邻接列表的节点和边添加属性。我使用以下代码为每个边添加3.1的距离:
typedef property < edge_weight_t, double >Weight;
using std::vector;
using Graph = adjacency_list<setS, vecS, undirectedS, Point, Weight>;
using vertex_descriptor = Graph::vertex_descriptor;
Graph lattuce; // add name of graph
for (auto vd : make_iterator_range(vertices(lattuce))) {
auto p = lattuce[vd];//pass number of vertice to p
for (Point neighbour : {
Point { p.x - 1, p.y - 1 }, Point { p.x - 1, p.y + 0 }, Point { p.x - 1, p.y + 1 },
Point { p.x + 0, p.y - 1 }, Point { p.x + 0, p.y + 1 },
Point { p.x + 1, p.y - 1 }, Point { p.x + 1, p.y + 0 }, Point { p.x + 1, p.y + 1 },
})//for loop goes around all neighbours, 8 per vertex
{
if (is_valid(neighbour)&&(arrayA[neighbour.x][neighbour.y]==0))//if there is a neighbour then add edge(gets rid off non zeros)
add_edge(nodes[neighbour.x][neighbour.y], vd, lattuce, 3.1);
};
}
我收到以下错误
main.cpp:105: error: no matching function for call to 'add_edge(__gnu_cxx::__alloc_traits<std::allocator<unsigned int> >::value_type&, unsigned int&, Graph&, double)'
add_edge(nodes[neighbour.x][neighbour.y], vd, lattuce, 3.1);
这只是我的代码的一部分,为了简洁起见,当我没有将权重属性和3.1值添加到边缘时,它可以正常工作。
任何帮助或指导都将非常感激:)