Exemplo n.º 1
0
def test_problem_grounding_on_parcprinter():
    # Test some grounding routines on parcprinter
    problem = parcprinter.create_small_task()
    grounding = NaiveGroundingStrategy(problem)

    # ATM we consider the grounding should not be responsible for including / discarding "total-cost"
    assert as_list1(grounding.static_symbols) == [
        'Prevsheet', 'Sheetsize', 'Uninitialized'
    ]
    assert as_list1(grounding.fluent_symbols) == [
        'Available', 'Location', 'Stackedin', 'total-cost'
    ]

    variables = grounding.ground_state_variables()
    # Make sure that Uninitialized is also grounded, even though it is a nullary symbol
    assert [
        'Available(Finisher2-RSRC)',
        'Location(dummy-sheet,Finisher2_Entry-Finisher1_Exit)',
        'Location(dummy-sheet,Finisher2_Tray)',
        'Location(dummy-sheet,Some_Feeder_Tray)',
        'Location(dummy-sheet,Some_Finisher_Tray)',
        'Location(sheet1,Finisher2_Entry-Finisher1_Exit)',
        'Location(sheet1,Finisher2_Tray)', 'Location(sheet1,Some_Feeder_Tray)',
        'Location(sheet1,Some_Finisher_Tray)',
        'Stackedin(dummy-sheet,Finisher2_Entry-Finisher1_Exit)',
        'Stackedin(dummy-sheet,Finisher2_Tray)',
        'Stackedin(dummy-sheet,Some_Feeder_Tray)',
        'Stackedin(dummy-sheet,Some_Finisher_Tray)',
        'Stackedin(sheet1,Finisher2_Entry-Finisher1_Exit)',
        'Stackedin(sheet1,Finisher2_Tray)',
        'Stackedin(sheet1,Some_Feeder_Tray)',
        'Stackedin(sheet1,Some_Finisher_Tray)', 'total-cost()'
    ] == as_list2(variables)
def test_action_costs_numeric_fluents_requirements():
    problem = parcprinter.create_small_task()
    writer = FstripsWriter(problem)

    # action costs should be required if there is a metric defined.
    domain_string = writer.print_domain()
    assert 'numeric-fluents' not in domain_string
    assert 'action-costs' in domain_string
Exemplo n.º 3
0
def test_all_state_variables_can_be_evaluated_in_init_parcprinter():
    prob = parcprinter.create_small_task()
    index = ProblemGrounding(prob)
    index.process_symbols(prob)
    index.state_variables = SymbolIndex()
    for var in create_all_possible_state_variables(index.fluent_terms):
        index.state_variables.add(var)
    for var in index.state_variables:
        val = prob.init[var.ground]
        assert val in (True, False, 0.0)
Exemplo n.º 4
0
def test_requirements_string():
    problem = parcprinter.create_small_task()

    # action costs should be required if there is a metric defined.
    assert sorted(get_requirements_string(problem)) == [':action-costs', ':equality', ':numeric-fluents', ':typing']

    problem, loc, clear, b1, table = get_bw_elements()
    assert sorted(get_requirements_string(problem)) == [':equality', ':typing']

    problem = generate_fstrips_counters_problem()
    assert sorted(get_requirements_string(problem)) == [':equality', ':numeric-fluents', ':typing']
Exemplo n.º 5
0
def test_all_state_variables_can_be_evaluated_in_init_parcprinter():
    prob = parcprinter.create_small_task()
    index = ProblemGrounding(prob)
    index.process_symbols(prob)
    index.state_variables = IndexDictionary()
    for var in create_all_possible_state_variables(index.fluent_terms):
        index.state_variables.add(var)
    for var in index.state_variables:
        # print("type: {} expr: {} value: {}".format(type(var.ground), str(var.ground), prob.init[var.ground]))
        assert (prob.init[var.ground] is True or
                prob.init[var.ground] is False or
                prob.init[var.ground] == 0.0)
Exemplo n.º 6
0
def test_requirements_string():
    problem = parcprinter.create_small_task()

    # action costs should be required if there is a metric defined, but if "total-cost" is the only arithmetic
    # function, we don't print the ':numeric-fluents' requirement
    assert sorted(get_requirements_string(problem)) == [
        ':action-costs', ':equality', ':typing'
    ]

    problem, loc, clear, b1, table = get_bw_elements()
    assert sorted(get_requirements_string(problem)) == [':equality', ':typing']

    problem = generate_fstrips_counters_problem()
    assert sorted(get_requirements_string(problem)) == [
        ':equality', ':numeric-fluents', ':typing'
    ]
Exemplo n.º 7
0
def test_problem_grounding_on_two_domains():

    # Test some grounding routines on parcprinter
    problem = parcprinter.create_small_task()
    grounding = NaiveGroundingStrategy(problem)

    as_list1 = lambda symbols: sorted(s.symbol for s in symbols)
    # ATM we consider the grounding should not be responsible for including / discarding "total-cost"
    assert as_list1(grounding.static_symbols) == ['Prevsheet', 'Sheetsize', 'Uninitialized']
    assert as_list1(grounding.fluent_symbols) == ['Available', 'Location', 'Stackedin', 'total-cost']

    as_list2 = lambda symbols: sorted(map(str, symbols))
    variables = grounding.ground_state_variables()
    # Make sure that Uninitialized is also grounded, even though it is a nullary symbol
    assert ['Available(Finisher2-RSRC)', 'Location(dummy-sheet,Finisher2_Entry-Finisher1_Exit)',
            'Location(dummy-sheet,Finisher2_Tray)', 'Location(dummy-sheet,Some_Feeder_Tray)',
            'Location(dummy-sheet,Some_Finisher_Tray)', 'Location(sheet1,Finisher2_Entry-Finisher1_Exit)',
            'Location(sheet1,Finisher2_Tray)', 'Location(sheet1,Some_Feeder_Tray)',
            'Location(sheet1,Some_Finisher_Tray)', 'Stackedin(dummy-sheet,Finisher2_Entry-Finisher1_Exit)',
            'Stackedin(dummy-sheet,Finisher2_Tray)', 'Stackedin(dummy-sheet,Some_Feeder_Tray)',
            'Stackedin(dummy-sheet,Some_Finisher_Tray)', 'Stackedin(sheet1,Finisher2_Entry-Finisher1_Exit)',
            'Stackedin(sheet1,Finisher2_Tray)', 'Stackedin(sheet1,Some_Feeder_Tray)',
            'Stackedin(sheet1,Some_Finisher_Tray)', 'total-cost()'] == as_list2(variables)

    # Test some grounding routines on a STRIPS blocksworld
    problem = generate_small_strips_bw_problem()
    grounding = NaiveGroundingStrategy(problem)
    assert as_list1(grounding.static_symbols) == []
    assert as_list1(grounding.fluent_symbols) == ['clear', 'handempty', 'holding', 'on', 'ontable']

    variables = grounding.ground_state_variables()
    assert len(variables) == 29

    # Test some grounding routines on a (typed) Functional STRIPS blocksworld
    problem = generate_small_fstrips_bw_problem()
    grounding = NaiveGroundingStrategy(problem)
    assert as_list1(grounding.static_symbols) == []
    assert as_list1(grounding.fluent_symbols) == ['clear', 'loc']

    variables = grounding.ground_state_variables()
    assert ['clear(b1)', 'clear(b2)', 'clear(b3)', 'clear(b4)', 'clear(table)', 'loc(b1)', 'loc(b2)', 'loc(b3)',
            'loc(b4)'] == as_list2(variables)