1

如何将权重添加到使用 add_edge_by_label 用于 dijkstra_shortest_paths 的标记图?我试图用一个例子 谢谢

#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;
}
4

1 回答 1

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(或搜索我的答案以获取示例)。

于 2016-03-08T22:46:45.780 回答