Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def uniformCostSearch(problem):
- """Search the node of least total cost first."""
- "*** YOUR CODE HERE ***"
- fringe = util.PriorityQueue()
- generated = {}
- n = node.Node(problem.getStartState(), None, None, 0)
- fringe.push(n, n.pathcost) #COMPROBAR SI ES UN ESTADO SOLUCION
- generated[n.state] = [n, 'F']
- while True:
- if fringe.isEmpty():
- sys.exit("failure")
- n = fringe.pop()
- if problem.isGoalState(n.state):
- return ns.path() #COMPROBAR QUE NO ESTA EN EL FRINGE
- if n.state in generated:
- if generated[n.state] != 'E':
- generated[n.state] = [n, 'E']
- for suc, action, cost in problem.getSuccessors(n.state):
- ns=node.Node(suc, n, action, n.pathcost + cost)
- if suc not in generated:
- fringe.push(ns, ns.pathcost)
- generated[ns.state] = [ns, 'F']
- elif n.pathcost > ns.pathcost:
- fringe.push(ns, ns.pathcost)
- generated[ns.state] = [ns, 'F']
- util.raiseNotDefined()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement