Example #1
0
 def belong(self,
            state: Union[clingo.Symbol, SymbolHash, Node] = None,
            const: Union[clingo.Symbol, SymbolHash] = None):
     if state is not None:
         if isinstance(state, Node):
             state = state.name
         if not isinstance(state, clingo.Symbol) and not isinstance(
                 state, SymbolHash):
             raise TypeError('Unexpected type {}'.format(type(state)))
         if not isinstance(state, SymbolHash):
             state = SymbolHash(state)
     if const is not None:
         if not isinstance(const, clingo.Symbol) and not isinstance(
                 state, SymbolHash):
             raise TypeError('Unexpected type {}'.format(type(const)))
         if not isinstance(const, SymbolHash):
             const = SymbolHash(const)
     if state is not None:
         b_state = self._st_hash.get(state, {})
         if const is not None:
             return b_state.get(const, False)
         else:
             return b_state
     if const is not None:
         return dict([(st, True) for st in self._st_hash if st[const]])
     return self._st_hash
Example #2
0
 def _calc_hash(self):
     assert (self._hash == None)
     self._hash = 0
     for atom in self.symbols.get_atoms('belong', 3):
         st = atom.arguments[2]
         const = atom.arguments[0]
         self._hash += hash(str(st) + str(const))
         st = SymbolHash(st)
         if st not in self._st_hash:
             self._st_hash[st] = {}
         self._st_hash[st][SymbolHash(const)] = True
Example #3
0
 def _calc_hash(self):
     assert (self._hash == None)
     self._hash = 0
     for st, val in self.value:
         self._hash += hash(str(st) + str(val))
         assert (SymbolHash(st) not in self._val_hash)
         self._val_hash[SymbolHash(st)] = SymbolHash(val)
     for (st1, st2), d in self.delta:
         self._hash += hash(str(st1) + str(st2) + str(d))
         assert ((SymbolHash(st1), SymbolHash(st2)) not in self._del_hash)
         self._del_hash[(SymbolHash(st1), SymbolHash(st2))] = SymbolHash(d)
Example #4
0
 def holds(self, variable: clingo.Symbol, value: clingo.Symbol):
     return self._sym_hash.get((SymbolHash(variable), SymbolHash(value)),
                               False)
Example #5
0
 def _calc_hash(self):
     if self._hash != None: return
     self._hash = 0
     for var, val in self.description:
         self._hash += hash(str(var) + str(val))
         self._sym_hash[(SymbolHash(var), SymbolHash(val))] = True
Example #6
0
 def delta_states(self, state1: clingo.Symbol, state2: clingo.Symbol):
     return self._del_hash.get((SymbolHash(state1), SymbolHash(state2)),
                               None)
Example #7
0
 def value_state(self, state: clingo.Symbol):
     return self._val_hash.get(SymbolHash(state), None)