示例#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(cajas):
    problema = ProblemaAmagon(cajas)

    visor = BaseViewer()
    inicio = datetime.datetime.now()
    resultado = astar(problema, graph_search=True, viewer=visor)
    tiempo = (datetime.datetime.now() - inicio).total_seconds()

    for i, (accion, estado) in enumerate(resultado.path()):
        print('Acción N: {} {} ## Estado: {}'.format(i, accion, estado))

    print("Costo: {}".format(resultado.cost))
    print("Nodos explorados: {}".format(visor.stats['visited_nodes']))
    print("Tamaño máximo frontera: {}".format(visor.stats['max_fringe_size']))
    print("Tiempo transcurrido: {} segundos".format(tiempo))
示例#3
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
示例#4
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
示例#5
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
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
示例#7
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
示例#8
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"
示例#9
0
 def test_astar_graph_inadmissible_heuristic(self):
     v = SampleViewer([[('s', 0)], [('l', 26), ('a', 15)], [('r', 42), ('a', 15)]])
     self.graph_problem.heuristic_dict = DummyGraphProblem.inadmissible
     result = astar(self.graph_problem, graph_search=True, viewer=v)
     self.assertEqual(result.state, self.graph_problem.goal)
示例#10
0
 def test_astar_graph_consistent_heuristic(self):
     v = TestViewer([[('s', 0)], [('a', 15), ('l', 26)], [('l', 25)], [('r', 41)]])
     self.graph_problem.heuristic_dict = DummyGraphProblem.consistent
     result = astar(self.graph_problem, graph_search=True, viewer=v)
     self.assertEquals(result.state, self.graph_problem.goal)
示例#11
0
 def test_astar_tree_inadmissible_heuristic(self):
     v = TestViewer([[('s', 0)], [('l', 26), ('a', 15)], [('r', 42), ('a', 15), ('a', 36), ('s', 52)]])
     self.graph_problem.heuristic_dict = DummyGraphProblem.inadmissible
     result = astar(self.graph_problem, graph_search=False, viewer=v)
     self.assertEquals(result.state, self.graph_problem.goal)
示例#12
0
 def test_astar_graph_execution_with_repeated_states_chooses_better_state(self):
     result = astar(self.graph_problem, graph_search=True)
     self.assertEquals(result.state, self.graph_problem.goal)
示例#13
0
 def test_astar_graph_doesnt_repeat_states_in_explore_set(self):
     v = TestViewer([[('s', 0)], [('l', 26), ('a', 15)], [('a', 15), ('r', 42)], [('r', 42)]])
     self.graph_problem.heuristic_dict = DummyGraphProblem.inconsistent
     result = astar(self.graph_problem, graph_search=True, viewer=v)
     self.assertEquals(result.state, self.graph_problem.goal)
示例#14
0
 def test_astar(self):
     result = astar(self.problem)
     self.assertEquals(result.state, GOAL)
示例#15
0
 def test_astar_graph_doesnt_repeat_states_in_explore_set(self):
     v = SampleViewer([[("s", 0)], [("l", 26), ("a", 15)], [("a", 15), ("r", 42)], [("r", 42)]])
     self.graph_problem.heuristic_dict = DummyGraphProblem.inconsistent
     result = astar(self.graph_problem, graph_search=True, viewer=v)
     self.assertEqual(result.state, self.graph_problem.goal)
        (1, 2),
        (1, 3),
        (2, 1),
        (2, 2),
        (2, 3),
        (3, 0),
        (3, 1),
        (3, 2),
        (4, 0),
        (4, 1),
        (5, 0),
    )
    piratas_consigna = (
        (4, 4),
        (4, 5),
        (5, 4),
    )

    initial = createState(franceses_consigna, piratas_consigna)
    #result = breadth_first(Intelligents_Pirates(initial), graph_search=True, viewer=my_viewer)
    #result = depth_first(Intelligents_Pirates(initial), graph_search=True, viewer=my_viewer)
    #result = greedy(Intelligents_Pirates(initial), graph_search=True, viewer=my_viewer)
    result = astar(Intelligents_Pirates(initial),
                   graph_search=True,
                   viewer=my_viewer)

    print("visited nodes: {}".format(my_viewer.stats['visited_nodes']))
    print("depth: {}".format(len(result.path())))
    print("cost: {}".format(result.cost))
    print("max fringe size : {}".format(my_viewer.stats['max_fringe_size']))
示例#17
0
 def test_astar_graph_consistent_heuristic(self):
     v = SampleViewer([[("s", 0)], [("a", 15), ("l", 26)], [("l", 25)], [("r", 41)]])
     self.graph_problem.heuristic_dict = DummyGraphProblem.consistent
     result = astar(self.graph_problem, graph_search=True, viewer=v)
     self.assertEqual(result.state, self.graph_problem.goal)
示例#18
0
 def test_astar_tree_inadmissible_heuristic(self):
     v = SampleViewer([[("s", 0)], [("l", 26), ("a", 15)], [("r", 42), ("a", 15), ("a", 36), ("s", 52)]])
     self.graph_problem.heuristic_dict = DummyGraphProblem.inadmissible
     result = astar(self.graph_problem, graph_search=False, viewer=v)
     self.assertEqual(result.state, self.graph_problem.goal)