n Model problem ä specify in terms of constraints on acceptable solutions ä define variables (denotations) and domains ä define constraints in some language n Solve model ä define search space / choose algorithm –incremental assignment / backtracking search –complete assignments / stochastic search ä design/choose heuristics n Verify and analyze solution Constraint-based problem solving
Example: n-queens Place n-queens on an n n board so that no pair of queens attacks each other
Example: 4-queens x1 x1 x2x2 x3 x3 x4 x4 Variables: x 1, x 2, x 3, x 4 Domains: {1, 2, 3, 4} Constraints: x i x j and | x i - x j | | i - j |
Example: 4-queens One solution: x 1 2 x 2 4 x 3 1 x 4 x1 x1 x2x2 x3 x3 x4 x4 Q Q Q Q
Search tree for 4-queens x1 x1 x2x2 x3 x3 x4 x (1,1,1,1)(4,4,4,4)(2,4,1,3)(3,1,4,2)
Specification of backtracking Invariant:1 i, j c, ( x i, x j ) is consistent x1 x1 x c-1 xc xc x c+1 xn xn currentpastfuture
Backtracking (BT) {2}{5} {1,...,6} x1 x1 x5 x5 x6x6 x4 x4 x2x2 Q Q x1 x1 x5 x5 x6x6 x3 x3 x4 x4 x2x2 x3 x3
Enforcing arc-consistency {a, b, c} < xi xi xj xj
Specification of forward checking Invariant:1 i c, c j n, ( x i, x j ) is arc-consistent x1 x1 x c-1 xc xc x c+1 xn xn currentpastfuture
Forward checking (FC) Q Q x1 x1 x5 x5 x6x6 x3 x3 x4 x4 x2x {2}{5} x1 x1 x5 x5 x6x6 x4 x4 x2x2 {1,2,3,4,5,6} x3 x3
Forward checking (FC) Q Q x1 x1 x5 x5 x6x6 x3 x3 x4 x4 x2x {2}{5} x1 x1 x5 x5 x6x6 x4 x4 x2x2 {1, 3} x3 x3 {1, 4, 6} {1, 3, 4} {3, 4, 6}
Forward checking {2}{5} Q Q Q {3} {1,4,6} {1,3,4} {3,4,6} x1 x1 x5 x5 x6x6 x3 x3 x4 x4 x2x x1 x1 x5 x5 x6x6 x3 x3 x4 x4 x2x2 1
Specification of maintaining arc consistency Invariant:1 i c, c j, k n, ( x j, x k ) is arc-consistent x1 x1 x c-1 xc xc x c+1 xn xn currentpastfuture ( x i, x j ) is arc-consistent,
Maintaining arc consistency (MAC) Q Q {2}{5} x1 x1 x5 x5 x6x6 x4 x4 x2x2 {1,2,3,4,5,6} x3 x3 {1,2,3,4,5,6}{1,2,3,4,5,6} 1 2a x1 x1 x5 x5 x6x6 x3 x3 x4 x4 x2x2 1a
Maintaining arc consistency (MAC) Q Q {2}{5} x1 x1 x5 x5 x6x6 x4 x4 x2x2 {1} x3 x3 { } {4} {6} 1 2a x1 x1 x5 x5 x6x6 x3 x3 x4 x4 x2x2
Enforcing path-consistency < {a, b, c} xi xi xj xj xk xk < <
Some history n Informal statement ä Golomb & Baumert (1965), Mackworth (1977), Lauriere (1978) n Algorithms ä Gaschnig (1978) backtracking algorithm with arc consistency ä McGregor (1979) backtracking algorithm with arc consistency, backtracking algorithm with forward checking ä Haralick & Elliott (1980) forward checking ä Nadel (1989) backtracking with partial arc consistency n Experiments ä McGregor (1979), Haralick & Elliott (1980), Gaschnig (1978), Nadel (1989), Sabin & Freuder (1994)