Exemplo n.º 1
0
def _init_data_structures(symbols, fluent_symbols):
    init, static_data = {}, {}
    for s in symbols.values():
        if util.is_external(s.name):
            continue

        var = init if s.name in fluent_symbols else static_data
        var[s.name] = static.instantiate_extension(s)

    return init, static_data
Exemplo n.º 2
0
def _init_data_structures(symbols, fluent_symbols):
    init, static_data = {}, {}
    for s in symbols.values():
        if util.is_external(s.name):
            continue

        var = init if s.name in fluent_symbols else static_data
        var[s.name] = static.instantiate_extension(s)

    return init, static_data
Exemplo n.º 3
0
def _check_symbol_in_initial_state(s, symbols):  # A small helper
    if s == 'total-cost':  # We ignore the 'total-cost' initial specification
        return False

    if util.is_external(s):
        raise RuntimeError("The extension of an external symbol cannot ne specified in the initial state")

    if s not in symbols:
        raise ParseException("Unknown symbol: '{}'".format(s))

    return True
Exemplo n.º 4
0
    def process_predicative_expression(self, exp):
        assert isinstance(exp, (Atom, NegatedAtom))
        name = exp.predicate
        args = self.process_arguments(exp.args)

        if is_external(name) and (exp.negated or not self.is_static(name)):
            raise RuntimeError("External symbols cannot be fluent nor negated")

        if is_relational_operator(name):
            return RelationalExpression(exp.predicate, exp.negated, args)
        else:
            return PredicativeExpression(name, exp.negated, args, static=self.is_static(name))
Exemplo n.º 5
0
def _check_symbol_in_initial_state(s, symbols):  # A small helper
    if s == 'total-cost':  # We ignore the 'total-cost' initial specification
        return False

    if util.is_external(s):
        raise RuntimeError(
            "The extension of an external symbol cannot ne specified in the initial state"
        )

    if s not in symbols:
        raise ParseException("Unknown symbol: '{}'".format(s))

    return True
Exemplo n.º 6
0
def create_all_possible_state_variables(symbols, static_symbols, type_map):
    """ Creates an index with all possible state variables """
    variables = IndexDictionary()

    for symbol in symbols.values():
        name = symbol.name
        if is_external(
                name
        ) or name in static_symbols:  # The symbol won't yield any state variable
            continue
        instantiations = [type_map[t] for t in symbol.arguments]
        for instantiation in itertools.product(*instantiations):
            variables.add(Variable(symbol.name, instantiation))
    return variables
Exemplo n.º 7
0
 def get_function_instantiations(self):
     return [tplManager.get('function_instantiation').substitute(name=symbol, accessor=symbol[1:])
             for symbol in self.index.static_symbols if is_external(symbol)]
Exemplo n.º 8
0
 def requires_compilation(self):
     # The problem requires compilation iff there are external symbols involved.
     return len([s for s in self.index.static_symbols if is_external(s)])
Exemplo n.º 9
0
 def get_function_instantiations(self):
     return [
         tplManager.get('function_instantiation').substitute(
             name=symbol, accessor=symbol[1:])
         for symbol in self.index.static_symbols if is_external(symbol)
     ]
Exemplo n.º 10
0
 def requires_compilation(self):
     # The problem requires compilation iff there are external symbols involved.
     return len([s for s in self.index.static_symbols if is_external(s)])
Exemplo n.º 11
0
 def check_declared(self, symbol):
     if not is_builtin_operator(symbol) and symbol not in self.index.all_symbols and not is_external(symbol):
         raise exceptions.UndeclaredSymbol("Undeclared symbol '{0}'".format(symbol))
Exemplo n.º 12
0
 def is_static(self, symbol):
     return symbol in self.index.static_symbols or is_builtin_operator(symbol) or is_external(symbol)