如何为使用add_edge_by_label在dijkstra_shortest_paths中使用的带标签的图形添加权重? 我试图使用example 感谢
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/copy.hpp>
#include <boost/graph/labeled_graph.hpp>
#include <boost/graph/graph_utility.hpp>
struct NodeInfo1 { int i; };
struct EdgeInfo1 { int j; };
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, NodeInfo1, EdgeInfo1> AList;
typedef boost::labeled_graph<AList, std::string> Graph;
auto TestCopyGraph()
{
std::string names[3] = { "A", "B", "C" };
NodeInfo1 props[3] = { {11}, {22}, {33} };
Graph grid(3, names, props);
/*auto e =*/ add_edge_by_label("C", "B", EdgeInfo1{17}, grid);
Graph g1 = grid; // just copy-construct
return g1;
}
答案 0 :(得分:1)
随时随地。在捆绑的j
字段中?
auto weight_map = boost::get(&EdgeInfo1::j, g1);
在外部地图中?
std::map<Graph::edge_descriptor, double> weights;
auto weight_map = boost::make_assoc_property_map(weights);
根据文档直接或作为命名参数传递给dijkstra(或搜索我的答案以获取示例)。