Ejemplo n.º 1
0
def add_optimizer_effects(instantiated, node_from_atom):
    # TODO: instantiate axioms with negative on effects for blocking
    # TODO: fluent streams using conditional effects. Special fluent predicate for inputs to constraint
    # TODO: bug! The FD instantiator prunes the result.external.stream_fact
    for instance in instantiated.actions:
        # TODO: need to handle case where a negative preconditions is used in an optimizer
        for condition, effect in (instance.add_effects + instance.del_effects):
            for literal in condition:
                fact = fact_from_fd(literal)
                if (fact in node_from_atom) and (node_from_atom[fact].result
                                                 is not None):
                    raise NotImplementedError(literal)
        facts = get_instance_facts(instance, node_from_atom)
        stream_plan = []
        extract_stream_plan(node_from_atom, facts, stream_plan)
        # TODO: can detect if some of these are simultaneous and add them as preconditions
        for result in stream_plan:
            #if isinstance(result.external, ComponentStream):
            if True:  # TODO: integrate sampler and optimizer treatments
                # TODO: need to make multiple versions if several ways of achieving the action
                atom = fd_from_fact(result.stream_fact)
                instantiated.atoms.add(atom)
                effect = (tuple(), atom)
                instance.add_effects.append(effect)
                instance.effect_mappings.append(effect + (None, None))
Ejemplo n.º 2
0
def add_stream_efforts(node_from_atom, instantiated, effort_weight, **kwargs):
    if effort_weight is None:
        return
    # TODO: make effort just a multiplier (or relative) to avoid worrying about the scale
    # TODO: regularize & normalize across the problem?
    #efforts = []
    for instance in instantiated.actions:
        # TODO: prune stream actions here?
        # TODO: round each effort individually to penalize multiple streams
        facts = get_instance_facts(instance, node_from_atom)
        #effort = COMBINE_OP([0] + [node_from_atom[fact].effort for fact in facts])
        stream_plan = []
        extract_stream_plan(node_from_atom, facts, stream_plan)
        effort = compute_plan_effort(stream_plan, **kwargs)
        instance.cost += scale_cost(effort_weight * effort)