A*算法最快时间
A* Algorithm Quickest Time
我已经实施了 A* 算法来提供最短距离路线,但是我正试图改变它,以便它计算出最快的路线。
使用此伪代码:
function A*(start,goal)
closedset := the empty set // The set of nodes already evaluated.
openset := {start} // The set of tentative nodes to be evaluated, initially containing the start node
came_from := the empty map // The map of navigated nodes.
g_score[start] := 0 // Cost from start along best known path.
// Estimated total cost from start to goal through y.
f_score[start] := g_score[start] + heuristic_cost_estimate(start, goal)
while openset is not empty
current := the node in openset having the lowest f_score[] value
if current = goal
return reconstruct_path(came_from, goal)
remove current from openset
add current to closedset
for each neighbor in neighbor_nodes(current)
if neighbor in closedset
continue
tentative_g_score := g_score[current] + dist_between(current,neighbor)
if neighbor not in openset or tentative_g_score < g_score[neighbor]
came_from[neighbor] := current
g_score[neighbor] := tentative_g_score
f_score[neighbor] := g_score[neighbor] + heuristic_cost_estimate(neighbor, goal)
if neighbor not in openset
add neighbor to openset
return failure
我认为计算最快路线的最简单方法是将当前和邻居之间的距离除以该道路的限速:tentative_g_score := g_score[当前] + (dist_between(当前,邻居)/neighbor.speedlimit)
然而,这并没有在我的算法中给出正确的结果。
任何人都可以为我指出正确的方向,告诉我如何有效地做到这一点吗?
这是我当前的代码:http://pastebin.com/QWi6AwF9
最快路线,即从起点到达目的地所需时间最少的路线。
我的启发式函数是这样的
private double heuristic(Vertex goal, Vertex next)
{
return (Math.sqrt(Math.pow((goal.x - next.x), 2) + Math.pow((goal.y - next.y), 2)));
}
干杯
启发式函数必须是可接受的(也就是说,它不应该高估到目标的距离)。一旦开始将边的长度除以 speedlimit
,到目标的实际距离可能小于到目标的欧几里得距离(如果 speedlimit > 1
)。它打破了算法。如何解决?例如,您可以使用 dist / MAX_SPEED_LIMIT
作为启发式函数。
我已经实施了 A* 算法来提供最短距离路线,但是我正试图改变它,以便它计算出最快的路线。 使用此伪代码:
function A*(start,goal)
closedset := the empty set // The set of nodes already evaluated.
openset := {start} // The set of tentative nodes to be evaluated, initially containing the start node
came_from := the empty map // The map of navigated nodes.
g_score[start] := 0 // Cost from start along best known path.
// Estimated total cost from start to goal through y.
f_score[start] := g_score[start] + heuristic_cost_estimate(start, goal)
while openset is not empty
current := the node in openset having the lowest f_score[] value
if current = goal
return reconstruct_path(came_from, goal)
remove current from openset
add current to closedset
for each neighbor in neighbor_nodes(current)
if neighbor in closedset
continue
tentative_g_score := g_score[current] + dist_between(current,neighbor)
if neighbor not in openset or tentative_g_score < g_score[neighbor]
came_from[neighbor] := current
g_score[neighbor] := tentative_g_score
f_score[neighbor] := g_score[neighbor] + heuristic_cost_estimate(neighbor, goal)
if neighbor not in openset
add neighbor to openset
return failure
我认为计算最快路线的最简单方法是将当前和邻居之间的距离除以该道路的限速:tentative_g_score := g_score[当前] + (dist_between(当前,邻居)/neighbor.speedlimit) 然而,这并没有在我的算法中给出正确的结果。
任何人都可以为我指出正确的方向,告诉我如何有效地做到这一点吗?
这是我当前的代码:http://pastebin.com/QWi6AwF9
最快路线,即从起点到达目的地所需时间最少的路线。
我的启发式函数是这样的
private double heuristic(Vertex goal, Vertex next)
{
return (Math.sqrt(Math.pow((goal.x - next.x), 2) + Math.pow((goal.y - next.y), 2)));
}
干杯
启发式函数必须是可接受的(也就是说,它不应该高估到目标的距离)。一旦开始将边的长度除以 speedlimit
,到目标的实际距离可能小于到目标的欧几里得距离(如果 speedlimit > 1
)。它打破了算法。如何解决?例如,您可以使用 dist / MAX_SPEED_LIMIT
作为启发式函数。