mirror of
https://github.com/zhm-real/PathPlanning.git
synced 2026-08-29 16:40:46 +08:00
added queue
This commit is contained in:
@@ -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 = {}
|
||||
|
||||
Binary file not shown.
@@ -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
|
||||
Reference in New Issue
Block a user