Пример #1
0
 def test_automaton_compute_parameters_1(self):
     """Test that the computation of parameters and object mapping are correct on triangle-tireworld."""
     pddl_domain = self.parser(
         open(
             str(
                 Path(
                     TEST_ROOT_DIR,
                     "data",
                     "pddl-domains",
                     "triangle-tireworld",
                     "domain.pddl",
                 ))).read())
     grounded_symbols = [
         Symbol("vehicleat", ["l31"]),
         Symbol("vehicleat", ["l12"]),
         Symbol("vehicleat", ["l22"]),
     ]
     actual_params, actual_obj_map = self.aut_obj.compute_parameters(
         pddl_domain.predicates, grounded_symbols)
     expected_params = [
         Term.variable("?loc-00", "location"),
         Term.variable("?loc-01", "location"),
         Term.variable("?loc-02", "location"),
     ]
     expected_objmap = {
         "l31": ["?loc-00", "location"],
         "l12": ["?loc-01", "location"],
         "l22": ["?loc-02", "location"],
     }
     assert actual_params == expected_params and actual_obj_map == expected_objmap
Пример #2
0
 def test_automaton_compute_parameters_2(self):
     """Test that the computation of parameters and object mapping are correct on blocksworld."""
     pddl_domain = self.parser(
         open(
             str(
                 Path(
                     TEST_ROOT_DIR,
                     "data",
                     "pddl-domains",
                     "blocksworld-ipc08",
                     "domain.pddl",
                 ))).read())
     grounded_symbols = [
         Symbol("on", ["b1", "b2"]),
         Symbol("on", ["b2", "b5"]),
         Symbol("emptyhand"),
     ]
     actual_params, actual_obj_map = self.aut_obj.compute_parameters(
         pddl_domain.predicates, grounded_symbols)
     expected_params = [
         Term.variable("?b1-00", "block"),
         Term.variable("?b2-01", "block"),
         Term.variable("?b2-02", "block"),
     ]
     expected_objmap = {
         "b1": ["?b1-00", "block"],
         "b2": ["?b2-01", "block"],
         "b5": ["?b2-02", "block"],
     }
     assert actual_params == expected_params and actual_obj_map == expected_objmap
Пример #3
0
 def test_automaton_compute_vars_mapping_1(self):
     """Test that the vars mapping is correct."""
     grounded_symbols = [Symbol("vehicleat", ["l31"])]
     objmap = {"l31": ["?loc-00", "location"]}
     actual_vars_map = self.aut_obj.compute_varsMapping(
         grounded_symbols, objmap)
     expected_vars_map = {
         Symbol("vehicleat", ["l31"]): [("?loc-00", "location")]
     }
     assert actual_vars_map == expected_vars_map
Пример #4
0
 def test_automaton_compute_vars_mapping_2(self):
     """Test that the vars mapping is correct."""
     grounded_symbols = [Symbol("on", ["b1", "b2"])]
     objmap = {"b1": ["?b1-00", "block"], "b2": ["?b2-01", "block"]}
     actual_vars_map = self.aut_obj.compute_varsMapping(
         grounded_symbols, objmap)
     expected_vars_map = {
         Symbol("on", ["b1", "b2"]): [("?b1-00", "block"),
                                      ("?b2-01", "block")]
     }
     assert actual_vars_map == expected_vars_map
Пример #5
0
def compute_symb_vars(formula):
    """Compute Symbols from the temporal formula."""
    ground_predicates = re.findall(r"(?!true|false)[_a-z0-9]+", str(formula))
    symb_vars_list = []
    for predicate in ground_predicates:
        temp = predicate.split("_")
        if len(temp) == 1:
            symb_vars_list.append(Symbol(temp[0]))
        else:
            symb_vars_list.append(Symbol(temp[0], temp[1:]))
    return symb_vars_list
def test_compute_formula_symbols():
    """Test symbols check."""
    formula = "vehicleat_l31 & O(vehicleat_l12)"
    syms = fond4ltlfpltlf.core.compute_symb_vars(formula)
    true_syms = [Symbol("vehicleat", ["l31"]), Symbol("vehicleat", ["l12"])]
    assert true_syms == syms

    formula = "F(emptyhand & on_b_e & ontable_e)"
    syms = fond4ltlfpltlf.core.compute_symb_vars(formula)
    true_syms = [
        Symbol("emptyhand"),
        Symbol("on", ["b", "e"]),
        Symbol("ontable", ["e"]),
    ]
    assert true_syms == syms
Пример #7
0
 def test_automaton_create_trans_op_2(self):
     """Test that the created trans operator is correct."""
     pddl_domain = self.parser(
         open(
             str(
                 Path(
                     TEST_ROOT_DIR,
                     "data",
                     "pddl-domains",
                     "blocksworld-ipc08",
                     "domain.pddl",
                 ))).read())
     grounded_symbols = [
         Symbol("emptyhand"),
         Symbol("on", ["b", "e"]),
         Symbol("ontable", ["e"]),
     ]
     actual_trans_ops, actual_params = self.aut_obj.create_operators_trans(
         pddl_domain.predicates, grounded_symbols)
     expected_trans_ops = [
         Action(
             name="trans-0",
             parameters=[
                 Term.variable("?b1-00", "block"),
                 Term.variable("?b2-01", "block"),
             ],
             preconditions=FormulaAnd([
                 FormulaOr([
                     FormulaAnd([
                         Literal.positive(
                             Predicate(
                                 "q1",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.negative(Predicate("emptyhand")),
                     ]),
                     FormulaAnd([
                         Literal.positive(
                             Predicate(
                                 "q1",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.positive(Predicate("emptyhand")),
                         Literal.negative(
                             Predicate(
                                 "on",
                                 ["?b1-00", "?b2-01"],
                             )),
                     ]),
                     FormulaAnd([
                         Literal.positive(
                             Predicate(
                                 "q1",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.positive(Predicate("emptyhand")),
                         Literal.positive(
                             Predicate(
                                 "on",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.negative(Predicate(
                             "ontable",
                             ["?b2-01"],
                         )),
                     ]),
                     FormulaAnd([
                         Literal.positive(
                             Predicate(
                                 "q2",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.negative(Predicate("emptyhand")),
                     ]),
                     FormulaAnd([
                         Literal.positive(
                             Predicate(
                                 "q2",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.positive(Predicate("emptyhand")),
                         Literal.negative(
                             Predicate(
                                 "on",
                                 ["?b1-00", "?b2-01"],
                             )),
                     ]),
                     FormulaAnd([
                         Literal.positive(
                             Predicate(
                                 "q2",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.positive(Predicate("emptyhand")),
                         Literal.positive(
                             Predicate(
                                 "on",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.negative(Predicate(
                             "ontable",
                             ["?b2-01"],
                         )),
                     ]),
                 ]),
                 Literal.negative(Predicate("turnDomain")),
             ]),
             effects=FormulaAnd([
                 Literal.positive(Predicate(
                     "q2",
                     ["?b1-00", "?b2-01"],
                 )),
                 Literal.negative(Predicate(
                     "q1",
                     ["?b1-00", "?b2-01"],
                 )),
                 Literal.negative(Predicate(
                     "q3",
                     ["?b1-00", "?b2-01"],
                 )),
                 Literal.positive(Predicate("turnDomain")),
             ]),
         ),
         Action(
             name="trans-1",
             parameters=[
                 Term.variable("?b1-00", "block"),
                 Term.variable("?b2-01", "block"),
             ],
             preconditions=FormulaAnd([
                 FormulaOr([
                     FormulaAnd([
                         Literal.positive(
                             Predicate(
                                 "q1",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.positive(Predicate("emptyhand")),
                         Literal.positive(
                             Predicate(
                                 "on",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.positive(Predicate(
                             "ontable",
                             ["?b2-01"],
                         )),
                     ]),
                     FormulaAnd([
                         Literal.positive(
                             Predicate(
                                 "q2",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.positive(Predicate("emptyhand")),
                         Literal.positive(
                             Predicate(
                                 "on",
                                 ["?b1-00", "?b2-01"],
                             )),
                         Literal.positive(Predicate(
                             "ontable",
                             ["?b2-01"],
                         )),
                     ]),
                     Literal.positive(
                         Predicate(
                             "q3",
                             ["?b1-00", "?b2-01"],
                         )),
                 ]),
                 Literal.negative(Predicate("turnDomain")),
             ]),
             effects=FormulaAnd([
                 Literal.positive(Predicate(
                     "q3",
                     ["?b1-00", "?b2-01"],
                 )),
                 Literal.negative(Predicate(
                     "q1",
                     ["?b1-00", "?b2-01"],
                 )),
                 Literal.negative(Predicate(
                     "q2",
                     ["?b1-00", "?b2-01"],
                 )),
                 Literal.positive(Predicate("turnDomain")),
             ]),
         ),
     ]
     expected_params = [
         Term.variable("?b1-00", "block"),
         Term.variable("?b2-01", "block"),
     ]
     assert actual_trans_ops == expected_trans_ops
     assert actual_params == expected_params
Пример #8
0
 def test_automaton_create_trans_op(self):
     """Test that the created trans operator is correct."""
     pddl_domain = self.parser(
         open(
             str(
                 Path(
                     TEST_ROOT_DIR,
                     "data",
                     "pddl-domains",
                     "triangle-tireworld",
                     "domain.pddl",
                 ))).read())
     grounded_symbols = [Symbol("vehicleat", ["l31"])]
     actual_trans_ops, actual_params = self.aut_obj.create_operators_trans(
         pddl_domain.predicates, grounded_symbols)
     expected_trans_ops = [
         Action(
             name="trans-0",
             parameters=[Term.variable("?loc-00", "location")],
             preconditions=FormulaAnd([
                 FormulaOr([
                     FormulaAnd([
                         Literal.positive(Predicate("q1", ["?loc-00"])),
                         Literal.negative(
                             Predicate("vehicleat", ["?loc-00"])),
                     ]),
                     FormulaAnd([
                         Literal.positive(Predicate("q2", ["?loc-00"])),
                         Literal.negative(
                             Predicate("vehicleat", ["?loc-00"])),
                     ]),
                 ]),
                 Literal.negative(Predicate("turnDomain")),
             ]),
             effects=FormulaAnd([
                 Literal.positive(Predicate("q2", ["?loc-00"])),
                 Literal.negative(Predicate("q1", ["?loc-00"])),
                 Literal.negative(Predicate("q3", ["?loc-00"])),
                 Literal.positive(Predicate("turnDomain")),
             ]),
         ),
         Action(
             name="trans-1",
             parameters=[Term.variable("?loc-00", "location")],
             preconditions=FormulaAnd([
                 FormulaOr([
                     FormulaAnd([
                         Literal.positive(Predicate("q1", ["?loc-00"])),
                         Literal.positive(
                             Predicate("vehicleat", ["?loc-00"])),
                     ]),
                     FormulaAnd([
                         Literal.positive(Predicate("q2", ["?loc-00"])),
                         Literal.positive(
                             Predicate("vehicleat", ["?loc-00"])),
                     ]),
                     Literal.positive(Predicate("q3", ["?loc-00"])),
                 ]),
                 Literal.negative(Predicate("turnDomain")),
             ]),
             effects=FormulaAnd([
                 Literal.positive(Predicate("q3", ["?loc-00"])),
                 Literal.negative(Predicate("q1", ["?loc-00"])),
                 Literal.negative(Predicate("q2", ["?loc-00"])),
                 Literal.positive(Predicate("turnDomain")),
             ]),
         ),
     ]
     expected_params = [Term.variable("?loc-00", "location")]
     assert actual_trans_ops == expected_trans_ops
     assert actual_params == expected_params