diff --git a/csp.py b/csp.py index 9e933c266..62772c322 100644 --- a/csp.py +++ b/csp.py @@ -168,7 +168,7 @@ def AC3(csp, queue=None, removals=None): if not csp.curr_domains[Xi]: return False for Xk in csp.neighbors[Xi]: - if Xk != Xi: + if Xk != Xj: queue.append((Xk, Xi)) return True diff --git a/tests/test_csp.py b/tests/test_csp.py index 4e2c4f119..f63e657aa 100644 --- a/tests/test_csp.py +++ b/tests/test_csp.py @@ -210,6 +210,13 @@ def test_AC3(): assert AC3(csp, removals=removals) is True assert (removals == [('A', 1), ('A', 3), ('B', 1), ('B', 3)] or removals == [('B', 1), ('B', 3), ('A', 1), ('A', 3)]) + + domains = {'A': [ 2, 4], 'B': [ 3, 5]} + constraints = lambda X, x, Y, y: int(x) > int (y) + removals=[] + csp = CSP(variables=None, domains=domains, neighbors=neighbors, constraints=constraints) + + assert AC3(csp, removals=removals) def test_first_unassigned_variable():