def busca(a, b): ab = search.GPSProblem(a, b, search.romania) sol = search.breadth_first_graph_search(ab) print "\nAnchura: nodos exapndidos = " + str(sol[1]) print sol[0].path() sol = search.depth_first_graph_search(ab) print "\nProfundidad: nodos exapndidos = " + str(sol[1]) print sol[0].path() sol = search.branch_and_bound(ab) print "\nRamificacion y acotacion: nodos exapndidos = " + str(sol[1]) print sol[0].path() sol = search.branch_and_bound_sub(ab) print "\nRamificacion y acotacion con subestimacion: nodos exapndidos = " + str( sol[1]) print sol[0].path() print '==================================================================================='
# Search methods import search ab = search.GPSProblem('O', 'E', search.romania) #af = search.GPSProblem('A', 'F', search.romania) #ae = search.GPSProblem('A', 'E', search.romania) # Alredy implemented ''' print "Breadth First: ", search.breadth_first_graph_search(ab).path() print "Depth First: ", search.depth_first_graph_search(ab).path() print "Depth limited:", search.iterative_deepening_search(ab).path() print search.depth_limited_search(ab).path() print search.astar_search(ab).path() ''' # Student methods print "Branch and Bound: ", search.branch_and_bound(ab).path() print "\nB&B Subestimate: ", search.branch_and_bound_subestimate(ab).path() # Result: # [<Node B>, <Node P>, <Node R>, <Node S>, <Node A>] : 101 + 97 + 80 + 140 = 418 # [<Node B>, <Node F>, <Node S>, <Node A>] : 211 + 99 + 140 = 450
# Search methods import search ab = search.GPSProblem('Z', 'L', search.romania) print "Busqueda por anchura" print search.breadth_first_graph_search(ab).path() print "Busqueda por profundidad" print search.depth_first_graph_search(ab).path() #print search.iterative_deepening_search(ab).path() #print search.depth_limited_search(ab).path() print "Ramificacion y acotacion. Debe dar [<Node L>, <Node T>, <Node A>, <Node Z>] y 18 Nodos expandidos" print search.branch_and_bound(ab).path() print "Ramificacion y acotacion con subestimacion. Debe dar [<Node L>, <Node T>, <Node A>, <Node Z>] y 6 Nodos expandidos" print search.branch_and_bound_with_underestimation(ab).path() #print search.astar_search(ab).path() # Result: # [<Node B>, <Node P>, <Node R>, <Node S>, <Node A>] : 101 + 97 + 80 + 140 = 418 # [<Node B>, <Node F>, <Node S>, <Node A>] : 211 + 99 + 140 = 450
# Search methods import search ab = search.GPSProblem('A', 'B', search.romania) az = search.GPSProblem('A', 'Z', search.romania) print(search.breadth_first_graph_search(ab).path()) print(search.depth_first_graph_search(ab).path()) print(search.branch_and_bound(ab).path()) print(search.branch_and_bound_h(ab).path()) print('-------------------------------------------------------') print(search.breadth_first_graph_search(az).path()) print(search.depth_first_graph_search(az).path()) print(search.branch_and_bound(az).path()) print(search.branch_and_bound_h(az).path()) # Result: # [<Node B>, <Node P>, <Node R>, <Node S>, <Node A>] : 101 + 97 + 80 + 140 = 418 # [<Node B>, <Node F>, <Node S>, <Node A>] : 211 + 99 + 140 = 450