Ejemplo n.º 1
0
def plan_subgoals(sas_task, subgoal_plan, temp_dir, **kwargs):
    full_plan = []
    full_cost = 0
    for subgoal in subgoal_plan:
        sas_task.goal.pairs = subgoal
        write_sas_task(sas_task, temp_dir)
        plan, cost = run_search(temp_dir, debug=True, **kwargs)
        if plan is None:
            return None, INF
        full_plan.extend(plan)
        full_cost += cost
        for sas_action in parse_sas_plan(sas_task, plan):
            apply_sas_operator(sas_task.init, sas_action)
    return full_plan, full_cost
Ejemplo n.º 2
0
def abstrips_solve_from_task(sas_task,
                             temp_dir=TEMP_DIR,
                             clean=False,
                             debug=False,
                             hierarchy=[],
                             **kwargs):
    # Like partial order planning in terms of precondition order
    # TODO: add achieve subgoal actions
    # TODO: most generic would be a heuristic on each state
    if hierarchy is None:
        return solve_from_task(sas_task,
                               temp_dir=temp_dir,
                               clean=clean,
                               debug=debug,
                               **kwargs)
    if hierarchy == SERIALIZE:
        return serialized_solve_from_task(sas_task,
                                          temp_dir=temp_dir,
                                          clean=clean,
                                          debug=debug,
                                          **kwargs)
    start_time = time()
    plan, cost = None, INF
    with Verbose(debug):
        print('\n' + 50 * '-' + '\n')
        last_plan = []
        for level in range(len(hierarchy) + 1):
            local_sas_task = deepcopy(sas_task)
            prune_hierarchy_pre_eff(
                local_sas_task, hierarchy[level:])  # TODO: break if no pruned
            add_subgoals(local_sas_task, last_plan)
            write_sas_task(local_sas_task, temp_dir)
            plan, cost = run_search(temp_dir, debug=True, **kwargs)
            if (level == len(hierarchy)) or (plan is None):
                # TODO: fall back on standard search
                break
            last_plan = [
                name_from_action(action, args) for action, args in plan
            ]
        if clean:
            safe_rm_dir(temp_dir)
        print('Total runtime:', time() - start_time)
    return plan, cost
Ejemplo n.º 3
0
def solve_from_task(sas_task,
                    temp_dir=TEMP_DIR,
                    clean=False,
                    debug=False,
                    hierarchy=[],
                    **search_args):
    # TODO: can solve using another planner and then still translate using FastDownward
    # Can apply plan constraints (skeleton constraints) here as well
    start_time = time()
    with Verbose(debug):
        print('\n' + 50 * '-' + '\n')
        write_sas_task(sas_task, temp_dir)
        solution = run_search(temp_dir, debug=True, **search_args)
        if clean:
            safe_rm_dir(temp_dir)
        print('Total runtime:', time() - start_time)
    #for axiom in sas_task.axioms:
    #    # TODO: return the set of axioms here as well
    #    var, value = axiom.effect
    #    print(sas_task.variables.value_names[var])
    #    axiom.dump()
    return solution