이것은 내가 작성한 A*
알고리즘입니다. "제거 된 것이 아니라 후미가 프론티어에 추가되었을 때 목표 테스트를 수행합니다.이 절충안 최적 ". "제거되지 않을 때"라는 의미는 무엇입니까? 바로 견적 전에`A *`노드를 프론티어에서 제거함
def solve(problem, heuristic) :
"""
A* search algorithm finding the shortest path.
Returns:
A list of actions.
"""
s0 = problem.get_initial_state()
queue = PriorityQueue()
queue.push((0,s0,[]),0) # second 0 is priority
cost_so_far = dict()
cost_so_far[s0] = 0
while not queue.is_empty():
current_cost, s, actions = queue.pop()
for successor, action, cost in problem.get_successors(s):
new_cost = current_cost + cost
if problem.goal_test(successor):
return actions + [action]
else:
h = heuristic(successor, problem)
if successor not in cost_so_far or cost_so_far[successor] > new_cost + h:
cost_so_far[successor] = new_cost + h
queue.push((new_cost, successor, actions + [action]), new_cost + h)
수정 된 버전 (업데이트) 위키
def solve(problem, heuristic) :
"""
A* search algorithm finding the shortest path.
Returns:
A list of actions.
"""
s0 = problem.get_initial_state()
queue = PriorityQueue()
queue.push((s0,[]),0) # 0 is the priority
cost_so_far = {s0:0}
while not queue.is_empty():
s, actions = queue.pop()
if problem.goal_test(s):
return actions
for successor, action, cost in problem.get_successors(s):
successor_cost = current_cost + cost
new_cost = successor_cost + heuristic(successor, problem)
if successor not in cost_so_far or cost_so_far[successor] > new_cost:
cost_so_far[successor] = new_cost
queue.push((successor, actions + [action]), new_cost)
이것은 아마도 귀하의 평가사와 이야기 할 내용입니다. –