コード例 #1
0
def main():
    metodo = raw_input(
        "Ingrese el metodo de busqueda-- (greedy,depth_first,breadth_first,astar)\n"
    )
    STATE = generarEstado(LABERINTO)
    problema = rataProblem(STATE)
    if metodo == "breadth_first":
        r = breadth_first(problema, graph_search=True, viewer=ConsoleViewer())

    if metodo == "greedy":
        r = greedy(problema, graph_search=True, viewer=ConsoleViewer())

    if metodo == "depth_first":
        r = depth_first(problema, graph_search=True, viewer=ConsoleViewer())

    if metodo == "astar":
        r = astar(problema, graph_search=True, viewer=ConsoleViewer())

    print(
        "=======================================================================\n"
    )
    print "Estado final :", r.state, "\n"
    print "Path :", r.path(), "\n"
    l = [x[0] for x in r.path()]
    print "Acciones tomadas", l, "\n"
    print "Costo :", r.cost, "\n"
コード例 #2
0
def resolver(metodo_busqueda, posiciones_personas):

    state = (posicionRobot, hielosRotos, posiciones_personas)

    if metodo_busqueda == 'astar':
        visor=BaseViewer()
        result = astar(RescateSobreHielo(state),graph_search=True, viewer=visor)
    elif metodo_busqueda =='breadth_first':
        visor=BaseViewer()
        result = breadth_first(RescateSobreHielo(state),graph_search=True, viewer=visor)
    elif metodo_busqueda =='depth_first':
        visor=BaseViewer()
        result = depth_first(RescateSobreHielo(state),graph_search=True,viewer=visor)
    elif metodo_busqueda =='greedy':
        visor=BaseViewer()
        result = greedy(RescateSobreHielo(state),graph_search=True,viewer=visor)
    return result
コード例 #3
0
def resolver(metodo_busqueda, posiciones_personas):

    state = (posicionRobot, hielosRotos, posiciones_personas)

    if metodo_busqueda == 'astar':
        result = astar(RescateSobreHielo(state))

    elif metodo_busqueda == 'breadth_first':
        result = breadth_first(RescateSobreHielo(state))

    elif metodo_busqueda == 'depth_first':
        result = depth_first(RescateSobreHielo(state))

    elif metodo_busqueda == 'greedy':
        result = greedy(RescateSobreHielo(state))

    return result
コード例 #4
0
def resolver(metodo_busqueda, franceses, piratas):
    viewer = None
    barcos = []

    inicial = (tuple(franceses), tuple(piratas))

    problem = entrega1(inicial)
    if metodo_busqueda == "breadth_first":
        resultado = breadth_first(problem, graph_search=True, viewer=viewer)
    elif metodo_busqueda == "greedy":
        resultado = greedy(problem, graph_search=True, viewer=viewer)
    elif metodo_busqueda == "depth_first":
        resultado = depth_first(problem, graph_search=True, viewer=viewer)
    elif metodo_busqueda == "astar":
        resultado = astar(problem, graph_search=True, viewer=viewer)
    elif metodo_busqueda == "uniform_cost":
        resultado = uniform_cost(problem, graph_search=True, viewer=viewer)

    return resultado
コード例 #5
0
def main():
	estado = "{}|0|I|".format("1-3-6-8-12")
	problema = problemaLinterna(estado)
	metodo = raw_input("Ingrese el metodo de busqueda-- (greedy,depth_first,breadth_first)\n")

	if metodo == "breadth_first":    
 		p = breadth_first(problema,graph_search=True,viewer=ConsoleViewer())
    	
	if metodo == "greedy":    
		p = greedy(problema,graph_search=True,viewer=ConsoleViewer())

	if metodo == "depth_first":    
		p = depth_first(problema,graph_search=True,viewer=ConsoleViewer())

	
	print("=======================================================================\n")
	print "Estado final :",p.state,"\n"
	print "Path :",p.path(),"\n"
	l = [x[0] for x in p.path()]
	print "Acciones tomadas",l,"\n"
	print "Costo :",p.cost*10,"segundos","\n"
コード例 #6
0
def main():

    metodo = raw_input(
        "Ingrese el metodo de busqueda-- (greedy,depth_first,breadth_first)\n")
    problema = problemaLaberinto("1")

    if metodo == "breadth_first":
        p = breadth_first(problema, graph_search=True, viewer=ConsoleViewer())

    if metodo == "greedy":
        p = greedy(problema, graph_search=True, viewer=ConsoleViewer())

    if metodo == "depth_first":
        p = depth_first(problema, graph_search=True, viewer=ConsoleViewer())

    print(
        "=======================================================================\n"
    )
    print "Estado final :", p.state, "\n"
    print "Path :", p.path(), "\n"
    l = [x[0] for x in p.path()]
    print "Acciones tomadas", l, "\n"
    print "Costo :", p.cost, "\n"
コード例 #7
0
def resolver(metodo_busqueda, franceses, piratas):

    initial = createState(franceses, piratas)
    my_viewer = None
    #my_viewer=BaseViewer()
    if metodo_busqueda == 'astar':
        result = astar(Intelligents_Pirates(initial),
                       graph_search=True,
                       viewer=my_viewer)
    elif metodo_busqueda == 'breadth_first':
        result = breadth_first(Intelligents_Pirates(initial),
                               graph_search=True,
                               viewer=my_viewer)
    elif metodo_busqueda == 'depth_first':
        result = depth_first(Intelligents_Pirates(initial),
                             graph_search=True,
                             viewer=my_viewer)
    elif metodo_busqueda == 'greedy':
        result = greedy(Intelligents_Pirates(initial),
                        graph_search=True,
                        viewer=my_viewer)

    return result
コード例 #8
0
def resolver(metodo_busqueda, franceses, piratas):
    viewer = BaseViewer()
    barcos_piratas = []

    for pirata in piratas:
        barcos_piratas.append((pirata, 0))

    initial = (tuple(franceses), tuple(barcos_piratas))

    problem = entrega1(initial)

    if metodo_busqueda == "breadth_first":
        resultado = breadth_first(problem, graph_search=True, viewer=viewer)
    elif metodo_busqueda == "greedy":
        resultado = greedy(problem, graph_search=True, viewer=viewer)
    elif metodo_busqueda == "depth_first":
        resultado = depth_first(problem, graph_search=True, viewer=viewer)
    elif metodo_busqueda == "astar":
        resultado = astar(problem, graph_search=True, viewer=viewer)
    elif metodo_busqueda == "uniform_cost":
        resultado = uniform_cost(problem, graph_search=True, viewer=viewer)

    return resultado
コード例 #9
0
def main():

    jugador = raw_input("Ingrese la posicion del jugador EJ: 0-2\n")
    enemigo = raw_input("Ingrese la posicion del enemigo EJ: 0-5\n")
    castillo = raw_input("Ingrese la posicion del castillo EJ: 3-2\n")

    global longitud
    longitud = int(raw_input("Ingrese la longitud de la grilla \n")) - 1

    metodo = raw_input(
        "Ingrese el metodo de busqueda-- (greedy,depth_first,breadth_first,astar)\n"
    )

    estado = generar_estados([jugador, enemigo, castillo])
    problema = prolemaDota(estado)

    if metodo == "breadth_first":
        p = breadth_first(problema, graph_search=True, viewer=ConsoleViewer())

    if metodo == "greedy":
        p = greedy(problema, graph_search=True, viewer=ConsoleViewer())

    if metodo == "depth_first":
        p = depth_first(problema, graph_search=True, viewer=ConsoleViewer())

    if metodo == "astar":
        p = astar(problema, graph_search=True, viewer=ConsoleViewer())

    print(
        "=======================================================================\n"
    )
    print "Estado final :", p.state, "\n"
    print "Path :", p.path(), "\n"
    l = [x[0] for x in p.path()]
    print "Acciones tomadas", l, "\n"
    print "Costo :", p.cost, "\n"
コード例 #10
0
 def test_breadth_first(self):
     result = breadth_first(self.problem)
     self.assertEquals(result.state, GOAL)