Example #1
0
    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])
Example #2
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])
Example #3
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__)
Example #4
0
    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__)
Example #5
0
    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])
Example #6
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__)
Example #7
0
#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"