CS156
Chris Pollett
Sep 27, 2017
#in python def print_some_args(*args): for arg in args: print argSuch constraints are called global constraints. For example, `Alldi\ff` is a constraint among two or more arguments saying that all of the arguments are different.
A Latin Square is a `n`x`n` matrix with entries from `1, ..., n` such that no row or column has the same number twice.
Model a matrix being a 4x4 latin square as a CSP and post your solution to the Sep 27 In-Class Exercise Thread.
function AC-3(csp) returns false if an inconsistency is found and true otherwise inputs: csp, a binary CSP with components (X, D, C) local variables: queue, a queue of arcs, initially all the arcs in csp while (queue is not empty) do (X_i, X_j) := REMOVE_FIRST(queue) if(REVISE(csp, X_i, X_j)) then if (size of D_i == 0) then return false for each X_k in X_i-NEIGHBORS - {X_j} do add (X_k, X_i) to queue # since X_i's domains change might affect X_k return true function REVISE(csp, X_i, X_j) returns true iff we revise the domain of X_i revised := false for each x in D_i do if no value y in D_j allows (x,y) to satisfy the constraint between X_i and X_j then delete x from D_i revised := true return revised