//我也不知道写的对吗,先放上,之后再改
Astar(graph,start, end):
closed_set = set()
open_set = set()
g_func = {}
h_func = {}
f_func = {}
// f = g + h
g_func[start] = 0
parent = {} //key 为一个节点, value为其父节点
open_set = open_set ∪ {start} //集合并
while open_set != 空集: //open_set不为空
u := min_f(open_set) //open_set中最小 f 值
if u == end:
return parent
closed_set = closed_set ∪ {u}
for v in adj(u): //u的邻接点
if v not in closed_set: #v不在closed_set里面
parent[v] = u
if v not in open_set: #v不在open_set里面
h_func[v] = 启发函数h(v,end)
g_func[v] = 函数g(start,v)
open_set = open_set ∪ {v}
else:
if g_func[v] > 函数g(start,v):
g_func[v] = 函数g(start,v)
A*算法
最新推荐文章于 2021-03-26 19:28:16 发布