コード例 #1
0
ファイル: test_grounding.py プロジェクト: KDercksen/SPML
def test_statics1():
    """
    A static predicate is a predicate, which doesn't occur in an effect of an
    action.
    """
    type_object = Type("object", None)
    type_car = Type("car", type_vehicle)
    type_city = Type("city", type_object)
    type_country = Type("country", type_object)
    types = {"object": type_object, "car": type_car, "city": type_city,
             "country": type_country}

    predicate_orig = Predicate("at", [("car", types["car"]),
                                      ("dest", types["city"])])
    predicate_dest = Predicate("at", [("car", types["car"]),
                                      ("orig", types["city"])])
    predicate_in = Predicate("in", [("city", types["city"]),
                                    ("country", types["country"])])

    action_drive_car = get_action("DRIVE-CAR", [("car", [types["car"]]),
                             ("loc-orig", [types["city"]]),
                             ("loc-dest", [types["city"]])],
                             [predicate_orig], [predicate_dest],
                             [predicate_orig])

    expected = [("in", grounding._get_statics([predicate_in],
                                              [action_drive_car]), True),
                ("dest", grounding._get_statics([predicate_dest],
                                                [action_drive_car]), False),
                ("orig", grounding._get_statics([predicate_orig],
                                                [action_drive_car]), False)]

    for pre, statics, element in expected:
        yield in_statics, pre, statics, element
コード例 #2
0
def test_statics2():
    type_object = Type("object", None)

    predicate_a = Predicate("a", [])
    predicate_b = Predicate("b", [])

    the_action = get_action("the-action", [], [predicate_a], [predicate_b], [])

    statics = grounding._get_statics([predicate_a, predicate_b], [the_action])

    assert predicate_a.name in statics and predicate_b.name not in statics
コード例 #3
0
ファイル: test_grounding.py プロジェクト: KDercksen/SPML
def test_statics2():
    type_object = Type("object", None)

    predicate_a = Predicate("a", [])
    predicate_b = Predicate("b", [])

    the_action = get_action("the-action", [], [predicate_a], [predicate_b], [])

    statics = grounding._get_statics([predicate_a, predicate_b], [the_action])

    assert predicate_a.name in statics and predicate_b.name not in statics
コード例 #4
0
def test_statics1():
    """
    A static predicate is a predicate, which doesn't occur in an effect of an
    action.
    """
    type_object = Type("object", None)
    type_car = Type("car", type_vehicle)
    type_city = Type("city", type_object)
    type_country = Type("country", type_object)
    types = {
        "object": type_object,
        "car": type_car,
        "city": type_city,
        "country": type_country,
    }

    predicate_orig = Predicate("at", [("car", types["car"]),
                                      ("dest", types["city"])])
    predicate_dest = Predicate("at", [("car", types["car"]),
                                      ("orig", types["city"])])
    predicate_in = Predicate("in", [("city", types["city"]),
                                    ("country", types["country"])])

    action_drive_car = get_action(
        "DRIVE-CAR",
        [
            ("car", [types["car"]]),
            ("loc-orig", [types["city"]]),
            ("loc-dest", [types["city"]]),
        ],
        [predicate_orig],
        [predicate_dest],
        [predicate_orig],
    )

    assert "in" in grounding._get_statics([predicate_in], [action_drive_car])
    assert "dest" not in grounding._get_statics([predicate_dest],
                                                [action_drive_car])
    assert "orig" not in grounding._get_statics([predicate_orig],
                                                [action_drive_car])
コード例 #5
0
def test_statics1():
    """
    A static predicate is a predicate, which doesn't occur in an effect of an
    action.
    """
    type_object = Type("object", None)
    type_car = Type("car", type_vehicle)
    type_city = Type("city", type_object)
    type_country = Type("country", type_object)
    types = {
        "object": type_object,
        "car": type_car,
        "city": type_city,
        "country": type_country
    }

    predicate_orig = Predicate("at", [("car", types["car"]),
                                      ("dest", types["city"])])
    predicate_dest = Predicate("at", [("car", types["car"]),
                                      ("orig", types["city"])])
    predicate_in = Predicate("in", [("city", types["city"]),
                                    ("country", types["country"])])

    action_drive_car = get_action("DRIVE-CAR", [("car", [types["car"]]),
                                                ("loc-orig", [types["city"]]),
                                                ("loc-dest", [types["city"]])],
                                  [predicate_orig], [predicate_dest],
                                  [predicate_orig])

    expected = [
        ("in", grounding._get_statics([predicate_in],
                                      [action_drive_car]), True),
        ("dest", grounding._get_statics([predicate_dest],
                                        [action_drive_car]), False),
        ("orig", grounding._get_statics([predicate_orig],
                                        [action_drive_car]), False)
    ]

    for pre, statics, element in expected:
        yield in_statics, pre, statics, element
コード例 #6
0
ファイル: test_grounding.py プロジェクト: KDercksen/SPML
def test_create_operator():
    statics = grounding._get_statics(standard_domain.predicates.values(),
                                     [action_drive_car])
    initial_state = [Predicate("at", [("ford", types["car"]),
                                      ("freiburg", types["city"])])]

    operator = grounding._create_operator(
        action_drive_car,
        {"car": "ford", "dest": "berlin", "orig": "freiburg"},
        [], initial_state)
    assert operator.name == "(DRIVE-CAR ford freiburg berlin)"
    assert operator.preconditions == {'(at ford berlin)'}
    assert operator.add_effects == {'(at ford freiburg)'}
    assert operator.del_effects == {'(at ford berlin)'}
コード例 #7
0
def test_create_operator():
    statics = grounding._get_statics(standard_domain.predicates.values(),
                                     [action_drive_car])
    initial_state = [
        Predicate("at", [("ford", types["car"]), ("freiburg", types["city"])])
    ]

    operator = grounding._create_operator(action_drive_car, {
        "car": "ford",
        "dest": "berlin",
        "orig": "freiburg"
    }, [], initial_state)
    assert operator.name == "(DRIVE-CAR ford freiburg berlin)"
    assert operator.preconditions == {'(at ford berlin)'}
    assert operator.add_effects == {'(at ford freiburg)'}
    assert operator.del_effects == {'(at ford berlin)'}
コード例 #8
0
def test_add_del_effects():
    parser = Parser("")

    def parse_problem(domain, problem):
        parser.domInput = domain
        parser.probInput = problem
        domain = parser.parse_domain(False)
        return parser.parse_problem(domain, False)

    dom_pddl = """
    (define (domain dom)
      (:requirements :typing)
      (:predicates (ok ?v - object))

      (:action theaction
       :parameters (?x - object)
       :precondition {0}
       :effect {1}
      )
    )
    """

    prob_pddl = """
    ;; See domain file for description of this test.

    (define (problem prob)
      (:domain dom)
      (:objects y - object)
      (:init)
      (:goal (ok y)))
    """

    tests = [
        # Only add effect
        ("(and)", "(ok ?x)", set(), {"(ok y)"}, set()),
        # Only delete effect
        ("(and)", "(and (not (ok ?x)))", set(), set(), {"(ok y)"}),
        # Both add and delete effect
        ("(and)", "(and (ok ?x) (not (ok ?x)))", set(), {"(ok y)"}, set()),
        # Precondition and add effect
        ("(and (ok ?x))", "(ok ?x)", {"(ok y)"}, set(), set()),
        # Precondition and delete effect
        ("(and (ok ?x))", "(and (not (ok ?x)))", {"(ok y)"}, set(), {"(ok y)"}
         ),
        # Precondition and both add and delete effect
        ("(and (ok ?x))", "(and (ok ?x) (not (ok ?x)))", {"(ok y)"}, set(),
         set()),
    ]

    for pre_in, eff_in, pre_exp, add_exp, del_exp in tests:
        dom = dom_pddl.format(pre_in, eff_in)
        problem = parse_problem(dom, prob_pddl)

        domain = problem.domain
        actions = domain.actions.values()
        predicates = domain.predicates.values()

        # Objects
        objects = problem.objects
        objects.update(domain.constants)

        # Get the names of the static predicates
        statics = grounding._get_statics(predicates, actions)

        # Create a map from types to objects
        type_map = grounding._create_type_map(objects)

        # Transform initial state into a specific
        init = grounding._get_partial_state(problem.initial_state)

        # Ground actions
        operators = grounding._ground_actions(actions, type_map, statics, init)

        assert len(operators) == 1
        op = operators[0]
        assert op.preconditions == pre_exp
        assert op.add_effects == add_exp
        assert op.del_effects == del_exp
コード例 #9
0
ファイル: test_grounding.py プロジェクト: KDercksen/SPML
def test_add_del_effects():
    parser = Parser('')

    def parse_problem(domain, problem):
        parser.domInput = domain
        parser.probInput = problem
        domain = parser.parse_domain(False)
        return parser.parse_problem(domain, False)

    dom_pddl = """
    (define (domain dom)
      (:requirements :typing)
      (:predicates (ok ?v - object))

      (:action theaction
       :parameters (?x - object)
       :precondition {0}
       :effect {1}
      )
    )
    """

    prob_pddl = """
    ;; See domain file for description of this test.

    (define (problem prob)
      (:domain dom)
      (:objects y - object)
      (:init)
      (:goal (ok y)))
    """

    tests = [
        # Only add effect
        ('(and)', '(ok ?x)', set(), {'(ok y)'}, set()),
        # Only delete effect
        ('(and)', '(and (not (ok ?x)))', set(), set(), {'(ok y)'}),
        # Both add and delete effect
        ('(and)', '(and (ok ?x) (not (ok ?x)))', set(), {'(ok y)'}, set()),
        # Precondition and add effect
        ('(and (ok ?x))', '(ok ?x)', {'(ok y)'}, set(), set()),
        # Precondition and delete effect
        ('(and (ok ?x))', '(and (not (ok ?x)))', {'(ok y)'}, set(),
         {'(ok y)'}),
        # Precondition and both add and delete effect
        ('(and (ok ?x))', '(and (ok ?x) (not (ok ?x)))', {'(ok y)'}, set(),
         set()),
            ]

    for pre_in, eff_in, pre_exp, add_exp, del_exp in tests:
        dom = dom_pddl.format(pre_in, eff_in)
        problem = parse_problem(dom, prob_pddl)

        domain = problem.domain
        actions = domain.actions.values()
        predicates = domain.predicates.values()

        # Objects
        objects = problem.objects
        objects.update(domain.constants)

        # Get the names of the static predicates
        statics = grounding._get_statics(predicates, actions)

        # Create a map from types to objects
        type_map = grounding._create_type_map(objects)

        # Transform initial state into a specific
        init = grounding._get_partial_state(problem.initial_state)

        # Ground actions
        operators = grounding._ground_actions(actions, type_map, statics, init)

        yield assert_equal, len(operators), 1
        op = operators[0]
        yield assert_equal, op.preconditions, pre_exp
        yield assert_equal, op.add_effects, add_exp
        yield assert_equal, op.del_effects, del_exp