Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def search(problem, heuristic, usegN, astar):
- """Multifunctional Algorithm"""
- fringe = util.PriorityQueue()
- generated = {}
- n = node.Node(problem.getStartState())
- fringe.push(n, 0)#el cost=0 ja que es el node inicial
- generated[n.state] = ['F', n]
- while True:
- #TEST OBJETIVO
- if fringe.isEmpty():
- print "No Solution"
- sys.exit(-1)
- n = fringe.pop()
- if problem.isGoalState(n.state):
- return n.path()
- print "Solution"
- if not generated[n.state][0] == 'E':
- generated[n.state] = ['E', n]
- #GENERAR SUCESORES
- for s, a, c in problem.getSuccessors(n.state):
- #FUNCION DE COSTE ADAPTABLE AL ALGORITMO
- fdeNsuc = max(n.fdeN * astar, heuristic(s, problem) + (n.gdeN + c) * usegN)
- ns = node.Node(s, n, a, fdeNsuc, n.gdeN + c)
- #CONTROLAR NODOS YA EXPANDIDOS O EN EL FRINGE
- if not generated.get(ns.state) == None:
- if generated.get(ns.state)[0] == 'E':
- continue
- if generated.get(ns.state)[0] == 'F' and generated[ns.state][1].fdeN <= ns.fdeN:
- continue
- fringe.push(ns, fdeNsuc)
- generated[ns.state] = ['F', ns]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement