示例#1
0
def get_stream_actions(results,
                       unique_binding=False,
                       effort_scale=1,
                       max_effort=INF,
                       **kwargs):
    result_from_name = OrderedDict()
    stream_actions = []
    for result in results:
        #if not isinstance(stream_result, StreamResult):
        if type(result) == FunctionResult:
            continue
        effort = result.get_effort(**kwargs)
        if not check_effort(effort, max_effort):
            continue
        name = '{}-{}'.format(result.external.name, len(result_from_name))
        #name = '{}_{}_{}'.format(result.external.name, # No spaces & parens
        #                        ','.join(map(pddl_from_object, result.instance.input_objects)),
        #                        ','.join(map(pddl_from_object, result.output_objects)))
        assert name not in result_from_name
        result_from_name[name] = result

        preconditions = list(result.instance.get_domain())
        effects = list(result.get_certified()) + [result.stream_fact]
        if unique_binding:
            enforce_single_binding(result, preconditions, effects)
        cost = effort_scale * effort
        stream_actions.append(
            make_action(name, [], preconditions, effects, cost))
    return stream_actions, result_from_name
示例#2
0
def prune_high_effort_streams(streams, max_effort=INF, **effort_args):
    # TODO: convert streams to test streams with extremely high effort
    low_effort_streams = []
    for stream in streams:
        effort = stream.get_effort(**effort_args)
        if isinstance(stream, Function) or check_effort(effort, max_effort):
            low_effort_streams.append(stream)
    return low_effort_streams
示例#3
0
def evaluations_from_stream_plan(evaluations, stream_results, max_effort=INF):
    opt_evaluations = set(evaluations)
    for result in stream_results:
        assert (not result.instance.disabled)
        assert (not result.instance.enumerated)
        domain = set(map(evaluation_from_fact, result.instance.get_domain()))
        assert (domain <= opt_evaluations)
        opt_evaluations.update(
            map(evaluation_from_fact, result.get_certified()))
    node_from_atom = get_achieving_streams(evaluations, stream_results)
    result_from_evaluation = {
        evaluation_from_fact(f): n.result
        for f, n in node_from_atom.items()
        if check_effort(n.effort, max_effort)
    }
    return result_from_evaluation