Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def uniformCostSearch(problem):
- fridges = util.PriorityQueue()
- fridges.push([[problem.getStartState(), 'Start', 0]], 0)
- visited = [problem.getStartState()]
- while not fridges.isEmpty():
- fridge = fridges.pop()
- state, dir, cost = fridge[-1]
- if (problem.isGoalState(state)):
- path = []
- for state, dir, cost in fridge:
- path.append(dir)
- path.remove('Start');
- return path
- visited.append(state)
- newStates = problem.getSuccessors(state)
- for newState, newDir, newCost in newStates:
- if (visited.count(newState) == 0):
- fridges.push(fridge + [[newState, newDir, newCost]], cost + newCost)
Add Comment
Please, Sign In to add comment