def test_completeGraphTwoCollors(self): solver = SAT_solver() graph = [[1, 1, 1], [1, 1, 1], [1, 1, 1]] colors = 2 formula = graph_coloring(graph, colors) solution = solver.solve(formula) self.assertFalse(solution[0])
def test_CustomGraphOneTwoCollors(self): solver = SAT_solver() graph = [[0, 1, 1, 1, 1], [1, 0, 1, 1, 0], [1, 1, 0, 1, 0], [1, 1, 1, 0, 1], [1, 0, 0, 1, 0]] colors = 2 formula = graph_coloring(graph, colors) solution = solver.solve(formula) self.assertFalse(solution[0])
def test_CustomGraphOneFourCollors(self): solver = SAT_solver() graph = [[0, 1, 1, 1, 1], [1, 0, 1, 1, 0], [1, 1, 0, 1, 0], [1, 1, 1, 0, 1], [1, 0, 0, 1, 0]] colors = 4 formula = graph_coloring(graph, colors) solution = solver.solve(formula) self.assertTrue(solution[0]) self.assertEqual("true", formula.nnf().cnf().evaluate(solution[1]).__class__.__name__)
def test_completeGraphThreeCollors(self): solver = SAT_solver() graph = [[1, 1, 1], [1, 1, 1], [1, 1, 1]] colors = 3 formula = graph_coloring(graph, colors) solution = solver.solve(formula) self.assertTrue(solution[0]) self.assertEqual("true", formula.nnf().cnf().evaluate(solution[1]).__class__.__name__)
def test_OddCicleGraphTwoCollors(self): solver = SAT_solver() graph = [ [0, 1, 1], [1, 0, 1], [1, 1, 0], ] colors = 2 formula = graph_coloring(graph, colors) solution = solver.solve(FlatCNF(formula)) self.assertFalse(solution[0])
def test_EvenCicleGraphTwoCollors(self): solver = SAT_solver() graph = [ [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], ] colors = 2 formula = graph_coloring(graph, colors) solution = solver.solve(FlatCNF(formula)) self.assertTrue(solution[0]) self.assertEqual("true", formula.nnf().cnf().evaluate(solution[1]).__class__.__name__)
#instance of sat solver solver = SAT_solver() #graph represented with adjacency matrix graph = [ [1, 1, 1], [1, 1, 1], [1, 1, 1], ] #number of colors for graph coloring colors = 3 #construct formula for certain graph and number of colors formula = graph_coloring(graph, colors) #solve formula solution = solver.solve(formula) #solve2 formula solution2 = solver.solve(formula,True) #flatcnf solution solution3 = solver.solve(FlatCNF(formula)) print "Graph (" + str(colors) + " colors):" print printGraph(graph) print "SAT"