Initialize queue only in init_queue function

This commit is contained in:
mrg 2021-01-06 09:40:49 -08:00
parent ec6f0f1873
commit 72dc1c58da
1 changed files with 5 additions and 17 deletions

View File

@ -23,9 +23,6 @@ class signal_grid(grid):
""" Create a routing map of width x height cells and 2 in the z-axis. """ """ Create a routing map of width x height cells and 2 in the z-axis. """
grid.__init__(self, ll, ur, track_factor) grid.__init__(self, ll, ur, track_factor)
# priority queue for the maze routing
self.q = []
def reinit(self): def reinit(self):
""" Reinitialize everything for a new route. """ """ Reinitialize everything for a new route. """
@ -33,14 +30,8 @@ class signal_grid(grid):
for p in self.map.values(): for p in self.map.values():
p.reset() p.reset()
# clear source and target pins self.clear_source()
self.source = set() self.clear_target()
self.target = set()
# Clear the queue
while len(self.q) > 0:
heappop(self.q)
self.counter = 0
def init_queue(self): def init_queue(self):
""" """
@ -51,12 +42,13 @@ class signal_grid(grid):
""" """
# Counter is used to not require data comparison in Python 3.x # Counter is used to not require data comparison in Python 3.x
# Items will be returned in order they are added during cost ties # Items will be returned in order they are added during cost ties
self.q = []
self.counter = 0 self.counter = 0
for s in self.source: for s in self.source:
cost = self.cost_to_target(s) cost = self.cost_to_target(s)
debug.info(3, "Init: cost=" + str(cost) + " " + str([s])) debug.info(3, "Init: cost=" + str(cost) + " " + str([s]))
heappush(self.q, (cost, self.counter, grid_path([vector3d(s)]))) heappush(self.q, (cost, self.counter, grid_path([vector3d(s)])))
self.counter+=1 self.counter += 1
def route(self, detour_scale): def route(self, detour_scale):
""" """
@ -72,11 +64,7 @@ class signal_grid(grid):
# Check if something in the queue is already a source and a target! # Check if something in the queue is already a source and a target!
for s in self.source: for s in self.source:
if self.is_target(s): if self.is_target(s):
return((grid_path([vector3d(s)]),0)) return((grid_path([vector3d(s)]), 0))
# Make sure the queue is empty if we run another route
while len(self.q)>0:
heappop(self.q)
# Put the source items into the queue # Put the source items into the queue
self.init_queue() self.init_queue()