Esempio n. 1
0
 def update(self, var, val):
     '''
     Updates the clause information with the given variable and value set in a SampleSAT state.
     '''
     for a, v in var.atomvalues(val):
         if v not in self.atomidx2lits[a.idx]:
             if a.idx in self.truelits: self.truelits.remove(a.idx)
         else: self.truelits.add(a.idx)
     if len(self.truelits) == 1 and self._isbottleneck(item(self.truelits)):
         self.bottleneck = item(self.truelits)
     else:
         self.bottleneck = None
     return self.satisfied, self.bottleneck
Esempio n. 2
0
 def _isbottleneck(self, atomidx):
     atomidx2lits = self.atomidx2lits
     if len(self.truelits) != 1 or atomidx not in self.truelits: return False
     if len(atomidx2lits[atomidx]) == 1: return True
     fst = item(atomidx2lits[atomidx])
     if all(map(lambda x: x == fst, atomidx2lits[atomidx])): return False # the atom appears with different polarity in the clause, this is not a bottleneck
     return True
Esempio n. 3
0
 def __init__(self, lits, world, idx, mrf):
     self.cidx = idx
     self.world = world
     self.bottleneck = None
     self.mrf = mrf
     # check all the literals
     self.lits = lits
     self.truelits = set()
     self.atomidx2lits = defaultdict(set)
     for lit in lits:
         if isinstance(lit, Logic.TrueFalse): continue
         atomidx = lit.gndatom.idx
         self.atomidx2lits[atomidx].add(0 if lit.negated else 1)
         if lit(world) == 1:
             self.truelits.add(atomidx)
     if len(self.truelits) == 1 and self._isbottleneck(item(self.truelits)):
         self.bottleneck = item(self.truelits)