[英]QuickGraph - How can I make A* to skip particular edges?
我進行了一個尋路庫。 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);
我可以想象通過創建圖形副本並刪除不可通過的邊緣來解決這個問題,但這是不必要的浪費計算機資源。 請問,我可以提示我如何解決這個問題? 或者沒有解決方案,我應該更新源?
鑒於你的權重是double
類型,你應該能夠使用double.PositiveInfinity
來獲得無法通行的邊緣的權重。
正如Eric Lippert所說,高權重的失敗案例是一條完整的路徑,但是double.PositiveInfinity
任何加法或減法double.PositiveInfinity
應該是無限的。 double
類型有一個IsPositiveInfinity
方法來測試。
因此,嘗試將無法通過的權重設置為無窮大並測試最終路徑長度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.