5

我进行了一个寻路库。QuickGraph,开放式图形库,符合我的所有要求,但我遇到了一个问题。我需要最短路径算法来跳过当前移动代理无法通过的边缘。我想要的是这样的:

Func<SEquatableEdge<VectorD3>, double> cityDistances = delegate(SEquatableEdge<VectorD3> edge)
{

    if(edge.IsPassableBy(agent))
        return edgeWeight; // Edge is passable, return its weight
    else
        return -1; // Edge is impassable, return -1, which means, that path finder should skip it

};

Func<VectorD3, double> heuristic = ...;

TryFunc<VectorD3, IEnumerable<SEquatableEdge<VectorD3>>> tryGetPath = graph2.ShortestPathsAStar(cityDistances, heuristic, sourceCity);

我可以想象通过创建图形副本并删除无法通过的边来解决这个问题,但这对计算机资源来说是不必要的浪费。有人可以提示我如何解决这个问题吗?还是没有解决方案,我应该更新源?

4

1 回答 1

0

鉴于您的权重是double类型,您应该能够使用无法通过double.PositiveInfinity的边缘的权重。

正如 Eric Lippert 所说,高权重的失败案例是一条完整的路径,但是任何加法或减法double.PositiveInfinity都应该是无限的。该double类型有一个IsPositiveInfinity测试方法。

因此,尝试将不可通过权重设置为无穷大并测试最终路径长度。

于 2014-03-20T19:52:02.797 回答