def parse_condition_aux(alist, negated): """Parse a PDDL condition. The condition is translated into NNF on the fly.""" tag = alist[0] if is_function_comparison(alist): args = [f_expression.parse_expression(arg) for arg in alist[1:]] assert len(args) == 2, args if negated: return NegatedFunctionComparison(tag, args, True) else: return 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) elif tag in ("forall", "exists"): parameters = pddl_types.parse_typed_list(alist[1]) args = alist[2:] assert len(args) == 1 elif tag == "[": assert not negated assert alist[-1] == "]" alist = alist[1:-1] # strip [ and ] # where go the type checks here? parameter should match the module... # somewhere check the "nestedness" as we want them at the top only? # Perhaps later in translate meckern return ModuleCall(alist[0], [parse_term(term) for term in alist[1:]]) elif negated: return NegatedAtom(alist[0], [parse_term(term) for term in alist[1:]]) else: return Atom(alist[0], [parse_term(term) for term in alist[1:]]) if tag == "imply": parts = [ parse_condition_aux(args[0], not negated), parse_condition_aux(args[1], negated) ] tag = "or" else: parts = [parse_condition_aux(part, negated) for part in args] if tag == "and" and not negated or tag == "or" and negated: return Conjunction(parts) elif tag == "or" and not negated or tag == "and" and negated: return Disjunction(parts) elif tag == "forall" and not negated or tag == "exists" and negated: return UniversalCondition(parameters, parts) elif tag == "exists" and not negated or tag == "forall" and negated: return ExistentialCondition(parameters, parts)
def parse_condition_aux(alist, negated): """Parse a PDDL condition. The condition is translated into NNF on the fly.""" tag = alist[0] if is_function_comparison(alist): args = [f_expression.parse_expression(arg) for arg in alist[1:]] assert len(args) == 2, args if negated: return NegatedFunctionComparison(tag, args, True) else: return 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) elif tag in ("forall", "exists"): parameters = pddl_types.parse_typed_list(alist[1]) args = alist[2:] assert len(args) == 1 elif tag == "[": assert not negated assert alist[-1] == "]" alist = alist[1:-1] # strip [ and ] # where go the type checks here? parameter should match the module... # somewhere check the "nestedness" as we want them at the top only? # Perhaps later in translate meckern return ModuleCall(alist[0], [parse_term(term) for term in alist[1:]]) elif negated: return NegatedAtom(alist[0], [parse_term(term) for term in alist[1:]]) else: return Atom(alist[0],[parse_term(term) for term in alist[1:]]) if tag == "imply": parts = [parse_condition_aux(args[0], not negated), parse_condition_aux(args[1], negated)] tag = "or" else: parts = [parse_condition_aux(part, negated) for part in args] if tag == "and" and not negated or tag == "or" and negated: return Conjunction(parts) elif tag == "or" and not negated or tag == "and" and negated: return Disjunction(parts) elif tag == "forall" and not negated or tag == "exists" and negated: return UniversalCondition(parameters, parts) elif tag == "exists" and not negated or tag == "forall" and negated: return ExistentialCondition(parameters, parts)
def parse(alist): iterator = iter(alist) assert iterator.next() == ":durative-action" name = iterator.next() parameters_tag_opt = iterator.next() if parameters_tag_opt == ":parameters": parameters = pddl_types.parse_typed_list(iterator.next(), only_variables=True) duration_tag = iterator.next() else: parameters = [] duration_tag = parameters_tag_opt assert duration_tag == ":duration" duration_list = iterator.next() if duration_list[0] == "and": duration_list = duration_list[1:] else: duration_list = [duration_list] duration_start = [] duration_end = [] for item in duration_list: # each item is a simple-duration-constraint duration = duration_start if item[0] == "at": if item[1] == "end": duration = duration_end item = item[2] assert item[0] in ("<=", ">=", "=") assert len(item) == 3 assert item[1] == "?duration" op = item[0] value = f_expression.parse_expression(item[2]) duration += [(op, value)] condition_tag = iterator.next() if condition_tag == ":condition": condition = conditions.parse_durative_condition(iterator.next()) effect_tag = iterator.next() else: condition = conditions.parse_durative_condition([]) effect_tag = condition_tag assert effect_tag == ":effect" effect_list = iterator.next() effect = [[], []] effects.parse_durative_effects(effect_list, effect) for rest in iterator: assert False, rest return DurativeAction(name, parameters, (duration_start, duration_end), condition, effect)
def parse(alist): iterator = iter(alist) assert iterator.next() == ":durative-action" name = iterator.next() parameters_tag_opt = iterator.next() if parameters_tag_opt == ":parameters": parameters = pddl_types.parse_typed_list(iterator.next(), only_variables=True) duration_tag = iterator.next() else: parameters = [] duration_tag = parameters_tag_opt assert duration_tag == ":duration" duration_list = iterator.next() if duration_list[0] == "and": duration_list = duration_list[1:] else: duration_list = [duration_list] duration_start = [] duration_end = [] for item in duration_list: # each item is a simple-duration-constraint duration = duration_start if item[0] == "at": if item[1] == "end": duration = duration_end item = item[2] assert item[0] in ("<=",">=","=") assert len(item) == 3 assert item[1] == "?duration" op = item[0] value = f_expression.parse_expression(item[2]) duration += [(op,value)] condition_tag = iterator.next() if condition_tag == ":condition": condition = conditions.parse_durative_condition(iterator.next()) effect_tag = iterator.next() else: condition = conditions.parse_durative_condition([]) effect_tag = condition_tag assert effect_tag == ":effect" effect_list = iterator.next() effect = [[],[]] effects.parse_durative_effects(effect_list, effect) for rest in iterator: assert False, rest return DurativeAction(name, parameters, (duration_start,duration_end), condition, effect)
def parse_condition_aux(alist, negated): """Parse a PDDL condition. The condition is translated into NNF on the fly.""" tag = alist[0] if is_function_comparison(alist): args = [f_expression.parse_expression(arg) for arg in alist[1:]] assert len(args) == 2, args if negated: return NegatedFunctionComparison(tag, args, True) else: return 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) elif tag in ("forall", "exists"): import __builtin__ __builtin__.containsQuantifiedConditions = True parameters = pddl_types.parse_typed_list(alist[1]) args = alist[2:] assert len(args) == 1 elif negated: return NegatedAtom(alist[0], [parse_term(term) for term in alist[1:]]) else: return Atom(alist[0], [parse_term(term) for term in alist[1:]]) if tag == "imply": parts = [ parse_condition_aux(args[0], not negated), parse_condition_aux(args[1], negated) ] tag = "or" else: parts = [parse_condition_aux(part, negated) for part in args] if tag == "and" and not negated or tag == "or" and negated: return Conjunction(parts) elif tag == "or" and not negated or tag == "and" and negated: return Disjunction(parts) elif tag == "forall" and not negated or tag == "exists" and negated: return UniversalCondition(parameters, parts) elif tag == "exists" and not negated or tag == "forall" and negated: return ExistentialCondition(parameters, parts)
def parse_condition_aux(alist, negated): """Parse a PDDL condition. The condition is translated into NNF on the fly.""" tag = alist[0] if is_function_comparison(alist): args = [f_expression.parse_expression(arg) for arg in alist[1:]] assert len(args) == 2, args if negated: return NegatedFunctionComparison(tag, args, True) else: return 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) elif tag in ("forall", "exists"): parameters = pddl_types.parse_typed_list(alist[1]) args = alist[2:] assert len(args) == 1 elif negated: return NegatedAtom(alist[0], [parse_term(term) for term in alist[1:]]) else: return Atom(alist[0],[parse_term(term) for term in alist[1:]]) if tag == "imply": parts = [parse_condition_aux(args[0], not negated), parse_condition_aux(args[1], negated)] tag = "or" else: parts = [parse_condition_aux(part, negated) for part in args] if tag == "and" and not negated or tag == "or" and negated: return Conjunction(parts) elif tag == "or" and not negated or tag == "and" and negated: return Disjunction(parts) elif tag == "forall" and not negated or tag == "exists" and negated: return UniversalCondition(parameters, parts) elif tag == "exists" and not negated or tag == "forall" and negated: return ExistentialCondition(parameters, parts)
def parse(alist): assert len(alist) >= 3 name = alist[0] # effects might contain (set) functions here like (x ?a) parameterList = [ someParam for someParam in alist[1:-2] if not isinstance(someParam, list) ] functionParamList = [ someParam for someParam in alist[1:-2] if isinstance(someParam, list) ] parameters = pddl_types.parse_typed_list(parameterList) effects = [ f_expression.parse_expression(entry) for entry in functionParamList ] #effects = [functions.Function.parse_typed(entry, "number") for entry in functionParamList] modulecall = alist[-1] type = alist[-2] return Module(name, parameters, type, modulecall, effects)
def parse(alist): iterator = iter(alist) assert iterator.next() == ":durative-action" name = iterator.next() print "Parsing durative-action", name parameters_tag_opt = iterator.next() if parameters_tag_opt == ":parameters": parameters = pddl_types.parse_typed_list(iterator.next(), only_variables=True) grounding_tag = iterator.next() else: parameters = [] grounding_tag = parameters_tag_opt if grounding_tag == ":grounding": grounding_list = iterator.next() grounding_call = conditions.parse_condition(grounding_list) duration_tag = iterator.next() else: grounding_call = None duration_tag = grounding_tag assert duration_tag == ":duration" duration_list = iterator.next() if duration_list[0] == "and": duration_list = duration_list[1:] else: duration_list = [duration_list] duration_start = [] duration_end = [] for item in duration_list: # each item is a simple-duration-constraint duration = duration_start if item[0] == "at": if item[1] == "end": duration = duration_end item = item[2] assert item[0] in ("<=",">=","=") if len(item) == 3: # = ?duration 1 assert item[1] == "?duration" op = item[0] value = f_expression.parse_expression(item[2]) duration += [(op,value)] else: # should be module: = ?duration [module] assert item[1] == "?duration" op = item[0] mod_list = item[2:] #print "Modlist:", mod_list value = conditions.parse_condition(mod_list) #print "parse to ", value duration += [(op,value)] pass condition_tag = iterator.next() if condition_tag == ":condition": condition = conditions.parse_durative_condition(iterator.next()) effect_tag = iterator.next() else: condition = conditions.parse_durative_condition([]) effect_tag = condition_tag assert effect_tag == ":effect" effect_list = iterator.next() effect = [[],[]] effects.parse_durative_effects(effect_list, effect) for rest in iterator: assert False, rest return DurativeAction(name, parameters, grounding_call, (duration_start,duration_end), condition, effect)
def parse(alist): iterator = iter(alist) assert iterator.next() == ":durative-action" name = iterator.next() print "Parsing durative-action", name parameters_tag_opt = iterator.next() if parameters_tag_opt == ":parameters": parameters = pddl_types.parse_typed_list(iterator.next(), only_variables=True) grounding_tag = iterator.next() else: parameters = [] grounding_tag = parameters_tag_opt if grounding_tag == ":grounding": grounding_list = iterator.next() grounding_call = conditions.parse_condition(grounding_list) duration_tag = iterator.next() else: grounding_call = None duration_tag = grounding_tag assert duration_tag == ":duration" duration_list = iterator.next() if duration_list[0] == "and": duration_list = duration_list[1:] else: duration_list = [duration_list] duration_start = [] duration_end = [] for item in duration_list: # each item is a simple-duration-constraint duration = duration_start if item[0] == "at": if item[1] == "end": duration = duration_end item = item[2] assert item[0] in ("<=", ">=", "=") if len(item) == 3: # = ?duration 1 assert item[1] == "?duration" op = item[0] value = f_expression.parse_expression(item[2]) duration += [(op, value)] else: # should be module: = ?duration [module] assert item[1] == "?duration" op = item[0] mod_list = item[2:] #print "Modlist:", mod_list value = conditions.parse_condition(mod_list) #print "parse to ", value duration += [(op, value)] pass condition_tag = iterator.next() if condition_tag == ":condition": condition = conditions.parse_durative_condition(iterator.next()) effect_tag = iterator.next() else: condition = conditions.parse_durative_condition([]) effect_tag = condition_tag assert effect_tag == ":effect" effect_list = iterator.next() effect = [[], []] effects.parse_durative_effects(effect_list, effect) for rest in iterator: assert False, rest return DurativeAction(name, parameters, grounding_call, (duration_start, duration_end), condition, effect)