Presentation is loading. Please wait.

Presentation is loading. Please wait.

PSU CS 370 – Introduction to Artificial Intelligence 1 Constraint Satisfaction Problems Chapter 5.

Similar presentations


Presentation on theme: "PSU CS 370 – Introduction to Artificial Intelligence 1 Constraint Satisfaction Problems Chapter 5."— Presentation transcript:

1 PSU CS 370 – Introduction to Artificial Intelligence 1 Constraint Satisfaction Problems Chapter 5

2 PSU CS 370 – Introduction to Artificial Intelligence 2 Outline n Constraint Satisfaction Problems (CSP) n Backtracking search for CSPs n Local search for CSPs

3 PSU CS 370 – Introduction to Artificial Intelligence Intro Example: 8-Queens Purely generate-and-test The “search” tree is only used to enumerate all possible 64 8 combinations

4 PSU CS 370 – Introduction to Artificial Intelligence Intro Example: 8-Queens Another form of generate-and-test, with no redundancies  “only” 8 8 combinations

5 PSU CS 370 – Introduction to Artificial Intelligence Intro Example: 8-Queens

6 PSU CS 370 – Introduction to Artificial Intelligence What is Needed? n Not just a successor function and goal test n But also a means to propagate the constraints imposed by one queen on the others and an early failure test n  Explicit representation of constraints and constraint manipulation algorithms

7 PSU CS 370 – Introduction to Artificial Intelligence Constraint Satisfaction Problem n Set of variables {X1, X2, …, X n } n Each variable Xi has a domain Di of possible values n Usually Di is discrete and finite n Set of constraints {C1, C2, …, Cp} n Each constraint Ck involves a subset of variables and specifies the allowable combinations of values of these variables

8 PSU CS 370 – Introduction to Artificial Intelligence Constraint Satisfaction Problem n Set of variables {X1, X2, …, Xn} n Each variable Xi has a domain Di of possible values n Usually Di is discrete and finite n Set of constraints {C1, C2, …, Cp} n Each constraint C k involves a subset of variables and specifies the allowable combinations of values of these variables n Assign a value to every variable such that all constraints are satisfied

9 PSU CS 370 – Introduction to Artificial Intelligence Example: 8-Queens Problem n 64 variables Xij, i = 1 to 8, j = 1 to 8 n Domain for each variable {yes,no} n Constraints are of the forms: Xij = yes  Xik = no for all k = 1 to 8, kj Xij = yes  Xkj = no for all k = 1 to 8, kI l Similar constraints for diagonals

10 PSU CS 370 – Introduction to Artificial Intelligence Example: 8-Queens Problem n 8 variables Xi, i = 1 to 8 n Domain for each variable {1,2,…,8} n Constraints are of the forms: Xi = k  Xj  k for all j = 1 to 8, ji l Similar constraints for diagonals

11 PSU CS 370 – Introduction to Artificial Intelligence Example: Map Coloring 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 WA NT SA Q NSW V T WA NT SA Q NSW V T

12 PSU CS 370 – Introduction to Artificial Intelligence Example: Street Puzzle 1 2 34 5 Ni = {English, Spaniard, Japanese, Italian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Coffee, Milk, Fruit-juice, Water} Ji = {Painter, Sculptor, Diplomat, Violonist, Doctor} Ai = {Dog, Snails, Fox, Horse, Zebra}

13 PSU CS 370 – Introduction to Artificial Intelligence Example: Street Puzzle 1 2 34 5 Ni = {English, Spaniard, Japanese, Italian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Coffee, Milk, Fruit-juice, Water} Ji = {Painter, Sculptor, Diplomat, Violonist, Doctor} Ai = {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 Violonist 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?

14 PSU CS 370 – Introduction to Artificial Intelligence Example: Task Scheduling 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? Find the temporal relation between every two tasks T1 T2 T3 T4

15 PSU CS 370 – Introduction to Artificial Intelligence Finite vs. Infinite CSP n Finite domains of values  finite CSP n Infinite domains  infinite CSP

16 PSU CS 370 – Introduction to Artificial Intelligence Finite vs. Infinite CSP n Finite domains of values  finite CSP n Infinite domains  infinite CSP n We will only consider finite CSP

17 PSU CS 370 – Introduction to Artificial Intelligence Constraint Graph Binary constraints T WA NT SA Q NSW V Two variables are adjacent or neighbors if they are connected by an edge or an arc T1 T2 T3 T4

18 PSU CS 370 – Introduction to Artificial Intelligence CSP as a Search Problem n Initial state: empty assignment n Successor function: a value is assigned to any unassigned variable, which does not conflict with the currently assigned variables n Goal test: the assignment is complete n Path cost: irrelevant

19 PSU CS 370 – Introduction to Artificial Intelligence CSP as a Search Problem n Initial state: empty assignment n Successor function: a value is assigned to any unassigned variable, which does not conflict with the currently assigned variables n Goal test: the assignment is complete n Path cost: irrelevant n variables of domain size d  O(d n ) distinct complete assignments

20 PSU CS 370 – Introduction to Artificial Intelligence Remark n Finite CSP include 3SAT as a special case (see class of CS311) n 3SAT is known to be NP-complete n So, in the worst-case, we cannot expect to solve a finite CSP in less than exponential time

21 PSU CS 370 – Introduction to Artificial Intelligence Commutativity of CSP 1. Generate successors of a node by considering assignments for only one variable 2. Do not store the path to node

22 PSU CS 370 – Introduction to Artificial Intelligence  Backtracking Search empty assignment 1 st variable 2 nd variable 3 rd variable Assignment = {}

23 PSU CS 370 – Introduction to Artificial Intelligence  Backtracking Search empty assignment 1 st variable 2 nd variable 3 rd variable Assignment = {(var1=v11)}

24 PSU CS 370 – Introduction to Artificial Intelligence  Backtracking Search empty assignment 1 st variable 2 nd variable 3 rd variable Assignment = {(var1=v11),(var2=v21)}

25 PSU CS 370 – Introduction to Artificial Intelligence  Backtracking Search empty assignment 1 st variable 2 nd variable 3 rd variable Assignment = {(var1=v11),(var2=v21),(var3=v31)}

26 PSU CS 370 – Introduction to Artificial Intelligence  Backtracking Search empty assignment 1 st variable 2 nd variable 3 rd variable Assignment = {(var1=v11),(var2=v21),(var3=v32)}

27 PSU CS 370 – Introduction to Artificial Intelligence  Backtracking Search empty assignment 1 st variable 2 nd variable 3 rd variable Assignment = {(var1=v11),(var2=v22)}

28 PSU CS 370 – Introduction to Artificial Intelligence  Backtracking Search empty assignment 1 st variable 2 nd variable 3 rd variable Assignment = {(var1=v11),(var2=v22),(var3=v31)}

29 PSU CS 370 – Introduction to Artificial Intelligence 29 Backtracking search n Variable assignments are commutative}, i.e., [ WA = red then NT = green ] same as [ NT = green then WA = red ] n Only need to consider assignments to a single variable at each node  b = d and there are d n leaves n Depth-first search for CSPs with single-variable assignments is called backtracking search n Backtracking search is the basic uninformed algorithm for CSPs n Can solve n-queens for n ≈ 25

30 PSU CS 370 – Introduction to Artificial Intelligence 30 Backtracking search

31 PSU CS 370 – Introduction to Artificial Intelligence 31 Backtracking example

32 PSU CS 370 – Introduction to Artificial Intelligence 32 Backtracking example

33 PSU CS 370 – Introduction to Artificial Intelligence 33 Backtracking example

34 PSU CS 370 – Introduction to Artificial Intelligence 34 Backtracking example

35 PSU CS 370 – Introduction to Artificial Intelligence 35 Improving backtracking efficiency n General-purpose methods can give huge gains in speed: l Which variable should be assigned next? l In what order should its values be tried? l Can we detect inevitable failure early?

36 PSU CS 370 – Introduction to Artificial Intelligence 36 Most constrained variable n Most constrained variable: choose the variable with the fewest legal values n a.k.a. minimum remaining values (MRV) heuristic

37 PSU CS 370 – Introduction to Artificial Intelligence 37 Most constraining variable n Tie-breaker among most constrained variables n Most constraining variable: l choose the variable with the most constraints on remaining variables

38 PSU CS 370 – Introduction to Artificial Intelligence 38 Least constraining value n Given a variable, choose the least constraining value: l the one that rules out the fewest values in the remaining variables n Combining these heuristics makes 1000 queens feasible

39 PSU CS 370 – Introduction to Artificial Intelligence 39 Forward checking n Idea: l Keep track of remaining legal values for unassigned variables l Terminate search when any variable has no legal values

40 PSU CS 370 – Introduction to Artificial Intelligence 40 Forward checking n Idea: l Keep track of remaining legal values for unassigned variables l Terminate search when any variable has no legal values

41 PSU CS 370 – Introduction to Artificial Intelligence 41 Forward checking n Idea: l Keep track of remaining legal values for unassigned variables l Terminate search when any variable has no legal values

42 PSU CS 370 – Introduction to Artificial Intelligence 42 Forward checking n Idea: l Keep track of remaining legal values for unassigned variables l Terminate search when any variable has no legal values

43 PSU CS 370 – Introduction to Artificial Intelligence 43 Constraint propagation n Forward checking propagates information from assigned to unassigned variables, but doesn't provide early detection for all failures: n NT and SA cannot both be blue! Constraint propagation repeatedly enforces constraints locally

44 PSU CS 370 – Introduction to Artificial Intelligence 44 Arc consistency algorithm AC-3 n Time complexity: O(n 2 d 3 )

45 PSU CS 370 – Introduction to Artificial Intelligence Backtracking Algorithm CSP-BACKTRACKING({}) CSP-BACKTRACKING(a) l If a is complete then return a l X  select unassigned variable l D  select an ordering for the domain of X l For each value v in D do –If v is consistent with a then l Add (X= v) to a l result  CSP-BACKTRACKING(a) If result  failure then return result l Return failure partial assignment of variables

46 PSU CS 370 – Introduction to Artificial Intelligence Map Coloring {} WA=redWA=greenWA=blue WA=red NT=green WA=red NT=blue WA=red NT=green Q=red WA=red NT=green Q=blue WA NT SA Q NSW V T

47 PSU CS 370 – Introduction to Artificial Intelligence Questions 1. Which variable X should be assigned a value next? 2. In which order should its domain D be sorted?

48 PSU CS 370 – Introduction to Artificial Intelligence Questions 1. Which variable X should be assigned a value next? 2. In which order should its domain D be sorted? 3. What are the implications of a partial assignment for yet unassigned variables? (  Constraint Propagation)

49 PSU CS 370 – Introduction to Artificial Intelligence Choice of Variable n Map coloring WA NT SA Q NSW V T WA NTSA

50 PSU CS 370 – Introduction to Artificial Intelligence Choice of Variable n 8-queen

51 PSU CS 370 – Introduction to Artificial Intelligence Choice of Variable #1: Minimum Remaining Values (aka Most- constrained-variable heuristic): Select a variable with the fewest remaining values

52 PSU CS 370 – Introduction to Artificial Intelligence Choice of Variable #2: Degree Heuristic (aka Most- constraining-variable heuristic): Select the variable that is involved in the largest number of constraints on other unassigned variables WA NT SA Q NSW V T SA

53 PSU CS 370 – Introduction to Artificial Intelligence {} Choice of Value WA NT SA Q NSW V T WA NT

54 PSU CS 370 – Introduction to Artificial Intelligence Choice of Value #3: Least-constraining-value heuristic: Prefer the value that leaves the largest subset of legal values for other unassigned variables {blue} WA NT SA Q NSW V T WA NT

55 PSU CS 370 – Introduction to Artificial Intelligence Constraint Propagation … … is the process of determining how the possible values of one variable affect the possible values of other variables

56 PSU CS 370 – Introduction to Artificial Intelligence Forward Checking After a variable X is assigned a value v, look at each unassigned variable Y that is connected to X by a constraint and deletes from Y’s domain any value that is inconsistent with v

57 PSU CS 370 – Introduction to Artificial Intelligence Map Coloring WANTQNSWVSAT RGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB T WA NT SA Q NSW V

58 PSU CS 370 – Introduction to Artificial Intelligence Map Coloring WANTQNSWVSAT RGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB RGBGBRGBRGBRGBRGBRGBRGBGBGBRGBRGB T WA NT SA Q NSW V

59 PSU CS 370 – Introduction to Artificial Intelligence WANTQNSWVSAT RGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB RGBGBRGBRGBRGBRGBRGBRGBGBGBRGBRGB RBGRBRBRGBRGBBRGBRGB Map Coloring T WA NT SA Q NSW V

60 PSU CS 370 – Introduction to Artificial Intelligence Map Coloring WANTQNSWVSAT RGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB RGBGBRGBRGBRGBRGBRGBRGBGBGBRGBRGB RBGRBRBRGBRGBBRGBRGB RBGRBRGBRGB Impossible assignments that forward checking do not detect T WA NT SA Q NSW V

61 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

62 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

63 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

64 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

65 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

66 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

67 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

68 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

69 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

70 PSU CS 370 – Introduction to Artificial Intelligence 4-Queens Problem 1 3 2 4 3241 X1 {1,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}

71 PSU CS 370 – Introduction to Artificial Intelligence 71 Arc consistency n Simplest form of propagation makes each arc consistent n X  Y is consistent iff for every value x of X there is some allowed y

72 PSU CS 370 – Introduction to Artificial Intelligence 72 Arc consistency n Simplest form of propagation makes each arc consistent n X  Y is consistent iff for every value x of X there is some allowed y

73 PSU CS 370 – Introduction to Artificial Intelligence 73 Arc consistency n Simplest form of propagation makes each arc consistent n X  Y is consistent iff for every value x of X there is some allowed y n If X loses a value, neighbors of X need to be rechecked

74 PSU CS 370 – Introduction to Artificial Intelligence 74 Arc consistency n Simplest form of propagation makes each arc consistent n X  Y is consistent iff for every value x of X there is some allowed y n If X loses a value, neighbors of X need to be rechecked n Arc consistency detects failure earlier than forward checking Can be run as a preprocessor or after each assignment

75 PSU CS 370 – Introduction to Artificial Intelligence Local Search for CSP 1 2 3 3 2 2 3 2 2 2 2 2 0 2 Pick initial complete assignment (at random) Repeat Pick a conflicted variable var (at random) Set the new value of var to minimize the number of conflicts If the new assignment is not conflicting then return it (min-conflicts heuristics)

76 PSU CS 370 – Introduction to Artificial Intelligence Remark n Local search with min-conflict heuristic works extremely well for million-queen problems n The reason: Solutions are densely distributed in the O(n n ) space, which means that on the average a solution is a few steps away from a randomly picked assignment

77 PSU CS 370 – Introduction to Artificial Intelligence Infinite-Domain CSP n Variable domain is the set of the integers (discrete CSP) or of the real numbers (continuous CSP) n Constraints are expressed as equalities and inequalities n Particular case: Linear-programming problems

78 PSU CS 370 – Introduction to Artificial Intelligence Applications n CSP techniques allow solving very complex problems n Numerous applications, e.g.: l Crew assignments to flights l Management of transportation fleet l Flight/rail schedules l Task scheduling in port operations l Design l Brain surgery n Timetabling problems Transportation scheduling n Factory scheduling n See www.ilog.com

79 PSU CS 370 – Introduction to Artificial Intelligence Stereotaxic Brain Surgery

80 PSU CS 370 – Introduction to Artificial Intelligence Stereotaxic Brain Surgery 2000 < Tumor < 2200 2000 < B2 + B4 < 2200 2000 < B4 < 2200 2000 < B3 + B4 < 2200 2000 < B3 < 2200 2000 < B1 + B3 + B4 < 2200 2000 < B1 + B4 < 2200 2000 < B1 + B2 + B4 < 2200 2000 < B1 < 2200 2000 < B1 + B2 < 2200 0 < Critical < 500 0 < B2 < 500 T C B1 B2 B3 B4 T

81 PSU CS 370 – Introduction to Artificial Intelligence  Constraint Programming “Constraint programming represents one of the closest approaches computer science has yet made to the Holy Grail of programming: the user states the problem, the computer solves it.” Eugene C. Freuder, Constraints, April 1997

82 PSU CS 370 – Introduction to Artificial Intelligence When to Use CSP Techniques? n When the problem can be expressed by a set of variables with constraints on their values n When constraints are relatively simple (e.g., binary) n When constraints propagate well

83 PSU CS 370 – Introduction to Artificial Intelligence 83 Summary n CSPs are a special kind of problem: l states defined by values of a fixed set of variables l goal test defined by constraints on variable values n Backtracking = depth-first search with one variable assigned per node n Variable ordering and value selection heuristics help significantly n Forward checking prevents assignments that guarantee later failure n Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies n Iterative min-conflicts is usually effective in practice

84 PSU CS 370 – Introduction to Artificial Intelligence Additional References  Surveys: Kumar, AAAI Mag., 1992; Dechter and Frost, 1999  Text: Marriott and Stuckey, 1998; Russell and Norvig, 2 nd ed.  Applications: Freuder and Mackworth, 1994  Conference series: Principles and Practice of Constraint Programming (CP)  Journal: Constraints (Kluwer Academic Publishers)  Internet  Constraints Archive http://www.cs.unh.edu/ccc/archive


Download ppt "PSU CS 370 – Introduction to Artificial Intelligence 1 Constraint Satisfaction Problems Chapter 5."

Similar presentations


Ads by Google