Example #1
0
def test_epea_with_valid_solution2():
    file_name = "instances/exp2_2.txt"
    my_map, starts, goals = map_utils.import_mapf_instance(file_name)
    map_details = MapDetails(output_file_name, file_name, my_map, starts, goals)
    epea_sol = epea.EPEASolver(map_details)
    solution = epea_sol.find_solution()
    assert solution == [[(1,2), (1,3), (1,4), (2,4), (1,4)],
                        [(1,1), (1,2), (1,3), (1,4), (1,5)]], "EPEA* could not find solution even though valid solution exists"
Example #2
0
    parser.add_argument(
        '--solver',
        type=str,
        default=SOLVER,
        help='The solver to use (one of: {ICTS,EPEA}), defaults to ' +
        str(SOLVER))

    args = parser.parse_args()

    result_file = None

    for file in sorted(glob.glob(args.instance)):

        print("Solving instance: " + file)
        print("***Import an instance***")
        my_map, starts, goals = util.import_mapf_instance(file)
        util.print_mapf_instance(my_map, starts, goals)

        map_details = MapDetails(args.instance, file, my_map, starts, goals)

        paths = []
        if args.solver == "ICTS":
            print("***Run ICTS***")
            t1 = time.time()
            icts = ICTSSolver(map_details)
            if not icts.ict:
                paths = []
            else:
                paths = icts.find_solution()
                t2 = time.time()
                print("\nFound solution in this many seconds = ", t2 - t1)
Example #3
0
def all_moves_valid(this_locs, next_locs):
    forward = [pair for pair in zip(this_locs, next_locs)]
    has_edge_collision = mdd.has_edge_collisions(this_locs, next_locs)
    for pair in forward:
        this_loc = pair[0]
        next_loc = pair[1]
        if sum(
            [abs(this_loc[0] - next_loc[0]),
             abs(this_loc[1] - next_loc[1])]) > 1:
            return False
    return not has_edge_collision


if __name__ == '__main__':
    my_map, starts, goals = util.import_mapf_instance("instances/mdd_test.txt")
    print(" === Running MDD Tests === ")
    test_simple_construction(my_map, starts, goals)
    test_depth_d_bfs_tree(my_map, starts, goals)
    test_bootstrap_bfs_tree(my_map, starts, goals)
    test_mdd_generation(my_map, starts, goals)
    test_mdd_level_i(my_map, starts, goals)

    my_joint_map, starts, goals = util.import_mapf_instance(
        "instances/joint_mdd_test.txt")
    test_two_agent_joint_mdd_search(my_joint_map, starts, goals)

    my_3_agent_joint_map, starts, goals = util.import_mapf_instance(
        "instances/joint_mdd_3_agent_test.txt")
    test_three_agent_joint_mdd_search(my_3_agent_joint_map, starts, goals)
    test_find_solution_in_joint_mdd(my_3_agent_joint_map, starts, goals)
Example #4
0
import map_utils
from map_utils import MapDetails
from ict import IncreasingCostTree, TreeNode
from icts import ICTSSolver

file_name = "instances/exp2_1.txt"
my_map, starts, goals = map_utils.import_mapf_instance(file_name)
map_details1 = MapDetails("results/icts_test.txt", file_name, my_map, starts,
                          goals)

no_solutions = "instances/no_solution.txt"
my_map, starts, goals = map_utils.import_mapf_instance(no_solutions)
map_details2 = MapDetails("results/icts_test.txt", no_solutions, my_map,
                          starts, goals)


def test_find_most_optimal_paths():
    icts = ICTSSolver(map_details1)
    optimal_paths = icts.find_most_optimal_paths()
    assert optimal_paths == [[
        (1, 1), (1, 2), (1, 3), (1, 4), (1, 5)
    ], [(1, 2), (1, 3),
        (1, 4)]], "Cannot find most optimal paths of a map instance"


def test_find_most_optimal_cost_of_paths():
    icts = ICTSSolver(map_details1)
    cost_of_optimal_paths = icts.find_cost_of_initial_estimate_for_root()
    assert cost_of_optimal_paths == [
        4, 2
    ], "Cannot find cost of most optimal paths of a map instance"
Example #5
0
def test_three_agent_around(my_map, starts, goals):
    new_osf = osf.OSF(my_map, goals)
    agent_locs = starts
    h = new_osf.list_of_locations_to_heuristic(agent_locs)
    g = 0
    big_F = h + g
    node = {
        'agent_locs': agent_locs,
        'g': g,
        'h': h,
        'small_f': g + h,
        'big_F': big_F,
        'parent': False
    }
    children, next_big_F = new_osf.get_children_and_next_F(node)
    assert not children, "test_three_agent_around Failed: Children found when no possible operators should allow for the requested big_F"
    print("test_new_children Passed")


if __name__ == '__main__':
    print(" === Running OSF Tests === ")
    my_map, starts, goals = util.import_mapf_instance("instances/osf_test.txt")
    test_simple_osf_construction(my_map, goals)
    test_operator_selection(my_map, starts, goals)
    test_new_children(my_map, starts, goals)

    my_map, starts, goals = util.import_mapf_instance(
        "instances/osf_3_agent_around_test.txt")
    test_three_agent_around(my_map, starts, goals)
    print("All Tests Passed!")