ARTICLE · 1355874
A*算法与救援路径规划问题(提供源码)
本期主题:针对火灾救援路径规划问题,本文给出了使用A*算法求解该问题的解决方案。此外,本文给出了相关求解代码和数值分析,供大家参考。
模型简略介绍:
在这期公众号基础上(基于改进蚁群算法的火灾救援路径规划:附完整代码实现和数学模型,链接https://mp.weixin.qq.com/s/-ma9FxRZJ0izPwBNxeUFtQ),本文使用精确A*算法代替EACO算法进行求解。感兴趣的宝子,可以先去看看这篇公众号的三值栅格模型。
一、A*算法简略介绍

二、 实验结果与分析
图1 仿真环境模型
图1定义了救援路径的起点和终点、火灾风险区域(绿色部分)、障碍物区域(黑色部分)以及白色区域的完全可通行区。
图2 在不同权重下,A*算法的路径规划情况
由图2可知,当较小的情况下,也称风险较小时,救援人员可以通过多个低风险区域到终点,实现救援路径的最短化。随着系数的增加,救援人员逐渐减少经过风险区域的次数,甚至完全避开风险区域。
图3 权重的影响
由图3可知,在低风险情况下,实际救援路径长度低于加权救援路径长度,说明此时救援可经过部分风险区域,实现救援路径最小化且赢得宝贵救援时间。然而,随着风险增大到一定值,此时实际救援路径长度等于加权救援路径长度,说明救援人员不能通过高风险区域,风险极大。
图4 A*算法的性能测试
三、 相关资料和关键代码
[1] Xu L , Wang J , Kuang C ,et al.A novel three-value grid scheme and rescue path planning algorithm for building fire[J].Journal of Intelligent & Fuzzy Systems, 2023, 45(6):12185-12200.DOI:10.3233/jifs-233862.
本文完整代码,可@我~~~~~
def a_star(gm, w=1.1, eps=1e-12): gm.risk_weight = float(w) start, end = gm.start, gm.end def h(node):return math.hypot(node[0] - end[0], node[1] - end[1]) t0 = time.perf_counter() tie = 0 open_heap = [(h(start), 0.0, tie, start)] g_score = {start: 0.0} parent = {start: None} closed = set() expanded = 0if start == end:return {"path": [start], "cost": 0.0,"expanded": 0, "time": time.perf_counter() - t0}while open_heap: f, _g_old, _, cur = heapq.heappop(open_heap)if cur in closed:continue g = g_score[cur]if cur == end: path = [] node = curwhile node is not None: path.append(node) node = parent[node] path.reverse()return {"path": path,"cost": g,"expanded": expanded,"time": time.perf_counter() - t0, } closed.add(cur) expanded += 1 r, c = curfor idx, nxt, _step in gm.neighbors(r, c):if nxt in closed:continue tentative = g + gm.edge_cost(cur, nxt)if tentative < g_score.get(nxt, float("inf")) - eps: g_score[nxt] = tentative parent[nxt] = cur tie += 1 heapq.heappush( open_heap, (tentative + h(nxt), tentative, tie, nxt) )return {"path": None, "cost": float("inf"),"expanded": expanded, "time": time.perf_counter() - t0}以上如有问题,欢迎批评指出,谢谢~~~~~~~~我们下期见!!!!!!
















































































