240 likes | 369 Views
Constraint Propagation. influenced by Dr. Rina Dechter, “Constraint Processing”. why propagate constraints?. tightens networks leaves fewer choices for search by eliminating dead ends BUT propagating can be costly in resources tradeoff between constraint propagation and search
E N D
Constraint Propagation influenced by Dr. Rina Dechter, “Constraint Processing”
why propagate constraints? • tightens networks • leaves fewer choices for search by eliminating dead ends BUT • propagating can be costly in resources • tradeoff between constraint propagation and search • “bounded constraint propagation algorithms”
how constraints improve search • used in partial solution searches where the start state is root of search tree (no variables have assigned values) • at any level of tree, some variables are assigned, some are not • constraints reduce choice for next variable assigned
how constraints improve search - v1 v2 v3 v4 choosing v4 satisfy constraints on scopes containing v4 with v1, v2, v3
v1 red green v2 v3 red green red green example - red/green graph - v1 v2 v3
arc-consistency • local consistency property • involves binary constraint and its two variables any value in the domain of one variable can be extended by a value of the other variable consistent with the constraint
arc-consistency example x1, D1 = {1,2,4} {1,2} x2, D2 = {1,2,4} {2,4} C12: {(x1,x2) | x1 < x2 } = {(1,2),(1,4),(2,4)} x1 1 2 4 x2 1 2 4 x1 1 2 . x2 . 2 4 arc-inconsistent arc-consistent
enforcing arc-consistency reduces domains • algorithm to make xi arc-consistent w.r.t. xj Revise(Di) w.r.t. Cij on Sij={xi,xj} for each ai Di if no aj Dj such that (ai,aj) Cij delete ai from Di performance O(k2) in domain size
reducing search spaces • apply arc-consistency to all constraints in problem space • removes infeasible solutions • focuses search • arc consistency may be applied repeatedly to same constraints
interaction of constraints: example x1, D1 = {1,2,4} C12: {x1 = x2} x2, D2 = {1,2,4} C23: {x2 = x3} x3, D2 = {1,2,4} C31: {x1 = 2*x3} x1 1 2 4 x2 1 2 4 x3 1 2 4
AC-3 arc-consistency algorithm problem: R =(X,D,C) AC-3(R) q = new Queue() for every constraint Cij C q.add((xi,xj)); q.add((xj,xi)); while !q.empty() (xi,xj) = q.get(); Revise(Di) wrt Cij if(Di changed) for all k ≠i or j q.add( (xk,xi) performance O(c.k3) c binary constraints, k domain size
arc-consistency • automated version of problem-solving activity by people - propagating constraints
loopholes in arc-consistency x1, D1 = {1,2} C12: {x1 ≠ x2} x2, D2 = {1,2} C23: {x2 ≠ x3} x3, D2 = {1,2} C31: {x1 ≠ x3} x1 1 2 ≠ ≠ x2 1 2 x2 1 2 ≠
stronger constraint checking • path-consistency extends arc-consistency to three variables at once (tightening) • global constraints -specialized consistency for set of variables • e.g., alldifferent(x1, …, xm) - equivalent of permutation set • who owns the zebra? problem • fixed sum, cumulative maximum
z 2,3,5 x l y 2,3,4 2,5,6 2,3,4 constraints in partial solution search space example problem: V = {x,y,l,z}, D = {Dx, Dy, Dl, Dz} Dx={2,3,4}, Dy={2,3,4}, Dl={2,5,6}, Dz={2,3,5} C = {Czx, Czy, Czl}: z must divide other variables
reducing search space size • variable ordering • arc-consistency (or path-consistency, etc) • pre-search check to reduce domains • during search check for consistency with values already assigned
reducing space size • variable ordering
reducing space size • arc-consistency
reducing space size • path-consistency (tightening) • Cxl, Cxy, Cyl (slashed subtrees)
dfs with constraints - detail • extending a partial solution xk-1 xk xk+1 4 SELECT-VALUE(D`k+1) while (! D`k+1 .empty()) a = D`k+1 .pop() if (CONSISTENT(xk+1=a)) return a return null // dead end 2 ? D`k+1 = {1,2,3,4}
dfs algorithm with constraints dfs(X,D,C) returns consistent solution i=1, D`i = Di while (1≤ i ≤ n) // n=|X| xi = SELECT-VALUE(D`i) if(xi == null) // dead end i-- // backtrack else i++ D`i = Di if (i==0) return “no solution” return (x1, x2, …, xn)
improving search performance • changing the resource balance between • constraint propagation and • search • do more pruning by consistency checking • many strategies • e.g., look-ahead algorithms
SELECT-VALUE(D`k+1) while (!D`k+1.empty()) a = D`k+1 .pop() if (CONSISTENT(xk+1=a)) return a return null look-aheadconsistency SELECT-FORWARD(D`k+1) while (!D`k+1.empty()) a = D`k+1 .pop() if (CONSISTENT(xk+1=a)) for (i; k+1 < i ≤ n) for all bD`i if(!CONSISTENT(xi=b)) remove b from D`i if(D`i.empty()) // xk+1=a is dead end reset all D`j, j>k+1 else return a return null
optimization algorithms • same strategies can be used in other search algorithms • greedy, etc • example problem - sudoku