一、A*算法简介
A*算法最早可追溯到1968年,在IEEE Transactions on Systems Science and Cybernetics中的论文A Formal Basis for the Heuristic Determination of Minimum Cost Paths中首次提出。正如本文的摘要所说,A*算法是把启发式方法(heuristic approaches)如BFS(完全使用贪心策略),和常规方法如Dijsktra算法结合在一起的算法。有点不同的是,类似BFS的启发式方法经常给出一个近似解而不是保证最佳解。然而,尽管A*算法基于无法保证最佳解的启发式方法,A*算法却能保证找到一条最短路径。
参考文献:
[1]张海涛,程荫杭.基于A*算法的全局路径搜索[J].微计算机信息, 2007(17):3.DOI:10.3969/j.issn.1008-0570.2007.17.095.
[2]张红梅,李明龙,杨乐.基于改进A*算法的移动机器人安全路径规划[J].计算机仿真, 2018, 35(4): 319-324.
二、部分代码
import math
import matplotlib.pyplot as plt
show_animation = True
class AStarPlanner:
def __init__(self, ox, oy, resolution, rr):
"""
Initialize grid map for a star planning
ox: x position list of Obstacles [m]
oy: y position list of Obstacles [m]
resolution: grid resolution [m]
rr: robot radius[m]
"""
self.resolution = resolution
self.rr = rr
self.min_x, self.min_y = 0, 0
self.max_x, self.max_y = 0, 0
self.obstacle_map = None
self.x_width, self.y_width = 0, 0
self.motion = self.get_motion_model()
self.calc_obstacle_map(ox, oy)
class Node:
def __init__(self, x, y, cost, parent_index):
self.x = x # index of grid
self.y = y # index of grid
self.cost = cost
self.parent_index = parent_index
def __str__(self):
return str(self.x) + "," + str(self.y) + "," + str(
self.cost) + "," + str(self.parent_index)
三、部分结果
四、完整Python代码
见下方联系方式