Beispiel #1
0
def create_problem_instance_from_file(dir_path,
                                      domain_path_name,
                                      problem_index=0):
    domain_file = os.path.join(dir_path, 'pddl', f'{domain_path_name}.pddl')
    problem_dir = os.path.join(dir_path, 'pddl', f'{domain_path_name}')

    env = PDDLEnv(domain_file,
                  problem_dir,
                  raise_error_on_invalid_action=True,
                  dynamic_action_space=False)

    env.fix_problem_index(problem_index)
    return env, env.problems[problem_index]
Beispiel #2
0
def test_dynamic_action_space_same_obj():
    """
    """
    dir_path = os.path.join(
        os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "pddl")

    name = "dynamic_action_space_same_obj"
    domain_file = os.path.join(dir_path, "{}.pddl".format(name.lower()))
    problem_dir = os.path.join(dir_path, name.lower())

    env = PDDLEnv(
        domain_file,
        problem_dir,
        operators_as_actions=True,
        dynamic_action_space=True,
    )
    assert len(env.problems) == 2  # both problems have the same object set

    env.fix_problem_index(0)
    state1, _ = env.reset()
    # Only one action is possible: unstack(a, b)
    for _ in range(25):
        act1 = env.action_space.sample(state1)
        assert act1.predicate.name == "unstack"
        assert act1.variables[0].name == "a"
        assert act1.variables[1].name == "b"

    env.fix_problem_index(1)
    state2, _ = env.reset()
    assert state1.objects == state2.objects
    # Only one action is possible: unstack(d, c)
    for _ in range(25):
        act2 = env.action_space.sample(state2)
        assert act2.predicate.name == "unstack"
        assert act2.variables[0].name == "d"
        assert act2.variables[1].name == "c"

    print("Test passed.")