CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
1
Constraint Satisf action CS 486/ 686 May 17, 2005 Universit y of - - PowerPoint PPT Presentation
Constraint Satisf action CS 486/ 686 May 17, 2005 Universit y of Wat erloo 1 CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart Outline What are CSPs? St andard search and CSPs I mprovement s Backt r acking
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
1
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
2
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
3
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
5
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
6
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
7
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
8
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
9
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
10
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
11
1,…
m} is t he set of const raint s
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
12
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
13
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
14
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
15
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
T WA NT SA Q NSW V
Const raint graph
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
16
1 2 3 4 5
Ni = {English, Spaniard, Japanese, I talian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Cof f ee, Milk, Fruit- juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, 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 I talian drinks Tea The Norwegian lives in the f irst house on the lef t The owner of the Green house drinks Cof f ee 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
Example from R and N, Annotations from Stanford CS121
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
17
1 2 3 4 5
Ni = {English, Spaniard, Japanese, I talian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Cof f ee, Milk, Fruit- juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, 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 I talian drinks Tea The Norwegian lives in the f irst house on the lef t The owner of the Green house drinks Cof f ee 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
(Ni = English) ⇔ (C
i = Red)
(Ni = J apanese) ⇔ (J i = Paint er) (N1 = Norwegian) lef t as an exercise (C
i = Whit e) ⇔ (C i+1 = Green)
(C
5 ≠ Whit e)
(C
1 ≠ Green)
Example from R and N, Annotations from Stanford CS121
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
18
1 2 3 4 5
Ni = {English, Spaniard, Japanese, I talian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Cof f ee, Milk, Fruit- juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, 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 I talian drinks Tea The Norwegian lives in the f irst house on the lef t The owner of the Green house drinks Cof f ee 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
(Ni = English) ⇔ (C
i = Red)
(Ni = J apanese) ⇔ (J i = Paint er) (N1 = Norwegian) (C
i = Whit e) ⇔ (C i+1 = Green)
(C
5 ≠ Whit e)
(C
1 ≠ Green)
unary const raint s Example from R and N, Annotations from Stanford CS121
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
19
1 2 3 4 5
Ni = {English, Spaniard, Japanese, I talian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Cof f ee, Milk, Fruit- juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, 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 I talian drinks Tea The Norwegian lives in the f irst house on the lef t The owner of the Green house drinks Cof f ee 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 , Ni ≠ Nj ∀ ∀ ∀ ∀i,j ∈[1,5], i≠j , C
i ≠ C j
Example from R and N, Annotations from Stanford CS121
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
20
1 2 3 4 5
Ni = {English, Spaniard, Japanese, I talian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Cof f ee, Milk, Fruit- juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, 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 I talian drinks Tea The Norwegian lives in the f irst house on the lef t
The owner of the Green house drinks Cof f ee 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
Example from R and N, Annotations from Stanford CS121
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
21
1 2 3 4 5
Ni = {English, Spaniard, Japanese, I talian, Norwegian} Ci = {Red, Green, White, Yellow, Blue} Di = {Tea, Cof f ee, Milk, Fruit- juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} Ai = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house
1 ≠
≠ ≠ ≠ Red The Spaniard has a Dog
≠ ≠ ≠ Dog The Japanese is a Painter The I talian drinks Tea The Norwegian lives in the f irst house on the lef t
The owner of the Green house drinks Cof f ee 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
≠ ≠ ≠ Violinist The Fox is in the house next to the Doctor’s The Horse is next to the Diplomat’s
Example from R and N, Annotations from Stanford CS121
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
22
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
23
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
24
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
25
binary const raint s
,Vn)
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
26
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
27
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
28
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
29
Dept h f irst search which chooses values f or one variable at a t ime Backt racks when a variable has no legal values t o assign
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
30
T WA NT SA Q NSW V
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
31
T WA NT SA Q NSW V WA=blue WA=green WA=red
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
32
T WA NT SA Q NSW V WA=blue WA=green WA=red NT=red NT=green NT=blue
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
33
T WA NT SA Q NSW V WA=blue WA=green WA=red NT=red NT=green SA=green NT=blue SA=red SA=blue
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
34
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
35
DNT={green, blue} DSA={green, blue} Dothers={red, green, blue} DSA={blue} DQ={blue, red} Dothers={red,green,blue}
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
36
SA is involved in 5 constraints
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
37
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
38
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
39
RGB RGB RGB RGB RGB RGB RGB T SA V NSW Q NT WA
T WA NT SA Q NSW V
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
40
RGB RGB RGB RGB RGB RGB R RGB RGB RGB RGB RGB RGB RGB T SA V NSW Q NT WA
T WA NT SA Q NSW V
Forward checking removes t he value Red of NT and of SA
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
41
RGB GB RGB RGB G GB R RGB GB RGB RGB RGB GB R RGB RGB RGB RGB RGB RGB RGB T SA V NSW Q NT WA
T WA NT SA Q NSW V
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
42
RGB B B RB G B R RGB B RGB RB G B R RGB GB RGB RGB RGB GB R RGB RGB RGB RGB RGB RGB RGB T SA V NSW Q NT WA
T WA NT SA Q NSW V
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
43
RGB B B RB G B R RGB B RGB RB G B R RGB GB RGB RGB RGB GB R RGB RGB RGB RGB RGB RGB RGB T SA V NSW Q NT WA
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
44
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
45
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
46
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
47
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
48
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
49
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
50
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
51
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
52
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
53
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
54
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
55
1 2 3 4 1 2 3 4
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
56
CS486/686 Lecture Slides (c) 2005 K. Larson and P. Poupart
57