def search(start,stop,depthLimit,maxDepth=0): if depthLimit == 0: return None agenda, explored = Stack(), set() if (stop(start)): return trajectory(start) agenda.push(start) depth = 0 while(agenda): nodo = agenda.pop() if depth <= depthLimit: #nodo = agenda.pop() explored.add(nodo) for child in nodo.expand(): if (stop(child)): return trajectory(child) elif(not child in explored): agenda.push(child) else: break depth = depth + 1 return None
def search(start, stop, heuristic): agenda = queue.PriorityQueue() explored = set() memoria = 1 if (stop(start)): return (trajectory(start), memoria) cota = heuristic(start) mini = 0 while (True): agenda.put((0, start)) while (not agenda.empty()): nodo = agenda.get() if (stop(nodo[1])): return (trajectory(nodo[1]), memoria) explored.add(nodo[1]) for child in nodo[1].expand(): if (not child in explored): if (cota > child.depth + heuristic(child)): agenda.put((child.depth + heuristic(child), child)) if (agenda.qsize() > memoria): memoria = agenda.qsize() elif (child.depth + heuristic(child) != cota): if (mini == 0 or mini > child.depth + heuristic(child)): mini = child.depth + heuristic(child) cota = mini agenda = queue.PriorityQueue() explored = set() memoria = 1 mini = 0
def search(start,stop,heuristic): agenda = queue.PriorityQueue() explored = set() memoria = 1 if(stop(start)): return (trajectory(start),memoria) cota = heuristic(start) mini = 0 while (True): agenda.put((0,start)) while (not agenda.empty()): nodo = agenda.get() if(stop(nodo[1])): return (trajectory(nodo[1]),memoria) explored.add(nodo[1]) for child in nodo[1].expand(): if(not child in explored): if(cota > child.depth+heuristic(child)): agenda.put((child.depth+heuristic(child),child)) if(agenda.qsize()>memoria): memoria=agenda.qsize() elif (child.depth+heuristic(child) != cota): if(mini == 0 or mini > child.depth+heuristic(child)): mini = child.depth+heuristic(child) cota = mini agenda = queue.PriorityQueue() explored = set() memoria=1 mini = 0
def search(start, stop): if stop(start): return trajectory(start) bandera1, bandera2 = False, False #Front FF = deque() #Back FB = deque() FF.append(start) FB.append(stop) while (len(FF) != 0) or (len(FB) != 0): if len(FF) != 0: sol1 = FF.popleft() if (Bidirectional.exist(FB, sol1)): trajectoryFF = trajectory(sol1) bandera1 = True else: FF.append(sol1.expand()) if len(FB) != 0: sol2 = FB.popleft() if (Bidirectional.exist(FF, sol2)): trajectoryFB = trajectory(sol2) bandera2 = True else: FB.append(sol2.expand()) if bandera1 and bandera2: return trajectoryFF + trajectoryFB return None
def search(start,stop): Forward = set() Backward = set() Explored = set() Forward.add(start) Backward.add(stop) memoria1=1 memoria2=1 while (True): ForwardCpy = Forward.copy() while(ForwardCpy): Forward.pop() s = ForwardCpy.pop() Explored.add(s) if(s in Backward): tmp = Backward.copy() tmp2 = tmp.pop() while(not s.__eq__(tmp2)): tmp2 = tmp.pop() traj = trajectory(tmp2) traj.pop() traj.reverse() tmp2 = traj.pop() while(not stop.__eq__(tmp2)): tmp2 = traj.pop() traj.append(stop) return (trajectory(s)+traj,memoria1+memoria2) for child in s.expand(): if(not child in Explored): Forward.add(child) if(len(Forward)>memoria1): memoria1=len(Forward) BackwardCpy = Backward.copy() while (BackwardCpy): Backward.pop() s = BackwardCpy.pop() Explored.add(s) if(s in Forward): tmp = Forward.copy() tmp2 = tmp.pop() while(not s.__eq__(tmp2)): tmp2 = tmp.pop() traj = trajectory(s) traj.pop() traj.reverse() tmp3 = traj.pop() while (not stop.__eq__(tmp3)): tmp3 = traj.pop() traj.append(stop) return (trajectory(tmp2)+traj,memoria1+memoria2) for child in s.expand(): if(not child in Explored): Backward.add(child) if(len(Backward)>memoria2): memoria2=len(Backward)
def search(start, stop): Forward = set() Backward = set() Explored = set() Forward.add(start) Backward.add(stop) memoria1 = 1 memoria2 = 1 while (True): ForwardCpy = Forward.copy() while (ForwardCpy): Forward.pop() s = ForwardCpy.pop() Explored.add(s) if (s in Backward): tmp = Backward.copy() tmp2 = tmp.pop() while (not s.__eq__(tmp2)): tmp2 = tmp.pop() traj = trajectory(tmp2) traj.pop() traj.reverse() tmp2 = traj.pop() while (not stop.__eq__(tmp2)): tmp2 = traj.pop() traj.append(stop) return (trajectory(s) + traj, memoria1 + memoria2) for child in s.expand(): if (not child in Explored): Forward.add(child) if (len(Forward) > memoria1): memoria1 = len(Forward) BackwardCpy = Backward.copy() while (BackwardCpy): Backward.pop() s = BackwardCpy.pop() Explored.add(s) if (s in Forward): tmp = Forward.copy() tmp2 = tmp.pop() while (not s.__eq__(tmp2)): tmp2 = tmp.pop() traj = trajectory(s) traj.pop() traj.reverse() tmp3 = traj.pop() while (not stop.__eq__(tmp3)): tmp3 = traj.pop() traj.append(stop) return (trajectory(tmp2) + traj, memoria1 + memoria2) for child in s.expand(): if (not child in Explored): Backward.add(child) if (len(Backward) > memoria2): memoria2 = len(Backward)
def search(start, stop): agenda, explored = Stack(), set() if (stop(start)): return trajectory(start) agenda.push(start) while (agenda): nodo = agenda.pop() explored.add(nodo) for child in nodo.expand(): if (stop(child)): return trajectory(child) elif (not child in explored): agenda.push(child) return None
def search(start, stop): agenda = deque() explored = set() if (stop(start)): return trajectory(start) agenda.append(start) while (agenda): nodo = agenda.popleft() explored.add(nodo) for child in nodo.expand(): if (stop(child)): return trajectory(child) elif (not child in explored): agenda.append(child) return None
def search(start, stop, heuristic): agenda = [] explored = set() if (stop(start)): return trajectory(start) heapq.heappush(agenda, (0, start)) while (agenda): nodo = heapq.heappop(agenda)[-1] explored.add(nodo) for child in nodo.expand(): if (stop(child)): return trajectory(child) elif (not child in explored): heapq.heappush(agenda, (heuristic(child), child)) return None
def search(start,stop,heuristic): agenda = [] explored = set() if(stop(start)): return trajectory(start) heapq.heappush(agenda,(0,start)) while(agenda): nodo = heapq.heappop(agenda)[-1]; explored.add(nodo) for child in nodo.expand(): if(stop(child)): return trajectory(child) elif(not child in explored): heapq.heappush(agenda,(heuristic(child),child)) return None
def search(start, stop, depth): agenda = deque() memoria = 1 if (stop(start)): return (trajectory(start), memoria) elif (depth == 0): return (None, 0) agenda.append(start) while (agenda): nodo = agenda.pop() for child in nodo.expand(): if (stop(child)): return (trajectory(child), memoria) elif (child.depth < depth - 1): agenda.append(child) if (len(agenda) > memoria): memoria = len(agenda) return (None, 0)
def search(start,stop): agenda = deque() explored = set() if(stop(start)): return trajectory(start) agenda.append(start) while(agenda): nodo = agenda.popleft() explored.add(nodo) for child in nodo.expand(): if(stop(child)): return trajectory(child) elif(not child in explored): agenda.append(child) return None
def search(start,stop,depth): agenda=deque() memoria=1 if(stop(start)): return (trajectory(start),memoria) elif(depth==0): return (None,0) agenda.append(start) while(agenda): nodo=agenda.pop() for child in nodo.expand(): if(stop(child)): return (trajectory(child),memoria) elif(child.depth<depth-1): agenda.append(child) if(len(agenda)>memoria): memoria=len(agenda) return (None,0)
def search(start, stop, depthLimit, maxDepth): if maxDepth == 0: return None if (stop(start)): return trajectory(start) else: for i in range(0, maxDepth): if DLS.search(start, stop, depthLimit, maxDepth): return DLS.search(start, stop, depthLimit, maxDepth) depthLimit = depthLimit + 1 return None
def search(start, stop, heuristic): agenda = queue.PriorityQueue() explored = set() #tabla hash memoria = 1 if (stop(start)): return (trajectory(start), memoria) agenda.put((0, start)) while (not agenda.empty()): nodo = agenda.get() if (stop(nodo[1])): return (trajectory(nodo[1]), memoria) explored.add(nodo[1]) for child in nodo[1].expand(): if (not child in explored): agenda.put((child.depth + heuristic(child), child)) if (agenda.qsize() > memoria): memoria = agenda.qsize() return (False, 0)
def search(start, stop): agenda = deque() memoria = 1 if (stop(start)): return (trajectory(start), memoria) agenda.append(start) depth = 1 while (True): while (agenda): nodo = agenda.pop() for child in nodo.expand(): if (stop(child)): return (trajectory(child), memoria) elif (child.depth < depth - 1): agenda.append(child) if (len(agenda) > memoria): memoria = len(agenda) depth += 1 agenda = deque() memoria = 1 agenda.append(start)
def search(start,stop,heuristic): agenda = queue.PriorityQueue() explored = set() #tabla hash memoria = 1 if(stop(start)): return (trajectory(start),memoria) agenda.put((0,start)) while (not agenda.empty()): nodo = agenda.get() if(stop(nodo[1])): return (trajectory(nodo[1]),memoria) explored.add(nodo[1]) for child in nodo[1].expand(): if(not child in explored): agenda.put((child.depth+heuristic(child),child)) if(agenda.qsize()>memoria): memoria=agenda.qsize() return (False,0)