Example #1
0
def test_problem_grounding_on_bw():
    # Test some grounding routines on a STRIPS blocksworld
    problem = generate_strips_blocksworld_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

    actions = grounding.ground_actions()
    expected = {'pick-up': 4, 'put-down': 4, 'stack': 16, 'unstack': 16}
    assert all(
        len(groundings) == expected[schema]
        for schema, groundings in actions.items())

    # Test some grounding routines on a (typed) Functional STRIPS blocksworld
    problem = generate_fstrips_blocksworld_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)
Example #2
0
def test_is_typed():
    problem = generate_fstrips_blocksworld_problem()
    assert is_typed_problem(problem)

    problem = tarski.benchmarks.blocksworld.generate_strips_blocksworld_problem(
    )
    assert not is_typed_problem(problem)
Example #3
0
def test_on_fstrips_bw():
    # Let's test the approach on one problem with non-numeric functions and a simple nested expression:
    #     move(x, y) action has an add-effect $clear(loc(x))$
    problem = generate_fstrips_blocksworld_problem(
        nblocks=2,
        init=[('b1', 'b2'), ('b2', 'table')],
        goal=[('b2', 'table'), ('b1', 'table')]
    )

    plan = run_on_problem(problem, reachability="none", max_horizon=1, grounding='none',
                          smtlib_filename="theory.smtlib", print_full_model=True)
    assert plan == ['(move b1 table)']

    problem = generate_fstrips_blocksworld_problem(
        nblocks=2,
        init=[('b1', 'b2'), ('b2', 'table')],
        goal=[('b2', 'b1'), ('b1', 'table')]
    )

    assert run_on_problem(problem, reachability="none", max_horizon=1, grounding='none') is None
    assert run_on_problem(problem, reachability="none", max_horizon=2, grounding='none') ==\
           ['(move b1 table)', '(move b2 b1)']

    problem = generate_fstrips_blocksworld_problem(
        nblocks=4,
        init=[('b1', 'b2'), ('b2', 'table'), ('b3', 'b4'), ('b4', 'table')],
        goal=[('b2', 'b3'), ('b3', 'b4'), ('b4', 'b1'), ('b1', 'table')]
    )

    # h=3 is not enough
    assert run_on_problem(problem, reachability="none", max_horizon=3, grounding='none') is None

    # h=4 is not enough
    assert run_on_problem(problem, reachability="none", max_horizon=4, grounding='none') is None

    # But there is a length-5 plan
    plan = run_on_problem(problem, reachability="none", max_horizon=5, grounding='none')
    possible_plans = ({'(move b1 table)', '(move b3 table)', '(move b4 b1)', '(move b3 b4)', '(move b2 b3)'},
                      {'(move b1 table)', '(move b3 b2)', '(move b4 b1)', '(move b3 b4)', '(move b2 b3)'},)
    assert plan is not None and set(plan) in possible_plans
Example #4
0
def test_blocksworld():
    problem = generate_strips_blocksworld_problem(nblocks=5)
    assert problem

    problem = generate_fstrips_blocksworld_problem(nblocks=5)
    assert problem

    # Now let's test the generator with given, fixed configurations:
    problem = generate_fstrips_blocksworld_problem(nblocks=4,
                                                   init=[('b1', 'b2'),
                                                         ('b2', 'table'),
                                                         ('b3', 'b4'),
                                                         ('b4', 'table')],
                                                   goal=[('b2', 'b3'),
                                                         ('b3', 'b4'),
                                                         ('b4', 'b1'),
                                                         ('b1', 'table')])
    lang = problem.language
    loc, b1, b2, table = lang.get('loc', 'b1', 'b2', 'table')

    assert problem.init[loc(b1) == b2] and problem.init[loc(b2) == table]
    assert is_and(problem.goal) and problem.goal.subformulas[-1] == (loc(b1)
                                                                     == table)
Example #5
0
def get_bw_elements():
    problem = generate_fstrips_blocksworld_problem()
    loc, clear, b1, table = problem.language.get("loc", "clear", "b1", "table")
    return problem, loc, clear, b1, table
Example #6
0
def test_forward_search_model():
    problem = generate_fstrips_blocksworld_problem()
    model = ForwardSearchModel(problem)
    assert model.init() == problem.init
Example #7
0
def test_basic_search():
    problem = generate_fstrips_blocksworld_problem()
    lang = problem.language

    model = ForwardSearchModel(problem)
    search = BreadthFirstSearch(model, max_expansions=10)
Example #8
0
def test_free_variables_in_schema_manipulations():
    problem = generate_fstrips_blocksworld_problem()
    free = collect_effect_free_parameters(problem.get_action('move'))
    assert not free  # Move has no effect-free variable