def AC3(csp, queue=None, removals=None):
if queue is None:<EOL><INDENT>queue = [(Xi, Xk) for Xi in csp.vars for Xk in csp.neighbors[Xi]]<EOL><DEDENT>csp.support_pruning()<EOL>while queue:<EOL><INDENT>(Xi, Xj) = queue.pop()<EOL>if revise(csp, Xi, Xj, removals):<EOL><INDENT>if not csp.curr_domains[Xi]:<EOL><INDENT>return False<EOL><DEDENT>for Xk in csp.neighbors[Xi]:<EOL><INDENT>if Xk != Xi:<EOL><INDENT>queue.append((Xk, Xi))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return True<EOL>
[Fig. 6.3]