Presentation is loading. Please wait.

Presentation is loading. Please wait.

Constraint Satisfaction CSE 473 University of Washington.

Similar presentations


Presentation on theme: "Constraint Satisfaction CSE 473 University of Washington."— Presentation transcript:

1 Constraint Satisfaction CSE 473 University of Washington

2 © Daniel S. Weld 2 Today: Constraint Satisfaction Problems Definition Factoring state spaces Variable-ordering heuristics Backtracking policies Preprocessing algorithms

3 © Daniel S. Weld 3 Constraint Satisfaction Kind of search in which States are factored into sets of variables Search = assigning values to these variables Structure of space is encoded with constraints Backtracking-style algorithms work E.g. DFS for SAT (i.e. DPLL) But other techniques add speed Propagation Variable ordering Preprocessing

4 © Daniel S. Weld 4 Chinese Food as Search States? Operators? Start state? Goal states? Suppose every meal for n people has n dishes plus soup

5 © Daniel S. Weld 5 Chinese Food as Search States? Operators? Start state? Goal states? Partially specified meals Add, remove, change dishes Null meal Meal meeting certain conditions Two non-peanut dishes, with at least one of the others non-spicy. Suppose every meal for n people has n dishes plus soup

6 © Daniel S. Weld 6 Break the state into its independent components: State = (dish1, … dishN, soup) Becomes variables: Soup = Dish 1 = Dish 2 = … Dish n = Factoring States

7 © Daniel S. Weld 7 Encode the structure of the problem as constraints Often this structure is the description of the goal state: Goal condition = “Two peanut-free dishes; of the others, at least one must be non-spicy” How to express this as constraints? Factoring States

8 © Daniel S. Weld 8 Chinese Constraint Network Soup Total Cost < $30 Chicken Dish Vegetable RiceSeafood Pork Dish Appetizer Must be Hot&Sour No Peanuts No Peanuts Not Chow Mein Not Both Spicy

9 © Daniel S. Weld 9 Binary Constraint Network Set of n variables: x 1 … x n Value domains for each variable: D 1 … D n Set of binary constraints (also “relations”) Each binary constraint specifies which pairs (x i, x j ) are consistent R ij  D i  D j

10 © Daniel S. Weld 10 Binary Constraint Network Partial assignment of values = tuple of pairs {...(x, a)…} means variable x gets value a... Tuple=consistent if all constraints satisfied Tuple=full solution if consistent + has all vars Tuple {(x i, a i ) … (x j, a j )} = consistent w/ a set of vars {x m … x n } iff  a m … a n such that {(x i, a i )…(x j, a j ), (x m, a m )…(x n, a n )} } = consistent

11 © Daniel S. Weld 11 CSPs in the Real World Scheduling space shuttle repair Airport gate assignments Transportation Planning Supply-chain management Computer configuration Diagnosis UI optimization Etc...

12 © Daniel S. Weld 12 CSP Example: Cryptarithmetic State Space Set of states Operators [and costs] Start state Goal states Variables? Domains (variable values)? Constraints?

13 © Daniel S. Weld 13 CSP Example: Cryptarithmetic State Space Set of states Operators [and costs] Start state Goal states Variables? Domains (variable values)? Constraints?

14 © Daniel S. Weld 14 CSP Example: Classroom Scheduling Variables? Domains (possible values for variables)? Constraints?

15 © Daniel S. Weld 15 N Queens As a CSP?

16 © Daniel S. Weld 16 N Queens Variables = board columns Domain values = rows R ij = {(a i, a j ) : (a i  a j )  (|i-j|  |a i -a j |) e.g. R 12 = {(1,3), (1,4), (2,4), (3,1), (4,1), (4,2)} Q Q Q {(x 1, 2), (x 2, 4), (x 3, 1)} consistent with (x 4 ) Shorthand: “{2, 4, 1} consistent with x 4 ”

17 © Daniel S. Weld 17 CSP as a search problem? What are states? What are the operators? Initial state? Goal test? Q Q Q

18 © Daniel S. Weld 18 CSP as a search problem? What are states? (partial assignments) What are the operators? (add/change a single-variable assignment) Initial state? (empty assignment) Goal test? (full & consistent assignment) Q Q Q

19 © Daniel S. Weld 19 N-Queens CSP Search Q Q Q Q Q Q Q Q Q Q Q 1 2 3 4 5 6

20 © Daniel S. Weld 20 Which queen to place next? Variable Ordering Q Q

21 © Daniel S. Weld 21 Which queen to place next? Most constrained Least constraining Highest degree (as tiebreaker) Variable Ordering Q Q

22 © Daniel S. Weld 22 Chronological Backtracking (BT) (e.g., depth first search) Q Q Q Q Q Q Q Q Q Q Q 1 2 3 4 5 6 Consistency check performed in the order in which vars were instantiated If c-check fails, try next value of current var If no more values, backtrack to most recent var

23 © Daniel S. Weld 23 Backjumping (BJ) Similar to BT, but more efficient when no consistent instantiation can be found for the current var Instead of backtracking to most recent var… BJ reverts to deepest var which was c-checked against the current var BJ Discovers placement of queens (2, 3, 5, 6) is inconsistent with x 6 No sense trying other values of x 5 Backtrack to x 4 and try a new placement Q Q Q Q Q

24 © Daniel S. Weld 24 Forward Checking (FC) Perform Consistency Check Forward Whenever a var is assigned a value Prune inconsistent values from As-yet unvisited variables Backtrack if domain of any var ever collapses Q Q Q Q Q QQ Q Q Q Q Forward checking vs backjumping? Backtrack from here without trying any values for Q6

25 © Daniel S. Weld 25 Arc Consistency Stronger version of forward checking For every pair of variables (x, y), check that: For every value remaining in x’s domain, there is some value for y that is consistent. (Where ‘consistent’ means consistent with all current settings and the value of ‘x’ currently in question.) QQ Q Q Q Q Backtrack from here because there is a value in Q5’s domain that is inconsistent with all values in Q6’s domain. Q When a value is deleted from x’s domain, we must re-check consistency of all of x’s neighbors. Why?

26 © Daniel S. Weld 26 K-Consistency Arc consistency generalized to k-ary relations For every k-tuple of variables (x 1, …, x k ), check that: For every consisent set of values remaining in the domains of x 1 through x k-1, there is some value for x k that is consistent. Tradeoffs


Download ppt "Constraint Satisfaction CSE 473 University of Washington."

Similar presentations


Ads by Google