-
Notifications
You must be signed in to change notification settings - Fork 3
/
open.py
60 lines (46 loc) · 1.6 KB
/
open.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import heapq
from node import GridNode, CTNode
class CTOpen:
def __init__(self):
self.queue = []
def __iter__(self):
return iter(self.queue)
def __len__(self):
return len(self.queue)
def is_empty(self):
if len(self.queue) != 0:
return False
return True
def get_best_node(self):
best = heapq.heappop(self.queue)
return best
def add_node(self, item: CTNode):
heapq.heappush(self.queue, item)
class GridOpen:
def __init__(self):
self.queue = []
self.coord_to_node = {}
self.entry_counter = 0
def __iter__(self):
return iter(self.queue)
def __len__(self):
return len(self.queue)
def is_empty(self):
if len(self.queue) != 0:
return False
return True
def get_best_node(self):
best = heapq.heappop(self.queue)
return best[2]
def add_node(self, item: GridNode):
if (item.i, item.j, item.t) in self.coord_to_node:
if self.coord_to_node[(item.i, item.j, item.t)].g > item.g:
self.coord_to_node[(item.i, item.j, item.t)].f = item.f
self.coord_to_node[(item.i, item.j, item.t)].g = item.g
self.coord_to_node[(item.i, item.j, item.t)].parent = item.parent
heapq.heappush(self.queue, (item.f, self.entry_counter, item))
self.entry_counter += 1
else:
self.coord_to_node[(item.i, item.j, item.t)] = item
heapq.heappush(self.queue, (item.f, self.entry_counter, item))
self.entry_counter += 1