# Path: stripstream/utils.py
# def write(filename, string):
#     with open(filename, 'w') as f:
#         f.write(string)
# 
# def ensure_dir(f):
#     d = os.path.dirname(f)
#     if not os.path.exists(d):
#         os.makedirs(d)
# 
# def remove_dir(d):
#     if os.path.exists(d):
#         shutil.rmtree(d)
# 
# Path: stripstream/algorithms/search/utils.py
# TEMP_DIRECTORY = 'temp/'
# 
# DOMAIN_PATH = os.path.join(TEMP_DIRECTORY, 'domain.pddl')
# 
# PROBLEM_PATH = os.path.join(TEMP_DIRECTORY, 'problem.pddl')
# 
# Path: stripstream/algorithms/search/fast_downward.py
# def lookup_action(universe, action, parameters):
#     return universe.get_action(action), tuple(universe.get_object(param) for param in parameters)


import os
import re
from stripstream.utils import write, ensure_dir, remove_dir
from stripstream.algorithms.search.utils import TEMP_DIRECTORY, DOMAIN_PATH, PROBLEM_PATH
from stripstream.algorithms.search.fast_downward import lookup_action




ENV_VAR = 'FF_PATH'
SEARCH_COMMAND = 'ff -o %s -f %s'


def has_ff():
    return ENV_VAR in os.environ


def get_ff_root():
    if not has_ff():
        raise RuntimeError('Environment variable %s is not defined.' % ENV_VAR)
    return os.environ[ENV_VAR]


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 %

# Path: stripstream/utils.py
# def write(filename, string):
#     with open(filename, 'w') as f:
#         f.write(string)
# 
# def ensure_dir(f):
#     d = os.path.dirname(f)
#     if not os.path.exists(d):
#         os.makedirs(d)
# 
# def remove_dir(d):
#     if os.path.exists(d):
#         shutil.rmtree(d)
# 
# Path: stripstream/algorithms/search/utils.py
# TEMP_DIRECTORY = 'temp/'
# 
# DOMAIN_PATH = os.path.join(TEMP_DIRECTORY, 'domain.pddl')
# 
# PROBLEM_PATH = os.path.join(TEMP_DIRECTORY, 'problem.pddl')
# 
# Path: stripstream/algorithms/search/fast_downward.py
# def lookup_action(universe, action, parameters):
#     return universe.get_action(action), tuple(universe.get_object(param) for param in parameters)


# Path: stripstream/algorithms/search/fast_forward.py
import os
import re
from stripstream.utils import write, ensure_dir, remove_dir
from stripstream.algorithms.search.utils import TEMP_DIRECTORY, DOMAIN_PATH, PROBLEM_PATH
from stripstream.algorithms.search.fast_downward import lookup_action





ENV_VAR = 'FF_PATH'
SEARCH_COMMAND = 'ff -o %s -f %s'


def has_ff():
    return ENV_VAR in os.environ


def get_ff_root():
    if not has_ff():
        raise RuntimeError('Environment variable %s is not defined.' % ENV_VAR)
    return os.environ[ENV_VAR]


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))