Ejemplo n.º 1
0
def planner_comparison(seed):
    the_seed = seed
    print("seed: " + str(the_seed))
    params = get_data_random(the_seed,
                             map_res=8,
                             map_fill_perc=30,
                             agent_n=5,
                             job_n=5,
                             idle_goals_n=0)
    agent_pos, grid, idle_goals, jobs = params
    mapstr= get_map_str(grid)
    print(mapstr)
    maphash = str(hashlib.md5(mapstr.encode('utf-8')).hexdigest())[:8]
    print(maphash)

    fname = "planner/eval/cache/" + str(maphash) + '.pkl'  # unique filename based on map
    pre_calc_paths(jobs, idle_goals, grid, fname)

    config_opt = generate_config()
    config_opt['params'] = params
    config_opt['filename_pathsave'] = fname
    config_opt['finished_agents_block'] = True

    config_milp = config_opt.copy()
    config_milp['milp'] = 1

    config_cobra = config_opt.copy()
    config_cobra['cobra'] = 1

    config_greedy = config_opt.copy()
    config_greedy['greedy'] = 1

    config_nn = config_opt.copy()
    config_nn['number_nearest'] = 2

    config_col = config_nn.copy()
    config_col['all_collisions'] = True

    if is_cch():
        print("Configs: [config_opt, config_nn, config_milp, config_cobra, config_greedy]")
        configs = [config_opt, config_nn, config_milp, config_cobra, config_greedy]
        sizes = [2, 3, 4]
        timeout = 10000
    else:  # travis
        print("Configs: [config_opt, config_nn, config_milp, config_greedy]")
        configs = [config_opt, config_nn, config_milp, config_greedy]
        sizes = [2, 3, 4]
        timeout = 500

    ts, ress = benchmark(one_planner, [configs, sizes], samples=1, timeout=timeout)

    return ts, ress
Ejemplo n.º 2
0
def test_cobra_random(plot=False):
    agent_pos, grid, idle_goals, jobs = get_data_random(seed=1,
                                                        map_res=8,
                                                        map_fill_perc=20,
                                                        agent_n=3,
                                                        job_n=3,
                                                        idle_goals_n=0)
    res_agent_job, res_paths = plan_cobra(agent_pos, jobs, grid,
                                          generate_config())
    print(res_agent_job)
    all_alloc = reduce(lambda a, b: a + b, res_agent_job, tuple())
    jobs_is = list(range(len(jobs)))
    for i_j in all_alloc:
        jobs_is.remove(i_j)
    assert not jobs_is, "Not all jobs allocated"
    if plot:
        fig = plt.figure()
        ax = fig.add_subplot(121)
        plot_inputs(ax, agent_pos, idle_goals, jobs, grid)
        ax2 = fig.add_subplot(122, projection='3d')
        plot_results(ax2, [], res_paths, res_agent_job, agent_pos, grid, [],
                     jobs)
        plt.show()
Ejemplo n.º 3
0
import hashlib

from planner.tcbs_test import get_data_random
from planner.eval.display import plot_inputs, plot_results
from planner.tcbs.plan import plan, generate_config
from planner.milp.milp import plan_milp

import matplotlib.pyplot as plt

from tools import get_map_str

params = get_data_random(330,
                         map_res=8,
                         map_fill_perc=30,
                         agent_n=4,
                         job_n=4,
                         idle_goals_n=0)
agent_pos, grid, idle_goals, jobs = params

mapstr = get_map_str(grid)
maphash = str(hashlib.md5(mapstr.encode('utf-8')).hexdigest())[:8]
fname = "planner/eval/cache/" + str(maphash) + '.pkl'  # unique filename based on map

config = generate_config()
config['finished_agents_block'] = True
config['filename_pathsave'] = fname

tcbs_agent_job, tcbs_agent_idle, tcbs_paths = plan(agent_pos, jobs, [], [], grid, config, plot=False)
f = plt.figure()
ax0= f.add_subplot(111)
plot_results(ax0, tcbs_agent_idle, tcbs_paths, tcbs_agent_job, agent_pos, grid, [], jobs, "tcbs")
Ejemplo n.º 4
0
from planner.tcbs_test import get_data_random

agent_n_s = [2, 4, 6]
map_res_s = [10, 14]

results_mean = np.zeros([len(agent_n_s), len(map_res_s)])
results_std = np.zeros([len(agent_n_s), len(map_res_s)])

for agent_n, map_res in product(agent_n_s, map_res_s):
    print("\n---------\nagent_n:", agent_n, "map_res", map_res)
    duration = []
    for i in range(8):
        print("test", i)
        agent_pos, grid, idle_goals, jobs = get_data_random(map_res=map_res,
                                                            map_fill_perc=5,
                                                            agent_n=agent_n,
                                                            job_n=agent_n,
                                                            idle_goals_n=agent_n)

        try:
            fname = ''
            fname = pre_calc_paths(jobs, idle_goals, grid)

            start_time = datetime.datetime.now()
            res_agent_job, res_agent_idle, res_paths = plan(agent_pos, jobs, [], idle_goals, grid, filename=fname)

            d = (datetime.datetime.now() - start_time).total_seconds()
            # print("computation time:", d, "s")
            duration.append(d)
            # print("RESULTS:\nres_agent_job", res_agent_job)
            # print("res_agent_idle", res_agent_idle)
Ejemplo n.º 5
0
n_tests = 10
n_agent = [1, 2, 3, 4, 5]

res = np.zeros([len(n_agent), n_tests])
res2 = np.zeros([len(n_agent), n_tests])

for i_agents in range(len(n_agent)):
    print("i_agents", i_agents)
    for i_test in range(n_tests):
        print("i_test", i_test)
        if os.path.exists(fname):
            os.remove(fname)
        assert not os.path.exists(fname), "File exists already"

        agent_pos, grid, idle_goals, jobs = get_data_random(
            10, 5, n_agent[i_agents], n_agent[i_agents], 5)

        start_time = datetime.datetime.now()
        try:
            plan_cbsext(agent_pos, jobs, [], idle_goals, grid, filename=fname)
        except RuntimeError:
            print("NO SOLUTION")
        time1 = (datetime.datetime.now() - start_time).total_seconds()
        assert os.path.isfile(fname), "Algorithm has not created a file"

        start_time = datetime.datetime.now()
        try:
            plan_cbsext(agent_pos, jobs, [], idle_goals, grid, filename=fname)
        except RuntimeError:
            print("NO SOLUTION")
        time2 = (datetime.datetime.now() - start_time).total_seconds()