def p_typed_variables_lst(self, p): """typed_variables_lst : variables_lst HYPHEN type typed_variables_lst | variables_lst HYPHEN type""" if len(p) == 4: p[0] = [Term.variable(name, p[3]) for name in p[1]] else: p[0] = [Term.variable(name, p[3]) for name in p[1]] + p[4]
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
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
def test_domain_predicates(self): """Test that the domain predicates are correct.""" assert self.pddl_predicates == [ Predicate("vehicleat", [Term.variable("?loc", "location")]), Predicate("spare-in", [Term.variable("?loc", "location")]), Predicate( "road", [ Term.variable("?from", "location"), Term.variable("?to", "location") ], ), Predicate("not-flattire"), ]
def test_domain_operators(self): """Test that the domain operators are correct.""" op1 = Action( name="move-car", parameters=[ Term.variable("?from", "location"), Term.variable("?to", "location"), ], preconditions=FormulaAnd([ Literal.positive(Predicate("vehicleat", ["?from"])), Literal.positive(Predicate("road", ["?from", "?to"])), Literal.positive(Predicate("not-flattire")), ]), effects=FormulaAnd([ FormulaOneOf([ FormulaAnd([ Literal.positive(Predicate("vehicleat", ["?to"])), Literal.negative(Predicate("vehicleat", ["?from"])), ]), FormulaAnd([ Literal.positive(Predicate("vehicleat", ["?to"])), Literal.negative(Predicate("vehicleat", ["?from"])), Literal.negative(Predicate("not-flattire")), ]), ]), ]), ) op2 = Action( name="changetire", parameters=[ Term.variable("?loc", "location"), ], preconditions=FormulaAnd([ Literal.positive(Predicate("spare-in", ["?loc"])), Literal.positive(Predicate("vehicleat", ["?loc"])), ]), effects=FormulaAnd([ Literal.negative(Predicate("spare-in", ["?loc"])), Literal.positive(Predicate("not-flattire")), ]), ) assert self.pddl_operators == [ op1, op2, ]
def compute_parameters(self, domain_predicates, grounded_symbols): """Compute parameters.""" objs_set = set() obj_mapping = {} parameters = [] counter = 0 for symbol in grounded_symbols: if symbol.objects: i = 0 for obj in symbol.objects: if obj not in objs_set: objs_set.add(obj) (name_var, type_) = self.compute_type( domain_predicates, symbol.name, i, counter ) obj_mapping[obj] = [name_var, type_] parameters.append(Term.variable(name_var, type_)) counter += 1 else: pass i += 1 return parameters, obj_mapping
def test_domain_predicates(self): """Test that the domain predicates are correct.""" assert self.pddl_predicates == [ Predicate("up"), Predicate("position", [Term.variable("?p", "location")]), Predicate( "next-fwd", [ Term.variable("?p1", "location"), Term.variable("?p2", "location") ], ), Predicate( "next-bwd", [ Term.variable("?p1", "location"), Term.variable("?p2", "location") ], ), Predicate("ladder-at", [Term.variable("?p", "location")]), Predicate("broken-leg"), ]
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
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
def test_domain_operators(self): """Test that the domain operators are correct.""" op1 = Action( name="walk-on-beam", parameters=[ Term.variable("?from", "location"), Term.variable("?to", "location"), ], preconditions=FormulaAnd([ Literal.negative(Predicate("broken-leg")), Literal.positive(Predicate("up")), Literal.positive(Predicate("position", ["?from"])), Literal.positive(Predicate("next-fwd", ["?from", "?to"])), ]), effects=FormulaOneOf([ FormulaAnd([ Literal.positive(Predicate("position", ["?to"])), Literal.negative(Predicate("position", ["?from"])), ]), FormulaAnd([ Literal.negative(Predicate("up")), Literal.positive(Predicate("position", ["?to"])), Literal.negative(Predicate("position", ["?from"])), ]), ]), ) op2 = Action( name="walk-left", parameters=[ Term.variable("?from", "location"), Term.variable("?to", "location"), ], preconditions=FormulaAnd([ Literal.negative(Predicate("broken-leg")), Literal.negative(Predicate("up")), Literal.positive(Predicate("position", ["?from"])), Literal.positive(Predicate("next-bwd", ["?from", "?to"])), ]), effects=FormulaAnd([ Literal.positive(Predicate("position", ["?to"])), Literal.negative(Predicate("position", ["?from"])), ]), ) op3 = Action( name="walk-right", parameters=[ Term.variable("?from", "location"), Term.variable("?to", "location"), ], preconditions=FormulaAnd([ Literal.negative(Predicate("broken-leg")), Literal.negative(Predicate("up")), Literal.positive(Predicate("position", ["?from"])), Literal.positive(Predicate("next-fwd", ["?from", "?to"])), ]), effects=FormulaAnd([ Literal.positive(Predicate("position", ["?to"])), Literal.negative(Predicate("position", ["?from"])), ]), ) op4 = Action( name="climb", parameters=[Term.variable("?p", "location")], preconditions=FormulaAnd([ Literal.negative(Predicate("broken-leg")), Literal.negative(Predicate("up")), Literal.positive(Predicate("position", ["?p"])), Literal.positive(Predicate("ladder-at", ["?p"])), ]), effects=FormulaAnd([Literal.positive(Predicate("up"))]), ) op5 = Action( name="climb-down", parameters=[], preconditions=FormulaAnd([ Literal.negative(Predicate("broken-leg")), Literal.positive(Predicate("up")), ]), effects=FormulaAnd([Literal.negative(Predicate("up"))]), ) op6 = Action( name="jump-over", parameters=[ Term.variable("?from", "location"), Term.variable("?middle", "location"), Term.variable("?to", "location"), ], preconditions=FormulaAnd([ Literal.negative(Predicate("broken-leg")), Literal.positive(Predicate("up")), Literal.positive(Predicate("position", ["?from"])), Literal.positive(Predicate( "next-fwd", ["?from", "?middle"], )), Literal.positive(Predicate("next-fwd", ["?middle", "?to"])), ]), effects=FormulaOneOf([ FormulaAnd([ Literal.negative(Predicate("up")), Literal.positive(Predicate("broken-leg")), ]), FormulaAnd([ Literal.negative(Predicate("up")), Literal.positive(Predicate("broken-leg")), Literal.positive(Predicate("position", ["?middle"])), Literal.negative(Predicate("position", ["?from"])), ]), FormulaAnd([ Literal.negative(Predicate("up")), Literal.positive(Predicate("position", ["?middle"])), Literal.negative(Predicate("position", ["?from"])), ]), FormulaAnd([ Literal.negative(Predicate("up")), Literal.positive(Predicate("broken-leg")), Literal.positive(Predicate("position", ["?to"])), Literal.negative(Predicate("position", ["?from"])), ]), FormulaAnd([ Literal.negative(Predicate("up")), Literal.positive(Predicate("position", ["?to"])), Literal.negative(Predicate("position", ["?from"])), ]), FormulaAnd([ Literal.positive(Predicate("position", ["?to"])), Literal.negative(Predicate("position", ["?from"])), ]), ]), ) assert self.pddl_operators == [op1, op2, op3, op4, op5, op6]