def test_agent_evaluation():
    print()
    setup_tensorboard('training/results/tmp/', 'agent_eval')

    env = OnlineFlexibleResourceAllocationEnv('training/settings/basic.env')

    eval_envs = generate_eval_envs(env,
                                   5,
                                   'training/settings/tmp/',
                                   overwrite=True)
    assert len(os.listdir('training/settings/tmp/')) == 5
    total_auctions, total_resource_allocation = 0, 0
    for eval_env in eval_envs:
        env, state = OnlineFlexibleResourceAllocationEnv.load_env(eval_env)
        total_auctions += len(env._unallocated_tasks) + (
            1 if state.auction_task is not None else 0)
        total_resource_allocation += env._total_time_steps + 1

    pricing_agents = [
        TaskPricingDqnAgent(0, create_bidirectional_dqn_network(9, 5)),
        TaskPricingDdpgAgent(1, create_lstm_actor_network(9),
                             create_lstm_critic_network(9))
    ]
    weighting_agents = [
        ResourceWeightingDqnAgent(2, create_bidirectional_dqn_network(16, 5)),
        ResourceWeightingDdpgAgent(3, create_lstm_actor_network(16),
                                   create_lstm_critic_network(16)),
    ]

    results = eval_agent(eval_envs, 0, pricing_agents, weighting_agents)
    print(
        f'Results - Total prices: {results.total_prices}, Number of completed tasks: {results.num_completed_tasks}, '
        f'failed tasks: {results.num_failed_tasks}, winning prices: {results.winning_prices}, '
        f'Number of auctions: {results.num_auctions}, resource allocations: {results.num_resource_allocations}'
    )
    assert 0 < results.num_completed_tasks
    assert 0 < results.num_failed_tasks

    assert results.num_auctions == total_auctions
    assert results.num_resource_allocations == total_resource_allocation
Esempio n. 2
0
from training.train_agents import generate_eval_envs, run_training, setup_tensorboard

if __name__ == "__main__":
    # Setup tensorboard
    folder = 'bidirectional_agents'
    writer, datetime = setup_tensorboard('training/results/logs/', folder)

    save_folder = f'{folder}_{datetime}'

    env = OnlineFlexibleResourceAllocationEnv([
        './training/settings/basic.env',
        './training/settings/large_tasks_servers.env',
        './training/settings/limited_resources.env',
        './training/settings/mixture_tasks_servers.env'
    ])
    eval_envs = generate_eval_envs(
        env, 20, f'./training/settings/eval_envs/network_arch/')

    task_pricing_agents = [
        TaskPricingDqnAgent(agent_num,
                            create_bidirectional_dqn_network(9, 21),
                            save_folder=save_folder) for agent_num in range(3)
    ]
    resource_weighting_agents = [
        ResourceWeightingDqnAgent(0,
                                  create_bidirectional_dqn_network(16, 11),
                                  save_folder=save_folder)
    ]

    # Train the agents
    with writer.as_default():
        run_training(env, eval_envs, 600, task_pricing_agents,
Esempio n. 3
0
from env.environment import OnlineFlexibleResourceAllocationEnv
from training.train_agents import generate_eval_envs, run_training, setup_tensorboard

if __name__ == "__main__":
    folder = 'c51_agents'
    writer, datetime = setup_tensorboard('training/results/logs/', folder)

    save_folder = f'{folder}_{datetime}'

    env = OnlineFlexibleResourceAllocationEnv([
        './training/settings/basic.env',
        './training/settings/large_tasks_servers.env',
        './training/settings/limited_resources.env',
        './training/settings/mixture_tasks_servers.env'
    ])
    eval_envs = generate_eval_envs(env, 20,
                                   f'./training/settings/eval_envs/algo/')

    task_pricing_agents = [
        TaskPricingCategoricalDqnAgent(agent_num,
                                       create_lstm_categorical_dqn_network(
                                           9, 21),
                                       save_folder=save_folder)
        for agent_num in range(3)
    ]
    resource_weighting_agents = [
        ResourceWeightingCategoricalDqnAgent(
            0,
            create_lstm_categorical_dqn_network(16, 11),
            save_folder=save_folder)
    ]
Esempio n. 4
0

if __name__ == "__main__":
    eval_env = OnlineFlexibleResourceAllocationEnv([
        './analysis/fixed_heuristics/settings/basic.env',
        './analysis/fixed_heuristics/settings/large_tasks_servers.env',
        './analysis/fixed_heuristics/settings/limited_resources.env',
        './analysis/fixed_heuristics/settings/mixture_tasks_servers.env'
    ])

    eval_pos = 0
    while True:
        if not os.path.exists(
                f'./analysis/fixed_heuristics/eval_envs_{eval_pos}/'):
            eval_envs = generate_eval_envs(
                eval_env, 20,
                f'./analysis/fixed_heuristics/eval_envs_{eval_pos}/')
            break
        else:
            eval_pos += 1

    task_pricing_agents, resource_weighting_agents = load_agents()
    agent_results = eval_agent(eval_envs, 0, task_pricing_agents,
                               resource_weighting_agents)
    print('Agent results')
    print(f'Env completed tasks: {agent_results.env_completed_tasks}')
    print(f'Env failed tasks: {agent_results.env_failed_tasks}')
    print(f'Env attempted tasks: {agent_results.env_attempted_tasks}\n')

    fixed_results = eval_fixed_env(eval_envs)
    print(f'Fixed results env completed tasks: {fixed_results}')