我正在尝试在 Java 中实现A* 搜索算法,我有一个问题:
我需要运行多少次 A* 循环,直到显然没有现有路径?
例如:如果我有一个 for 循环;“我”应该增加多久?
当您探索了 A* 可以到达的所有节点时,没有找到您的目标,那么您可以假设没有路径。
我认为您以错误的方式思考A *。您运行它,直到没有更多要搜索的节点。如果你还没有达到你的目标,那么就没有路径。
伪:
//Our list of still open nodes
List<Node> nodesToSearch = new List<Node>();
while (nodesToSearch.Count > 0)
{
//SearchNode, if its our target we are done
//Add reachable neighbours to the list of nodes to search. So next iteration we will continue on searching those
//Remove current node.. since its searched
}
//If we end up here without a target there is no path.
//That means we have searched all nodes and their neighbours etc etc etc. Without reaching the target.