Guest User

Untitled

a guest
Dec 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. def uniformCostSearch(problem):
  2.     fridges = util.PriorityQueue()
  3.     fridges.push([[problem.getStartState(), 'Start', 0]], 0)
  4.     visited = [problem.getStartState()]
  5.  
  6.     while not fridges.isEmpty():
  7.         fridge = fridges.pop()
  8.         state, dir, cost = fridge[-1]
  9.  
  10.         if (problem.isGoalState(state)):
  11.             path = []
  12.  
  13.             for state, dir, cost in fridge:
  14.                 path.append(dir)
  15.  
  16.             path.remove('Start');
  17.             return path
  18.  
  19.         visited.append(state)
  20.         newStates = problem.getSuccessors(state)
  21.         for newState, newDir, newCost in newStates:
  22.             if (visited.count(newState) == 0):
  23.                 fridges.push(fridge + [[newState, newDir, newCost]], cost + newCost)
Add Comment
Please, Sign In to add comment