Advertisement
Guest User

pacman

a guest
Oct 30th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. def uniformCostSearch(problem):
  2.     """Search the node of least total cost first."""
  3.     "*** YOUR CODE HERE ***"
  4.     fringe = util.PriorityQueue()
  5.     generated = {}
  6.     n = node.Node(problem.getStartState(), None, None, 0)
  7.     fringe.push(n, n.pathcost) #COMPROBAR SI ES UN ESTADO SOLUCION
  8.     generated[n.state] = [n, 'F']
  9.     while True:
  10.         if fringe.isEmpty():
  11.             sys.exit("failure")
  12.         n = fringe.pop()
  13.         if problem.isGoalState(n.state):
  14.         return ns.path() #COMPROBAR QUE NO ESTA EN EL FRINGE
  15.     if n.state in generated:       
  16.         if generated[n.state] != 'E':
  17.                 generated[n.state] = [n, 'E']
  18.                 for suc, action, cost in problem.getSuccessors(n.state):
  19.                 ns=node.Node(suc, n, action, n.pathcost + cost)
  20.                     if suc not in generated:
  21.                     fringe.push(ns, ns.pathcost)
  22.                     generated[ns.state] = [ns, 'F']
  23.                 elif n.pathcost > ns.pathcost:
  24.                     fringe.push(ns, ns.pathcost)
  25.                     generated[ns.state] = [ns, 'F']
  26.     util.raiseNotDefined()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement