Exemple #1
0
def run_agents():
    # definition of the first environment
    dimension1 = (10, 10)
    location1 = (10, 1)
    direction1 = Direction.TOP
    environment1 = Environment('Environment 1 (Without Walls)', dimension1,
                               location1, direction1)
    environment1.reset()

    # definition of the second environment
    dimension2 = (11, 11)
    location2 = (11, 1)
    direction2 = Direction.TOP
    environment2 = Environment('Environment 2 (With Walls)', dimension2,
                               location2, direction2)
    centroid = (6, 6)
    for ind in range(13):
        environment2.add_wall((ind, centroid[1]))
        environment2.add_wall((centroid[0], ind))
    doors = [(6, 1), (1, 6), (11, 6), (6, 11)]
    for door in doors:
        environment2.add_door(door)
    environment2.reset()

    # simple reflex agent
    # print("\n\n\nRunning simple-reflex-agent")
    # print("=================================")
    # simple_reflex_agent_iterations = 80
    # run_simple_reflex_agent(environment1, simple_reflex_agent_iterations)
    # run_simple_reflex_agent(environment2, simple_reflex_agent_iterations)
    # plt.xticks([action for action in range(0, simple_reflex_agent_iterations+1, 10)])
    # plt.yticks([count for count in range(0, 41, 5)])
    # plt.xlabel('Number of actions taken')
    # plt.ylabel('Number of cleaned cells')
    # plt.legend()
    # plt.title('Simple Reflex Agent')
    # plt.savefig('outputs/simple_reflex_agent.png')
    # plt.gcf().clear()

    # randomized reflex agent
    print("\n\n\nRunning randomized-reflex-agent")
    print("=====================================")
    randomized_reflex_agent_epochs = 50
    randomized_reflex_agent_iterations = 6000
    run_randomized_reflex_agent(environment1, randomized_reflex_agent_epochs,
                                randomized_reflex_agent_iterations)
    # run_randomized_reflex_agent(environment2, randomized_reflex_agent_epochs, randomized_reflex_agent_iterations)
    plt.xticks(
        [epoch for epoch in range(0, randomized_reflex_agent_epochs + 1, 5)])
    plt.yticks([
        count
        for count in range(2000, randomized_reflex_agent_iterations + 1, 1000)
    ])
    plt.xlabel('Number of epochs')
    plt.ylabel('Average number of actions for 100% performance')
    plt.legend()
    plt.title('Randomized Reflex Agent')
    plt.savefig('outputs/randomized_reflex_agent.png')
    plt.gcf().clear()
Exemple #2
0
def run_with_second_environment():
    dimension = (11, 11)
    location = (11, 1)
    direction = Direction.TOP
    environment = Environment(dimension, location, direction)
    centroid = (6, 6)
    for ind in range(13):
        environment.add_wall((ind, centroid[1]))
        environment.add_wall((centroid[0], ind))
    doors = [(6, 1), (1, 6), (11, 6), (6, 11)]
    for door in doors:
        environment.add_door(door)
    environment.reset()

    # run simple-reflex-agent
    run_simple_reflex_agent(environment)

    # run randomized-reflex-agent
    run_randomized_reflex_agent(environment)

    # run states-reflex-agent
    run_model_reflex_agent(environment)