QuickGraph - 如何使A*跳过特定边缘?

Pan*_*zky 5 c# graph path-finding quickgraph

我进行了一个寻路库.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);
Run Code Online (Sandbox Code Playgroud)

我可以想象通过创建图形副本并删除不可通过的边缘来解决这个问题,但这是不必要的浪费计算机资源.请问,我可以提示我如何解决这个问题?或者没有解决方案,我应该更新源?

Iai*_*ard 0

鉴于您的权重是特定double类型的,您应该能够用于double.PositiveInfinity不可逾越边缘的权重。

正如埃里克·利珀特(Eric Lippert)所说,高权重的失败案例是一条完整的路径,但是任何加法或减法double.PositiveInfinity仍然应该是无穷大。该double类型有一个IsPositiveInfinity测试方法。

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