| 
1 | 1 | """CSP (Constraint Satisfaction Problems) problems and solvers. (Chapter 6)."""  | 
2 | 2 | 
 
  | 
3 |  | -from utils import count, first, every, argmin_random_tie  | 
 | 3 | +from utils import count, first, argmin_random_tie  | 
4 | 4 | import search  | 
5 | 5 | 
 
  | 
6 | 6 | from collections import defaultdict  | 
@@ -98,16 +98,16 @@ def actions(self, state):  | 
98 | 98 |             return [(var, val) for val in self.domains[var]  | 
99 | 99 |                     if self.nconflicts(var, val, assignment) == 0]  | 
100 | 100 | 
 
  | 
101 |  | -    def result(self, state, xxx_todo_changeme):  | 
 | 101 | +    def result(self, state, action):  | 
102 | 102 |         "Perform an action and return the new state."  | 
103 |  | -        (var, val) = xxx_todo_changeme  | 
 | 103 | +        (var, val) = action  | 
104 | 104 |         return state + ((var, val),)  | 
105 | 105 | 
 
  | 
106 | 106 |     def goal_test(self, state):  | 
107 | 107 |         "The goal is to assign all variables, with all constraints satisfied."  | 
108 | 108 |         assignment = dict(state)  | 
109 | 109 |         return (len(assignment) == len(self.variables) and  | 
110 |  | -                every(lambda variables: self.nconflicts(variables, assignment[variables], assignment) == 0, self.variables))  | 
 | 110 | +                all(self.nconflicts(variables, assignment[variables], assignment) == 0 for variables in  self.variables))  | 
111 | 111 | 
 
  | 
112 | 112 |     # These are for constraint propagation  | 
113 | 113 | 
 
  | 
@@ -177,8 +177,7 @@ def revise(csp, Xi, Xj, removals):  | 
177 | 177 |     revised = False  | 
178 | 178 |     for x in csp.curr_domains[Xi][:]:  | 
179 | 179 |         # If Xi=x conflicts with Xj=y for every possible y, eliminate Xi=x  | 
180 |  | -        if every(lambda y: not csp.constraints(Xi, x, Xj, y),  | 
181 |  | -                 csp.curr_domains[Xj]):  | 
 | 180 | +        if all(not csp.constraints(Xi, x, Xj, y) for y in csp.curr_domains[Xj]):  | 
182 | 181 |             csp.prune(Xi, x, removals)  | 
183 | 182 |             revised = True  | 
184 | 183 |     return revised  | 
 | 
0 commit comments