Example #1
0
    def test_ga_uses_one_iteration_for_trivially_satisfiable_problem(self):
        v1 = Variable('a')
        c1 = Clause([Literal(v1)])
        maxsat = MAXSAT([v1], [c1])

        ga = GA(maxsat)
        _, _, iteration = ga.run()
        self.assertEqual(1, iteration)
Example #2
0
    def test_ga_uses_one_iteration_for_unsatisfiable_problem_if_not_below_threshold(self):
        v1 = Variable('a')
        c1 = Clause([Literal(v1, positive=True)])
        c2 = Clause([Literal(v1, positive=False)])
        maxsat = MAXSAT([v1], [c1, c2])

        ga = GA(maxsat, fitness_threshold=0.5)
        _, _, iteration = ga.run()
        self.assertEqual(1, iteration)
Example #3
0
    def test_ga_achieves_fitness_of_one(self):
        v1 = Variable('a')
        c1 = Clause([Literal(v1)])
        maxsat = MAXSAT([v1], [c1])

        ga = GA(maxsat)
        _, fitness, _ = ga.run()

        self.assertEqual(1, fitness)
Example #4
0
    def test_ga_uses_all_iterations_for_unsatisfiable_problem_if_below_threshold(self):
        v1 = Variable('a')
        c1 = Clause([Literal(v1, positive=True)])
        c2 = Clause([Literal(v1, positive=False)])
        maxsat = MAXSAT([v1], [c1, c2])

        ga = GA(maxsat)
        _, _, iteration = ga.run()
        self.assertEqual(iteration, ga.max_iterations)
Example #5
0
    def test_ga_achieves_fitness_of_half(self):
        v1 = Variable('a')
        c1 = Clause([Literal(v1, positive=True)])
        c2 = Clause([Literal(v1, positive=False)])
        maxsat = MAXSAT([v1], [c1, c2])

        ga = GA(maxsat)
        _, fitness, _ = ga.run()

        self.assertEqual(0.5, fitness)