def toModuleCall(self): mod_args = [] for param in self.parameters: if param.name.startswith("?"): mod_args.append(conditions.Variable(param.name)) else: mod_args.append(conditions.ObjectTerm(param.name)) return conditions.ModuleCall(self.name, mod_args)
def instantiate(self, var_mapping, init_facts): args = [conditions.ObjectTerm(var_mapping.get(arg.name, arg.name)) for arg in self.args] pne = PrimitiveNumericExpression(self.symbol, args) assert not self.symbol == "total-cost" # We know this expression is constant. Substitute it by corresponding # initialization from task. for fact in init_facts: if isinstance(fact, FunctionAssignment): if fact.fluent == pne: return fact.expression assert False, "Could not find instantiation for PNE!"
def instantiate(self, var_mapping, init_facts, fluent_facts, init_function_vals, fluent_functions, task, new_axiom, objects_by_type, result): if self.parameters: var_mapping = var_mapping.copy() # Will modify this. object_lists = [objects_by_type.get(par.type, []) for par in self.parameters] for object_tuple in cartesian_product(*object_lists): for (par, obj) in zip(self.parameters, object_tuple): var_mapping[conditions.Variable(par.name)] = conditions.ObjectTerm(obj) self._instantiate(var_mapping, init_facts, fluent_facts, init_function_vals, fluent_functions, task, new_axiom, result) else: self._instantiate(var_mapping, init_facts, fluent_facts, init_function_vals, fluent_functions, task, new_axiom, result)
def normalize(self, time, results): used_variables = list(self.head.free_variables() | self.value.free_variables()) typed1, conjunction_parts1, term1 = self.head.compile_objectfunctions_aux( used_variables) typed2, conjunction_parts2, term2 = self.value.compile_objectfunctions_aux( used_variables) assert isinstance(term1, conditions.Variable) add_params = set( [typed for typed in typed1 if not typed.name == term1.name] + typed2) del_params = set(typed1 + typed2) add_conjunction_parts = conjunction_parts1[1:] + conjunction_parts2 del_conjunction_parts = conjunction_parts1 + conjunction_parts2 del_conjunction_parts = conjunction_parts1[1:] + conjunction_parts2 # conjunctive_parts1[0] is left out because we do not need the condition # that the atom in the del effect hast been true before # These conjunction parts are sufficient under the add-after-delete semantics. # Under the consistent effect semantics we need a further condition # that prevents deleting the added predicate. del_param = conjunction_parts1[0].args[-1] del_conjunction_parts.append( conditions.NegatedAtom("=", [del_param, term2])) del_effect = ConjunctiveEffect([ conjunction_parts1[0].negate(), ]) atom_name = conjunction_parts1[0].predicate atom_parts = list(conjunction_parts1[0].args) atom_parts[-1] = term2 add_effect = ConjunctiveEffect([ conditions.Atom(atom_name, atom_parts), ], time) add_conjunction = conditions.Conjunction(add_conjunction_parts) del_conjunction = conditions.Conjunction(del_conjunction_parts) if time == "start": del_condition = [ del_conjunction, conditions.Truth(), conditions.Truth() ] add_condition = [ add_conjunction, conditions.Truth(), conditions.Truth() ] elif time == "end": add_condition = [ conditions.Truth(), conditions.Truth(), add_conjunction ] del_condition = [ conditions.Truth(), conditions.Truth(), del_conjunction ] else: add_condition = add_conjunction del_condition = del_conjunction if len(add_conjunction_parts) > 0: add_effect = ConditionalEffect(add_condition, add_effect, time) del_effect = ConditionalEffect(del_condition, del_effect) if len(add_params) > 0: add_effect = UniversalEffect(add_params, add_effect, time) del_effect = UniversalEffect(del_params, del_effect, time) results.append(add_effect) results.append(del_effect) # value "undefined" must be treated specially because it has not the type # required in del_params if term2.name != "undefined": del_undef_params = set([ typed for typed in del_params if not typed.name == del_param.name ]) atom_parts = list(conjunction_parts1[0].args) atom_parts[-1] = conditions.ObjectTerm("undefined") del_undef_effect = ConjunctiveEffect([ conditions.NegatedAtom(atom_name, atom_parts), ], time) del_undef_conjunction_parts = del_conjunction_parts[:-1] del_undef_conjunction = conditions.Conjunction( del_undef_conjunction_parts) if time == "start": del_undef_condition = [ del_undef_conjunction, conditions.Truth(), conditions.Truth() ] elif time == "end": del_undef_condition = [ conditions.Truth(), conditions.Truth(), del_undef_conjunction ] else: del_undef_condition = del_undef_conjunction if len(del_undef_conjunction_parts) > 0: del_undef_effect = ConditionalEffect(del_undef_condition, del_undef_effect, time) if len(del_undef_params) > 0: del_undef_effect = UniversalEffect(del_undef_params, del_undef_effect, time) results.append(del_undef_effect)