예제 #1
0
def planner_comparison(seed):
    params = get_data_random(seed + 1,
                             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_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]")
        configs = [config_opt, config_nn,
                   config_milp]  #, config_cobra, config_greedy, config_col]
        sizes = [1, 2]
    else:
        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]
    ts, ress = benchmark(one_planner, [configs, sizes],
                         samples=1,
                         timeout=1000)

    return ts, ress
예제 #2
0
def eval(_map, agent_pos, jobs, fname, display=False, finished_blocking=True):
    from planner.milp.milp import plan_milp
    grid = np.repeat(_map[:, ::2, np.newaxis], 100, axis=2)

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

    print("Problem:")
    print(str(jobs))
    print(str(agent_pos))
    mapstr = get_map_str(grid)
    print(mapstr)

    print("TCBS")
    res_agent_job, res_agent_idle, res_paths = plan(agent_pos,
                                                    jobs, [], [],
                                                    grid,
                                                    config,
                                                    plot=False)
    print("agent_job: " + str(res_agent_job))
    print("paths: " + str(res_paths))
    costs_opt = get_costs(res_paths, jobs, res_agent_job, display)

    print("MINLP")
    minlp_res_agent_job, minlp_res_paths = plan_milp(agent_pos,
                                                     jobs,
                                                     grid,
                                                     config,
                                                     plot=False)
    print("agent_job: " + str(minlp_res_agent_job))
    print("paths: " + str(minlp_res_paths))
    costs_minlp = get_costs(minlp_res_paths, jobs, minlp_res_agent_job,
                            display)

    # MINLP VS PLAN
    if display:
        fig = plt.figure()
        ax1 = fig.add_subplot(121, projection='3d')
        ax1.set_title("Solution Optimal")
        ax2 = fig.add_subplot(122, projection='3d')
        plot_results(ax1, [], res_paths, res_agent_job, agent_pos, grid, [],
                     jobs, "Optimal")
        plot_results(ax2, [], minlp_res_paths, minlp_res_agent_job, agent_pos,
                     grid, [], jobs, "Separate")
        plt.show()

    print("TCBS (results again for comparison)")
    print("agent_job: " + str(res_agent_job))
    print("paths: " + str(res_paths))
    costs_tcbs = get_costs(res_paths, jobs, res_agent_job, display)

    return costs_tcbs, costs_minlp
예제 #3
0
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")

milp_agent_job, milp_agent_idle, milp_paths = plan_milp(agent_pos, jobs, [], [], grid, config, plot=False)
f1 = plt.figure()
ax1= f1.add_subplot(111)