Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit beaea67

Browse files
nvinayvarma189norvig
authored andcommitted
modify AC3 algorithm (#717)
* added submodule * fixed ac3 in csp.py * added a test to verify the modified ac3 algorithm in csp.py * Update .gitmodules
1 parent 485c94f commit beaea67

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

csp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def AC3(csp, queue=None, removals=None):
168168
if not csp.curr_domains[Xi]:
169169
return False
170170
for Xk in csp.neighbors[Xi]:
171-
if Xk != Xi:
171+
if Xk != Xj:
172172
queue.append((Xk, Xi))
173173
return True
174174

tests/test_csp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ def test_AC3():
210210
assert AC3(csp, removals=removals) is True
211211
assert (removals == [('A', 1), ('A', 3), ('B', 1), ('B', 3)] or
212212
removals == [('B', 1), ('B', 3), ('A', 1), ('A', 3)])
213+
214+
domains = {'A': [ 2, 4], 'B': [ 3, 5]}
215+
constraints = lambda X, x, Y, y: int(x) > int (y)
216+
removals=[]
217+
csp = CSP(variables=None, domains=domains, neighbors=neighbors, constraints=constraints)
218+
219+
assert AC3(csp, removals=removals)
213220

214221

215222
def test_first_unassigned_variable():

0 commit comments

Comments
 (0)