Пример #1
0
def parse_effect(alist, type_dict, predicate_dict):
    #     if DEBUG: print ("parsing effect %s" % [alist])
    tag = alist[0]
    if tag == "and":
        return pddl.ConjunctiveEffect([
            parse_effect(eff, type_dict, predicate_dict) for eff in alist[1:]
        ])
    elif tag == "forall":
        assert len(alist) == 3
        parameters = parse_typed_list(alist[1])
        effect = parse_effect(alist[2], type_dict, predicate_dict)
        return pddl.UniversalEffect(parameters, effect)
    elif tag == "when":
        assert len(alist) == 3
        condition = parse_condition(alist[1], type_dict, predicate_dict)
        effect = parse_effect(alist[2], type_dict, predicate_dict)
        return pddl.ConditionalEffect(condition, effect)
    elif tag in ("scale-up", "scale-down", "increase", "decrease"):
        return pddl.NumericEffect(parse_assignment(alist))
    elif tag == "assign":
        symbol = alist[1]
        if isinstance(symbol, list):
            symbol = symbol[0]
        return pddl.NumericEffect(parse_assignment(alist))
    else:
        # We pass in {} instead of type_dict here because types must
        # be static predicates, so cannot be the target of an effect.
        return pddl.SimpleEffect(parse_literal(alist, {}, predicate_dict))
Пример #2
0
def parse_effect(alist, type_dict, predicate_dict):
    tag = alist[0]
    if tag == "and":
        return pddl.ConjunctiveEffect([
            parse_effect(eff, type_dict, predicate_dict) for eff in alist[1:]
        ])
    elif tag == "forall":
        assert len(alist) == 3
        parameters = parse_typed_list(alist[1])
        effect = parse_effect(alist[2], type_dict, predicate_dict)
        return pddl.UniversalEffect(parameters, effect)
    elif tag == "when":
        assert len(alist) == 3
        condition = parse_condition(alist[1], type_dict, predicate_dict)
        effect = parse_effect(alist[2], type_dict, predicate_dict)
        return pddl.ConditionalEffect(condition, effect)
    elif tag == "increase":
        assert len(alist) == 3
        assert alist[1] == ['total-cost']
        assignment = parse_assignment(alist)
        return pddl.CostEffect(assignment)
    else:
        # We pass in {} instead of type_dict here because types must
        # be static predicates, so cannot be the target of an effect.
        return pddl.SimpleEffect(parse_literal(alist, {}, predicate_dict))
Пример #3
0
def parse_effect(alist, type_dict, predicate_dict):
    tag = alist[0]
    if tag == "and":
        return [
            pddl.ConjunctiveEffect(conjuncts)
            for conjuncts in cartesian_product(*[
                parse_effect(eff, type_dict, predicate_dict)
                for eff in alist[1:]
            ])
        ]
    elif tag == "forall":
        assert len(alist) == 3
        parameters = parse_typed_list(alist[1])
        effects = parse_effect(alist[2], type_dict, predicate_dict)
        assert 1 == len(effects), \
     "Error: Cannot embed non-determinism inside of a forall (for now)."
        return [pddl.UniversalEffect(parameters, effect) for effect in effects]
    elif tag == "when":
        assert len(alist) == 3
        condition = parse_condition(alist[1], type_dict, predicate_dict)
        effects = parse_effect(alist[2], type_dict, predicate_dict)
        assert all([eff.probability == 1 for eff in effects]), \
            "Error: (probabilistic ...) within (when ...) is currently not supported"
        return [
            pddl.ConditionalEffect(condition, effect) for effect in effects
        ]
    elif tag == "increase":
        assert len(alist) == 3
        assert alist[1] == ['total-cost']
        assignment = parse_assignment(alist)
        return [pddl.CostEffect(assignment)]
    elif tag == "probabilistic":
        # Generate effects for each outcome and then set their probability appropriately
        assert (len(alist)-1) % 2 == 0,\
     "Each probabilistic outcome must have an associated probability"
        outcome_pairs = [(alist[i], alist[i + 1])
                         for i in range(1, len(alist), 2)]

        remaining_probability = fractions.Fraction(1)
        outcomes = []
        for pair in outcome_pairs:
            effects = parse_effect(pair[1], type_dict, predicate_dict)
            for eff in effects:
                # Apply the base probability in the pair to this individual effect
                eff.probability *= fractions.Fraction(
                    pair[0]).limit_denominator()
                remaining_probability -= eff.probability
                outcomes.append(eff)
        remaining_probability = remaining_probability.limit_denominator()
        if (remaining_probability > 0):
            remaining_eff = pddl.SimpleEffect(None)
            remaining_eff.probability = remaining_probability
            outcomes.append(remaining_eff)
        return outcomes
    else:
        # We pass in {} instead of type_dict here because types must
        # be static predicates, so cannot be the target of an effect.
        return [pddl.SimpleEffect(parse_literal(alist, {}, predicate_dict))]