Formulation • Variables: WA, NT, Q, NSW, V, SA, T • Domain: {red, green, blue} • Constraints: adjacent regions must have different colors {SA WA, SA NT, SA Q, SA NSW, SA V, WA NT, NT Q, Q NSW, NSW V} Constraint Satisfaction Problems • CSP: a set of variables: {X1, X2, …, Xn} and a set of constraints: {C1, C2, …, Cm} • Each Xi has a nonempty domain Di of possible values • Each Ci involves some subset of variables, and specifies allowable combinations of values for that subset • • • • Constraint Graph • Nodes: variables • Arcs: constraints State: defined by an assignment of values to some or all variables consistent or legal assignment: does not violate any constraint complete assignment: every variable is mentioned solution: a complete, consistent assignment Example (Map Coloring): Note: n variables solution depth = n DFS algorithms are popular for CSPs Task: Color each region in red, green, or blue in such a way that no neighboring regions have same color Types of constraints • Unary constraint: involves a single variable • Binary constraint: involves a pair of variables • Higher‐order constraint: three or more variables (cryptarithmetic problems) 2 1 • CSPs with continuous domains are studied under OR (eg. LP) Example (Cryptarithmetic puzzle): + S E N D M O R E Backtracking Search for CSPs • DFS that chooses values for one variable at a time and backtracks when no legal values left to assign M O N E Y Task: Assign a digit (0‐9) to each letter such that answer to the problem is correct. No two letters are assigned the same digit Which variable is assigned next? • Selects next unassigned variable in order given by list of variables Formulation • Variables: S, E, N, D, M, O, R, Y • Domain: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} • Constraints: Alldiff(S, E, N, D, M, O, R, Y) D + E = Y + 10.C1 N + R + C1 = E + 10.C2 E + O + C2 = N + 10.C3 S + M + C3 = O + 10.C4 C4 = M Ci = 0 or 1 (carried over to next column) • Selects next unassigned variable randomly 3 4 • Most constrained variable (with fewest legal values) [minimum remaining values (MRV) heuristic] • Degree heuristic: variable with most constraints on remaining variables In what order should its values be tried? • As specified in the list of values • Randomly • Least constraining value: given a variable, choose the value that rules out fewest choices for the neighboring variables Variable ordering – reduces search space Value ordering – attempts to find the first answer quickly 5 7 Forward checking When variable X is assigned a value, process looks at each variable Y that is connected to X by a constraint, and deletes from Y’s domain any value that is inconsistent with value chosen for X 6