def test_not_equals_higher(self): equals = expr.exprvar("equals") cardinality = cardnet.equals(self.function.support, len(self.pos) + 1, ~equals) sat = expr.And(self.function, equals, *cardinality).to_cnf().satisfy_one() self.assertIsNotNone(sat) self.assertEqual(sat.get(equals), 1)
def test_equals_is(self): cardinality = cardnet.equals(self.function.support, len(self.pos)) sat = expr.And(self.function, *cardinality).to_cnf().satisfy_one() self.assertIsNotNone(sat) solution = {x: sat.get(x) for x in self.pos} self.assertEqual(solution, {x: 1 for x in self.pos})
def test_equals_one_small(self): (a, _b, _c) = self.pos self.function = a cardinality = cardnet.equals(self.function.support, 1) sat = expr.And(self.function, *cardinality).to_cnf().satisfy_one() self.assertIsNotNone(sat) self.assertEqual(sat.get(a), 1)
def test_equals_higher(self): cardinality = cardnet.equals(self.function.support, len(self.pos) + 1) sat = expr.And(self.function, *cardinality).to_cnf().satisfy_one() self.assertIsNone(sat)
def test_equals_zero(self): cardinality = cardnet.equals(self.function.support, 0) sat = expr.And(self.function, *cardinality).to_cnf().satisfy_one() self.assertIsNone(sat)
def equals(inputs, p, equivalent=None): if p == 1: yield from equals_one(inputs, equivalent) else: yield from cardnet.equals(inputs, p, equivalent)