added queue

This commit is contained in:
yue qi
2020-06-26 23:13:14 -07:00
parent b25bfec8d3
commit 3f087aa9ab
3 changed files with 68 additions and 6 deletions
+6 -6
View File
@@ -11,8 +11,8 @@ import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../../Search-based Planning/")
from Astar_3D.env3D import env
from Astar_3D.utils3D import getAABB, getDist, getRay, StateSpace, Heuristic
from queue import QueuePrior
from Astar_3D.utils3D import getAABB, getDist, getRay, StateSpace, Heuristic, getNearest
import queue
class Weighted_A_star(object):
@@ -22,10 +22,10 @@ class Weighted_A_star(object):
[1,-1,0],[-1,1,0],[1,0,-1],[-1,0, 1],[0,1, -1],[0, -1,1],\
[1,-1,-1],[-1,1,-1],[-1,-1,1],[1,1,-1],[1,-1,1],[-1,1,1]])
self.env = env()
self.Space = StateSpace(env.boundary) # key is the point, store g value
self.OPEN = QueuePrior() # store [point,priority]
self.start = getNearest(self.Space,env.start)
self.goal = getNearest(self.Space,env.goal)
self.Space = StateSpace(self.env.boundary) # key is the point, store g value
self.OPEN = queue.QueuePrior() # store [point,priority]
self.start = getNearest(self.Space,self.env.start)
self.goal = getNearest(self.Space,self.env.goal)
self.h = Heuristic(self.Space,self.goal)
self.Parent = {}
self.CLOSED = {}
+62
View File
@@ -0,0 +1,62 @@
import collections
import heapq
class QueueFIFO:
"""
Class: QueueFIFO
Description: QueueFIFO is designed for First-in-First-out rule.
"""
def __init__(self):
self.queue = collections.deque()
def empty(self):
return len(self.queue) == 0
def put(self, node):
self.queue.append(node) # enter from back
def get(self):
return self.queue.popleft() # leave from front
class QueueLIFO:
"""
Class: QueueLIFO
Description: QueueLIFO is designed for Last-in-First-out rule.
"""
def __init__(self):
self.queue = collections.deque()
def empty(self):
return len(self.queue) == 0
def put(self, node):
self.queue.append(node) # enter from back
def get(self):
return self.queue.pop() # leave from back
class QueuePrior:
"""
Class: QueuePrior
Description: QueuePrior reorders elements using value [priority]
"""
def __init__(self):
self.queue = []
def empty(self):
return len(self.queue) == 0
def put(self, item, priority):
heapq.heappush(self.queue, (priority, item)) # reorder x using priority
def get(self):
return heapq.heappop(self.queue)[1] # pop out the smallest item
def enumerate(self):
return self.queue