Lemon dijkstra计算错误的路径/路径长度,为什么?

时间:2015-09-04 08:05:49

标签: c++ lemon-graph-library

我使用以下代码计算从G中的源节点到所有其他节点的最短路径长度:

void class::initilize(int T, ListDigraph &G, ListDigraph::ArcMap <int> &duration,
                                  ListDigraph::ArcMap <int> &capacity, ListDigraph::NodeMap <int> &supply) {
vector<int> to_dist(countNodes(G));
vector<int> from_dist(countNodes(G));
Node s = getsource();
Node t = getsink();
//ListDigraph::NodeMap<int> dist(G);
lemon::Dijkstra<ListDigraph, Duration> dijkstra_instance(G, duration);
dijkstra_instance.run(s);
for (ListDigraph::NodeIt n(G); n != INVALID; ++n) {
    for (Node v=n;v != s; v=dijkstra_instance.predNode(v)) {
        std::cout << G.id(v) << "<-";
    }
    cout << dijkstra_instance.dist(n) << endl;
    cout << G.id(n) << endl;
    to_dist[G.id(n)] = dijkstra_instance.dist(n);
    dijkstra_instance.run(n, t);
    from_dist[G.id(n)] = dijkstra_instance.dist(t);
}

但是,我将计算出的路径长度与实际路径长度进行比较,它们不是真的。即使路径错误,输出中也会出现节点为-1的节点。 当我现在将dijkstra_instance.run放入for循环时,计算是正确的。我使用dijkstra命令错了吗?

0 个答案:

没有答案