Beispiel #1
0
def test_ground_actions_for_small_gripper():
    problem = create_sample_problem()

    # First try with the variable-only grounding strategy
    varonly_grounding = LPGroundingStrategy(problem, ground_actions=False)
    varonly_variables = varonly_grounding.ground_state_variables()
    assert len(varonly_variables) == 20

    # Now try full LP grounding
    grounding = LPGroundingStrategy(problem)
    actions = grounding.ground_actions()

    assert len(actions['pick']) == len(
        actions['drop']) == 16  # 4 balls, two rooms, two grippers
    assert len(actions['move']) == 2  # 2 rooms

    lpvariables = grounding.ground_state_variables()
    assert len(lpvariables) == 20
    # Check both grounding methods produce same set of ground variables
    assert set(lpvariables) == set(varonly_variables)

    grounding = NaiveGroundingStrategy(problem)
    naive_variables = grounding.ground_state_variables()
    # The naive grounding strategy will result in many unreachable state variables such as 'carry(left,left)'
    assert len(set(naive_variables) - set(lpvariables)) == 124
def test_ground_actions_for_small_gripper():
    problem = create_sample_problem()
    grounding = LPGroundingStrategy(problem)
    actions = grounding.ground_actions()
    assert len(actions['pick']) == len(
        actions['drop']) == 16  # 4 balls, two rooms, two grippers
    assert len(actions['move']) == 2  # 2 rooms

    as_list2 = lambda symbols: sorted(map(str, symbols))
    lpvariables = grounding.ground_state_variables()
    assert len(lpvariables) == 20

    grounding = NaiveGroundingStrategy(problem)
    naive_variables = grounding.ground_state_variables()
    # The naive grounding strategy will result in many unreachable state variables such as 'carry(left,left)'
    assert len(set(as_list2(naive_variables)) -
               set(as_list2(lpvariables))) == 124
Beispiel #3
0
def do_reachability_analysis(problem, reachability):
    # ATM This is not being used

    do_reachability = reachability != 'none'

    if do_reachability:
        ground_actions = reachability == 'full'
        msg = "Computing reachable groundings " + (
            "(actions+vars)" if ground_actions else "(vars only)")
        with resources.timing(msg, newline=True):
            grounding = LPGroundingStrategy(
                problem,
                ground_actions=ground_actions,
                include_variable_inequalities=False)
            ground_variables = grounding.ground_state_variables()
            if ground_actions:
                action_groundings = grounding.ground_actions()
                # Prune those action schemas that have no grounding at all
                for name, a in list(problem.actions.items()):
                    if not action_groundings[name]:
                        del problem.actions[name]
    else:
        with resources.timing(f"Computing naive groundings", newline=True):
            grounding = NaiveGroundingStrategy(problem,
                                               ignore_symbols={'total-cost'})
            ground_variables = grounding.ground_state_variables()
            action_groundings = grounding.ground_actions()

    statics, fluents = grounding.static_symbols, grounding.fluent_symbols
    simplifier = Simplify(problem, problem.init)
    operators = []
    for name, act in problem.actions.items():
        for grounding in action_groundings[name]:
            op = ground_schema_into_plain_operator_from_grounding(
                act, grounding)
            if reachability == 'full':
                operators.append(op)
            else:
                s = simplifier.simplify_action(op, inplace=True)
                if s is not None:
                    operators.append(s)
Beispiel #4
0
def ground_generate_task(domain_file,
                         problem_file,
                         out_task=None,
                         verbose_flag=False,
                         lenient_flag=False):
    """
    Uses Tarski Grounder to generate the output task using pddl

    Arguments
    =========
    domain_file  : domain pddl file location
    problem_file : problem pddl file location
    output_task  : C++ container to store/process domain and problem

    Returns
    =======
    None
    """
    global VERBOSE
    VERBOSE = verbose_flag
    global LENIENT_MODE
    LENIENT_MODE = lenient_flag
    parsing_timer = time.process_time()
    #Setup a reader to read the domain and problem pddl files
    with time_taken("reading and parsing pddl file"):
        if LENIENT_MODE:
            problem = FstripsReader( raise_on_error=True,
                theories=None, strict_with_requirements=False).\
            read_problem( domain_file, problem_file)
        else:
            problem = FstripsReader( raise_on_error=True,
                theories=None).\
            read_problem( domain_file, problem_file)

    with time_taken("preprocessing tarski problem"):
        process_problem(problem)
        init = problem.init_bk

    with time_taken("grounding"):
        grounding = LPGroundingStrategy(problem)
        reachable_action_params = copy.deepcopy(grounding.ground_actions())
        fluents = copy.deepcopy(grounding.ground_state_variables())
        del grounding
        count_params = 0
        for x, y in reachable_action_params.items():
            for z in y:
                count_params += 1
        if VERBOSE:
            print("Total number of reachable action params = ", count_params)

    return True
Beispiel #5
0
                    format(st.sort.name))
        syms.append(st)
        instantiations.append(list(st.sort.domain()))
        cardinality *= len(instantiations[-1])
    return cardinality, syms, instantiations

if __name__ == "__main__" :
    reader = FstripsReader(raise_on_error=True, theories=None)
    ### Uncomment this for PARCPRINTER test
    """
    problem = reader.read_problem("parcprinter_p01-domain.pddl","parcprinter_p01.pddl")
    problem.init.function_extensions = dict()
    for _,action in problem.actions.items():
        new_effects = []
        for effect in action.effects:
            if not isinstance(effect, FunctionalEffect):
                new_effects.append(effect)
        action.effects = new_effects
    """
    ### Uncomment this for FLOORTILE TEST
    #problem = reader.read_problem("floortile_domain.pddl","floortile_p01-4-3-2.pddl")

    # Comment this
    problem = reader.read_problem("tidybot_domain.pddl","tidybot_p02.pddl")

    grounding = LPGroundingStrategy(problem)
    actions = grounding.ground_actions()
    actions = grounding.ground_state_variables()
    print(actions)
    print("Tests passed")