Exemple #1
0
def test_AStar_find(mapa='tests/mini.map'):
    algorithm = 'astar'

    # Inicializa os agentes
    world = load_world(mapa)
    robot = Robot(world)
    agent = InformedAgent(algorithm)

    print(f'Estado inicial:')
    robot.show()
    print(f'Bateria: {robot.max_battery}\n')

    solution, state = agent.search(MineState(robot))
    if state:
        print(f'Resultado final:')
        state.robot.show()
        print(f'Nós expandidos: {solution.nodes_expanded}')
        print(f'Bateria Restante: {state.robot.battery}')
        print(f'Ouro Restante: {state.gold}')
        print(f'Ouro Total Coletado: {solution.collected_gold}')
        print(f'{solution.actions}')
    else:
        print('Nenhuma solução encontrada para esse experimento.')

    return state
Exemple #2
0
def test_LDS_find(mapa='tests/mini.map', limit=0):
    algorithm = 'lds'

    # Inicializa os agentes
    world = load_world(mapa)
    robot = Robot(world)
    agent = UninformedAgent(algorithm)

    _, state = agent.search(
        MineState(robot), limit)
    return state
Exemple #3
0
    def test_goal_improved(self, state: MineState):
        if state.parent is not None:
            return state.gold > state.parent.gold
        return False
    
    def update(self, frontier, updated_state: MineState):
        i, old = updated_state.get_equal(frontier)
        if updated_state.h() < old.h():
            frontier[i] = updated_state

    def search_closest(self, start_state):
        return self.AStar(start_state, self.test_goal_improved)


if __name__ == '__main__':
    from miner.model.world import load_world
    w = load_world('./tests/example.map')
    r = Robot(w)
    ag = InformedAgent('improvedastar')
    solution, state = ag.search(MineState(r))
    if state:
        print(f'Resultado final:')
        state.robot.show()
        print(f'Nós expandidos: {solution.nodes_expanded}')
        print(f'Bateria Restante: {state.robot.battery}')
        print(f'Ouro Restante: {state.gold}')
        print(f'Ouro Total Coletado: {solution.collected_gold}')
        print(f'{solution.actions}')
    else:
        print('Nenhuma solução encontrada para esse experimento.')
Exemple #4
0
        print('Exemplo de entrada: python app.py ./tests/example.map LDS 20')
        exit()
    
    limit = 0
    if len(sys.argv) > 3:
        try:
            limit = int(sys.argv[3])
        except ValueError:
            pass

    debugging = False
    if 'debug' in sys.argv:
        debugging = True

    # Inicializa os agentes
    world = load_world(mapa)
    robot = Robot(world)
    if algorithm in UninformedAgent.algorithms:
        agent = UninformedAgent(algorithm, debugging)
    elif algorithm in InformedAgent.algorithms:
        agent = InformedAgent(algorithm, debugging)
    else:
        print('Algoritmo não implementado.')
        exit()

    print(f'Estado inicial:')
    robot.show()
    print(f'Bateria disponível: {robot.max_battery}')
    print(f'\nIniciando busca com {algorithm.upper()}...\n')

    solution, state = agent.search(