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
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
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))
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
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
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)]
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)])
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) ]
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))
def is_static(self, symbol): return symbol in self.index.static_symbols or is_builtin_operator(symbol) or is_external(symbol)