Esempio n. 1
0
def reschedule_stream_plan(evaluations,
                           target_facts,
                           domain,
                           stream_results,
                           unique_binding=False,
                           unsatisfiable=False,
                           max_effort=INF,
                           planner=RESCHEDULE_PLANNER,
                           debug=False):
    # TODO: search in space of partially ordered plans
    # TODO: constrain selection order to be alphabetical?
    domain.actions[:], stream_result_from_name = get_stream_actions(
        stream_results, unique_binding=unique_binding)
    goal_expression = And(*target_facts)
    if unsatisfiable:  # TODO: ensure that the copy hasn't harmed anything
        goal_expression = add_unsatisfiable_to_goal(domain, goal_expression)
    reschedule_problem = get_problem(evaluations,
                                     goal_expression,
                                     domain,
                                     unit_costs=False)
    reschedule_task = task_from_domain_problem(domain, reschedule_problem)
    #reschedule_task.axioms = [] # TODO: ensure that the constants are added in the event that axioms are needed?
    sas_task = sas_from_pddl(reschedule_task)
    stream_names, effort = solve_from_task(sas_task,
                                           planner=planner,
                                           max_planner_time=10,
                                           max_cost=max_effort,
                                           debug=debug)
    if stream_names is None:
        return None
    stream_plan = [stream_result_from_name[name] for name, _ in stream_names]
    return stream_plan
Esempio n. 2
0
def solve_finite(evaluations, goal_exp, domain, unit_costs=False, debug=False, **search_args):
    problem = get_problem(evaluations, goal_exp, domain, unit_costs)
    task = task_from_domain_problem(domain, problem)
    sas_task = sas_from_pddl(task, debug=debug)
    pddl_plan, cost = abstrips_solve_from_task(sas_task, debug=debug, **search_args)
    plan = obj_from_pddl_plan(pddl_plan)
    return plan, cost
Esempio n. 3
0
def reschedule_stream_plan(evaluations,
                           target_facts,
                           domain,
                           stream_results,
                           unique_binding=False,
                           unit_efforts=True):
    # TODO: search in space of partially ordered plans
    # TODO: constrain selection order to be alphabetical?
    goal_expression = And(*target_facts)
    reschedule_problem = get_problem(evaluations,
                                     goal_expression,
                                     domain,
                                     unit_costs=unit_efforts)
    reschedule_task = task_from_domain_problem(domain, reschedule_problem)
    reschedule_task.actions, stream_result_from_name = get_stream_actions(
        stream_results,
        unique_binding=unique_binding,
        unit_efforts=unit_efforts)
    #reschedule_task.axioms = [] # TODO: ensure that the constants are added in the event that axioms are needed?
    sas_task = sas_from_pddl(reschedule_task)
    stream_names, effort = solve_from_task(sas_task,
                                           planner=RESCHEDULE_PLANNER,
                                           max_planner_time=10,
                                           debug=False)
    if stream_names is None:
        return None
    stream_plan = [stream_result_from_name[name] for name, _ in stream_names]
    return stream_plan
Esempio n. 4
0
def solve_finite(evaluations,
                 goal_expression,
                 domain,
                 unit_costs=None,
                 debug=False,
                 **kwargs):
    if unit_costs is None:
        unit_costs = not has_costs(domain)
    problem = get_problem(evaluations, goal_expression, domain, unit_costs)
    task = task_from_domain_problem(domain, problem)
    sas_task = sas_from_pddl(task, debug=debug)
    plan_pddl, cost = abstrips_solve_from_task(sas_task, debug=debug, **kwargs)
    return obj_from_pddl_plan(plan_pddl), cost
Esempio n. 5
0
def sequential_stream_plan(evaluations, goal_expression, domain, stream_results,
                           negated, effort_weight, unit_costs=True, debug=False, **kwargs):
    # Intuitively, actions have infinitely more weight than streams
    if negated:
        raise NotImplementedError(negated)
    for result in stream_results:
        if isinstance(result.external, Stream) and result.external.is_fluent():
            raise NotImplementedError('Fluents are not supported')

    # TODO: compute preimage and make that the goal instead
    opt_evaluations = evaluations_from_stream_plan(evaluations, stream_results)
    opt_task = task_from_domain_problem(domain, get_problem(opt_evaluations, goal_expression, domain, unit_costs))
    action_plan, action_cost = abstrips_solve_from_task(sas_from_pddl(opt_task, debug=debug), debug=debug, **kwargs)
    if action_plan is None:
        return None, action_cost

    actions = domain.actions[:]
    domain.actions[:] = []
    stream_domain, stream_result_from_name = add_stream_actions(domain, stream_results) # TODO: effort_weight
    domain.actions.extend(actions)
    stream_task = task_from_domain_problem(stream_domain, get_problem(evaluations, goal_expression, stream_domain, unit_costs))
    action_from_name, function_plan = simplify_actions(opt_evaluations, action_plan, stream_task, actions, unit_costs)

    # TODO: lmcut?
    combined_plan, _ = solve_from_task(sas_from_pddl(opt_task, debug=debug),
                                       planner=kwargs.get('planner', 'ff-astar'),
                                       debug=debug, **kwargs)
    if combined_plan is None:
        return None, INF

    stream_plan, action_plan = [], []
    for name, args in combined_plan:
        if name in stream_result_from_name:
            stream_plan.append(stream_result_from_name[name])
        else:
            action_plan.append(action_from_name[name])
    combined_plan = stream_plan + function_plan + action_plan
    return combined_plan, action_cost