示例#1
0
 def check_random_cnf(self, width, numvariables, numclauses):
     F = RandomKCNF(width, numvariables, numclauses)
     self.assertListEqual(
         list(F.variables()),
         ['x_{0}'.format(i) for i in range(1, numvariables + 1)])
     self.assertEqual(len(F), numclauses)
     self.assertEqual(len(set(frozenset(x) for x in F.clauses())),
                      numclauses)
示例#2
0
 def test_one(self):
     ass = [{'x_1': True, 'x_2': False}]
     F = RandomKCNF(2, 2, 3, planted_assignments=ass)
     G = CNF([
         [(True, 'x_1'), (False, 'x_2')],
         [(False, 'x_1'), (False, 'x_2')],
         [(True, 'x_1'), (True, 'x_2')],
     ])
     self.assertCnfEqual(F, G)
示例#3
0
 def test_all(self):
     ass = [
         {'x_1': False, 'x_2': True},
         {'x_1': True, 'x_2': False},
         {'x_1': False, 'x_2': False},
         {'x_1': True, 'x_2': True},
     ]
     with self.assertRaises(ValueError):
         RandomKCNF(2, 2, 1, planted_assignments=ass)
示例#4
0
 def test_most(self):
     ass = [
         {'x_1': True, 'x_2': False},
         {'x_1': False, 'x_2': False},
         {'x_1': True, 'x_2': True},
     ]
     F = RandomKCNF(2, 2, 1, planted_assignments=ass)
     G = CNF([[(True, 'x_1'), (False, 'x_2')]])
     self.assertCnfEqual(F, G)
示例#5
0
 def check_random_cnf(self,width,numvariables,numclauses) :
     F = RandomKCNF(width,numvariables,numclauses)
     self.assertListEqual(list(F.variables()),
                          ['x_{0}'.format(i) for i in range(1,numvariables+1)])
     self.assertEqual(len(F),numclauses)
     self.assertEqual(len(set(frozenset(x) for x in F)),numclauses)
示例#6
0
 def test_not_planted(self):
     F = RandomKCNF(4, 10, 20, 42)
     G = RandomKCNF(4, 10, 20, 42, [])
     self.assertCnfEqual(F, G)
示例#7
0
 def test_negative_clauses(self):
     with self.assertRaises(ValueError):
         RandomKCNF(3, 5, -1)
示例#8
0
 def test_negative_variables(self):
     with self.assertRaises(ValueError):
         RandomKCNF(3, -1, 1)
示例#9
0
 def test_negative_width(self):
     with self.assertRaises(ValueError):
         RandomKCNF(-1, 5, 1)
示例#10
0
 def test_too_wide(self):
     with self.assertRaises(ValueError):
         RandomKCNF(10, 5, 1)
示例#11
0
 def test_too_full(self):
     with self.assertRaises(ValueError):
         RandomKCNF(3, 5, 5 * 4 * 3 / (1 * 2 * 3) * 2**5 + 1)