A*算法
A*算法是一种用于在地图上寻找两点之间距离最短的路径规划算法。他是dijkstra算法的扩展,使用启发式函数搜索到目标节点。
要实现A*,要维护两个列表;开放列表和关闭列表;开放列表中包含已经发现还没有探索的点,关闭列表中存放已经探索过的节点。
A*算法通过从开放列表中选择具有最低f值(g值和启发值之和)的节点并探索其邻居来工作,如果邻居不开开放列表中,则将其放置到开放列表中。如果已经在开放列表中,则如果到邻居的新路径比之前的路径更短,则更新其邻居的g值。
一旦到达目标节点,算法终止并返回起始点到目标点的最短路径。
def astar(start, goal, heuristic):
open_list = [start]
cloased_list = []
g_score = {node: float('inf') for node in graph}
g_score[start] = 0
f_score[start] = heuristic(start, goal)
while open_list:
current = min(open_list, key=lambda node: f_score[node])
if current == goal;
path = []
while current in came_front:
path.append(current)
current = came_front[current]
path.append(start)
path.reverse()
feturn path
open_list.remove(current)
closed_list.append(current)
for neighbor in graph[current]:
if neighbor in closed_list:
continue
tentative_g_score=g_score[current] + graph[current][neighbor]
if neighbor not in open_list:
open_list.append(neighbor)
elif tentative_g_score >= g_score[neighbor]:
continue
came_from[neighbor] = current
g_score[neighbor] = tentative_g_score
f_score[neighbor] = g_score[neighbor] + heuristic(neighbor, goal)
return None
实现过程中,start和goal是起始和目标节点。graph是一个字典,其中键是节点,值是与节点相邻的节点和他们之间的 距离。heuristic是一个函数,它接收两个节点作为参数并返回他们之间的启发式距离。
Hybrid A*
(5条消息) 混合A*算法研究_混合a*算法约束_robinvista的博客-CSDN博客
混合A(Hybrid A*)是一种基于A*搜索算法的路径规划算法。它的目标是在车辆导航等场景中高效的规划路径。
混合A*结合了连续和离散状态空间的优势,使用连续空间中的桶(bucket)表示离散空间,从而使搜索过程更加高效。它使用了一种称为Reeds-Shepp曲线的路径类型,可以在车辆导航中实现更加平滑的路劲规划。
混合A*使用了启发式函数来估计每个状态到达目标的代价,从而指导搜索方向。它还使用了一个称为代价到达图(cost-to-go map)的技术,将已知的最小代价存储在地图中,从而进一步优化搜索过程。
#define the A* search algorithm
def planning(self, sx, sy, syaw, gx, gy, gyaw):
待补充......