diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-12-18 02:14:20 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-12-18 02:14:20 +0000 |
commit | b092a120b8c940f1eed2539f9b6d937d347541f9 (patch) | |
tree | ce6b57cd2ac8b00067a35aaa5de2eb002c083001 | |
parent | ae614f5480c8dc403ec5b713bd745e93e0aa405f (diff) | |
download | aoc2023-b092a120b8c940f1eed2539f9b6d937d347541f9.tar.gz aoc2023-b092a120b8c940f1eed2539f9b6d937d347541f9.tar.xz aoc2023-b092a120b8c940f1eed2539f9b6d937d347541f9.zip |
undo some of the excessive "cleaning"
-rw-r--r-- | utils.py | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -38,9 +38,14 @@ def a_star( return ret open_heapq: list[tuple[float, int]] = [(h(start), intern(start))] + open_set: set[int] = {intern(start)} g_score: defaultdict[T, float] = defaultdict(lambda: float("inf"), [(start, 0)]) - while open_heapq: - f, current = heappop(open_heapq) + while open_set: + while True: + f, current = heappop(open_heapq) + if current in open_set: + break + open_set.remove(current) current = itov[current] if callable(goal): if goal(current): @@ -53,4 +58,5 @@ def a_star( g_score[neighbour] = tentative_g f_score = tentative_g + h(neighbour) heappush(open_heapq, (f_score, intern(neighbour))) + open_set.add(intern(neighbour)) return None |