def recurse(condition): if isinstance(condition, pddl.FunctionComparison) : parts = [task.function_administrator.get_derived_function(exp) for exp in condition.parts] if condition.negated: return pddl.NegatedFunctionComparison(condition.comparator,parts) else: return pddl.FunctionComparison(condition.comparator,parts) else: new_parts = [recurse(part) for part in condition.parts] return condition.change_parts(new_parts)
def parse_condition_aux(alist, negated, type_dict, predicate_dict): """Parse a PDDL condition. The condition is translated into NNF on the fly.""" # if DEBUG: print ("parsing condition aux %s" % [alist]) tag = alist[0] if is_function_comparison( alist ): # NFD conditions are always comparisons between 2 numeric expressions args = [parse_expression(arg) for arg in alist[1:]] assert len(args) == 2, args if negated: return pddl.NegatedFunctionComparison(tag, args, True) else: return pddl.FunctionComparison(tag, args, True) elif tag in ("and", "or", "not", "imply"): args = alist[1:] if tag == "imply": assert len(args) == 2 if tag == "not": assert len(args) == 1 return parse_condition_aux(args[0], not negated, type_dict, predicate_dict) elif tag in ("forall", "exists"): parameters = parse_typed_list(alist[1]) args = alist[2:] assert len(args) == 1 else: # if is_object_comparison(alist): # print("DEBUG: Object comparison!") # print(alist) return parse_literal(alist, type_dict, predicate_dict, negated=negated) if tag == "imply": parts = [ parse_condition_aux(args[0], not negated, type_dict, predicate_dict), parse_condition_aux(args[1], negated, type_dict, predicate_dict) ] tag = "or" else: parts = [ parse_condition_aux(part, negated, type_dict, predicate_dict) for part in args ] if tag == "and" and not negated or tag == "or" and negated: return pddl.Conjunction(parts) elif tag == "or" and not negated or tag == "and" and negated: return pddl.Disjunction(parts) elif tag == "forall" and not negated or tag == "exists" and negated: return pddl.UniversalCondition(parameters, parts) elif tag == "exists" and not negated or tag == "forall" and negated: return pddl.ExistentialCondition(parameters, parts)
def recurse(condition, act, time, duration, pnes): if isinstance(condition, pddl.FunctionComparison): parts = [ exp.remove_duration_variable(act, time, duration, pnes) for exp in condition.parts ] return pddl.FunctionComparison(condition.comparator, parts) return comp else: new_parts = [ recurse(part, act, time, duration, pnes) for part in condition.parts ] return condition.change_parts(new_parts)