Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fe514c6
changed queue to set in AC3
dmeoli Mar 24, 2019
0129aa9
re-added test commented by mistake
dmeoli Mar 28, 2019
03551fb
added the mentioned AC4 algorithm for constraint propagation
dmeoli Apr 11, 2019
c0b8383
Merge branch 'master' into master
dmeoli Apr 11, 2019
6986247
added doctest in Sudoku for AC4 and and the possibility of choosing t…
dmeoli Apr 11, 2019
b3cd24c
removed useless doctest for AC4 in Sudoku because AC4's tests are alr…
dmeoli Apr 11, 2019
9e0fa55
added map coloring SAT problems
dmeoli Jun 17, 2019
f743146
fixed typo errors and removed unnecessary brackets
dmeoli Jun 17, 2019
20ab0e5
reformulated the map coloring problem
dmeoli Jul 4, 2019
404b179
Revert "reformulated the map coloring problem"
dmeoli Jul 4, 2019
c9c5106
Revert "fixed typo errors and removed unnecessary brackets"
dmeoli Jul 4, 2019
3243ba1
Revert "added map coloring SAT problems"
dmeoli Jul 4, 2019
2af1659
Revert "removed useless doctest for AC4 in Sudoku because AC4's tests…
dmeoli Jul 4, 2019
0c7e5af
Revert "added doctest in Sudoku for AC4 and and the possibility of ch…
dmeoli Jul 4, 2019
ff8c411
Revert "added the mentioned AC4 algorithm for constraint propagation"
dmeoli Jul 4, 2019
93af259
added map coloring SAT problem
dmeoli Jul 4, 2019
002a34e
Merge remote-tracking branch 'upstream/master'
dmeoli Jul 4, 2019
6641c2c
fixed build error
dmeoli Jul 4, 2019
9399dfc
Revert "added map coloring SAT problem"
dmeoli Jul 29, 2019
e130909
Revert "fixed build error"
dmeoli Jul 29, 2019
78bdeb1
Merge remote-tracking branch 'upstream/master'
dmeoli Jul 29, 2019
2f62776
added map coloring SAT problem
dmeoli Jul 29, 2019
aaea704
removed redundant parentheses
dmeoli Jul 29, 2019
0cd6386
Merge remote-tracking branch 'upstream/master'
dmeoli Aug 7, 2019
be656aa
added Viterbi algorithm
dmeoli Aug 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
changed queue to set in AC3
Changed queue to set in AC3 (as in the pseudocode of the original algorithm) to reduce the number of consistency-check due to the redundancy of the same arcs in queue. For example, on the harder1 configuration of the Sudoku CSP the number consistency-check has been reduced from 40464 to 12562!
  • Loading branch information
dmeoli committed Mar 24, 2019
commit fe514c62ba7672c74d585a2dfce84c944ddf0318
8 changes: 4 additions & 4 deletions csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def conflicted_vars(self, current):
def AC3(csp, queue=None, removals=None):
"""[Figure 6.3]"""
if queue is None:
queue = [(Xi, Xk) for Xi in csp.variables for Xk in csp.neighbors[Xi]]
queue = {(Xi, Xk) for Xi in csp.variables for Xk in csp.neighbors[Xi]}
csp.support_pruning()
while queue:
(Xi, Xj) = queue.pop()
Expand All @@ -169,7 +169,7 @@ def AC3(csp, queue=None, removals=None):
return False
for Xk in csp.neighbors[Xi]:
if Xk != Xj:
queue.append((Xk, Xi))
queue.add((Xk, Xi))
return True


Expand Down Expand Up @@ -243,7 +243,7 @@ def forward_checking(csp, var, value, assignment, removals):

def mac(csp, var, value, assignment, removals):
"""Maintain arc consistency."""
return AC3(csp, [(X, var) for X in csp.neighbors[var]], removals)
return AC3(csp, {(X, var) for X in csp.neighbors[var]}, removals)

# The search, proper

Expand Down Expand Up @@ -374,7 +374,7 @@ def make_arc_consistent(Xj, Xk, csp):
# Found a consistent assignment for val1, keep it
keep = True
break

if not keep:
# Remove val1
csp.prune(Xj, val1, None)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_csp_assign():
assignment = {}
australia.assign(var, val, assignment)

assert australia.nassigns == 1
# assert australia.nassigns == 1
assert assignment[var] == val


Expand Down Expand Up @@ -210,7 +210,7 @@ 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=[]
Expand Down