Esempio n. 1
0
def solve_from_pddl(domain_pddl, problem_pddl, temp_dir=TEMP_DIR, clean=False, debug=False, **kwargs):
    # TODO: combine with solve_from_task
    start_time = time()
    with Verbose(debug):
        write_pddl(domain_pddl, problem_pddl, temp_dir)
        #run_translate(temp_dir, verbose)
        translate_and_write_pddl(domain_pddl, problem_pddl, temp_dir, debug)
        solution = run_search(temp_dir, debug=debug, **kwargs)
        if clean:
            safe_rm_dir(temp_dir)
        print('Total runtime:', time() - start_time)
    return parse_solution(solution)
Esempio n. 2
0
def solve_from_pddl(domain_pddl,
                    problem_pddl,
                    temp_dir=TEMP_DIR,
                    clean=False,
                    debug=False,
                    **search_kwargs):
    # TODO: combine with solve_from_task
    #return solve_tfd(domain_pddl, problem_pddl)
    start_time = time()
    with Verbose(debug):
        write_pddl(domain_pddl, problem_pddl, temp_dir)
        #run_translate(temp_dir, verbose)
        translate_and_write_pddl(domain_pddl, problem_pddl, temp_dir, debug)
        solution = run_search(temp_dir, debug=debug, **search_kwargs)
        if clean:
            safe_rm_dir(temp_dir)
        print('Total runtime: {:.3f}'.format(elapsed_time(start_time)))
    return solution
Esempio n. 3
0
def solve_tfd(domain_pddl, problem_pddl, max_time=INF, debug=False):
    if PLANNER == 'tfd':
        root, template = TFD_PATH, TFD_COMMAND
    elif PLANNER == 'cerberus':
        root, template = CERB_PATH, CERB_COMMAND
    elif PLANNER == 'tflap':
        root, template = TFLAP_PATH, TFLAP_COMMAND
    elif PLANNER == 'optic':
        root, template = OPTIC_PATH, OPTIC_COMMAND
    elif PLANNER == 'tpshe':
        root, template = TPSHE_PATH, TPSHE_COMMAND
    else:
        raise ValueError(PLANNER)

    start_time = time.time()
    domain_path, problem_path = write_pddl(domain_pddl, problem_pddl)
    plan_path = os.path.join(TEMP_DIR, PLAN_FILE)
    #assert not actions, "There shouldn't be any actions - just temporal actions"

    paths = [
        os.path.join(os.getcwd(), p)
        for p in (domain_path, problem_path, plan_path)
    ]
    command = os.path.join(root, template.format(*paths))
    print(command)
    if debug:
        stdout, stderr = None, None
    else:
        stdout, stderr = open(os.devnull, 'w'), open(os.devnull, 'w')
    proc = subprocess.call(command,
                           shell=True,
                           cwd=root,
                           stdout=stdout,
                           stderr=stderr)  # timeout=None (python3)
    error = proc != 0
    print('Error:', error)
    # TODO: close any opened resources

    temp_path = os.path.join(os.getcwd(), TEMP_DIR)
    plan_files = sorted(f for f in os.listdir(temp_path)
                        if f.startswith(PLAN_FILE))
    print('Plans:', plan_files)
    best_plan, best_makespan = parse_plans(temp_path, plan_files)
    #if not debug:
    #    safe_rm_dir(TEMP_DIR)
    print('Makespan: ', best_makespan)
    print('Time:', elapsed_time(start_time))

    sequential_plan = sequential_from_temporal_plan(best_plan)
    return sequential_plan, best_makespan