C ONSTRAINT S ATISFACTION P ROBLEMS Instructor: Kris Hauser 1.

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Problems
Advertisements

Constraint Satisfaction Problems Russell and Norvig: Chapter
Constraint Satisfaction Problems
Constraint Satisfaction Problems Russell and Norvig: Parts of Chapter 5 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2004/home.htm Prof: Dekang.
Lecture 11 Last Time: Local Search, Constraint Satisfaction Problems Today: More on CSPs.
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
1 Constraint Satisfaction Problems. 2 Intro Example: 8-Queens Generate-and-test: 8 8 combinations.
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
Constraint Satisfaction problems (CSP)
Constraint Satisfaction Problems. Constraint satisfaction problems (CSPs) Standard search problem: – State is a “black box” – any data structure that.
Constraint Satisfaction Problems
4 Feb 2004CS Constraint Satisfaction1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
Constraint Satisfaction Problems
Constraint Satisfaction Problems (CSP) (Where we postpone making difficult decisions until they become easy to make) R&N: Chap. 5.
Constraint Satisfaction Problems
Constraint Satisfaction
Constraint Satisfaction Problems Russell and Norvig: Chapter 3, Section 3.7 Chapter 4, Pages Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm.
Constraint Propagation (Where a better exploitation of the constraints further reduces the need to make decisions) R&N: Chap. 5 + Chap. 24, p
Constraint Satisfaction Problems Russell and Norvig: Chapter 5 CMSC 421 – Fall 2005.
Chapter 5 Outline Formal definition of CSP CSP Examples
Constraint Satisfaction Problems (CSP) (Where we postpone making difficult decisions until they become easy to make) R&N: Chap. 5 1.
Constraint Satisfaction Problems
Constraint Satisfaction Problems
ISC 4322/6300 – GAM 4322 Artificial Intelligence Lecture 4 Constraint Satisfaction Problems Instructor: Alireza Tavakkoli September 17, 2009 University.
1 Constraint Satisfaction Problems Slides by Prof WELLING.
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
Constraint Satisfaction Problems Chapter 6. Review Agent, Environment, State Agent as search problem Uninformed search strategies Informed (heuristic.
Chapter 5 Section 1 – 3 1.  Constraint Satisfaction Problems (CSP)  Backtracking search for CSPs  Local search for CSPs 2.
PSU CS 370 – Introduction to Artificial Intelligence 1 Constraint Satisfaction Problems Chapter 5.
1 CS B551: Elements of Artificial Intelligence Instructor: Kris Hauser
CS B551: E LEMENTS OF A RTIFICIAL I NTELLIGENCE Instructor: Kris Hauser 1.
Hande ÇAKIN IES 503 TERM PROJECT CONSTRAINT SATISFACTION PROBLEMS.
Chapter 5: Constraint Satisfaction ICS 171 Fall 2006.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
1 CS B551: Elements of Artificial Intelligence Instructor: Kris Hauser
Chapter 5 Constraint Satisfaction Problems
Constraint Satisfaction Problems (Chapter 6)
An Introduction to Artificial Intelligence Lecture 5: Constraint Satisfaction Problems Ramin Halavati In which we see how treating.
1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3 Grand Challenge:
CHAPTER 5 SECTION 1 – 3 4 Feb 2004 CS Constraint Satisfaction 1 Constraint Satisfaction Problems.
Constraint Satisfaction Problems University of Berkeley, USA
4/18/2005EE5621 EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS Lecture 5, 4/18/2005 University of Washington, Department of Electrical Engineering Spring.
Constraint Satisfaction Problems
1. 2 Outline of Ch 4 Best-first search Greedy best-first search A * search Heuristics Functions Local search algorithms Hill-climbing search Simulated.
Computing & Information Sciences Kansas State University Friday, 08 Sep 2006CIS 490 / 730: Artificial Intelligence Lecture 7 of 42 Friday, 08 September.
Chapter 5 Team Teaching AI (created by Dewi Liliana) PTIIK Constraint Satisfaction Problems.
Constraint Satisfaction Problems Russell and Norvig: Chapter 3, Section 3.7 Chapter 4, Pages CS121 – Winter 2003.
Constraint Satisfaction Problems Rich and Knight: 3.5 Russell and Norvig: Chapter 3, Section 3.7 Chapter 4, Pages Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm.
Dr. Shazzad Hosain Department of EECS North South University Lecture 01 – Part C Constraint Satisfaction Problems.
Constraint Satisfaction Problems (CSP) (Where we delay difficult decisions until they become easier) R&N: Chap. 6 (These slides are primarily from a course.
PSU CS 370 – Introduction to Artificial Intelligence 1 Constraint Satisfaction Problems.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
Constraint Satisfaction Problems Russell and Norvig: Chapter 5 CMSC 421 – Fall 2006.
CS 561, Session 8 1 This time: constraint satisfaction - Constraint Satisfaction Problems (CSP) - Backtracking search for CSPs - Local search for CSPs.
Constraint Satisfaction Problems (CSP) (Where we postpone making difficult decisions until they become easy to make) R&N: Chap. Slides taken from.
Constraint Satisfaction Problems (CSPs)
Constraint Satisfaction Problems Lecture # 14, 15 & 16
CS B551: Elements of Artificial Intelligence
Constraint Propagation
Constraint Satisfaction Problems
Artificial Intelligence
Constraint Satisfaction Problems
Constraint satisfaction problems
Constraint Satisfaction Problems. A Quick Overview
CS 8520: Artificial Intelligence
Constraint Propagation
Constraint Satisfaction Problems
Constraint satisfaction problems
Constraint Satisfaction Problems (CSP)
Presentation transcript:

C ONSTRAINT S ATISFACTION P ROBLEMS Instructor: Kris Hauser 1

C ONSTRAINT P ROPAGATION Place a queen in a square Remove the attacked squares from future consideration 2

C ONSTRAINT P ROPAGATION Count the number of non-attacked squares in every row and column Place a queen in a row or column with minimum number Remove the attacked squares from future consideration

C ONSTRAINT P ROPAGATION Repeat

C ONSTRAINT P ROPAGATION

C ONSTRAINT P ROPAGATION

C ONSTRAINT P ROPAGATION

C ONSTRAINT P ROPAGATION

9 1 1

10

W HAT DO WE NEED ? More than just a successor function and a goal test We also need: A means to propagate the constraints imposed by one queen’s position on the positions of the other queens An early failure test Explicit representation of constraints Constraint propagation algorithms 11

C ONSTRAINT S ATISFACTION P ROBLEM (CSP) Set of variables {X 1, X 2, …, X n } Each variable X i has a domain D i of possible values. Usually, D i is finite Set of constraints {C 1, C 2, …, C p } Each constraint relates a subset of variables by specifying the valid combinations of their values Goal: Assign a value to every variable such that all constraints are satisfied 12

M AP C OLORING 7 variables {WA,NT,SA,Q,NSW,V,T} Each variable has the same domain: {red, green, blue} No two adjacent variables have the same value: WA  NT, WA  SA, NT  SA, NT  Q, SA  Q, SA  NSW, SA  V, Q  NSW, NSW  V 13 WA NT SA Q NSW V T WA NT SA Q NSW V T 13

8-Q UEEN P ROBLEM 8 variables X i, i = 1 to 8 The domain of each variable is: {1,2,…,8} Constraints are of the forms: X i = k  X j  k for all j = 1 to 8, j  i Similar constraints for diagonals 14 All constraints are binary (in this class) 14

S UDOKU 81 variables Domain of each variable: {1,…,9} Constraints: x i  x j for all i  j in same row, same col, same cell x i =v i for fixed cells 15

S TREET P UZZLE N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor’s The Horse is next to the Diplomat’s Who owns the Zebra? Who drinks Water? Who owns the Zebra? Who drinks Water? 16

S TREET P UZZLE N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor’s The Horse is next to the Diplomat’s  i,j  [1,5], i  j, N i  N j  i,j  [1,5], i  j, C i  C j... 17

S TREET P UZZLE N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor’s The Horse is next to the Diplomat’s (N i = English)  (C i = Red) (N i = Japanese)  (J i = Painter) (N 1 = Norwegian) left as an exercise (C i = White)  (C i+1 = Green) (C 5  White) (C 1  Green)

S TREET P UZZLE N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor’s The Horse is next to the Diplomat’s (N i = English)  (C i = Red) (N i = Japanese)  (J i = Painter) (N 1 = Norwegian) (C i = White)  (C i+1 = Green) (C 5  White) (C 1  Green) unary constraints

S TREET P UZZLE N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left  N 1 = Norwegian The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk  D 3 = Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor’s The Horse is next to the Diplomat’s 20

S TREET P UZZLE N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house  C 1  Red The Spaniard has a Dog  A 1  Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left  N 1 = Norwegian The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk  D 3 = Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice  J 3  Violinist The Fox is in the house next to the Doctor’s The Horse is next to the Diplomat’s

T ASK S CHEDULING Four tasks T1, T2, T3, and T4 are related by time constraints: T1 must be done during T3 T2 must be achieved before T1 starts T2 must overlap with T3 T4 must start after T1 is complete Are the constraints compatible? What are the possible time relations between two tasks? What if the tasks use resources in limited supply? How to formulate this problem as a CSP? 22 T1T1 T2T2 T3T3 T4T4

3-SAT n Boolean variables u 1,..., u n p constraints of the form u i *  u j *  u k *= 1 where u* stands for either u or  u Known to be NP-complete 23

F INITE VS. I NFINITE CSP 24

CSP AS A S EARCH P ROBLEM n variables X 1,..., X n Valid assignment: {X i 1  v i 1,..., X ik  v ik }, 0  k  n, such that the values v i 1,..., v ik satisfy all constraints relating the variables X i 1,..., X ik Complete assignment: one where k = n [if all variable domains have size d, there are O(d n ) complete assignments] States : valid assignments Initial state : empty assignment {}, i.e. k = 0 Successor of a state: {X i 1  v i 1,..., X ik  v ik }  {X i 1  v i 1,..., X ik  v ik, X ik+1  v ik+1 } Goal test : k = n 25

26 {X i 1  v i 1,..., X ik  v ik } r = n - k variables with s values  r  s branching factor {X i 1  v i 1,..., X ik  v ik, X ik+1  v ik+1 } 26

A K EY PROPERTY OF CSP: C OMMUTATIVITY The order in which variables are assigned values has no impact on the reachable complete valid assignments 27 Hence: 1)One can expand a node N by first selecting one variable X not in the assignment A associated with N and then assigning every value v in the domain of X [  big reduction in branching factor] 27

28 The depth of the solutions in the search tree is un-changed ( n ) {X i 1  v i 1,..., X ik  v ik } {X i 1  v i 1,..., X ik  v ik, X ik+1  v ik+1 } r = n - k variables with s values  r  s branching factor r = n - k variables with s values  s branching factor

29  4 variables X 1,..., X 4  Let the valid assignment of N be: A = {X 1  v 1, X 3  v 3 }  For example pick variable X 4  Let the domain of X 4 be {v 4,1, v 4,2, v 4,3 }  The successors of A are all the valid assignments among: {X 1  v 1, X 3  v 3, X 4  v 4,1 } {X 1  v 1, X 3  v 3, X 4  v 4,2 } {X 1  v 1, X 3  v 3, X 4  v 4,3 } 29

A K EY PROPERTY OF CSP: C OMMUTATIVITY The order in which variables are assigned values has no impact on the reachable complete valid assignments 30 Hence: 1)One can expand a node N by first selecting one variable X not in the assignment A associated with N and then assigning every value v in the domain of X [  big reduction in branching factor] 2)One need not store the path to a node  Backtracking search algorithm

B ACKTRACKING S EARCH Essentially a simplified depth-first algorithm using recursion 31

B ACKTRACKING S EARCH (3 VARIABLES ) 32 Assignment = {} 32

B ACKTRACKING S EARCH (3 VARIABLES ) 33 Assignment = {(X 1,v 11 )} X1X1 v 11 33

B ACKTRACKING S EARCH (3 VARIABLES ) 34 Assignment = {(X 1,v 11 ), (X 3,v 31 )} X1X1 v 11 v 31 X3X3 34

B ACKTRACKING S EARCH (3 VARIABLES ) 35 Assignment = {(X 1,v 11 ), (X 3,v 31 )} X1X1 v 11 v 31 X3X3 X2X2 Assume that no value of X 2 leads to a valid assignment Then, the search algorithm backtracks to the previous variable (X 3 ) and tries another value 35

B ACKTRACKING S EARCH (3 VARIABLES ) 36 Assignment = {(X 1,v 11 ), (X 3,v 32 )} X1X1 v 11 X3X3 v 32 v 31 X2X2 36

B ACKTRACKING S EARCH (3 VARIABLES ) 37 Assignment = {(X 1,v 11 ), (X 3,v 32 )} X1X1 v 11 X3X3 v 32 X2X2 Assume again that no value of X 2 leads to a valid assignment The search algorithm backtracks to the previous variable (X 3 ) and tries another value. But assume that X 3 has only two possible values. The algorithm backtracks to X 1 v 31 X2X2 37

B ACKTRACKING S EARCH (3 VARIABLES ) 38 Assignment = {(X 1,v 12 )} X1X1 v 11 X3X3 v 32 X2X2 v 31 X2X2 v 12 38

B ACKTRACKING S EARCH (3 VARIABLES ) 39 Assignment = {(X 1,v 12 ), (X 2,v 21 )} X1X1 v 11 X3X3 v 32 X2X2 v 31 X2X2 v 12 v21v21 X2X2 39

B ACKTRACKING S EARCH (3 VARIABLES ) 40 Assignment = {(X 1,v 12 ), (X 2,v 21 )} X1X1 v 11 X3X3 v 32 X2X2 v 31 X2X2 v 12 v21v21 X2X2 The algorithm need not consider the variables in the same order in this sub-tree as in the other 40

B ACKTRACKING S EARCH (3 VARIABLES ) 41 Assignment = {(X 1,v 12 ), (X 2,v 21 ), (X 3,v 32 )} X1X1 v 11 X3X3 v 32 X2X2 v 31 X2X2 v 12 v21v21 X2X2 v 32 X3X3 41

B ACKTRACKING S EARCH (3 VARIABLES ) 42 Assignment = {(X 1,v 12 ), (X 2,v 21 ), (X 3,v 32 )} X1X1 v 11 X3X3 v 32 X2X2 v 31 X2X2 v 12 v21v21 X2X2 v 32 X3X3 The algorithm need not consider the values of X 3 in the same order in this sub-tree 42

B ACKTRACKING S EARCH (3 VARIABLES ) 43 Assignment = {(X 1,v 12 ), (X 2,v 21 ), (X 3,v 32 )} X1X1 v 11 X3X3 v 32 X2X2 v 31 X2X2 v 12 v21v21 X2X2 v 32 X3X3 Since there are only three variables, the assignment is complete 43

B ACKTRACKING A LGORITHM 44 CSP-BACKTRACKING(A) 1. If assignment A is complete then return A 2. X  select a variable not in A 3. D  select an ordering on the domain of X 4. For each value v in D do a. Add (X  v) to A b. If A is valid then i. result  CSP-BACKTRACKING(A) ii. If result  failure then return result c. Remove (X  v) from A 5. Return failure Call CSP-BACKTRACKING({}) [This recursive algorithm keeps too much data in memory. An iterative version could save memory (left as an exercise)] 44

C RITICAL Q UESTIONS FOR THE E FFICIENCY OF CSP-B ACKTRACKING 45 CSP-BACKTRACKING(A) 1.If assignment A is complete then return A 2.X  select a variable not in A 3.D  select an ordering on the domain of X 4.For each value v in D do a.Add (X  v) to A b.If a is valid then i.result  CSP-BACKTRACKING(A) ii.If result  failure then return result c.Remove (X  v) from A 5.Return failure 45

C RITICAL Q UESTIONS FOR THE E FFICIENCY OF CSP-B ACKTRACKING 1. Which variable X should be assigned a value next? 2. In which order should X’s values be assigned? 46

C RITICAL Q UESTIONS FOR THE E FFICIENCY OF CSP-B ACKTRACKING 1. Which variable X should be assigned a value next? The current assignment may not lead to any solution, but the algorithm does not know it yet. Selecting the right variable X may help discover the contradiction more quickly 2. In which order should X’s values be assigned? 47

C RITICAL Q UESTIONS FOR THE E FFICIENCY OF CSP-B ACKTRACKING 1. Which variable X should be assigned a value next? The current assignment may not lead to any solution, but the algorithm does not know it yet. Selecting the right variable X may help discover the contradiction more quickly 2. In which order should X’s values be assigned? The current assignment may be part of a solution. Selecting the right value to assign to X may help discover this solution more quickly 48

C RITICAL Q UESTIONS FOR THE E FFICIENCY OF CSP-B ACKTRACKING 1. Which variable X should be assigned a value next? The current assignment may not lead to any solution, but the algorithm does not know it yet. Selecting the right variable X may help discover the contradiction more quickly 2. In which order should X’s values be assigned? The current assignment may be part of a solution. Selecting the right value to assign to X may help discover this solution more quickly More on these questions very soon... 49

F ORWARD C HECKING 50 A simple constraint-propagation technique: Assigning the value 5 to X 1 leads to removing values from the domains of X 2, X 3,..., X X1 X2 X3 X4 X5 X6 X7 X8X1 X2 X3 X4 X5 X6 X7 X8 50

F ORWARD C HECKING IN M AP C OLORING 51 WANTQNSWVSAT RGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB T WA NT SA Q NSW V Constraint graph 51

F ORWARD C HECKING IN M AP C OLORING 52 WANTQNSWVSAT RGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB RRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB T WA NT SA Q NSW V Forward checking removes the value Red of NT and of SA 52

F ORWARD C HECKING IN M AP C OLORING 53 WANTQNSWVSAT RGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB RGBGBRGBRGBRGBRGBRGBRGBGBGBRGBRGB RGBGBGRGBRGBRGBRGBGBGBRGBRGB T WA NT SA Q NSW V 53

F ORWARD C HECKING IN M AP C OLORING 54 WANTQNSWVSAT RGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB RGBGBRGBRGBRGBRGBRGBRGBGBGBRGBRGB RBGRBRBRGBRGBBRGBRGB RBGRBRBBBRGBRGB T WA NT SA Q NSW V 54

F ORWARD C HECKING IN M AP C OLORING 55 WANTQNSWVSAT RGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB RGBGBRGBRGBRGBRGBRGBRGBGBGBRGBRGB RBGRBRBRGBRGBBRGBRGB RBGRBRBBBRGBRGB Empty set: the current assignment {(WA  R), (Q  G), (V  B)} does not lead to a solution 55

F ORWARD C HECKING (G ENERAL F ORM ) 56 Whenever a pair (X  v) is added to assignment A do: For each variable Y not in A do: For every constraint C relating Y to the variables in A do: Remove all values from Y’s domain that do not satisfy C 56

M ODIFIED B ACKTRACKING A LGORITHM 57 CSP-BACKTRACKING(A, var-domains) 1. If assignment A is complete then return A 2. X  select a variable not in A 3. D  select an ordering on the domain of X 4. For each value v in D do a. Add (X  v) to A b. var-domains  forward checking(var-domains, X, v, A) c. If no variable has an empty domain then (i) result  CSP-BACKTRACKING(A, var-domains) (ii) If result  failure then return result d. Remove (X  v) from A 5. Return failure 57

58 No need any more to verify that A is valid M ODIFIED B ACKTRACKING A LGORITHM CSP-BACKTRACKING(A, var-domains) 1. If assignment A is complete then return A 2. X  select a variable not in A 3. D  select an ordering on the domain of X 4. For each value v in D do a. Add (X  v) to A b. var-domains  forward checking(var-domains, X, v, A) c. If no variable has an empty domain then (i) result  CSP-BACKTRACKING(A, var-domains) (ii) If result  failure then return result d. Remove (X  v) from A 5. Return failure

Need to pass down the updated variable domains 59 M ODIFIED B ACKTRACKING A LGORITHM CSP-BACKTRACKING(A, var-domains) 1. If assignment A is complete then return A 2. X  select a variable not in A 3. D  select an ordering on the domain of X 4. For each value v in D do a. Add (X  v) to A b. var-domains  forward checking(var-domains, X, v, A) c. If no variable has an empty domain then (i) result  CSP-BACKTRACKING(A, var-domains) (ii) If result  failure then return result d. Remove (X  v) from A 5. Return failure

60 M ODIFIED B ACKTRACKING A LGORITHM CSP-BACKTRACKING(A, var-domains) 1. If assignment A is complete then return A 2. X  select a variable not in A 3. D  select an ordering on the domain of X 4. For each value v in D do a. Add (X  v) to A b. var-domains  forward checking(var-domains, X, v, A) c. If no variable has an empty domain then (i) result  CSP-BACKTRACKING(A, var-domains) (ii) If result  failure then return result d. Remove (X  v) from A 5. Return failure

61 1) Which variable X i should be assigned a value next?  Most-constrained-variable heuristic  Most-constraining-variable heuristic 2) In which order should its values be assigned?  Least-constraining-value heuristic

M OST -C ONSTRAINED -V ARIABLE H EURISTIC 62 1) Which variable X i should be assigned a value next? Select the variable with the smallest remaining domain [Rationale: Minimize the branching factor] 62

8-Q UEENS Numbers of values for each un-assigned variable New assignment Forward checking 63

8-Q UEENS New numbers of values for each un-assigned variable New assignment Forward checking 64

M AP C OLORING 65  SA’s remaining domain has size 1 (value B remaining)  Q’s remaining domain has size 2  NSW’s, V’s, and T’s remaining domains have size 3  Select SA WA NT SA Q NSW V T WA NTSA

M OST -C ONSTRAINING -V ARIABLE H EURISTIC 66 1) Which variable X i should be assigned a value next? Among the variables with the smallest remaining domains (ties with respect to the most-constrained- variable heuristic), select the one that appears in the largest number of constraints on variables not in the current assignment [Rationale: Increase future elimination of values, to reduce future branching factors] 66

M AP C OLORING 67  Before any value has been assigned, all variables have a domain of size 3, but SA is involved in more constraints (5) than any other variable  Select SA and assign a value to it (e.g., Blue) WA NT SA Q NSW V T SA 67

L EAST -C ONSTRAINING -V ALUE H EURISTIC 68 2) In which order should X’s values be assigned? Select the value of X that removes the smallest number of values from the domains of those variables which are not in the current assignment [Rationale: Since only one value will eventually be assigned to X, pick the least- constraining value first, since it is the most likely not to lead to an invalid assignment] [Note: Using this heuristic requires performing a forward-checking step for every value, not just for the selected value]

M AP C OLORING 69  Q’s domain has two remaining values: Blue and Red  Assigning Blue to Q would leave 0 value for SA, while assigning Red would leave 1 value {} WA NT SA Q NSW V T WA NT 69

M AP C OLORING 70  Q’s domain has two remaining values: Blue and Red  Assigning Blue to Q would leave 0 value for SA, while assigning Red would leave 1 value  So, assign Red to Q {Blue} WA NT SA Q NSW V T WA NT 70

M ODIFIED B ACKTRACKING A LGORITHM 71 1) Most-constrained-variable heuristic 2) Most-constraining-variable heuristic 3) Least-constraining-value heuristic CSP-BACKTRACKING(A, var-domains) 1.If assignment A is complete then return A 2.X  select a variable not in A 3.D  select an ordering on the domain of X 4.For each value v in D do a.Add (X  v) to A b.var-domains  forward checking(var-domains, X, v, A) c.If no variable has an empty domain then (i) result  CSP-BACKTRACKING(A, var-domains) (ii) If result  failure then return result d.Remove (X  v) from A 5.Return failure 71

A PPLICATIONS OF CSP CSP techniques are widely used Applications include: Crew assignments to flights Management of transportation fleet Flight/rail schedules Job shop scheduling Task scheduling in port operations Design, including spatial layout design 72

R ECAP CSPs Backtracking search Constraint propagation 73

H OMEWORK R&N