labeled_graph 中的权重

Weights in a labeled_graph

如何为这个使用 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;
}

随处可见。在捆绑的 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(或搜索我的答案以获取示例)。