def test_arc_will_restore_all_domains_when_not_given_the_last_queen(self): ac = ArcConsistency(Arcs(4)) problem = Variables(4) problem.queens[0].value = 1 problem.queens[1].value = 3 ac.arcConsistent(problem) self.assertEqual(set([1, 2, 3, 4]), problem.queens[1].domain) self.assertEqual(3, problem.queens[1].value)
def test_arc_will_not_backtrack_too_far_when_it_sees_a_failure(self): ac = ArcConsistency(Arcs(4)) problem = Variables(4) problem.queens[0].value = 2 problem.queens[3].value = 4 ac.arcConsistent(problem, problem.queens[3]) self.assertEqual(set([3]), problem.queens[3].domain) self.assertEqual(-1, problem.queens[3].value)
def setUp(self): self.ac = ArcConsistency(Arcs(8))
def __init__(self, Q): self.arcs = Arcs(Q)
def setUp(self): self.gac = GlobalArcConsistency(Arcs(8))
def test_global_arc_consistency_can_find_a_larger_solution(self): problem = Variables(8) gac = GlobalArcConsistency(Arcs(8)) gac.findSolution(problem) for queen in problem.queens: self.assertNotEqual(-1, queen.value)
def test_global_arc_consistency_can_find_a_solution(self): problem = Variables(4) gac = GlobalArcConsistency(Arcs(4)) gac.findSolution(problem) self.assertTrue(self.fourByFourSolution(problem.queens) or self.altFourByFourSolution(problem.queens))
def setUp(self): self.constraints = Arcs(8) self.variables = Variables(8)