yue qi před 5 roky
rodič
revize
3f087aa9ab

+ 6 - 6
Search-based Planning/Astar_3D/Astar3D.py

@@ -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 = {}

binární
Search-based Planning/Astar_3D/__pycache__/queue.cpython-37.pyc


+ 62 - 0
Search-based Planning/Astar_3D/queue.py

@@ -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