Esempio n. 1
0
def obj_from_pddl(pddl):
    if pddl in Object._obj_from_name:
        return Object.from_name(pddl)
    elif pddl in OptimisticObject._obj_from_name:
        return OptimisticObject.from_name(pddl)
    raise ValueError(pddl)
Esempio n. 2
0
def reset_globals():
    # TODO: maintain these dictionaries in an object
    Object.reset()
    OptimisticObject.reset()
    RULES[:] = []
    SOLUTIONS[:] = []
Esempio n. 3
0
def obj_from_value_expression(parent):
    return replace_expression(
        parent, lambda o: o if is_parameter(o) else Object.from_value(o))
Esempio n. 4
0
def convert_constants(fact):
    # TODO: take the constant map as an input
    # TODO: throw an error if undefined
    return Fact(get_prefix(fact), [
        p if is_parameter(p) else Object.from_name(p) for p in get_args(fact)
    ])
Esempio n. 5
0
def to_obj(value):
    # Allows both raw values as well as objects to be specified
    if any(isinstance(value, Class) for Class in [Object, OptimisticObject]):
        return value
    return Object.from_value(value)
Esempio n. 6
0
 def mapping(self):
     if self._mapping is None:
         self._mapping = get_mapping(self.external.inputs, self.input_objects)
         for constant in self.external.constants:
             self._mapping[constant] = Object.from_name(constant)
     return self._mapping
Esempio n. 7
0
import sys

from pddlstream.algorithms.algorithm import get_predicates
from pddlstream.algorithms.downward import get_literals, get_conjunctive_parts, fd_from_fact, EQ, make_object, \
    pddl_from_instance, DEFAULT_MAX_TIME
from pddlstream.language.object import Object
from pddlstream.language.conversion import obj_from_pddl, substitute_fact
from pddlstream.language.fluent import get_predicate_map, remap_certified
from pddlstream.language.stream import Stream
from pddlstream.utils import INF, invert_dict, get_mapping

# Intuition: static facts about whether this state satisfies a condition
# The state can be seen as a hidden parameter with a precondition that you are at it

PYPLANNERS_VAR = 'PYPLANNERS_PATH'
PLACEHOLDER = Object.from_value('~')


def get_pyplanners_path():
    return os.environ.get(PYPLANNERS_VAR, None)


def has_attachments(domain):
    return any(getattr(action, 'attachments', {}) for action in domain.actions)


def compile_fluents_as_attachments(domain, externals):
    import pddl
    state_streams = set(
        filter(lambda e: isinstance(e, Stream) and e.is_fluent(),
               externals))  # is_special
Esempio n. 8
0
def obj_from_existential_expression(parent):  # obj_from_value_expression
    return replace_expression(
        parent, lambda o: OptimisticObject.from_opt(o, o)
        if is_parameter(o) else Object.from_value(o))
Esempio n. 9
0
from pddlstream.algorithms.advanced import get_predicates
from pddlstream.algorithms.downward import get_literals, get_conjunctive_parts, fd_from_fact, EQ, make_object, \
    pddl_from_instance, DEFAULT_MAX_TIME, get_cost_scale
from pddlstream.language.object import Object
from pddlstream.language.conversion import obj_from_pddl, substitute_fact
from pddlstream.language.fluent import get_predicate_map, remap_certified
from pddlstream.language.stream import Stream
from pddlstream.utils import INF, invert_dict, get_mapping, safe_zip

# Intuition: static facts about whether this state satisfies a condition
# The state can be seen as a hidden parameter with a precondition that you are at it

# TODO: refactor to algorithms

PYPLANNERS_VAR = 'PYPLANNERS_PATH'
PLACEHOLDER_OBJ = Object.from_value('~')

DEFAULT_PYPLANNER = {
    'search': 'eager',
    'evaluator': 'greedy',
    'heuristic': 'ff',
    'successors': 'all',
}


def get_pyplanners_path():
    return os.environ.get(PYPLANNERS_VAR, None)


def has_attachments(domain):
    return any(getattr(action, 'attachments', {}) for action in domain.actions)
Esempio n. 10
0
def parse_value(value):
    return OptimisticObject.from_opt(
        value, value) if is_parameter(value) else Object.from_value(value)