def main():
    filename_template = os.path.dirname(os.path.realpath(__file__)) + \
                        '/../datasets/regression/{num_agents}_agents_{dataset_name}_cadrl_dataset_action_value_{mode}.p'
    env, one_env = create_env()
    modes = [
        {
            'mode': 'train',
            'num_datapts': 100000,
        },
        {
            'mode': 'test',
            'num_datapts': 20000,
        },
    ]
    for mode in modes:
        STATES, ACTIONS, VALUES = fill(env, one_env, num_datapts=mode['num_datapts'])
        filename = filename_template.format(mode = mode['mode'],
                                            dataset_name = Config.DATASET_NAME,
                                            num_agents = Config.MAX_NUM_AGENTS_IN_ENVIRONMENT)
        file_dir = os.path.dirname(filename)
        os.makedirs(file_dir, exist_ok=True)

        with open(filename, "wb") as f:
            pickle.dump([STATES, ACTIONS, VALUES], f)

    print("Files written.")
Пример #2
0
def main():
    np.random.seed(0)

    test_case_fn = tc.full_test_suite
    test_case_args = {}

    if Config.FIXED_RADIUS_AND_VPREF:
        radius_bounds = [0.5, 0.5]
        test_case_args['vpref_constraint'] = True
        test_case_args['radius_bounds'] = radius_bounds
        vpref1_str = 'vpref1.0_r{}-{}/'.format(radius_bounds[0],
                                               radius_bounds[1])
    else:
        vpref1_str = ''

    env, one_env = create_env()

    print(
        "Running {test_cases} test cases for {num_agents} for policies: {policies}"
        .format(
            test_cases=Config.NUM_TEST_CASES,
            num_agents=Config.NUM_AGENTS_TO_TEST,
            policies=Config.POLICIES_TO_TEST,
        ))

    with tqdm(total=len(Config.NUM_AGENTS_TO_TEST) *
              len(Config.POLICIES_TO_TEST) * Config.NUM_TEST_CASES) as pbar:
        for num_agents in Config.NUM_AGENTS_TO_TEST:
            one_env.set_plot_save_dir(
                os.path.dirname(os.path.realpath(__file__)) +
                '/results/full_test_suites/{vpref1_str}{num_agents}_agents/figs/'
                .format(vpref1_str=vpref1_str, num_agents=num_agents))
            for policy in Config.POLICIES_TO_TEST:
                np.random.seed(0)
                prev_agents = None
                df = pd.DataFrame()
                for test_case in range(Config.NUM_TEST_CASES):
                    ##### Actually run the episode ##########
                    _ = reset_env(env, one_env, test_case_fn, test_case_args,
                                  test_case, num_agents, policies, policy,
                                  prev_agents)
                    episode_stats, prev_agents = run_episode(env, one_env)
                    df = store_stats(df, {
                        'test_case': test_case,
                        'policy_id': policy
                    }, episode_stats)
                    ########################################
                    pbar.update(1)

                if Config.RECORD_PICKLE_FILES:
                    file_dir = os.path.dirname(os.path.realpath(__file__)) + \
                               '/results/full_test_suites/{vpref1_str}'.format(vpref1_str=vpref1_str)
                    file_dir += '{num_agents}_agents/stats/'.format(
                        num_agents=num_agents)
                    os.makedirs(file_dir, exist_ok=True)
                    log_filename = file_dir + '/stats_{}.p'.format(policy)
                    # log_filename = file_dir+'/stats_{}_{}.p'.format(policy, now.strftime("%m_%d_%Y__%H_%M_%S"))
                    df.to_pickle(log_filename)

    return True
Пример #3
0
def main():
    env, one_env = create_env()
    dt = one_env.dt_nominal
    file_dir_template = os.path.dirname(os.path.realpath(__file__)) + \
                        '/results/{results_subdir}/{num_agents}_agents'

    trajs = [[] for _ in range(num_test_cases)]

    for num_agents in num_agents_to_test:

        file_dir = file_dir_template.format(num_agents=num_agents,
                                            results_subdir=results_subdir)
        plot_save_dir = file_dir + '/figs/'
        os.makedirs(plot_save_dir, exist_ok=True)
        one_env.plot_save_dir = plot_save_dir

        test_case_args['num_agents'] = num_agents
        test_case_args['side_length'] = 7
        for test_case in tqdm(range(num_test_cases)):
            # test_case_args['test_case_index'] = test_case
            # test_case_args['num_test_cases'] = num_test_cases
            for policy in policies:
                one_env.plot_policy_name = policy
                policy_class = policies[policy]['policy']
                test_case_args['agents_policy'] = policy_class
                agents = test_case_fn(**test_case_args)
                for agent in agents:
                    if 'checkpt_name' in policies[policy]:
                        agent.policy.env = env
                        agent.policy.initialize_network(**policies[policy])
                one_env.set_agents(agents)
                one_env.test_case_index = test_case
                init_obs = env.reset()

                times_to_goal, extra_times_to_goal, collision, all_at_goal, any_stuck, agents = run_episode(
                    env, one_env)

                max_ts = [t / dt for t in times_to_goal]
                trajs = add_traj(agents, trajs, dt, test_case, max_ts)

        # print(trajs)

        one_env.reset()

        pkl_dir = file_dir + '/trajs/'
        os.makedirs(pkl_dir, exist_ok=True)
        fname = pkl_dir + policy + '.pkl'
        pickle.dump(trajs, open(fname, 'wb'))
        print('dumped {}'.format(fname))

    print("Experiment over.")
Пример #4
0
def main():
    np.random.seed(0)

    test_case_fn = tc.formation
    test_case_args = {}

    env, one_env = create_env()

    one_env.set_plot_save_dir(os.path.dirname(os.path.realpath(__file__)) + '/results/cadrl_formations/')

    for num_agents in Config.NUM_AGENTS_TO_TEST:
        for policy in Config.POLICIES_TO_TEST:
            np.random.seed(0)
            prev_agents = None
            for test_case in range(Config.NUM_TEST_CASES):
                _ = reset_env(env, one_env, test_case_fn, test_case_args, test_case, num_agents, policy_dict, policy, prev_agents)
                episode_stats, prev_agents = run_episode(env, one_env)

    return True
Пример #5
0
                                 ],
                                 policy_distr=[0.05, 0.9, 0.05],
                                 speed_bnds=[0.5, 2.0],
                                 radius_bnds=[0.2, 0.8],
                                 side_length=[
                                     {
                                         'num_agents': [0, 5],
                                         'side_length': [4, 5]
                                     },
                                     {
                                         'num_agents': [5, np.inf],
                                         'side_length': [6, 8]
                                     },
                                 ])

    env, one_env = create_env()
    one_env.set_agents(agents)
    one_env.plot_policy_name = policy
    one_env.set_plot_save_dir(
        os.path.dirname(os.path.realpath(__file__)) +
        '/results/cadrl_rand_case/')

    for agent in agents:
        if 'checkpt_name' in policy_cfg:
            agent.policy.env = env
            agent.policy.initialize_network(**policy_cfg)
        if 'sensor_args' in policy_cfg:
            for sensor in agent.sensors:
                sensor.set_args(policy_cfg['sensor_args'])

    env.reset()