def tfd(universe, verbose):
    remove_dir(TEMP_DIRECTORY)  # Ensures not using old plan
    ensure_dir(TEMP_DIRECTORY)
    write(DOMAIN_PATH,
          universe.domain_pddl(costs=True, derived=True, durative=True))
    write(PROBLEM_PATH, universe.problem_pddl(costs=True))

    plan_path = os.path.join(TEMP_DIRECTORY, PLAN_FILE)
    #assert not actions, "There shouldn't be any actions - just temporal actions"

    command = os.path.join(
        get_tfd_root(), COMMAND.format(DOMAIN_PATH, PROBLEM_PATH, plan_path))
    if verbose: print command

    paths = [
        os.path.join(os.getcwd(), p)
        for p in (DOMAIN_PATH, PROBLEM_PATH, plan_path)
    ]
    args = os.path.join('.', COMMAND.format(*paths)).split(' ')
    stdout = None if verbose else open(os.devnull, 'w')
    #stdout = open(os.devnull, 'w')
    #stderr = open(os.devnull, 'w')
    stderr = None
    try:
        proc = subprocess.Popen(args,
                                cwd=get_tfd_root(),
                                stdout=stdout,
                                stderr=stderr)
        proc.wait()
        #proc.terminate()
    except subprocess.CalledProcessError, e:
        print "Subprocess error", e.output
        raw_input("Continue?")
Example #2
0
def lapkt(universe, search, verbose):
    ensure_dir(TEMP_DIRECTORY)
    write(DOMAIN_PATH, universe.domain_pddl(True, False))
    write(PROBLEM_PATH, universe.problem_pddl(True))
    safe_remove(PLANNER_OUTPUT)

    planner_path = os.path.join(get_lapkt_root(), LAPKT_PLANNERS[search])
    command = planner_path + \
        COMMAND % (DOMAIN_PATH, PROBLEM_PATH, PLANNER_OUTPUT)
    if verbose:
        print command
    p = os.popen(command)
    output = p.read()
    if verbose:
        print output

    SUCCESS = 'Plan found'
    if output.find(SUCCESS) == -1:
        return None
    plan = []
    for line in read(PLANNER_OUTPUT).split('\n')[:-1]:
        entries = line.strip('()').lower().split(' ')
        plan.append(lookup_action(universe, entries[0], entries[1:]))
    if not verbose:
        remove_dir(TEMP_DIRECTORY)
        safe_remove(PLANNER_OUTPUT)
        safe_remove(PLANNER_DETAILS)
    return plan
def smtplan(universe, max_length, verbose):
    ensure_dir(TEMP_DIRECTORY)
    write(DOMAIN_PATH, universe.domain_pddl(True, False))
    write(PROBLEM_PATH, universe.problem_pddl(True))

    command = os.path.join(get_smtplan_root(),
                           COMMAND % (DOMAIN_PATH, PROBLEM_PATH, max_length))
    if verbose:
        print command
    p = os.popen(command)  # NOTE - cannot pipe input easily with subprocess
    output = p.read()
    if verbose:
        print output

    if FAILURE in output:
        return None
    plan = []
    for line in output.split('\n')[:-2]:
        #if 'sta' not in line:
        #  continue
        entries = line[line.find('(') + 1:line.find(')')].split(' ')
        plan.append(lookup_action(universe, entries[0], entries[1:]))
    if not verbose:
        remove_dir(TEMP_DIRECTORY)
    return plan
Example #4
0
def fast_downward(universe, planner, max_time, max_cost, verbose):
    ensure_dir(TEMP_DIRECTORY)
    write(DOMAIN_PATH, universe.domain_pddl(True, True))
    write(PROBLEM_PATH, universe.problem_pddl(True))

    solution = run_fastdownard(planner, max_time, max_cost, verbose)
    if solution is None:
        return None
    if not verbose:
        remove_dir(TEMP_DIRECTORY)
        safe_remove(TRANSLATE_OUTPUT)
        safe_remove(PREPROCESS_OUTPUT)
        safe_remove(SEARCH_OUTPUT)
    return convert_solution(solution, universe)
Example #5
0
def fast_forward(universe, derived, verbose):
    ensure_dir(TEMP_DIRECTORY)
    write(DOMAIN_PATH, universe.domain_pddl(False, derived))
    write(PROBLEM_PATH, universe.problem_pddl(False))

    command = os.path.join(get_ff_root(), SEARCH_COMMAND %
                           (DOMAIN_PATH, PROBLEM_PATH))
    p = os.popen(command)
    output = p.read()
    if verbose:
        print output
        print command
    if not verbose:
        remove_dir(TEMP_DIRECTORY)

    success = 'ff: found legal plan as follows'
    index = output.find(success)
    if index == -1:
        return None
    plan = []
    for line in re.findall('\d+:(?: \w+)+\n', output):
        entries = re.findall(' (\w+)', line.lower())
        plan.append(lookup_action(universe, entries[0], entries[1:]))
    return plan