Presentation is loading. Please wait.

Presentation is loading. Please wait.

Artificial Intelligence Constraint satisfaction Chapter 5, AIMA.

Similar presentations


Presentation on theme: "Artificial Intelligence Constraint satisfaction Chapter 5, AIMA."— Presentation transcript:

1 Artificial Intelligence Constraint satisfaction Chapter 5, AIMA

2 Constraint Satisfaction Problem (CSP) A set X = {X 1,X 2,...,X n } of variables Each variable X i has a nonempty domain D i = {v 1,v 2,...,v k(i) } of possible values A set C = {C 1,C 2,...,C m } of constraints A solution is a complete assignment of values for the variables, which satisfies all the constraints. Examples: Map coloring, scheduling, logistics (transportation), N-queens, crossword puzzles,...

3 Map coloring (Image borrowed from V. Pavlovic) X = {WA, NT, Q, NSW, V, SA, T} D = {R,G,B} (for all variables) C = {WA  NT, WA  SA, NT  SA, NT  Q, SA  Q, SA  NSW, SA  V, Q  NSW, NSW  V} (Neighboring regions must have different colors) Goal: All regions must have a color

4 Map coloring CSP can be visualized with constraint graph –Nodes = variables –Arcs = constraints

5 Types of constraints Unary: X i  v j Binary: X i  X j Higher order Preferences

6 CSP cast as a search problem Depth-first search (depth limit = n )  Backtracking search Very inefficient Initial state Successor function Goal test Path cost (not relevant)

7 ”Vanilla” backtracking WA NT SA Q NSW V T WA NT Q SA Animation adapted from V. Pavlovic V NSW Q WA NT QQQ SA VVV NSW VVV

8 Improve ”vanilla” Backtracking 1.Smart choice of next variable - Min. remaining values (+ degree heuristic) - Least constraining value 2.Check consequences of choice - Forward checking - Arc consistency 3.Intelligent backtracking - Backjumping

9 Minimum remaining values Choose next the variable that is most constrained based on current assignment (& choose the one with the highest degree first in ties) WA NT SA Q NSW V T WA NT SA Animation adapted from V. Pavlovic Q NSW V T

10 Least constraining value Image borrowed from V. Pavlovic Select the value that least constrains the other variables (rules our fewest other variables)

11 Forward checking Delete values that are inconsistent with the last selection Animation adapted from V. Pavlovic Stop search early, if necessary

12 Arc consistency The arc X i  X j is consistent if for every value of X j there exists some valid value of X i. Detects failures sooner than forward checking. Use as preprocessor or as check after each move (MAC) Animation adapted from V. Pavlovic

13 4-queens X = {q 1, q 2, q 3, q 4 } ( q i = queen in column i ) D = {1,2,3,4} (row for queen) C : No queen may attack another queen Goal: Place all queens on the board 788889 4 0q06 4% 0 6 4 0 %6 40q0 6 122223 q1q1 q4q4 q3q3 q2q2

14 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. F {1,2,3,4} q1q1 q3q3 q2q2 q4q4 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998

15 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 1 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223

16 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 1 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints.

17 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints. 1 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 (q 2,q 1 )

18 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints. 1 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 (q 3,q 1 )

19 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints. 1 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 (q 4,q 1 )

20 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints. 1 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 (q 3,q 2 )

21 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 q4q4 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints. 1 {1,2,3,4} q1q1 q3q3 q2q2 (q 3,q 2 )

22 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints. 1 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 (q 2,q 3 )

23 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints. 1 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 (q 2,q 3 )

24 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints. 1 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 (q 3,q 4 )

25 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 1 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4q0 06 40 0 6 4 0 06 40 0 6 122223 The arc (i,j) is consistent if each value at the tail j of the arc has at least one value at the head i that does not violate the constraints. 1 {1,2,3,4}{1,2,3,4} {1,2,3,4} q1q1 q3q3 q2q2 q4q4 (q 3,q 4 )  No solution with q 1 = 1

26 Arc consistency: 4-queens q i = queen placed in column i {1,2,3,4} = The allowed values (row number) for the queen. First move: q 1 = 2 2 {1,2,3,4} q1q1 q3q3 q2q2 q4q4 Example from N.J. Nilsson, ”Artificial Intelligence: A New Synthesis”, 1998 788889 4 0q06 4% 0 6 4 0 %6 40q0 6 122223 Arc consistency (constraint propagation) finds the solution

27 Local search: Simple and efficient Start with initial (invalid) state Modify this state, using the min-conflicts heuristic: Select the value that minimizes the number of conflicts Continue until a solution is found

28 788889 4 0 06 4% 0 6 4 0q06 40q0q6 122223 Local search: 4-queens 788889 4 0 %6 4% 0 6 4 0q06 40q0 6 122223 Stuck! Choose random move that does not increase conflicts. 788889 4 0q%6 4% 0 6 4 0 06 40q0 6 122223 788889 4 0q06 4% 0 6 4 0 %6 40q0 6 122223 Solution in three moves!

29 Map coloring: Australia Using Java code @ AIMA site, calling from within MATLAB. Backtracking ~ 1.5 sec 7 variables (countries) 9 constraints 3 values (R,G,B)

30 Map coloring: Africa 49 variables (countries) 107 constraints 4 values (R,G,B,Y)

31 Map coloring: Africa Modified the AIMA Java code, calling from within MATLAB. Backtracking ~ 5.5 min


Download ppt "Artificial Intelligence Constraint satisfaction Chapter 5, AIMA."

Similar presentations


Ads by Google