Chapter 3 Constraint Programming Paragraph 1 Puzzles, Domains, and - - PowerPoint PPT Presentation
Chapter 3 Constraint Programming Paragraph 1 Puzzles, Domains, and - - PowerPoint PPT Presentation
Chapter 3 Constraint Programming Paragraph 1 Puzzles, Domains, and Constraints Who Owns the Fish? 1. The Brit lives in the red house. 2. The Swede keeps dogs as pets. 3. The Dane drinks tea. 4. The green house is on the left of the white
CS 195 - Intro to CO 2
Who Owns the Fish?
1. The Brit lives in the red house. 2. The Swede keeps dogs as pets. 3. The Dane drinks tea. 4. The green house is on the left of the white house. 5. The green house's owner drinks coffee. 6. The person who smokes Pall Mall rears birds. 7. The owner of the yellow house smokes Dunhill. 8. The man living in the center house drinks milk. 9. The Norwegian lives in the first house. 10. The man who smokes Blends lives next to the one who keeps cats. 11. The man who keeps the horse lives next to the man who smokes Dunhill. 12. The owner who smokes Bluemasters drinks beer. 13. The German smokes Prince. 14. The Norwegian lives next to the blue house. 15. The man who smokes Blends has a neighbor who drinks water.
CS 195 - Intro to CO 3
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
CS 195 - Intro to CO 4
Constrained Programming – An Archeological Puzzle
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A DA CA CE A E A DE CA AB
+ + + + + + = = =
D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 5
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 6
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 7
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 8
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 9
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 10
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 11
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 12
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 13
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 14
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 15
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 16
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 17
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 18
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 19
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 20
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 21
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 22
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 23
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 24
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 25
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 26
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 27
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 28
Constrained Programming – An Archeological Puzzle
DA CA CE A E A DE CA AB
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 29
Constrained Programming – An Archeological Puzzle
41 21 20 1 1 40 21 19
+ + + + + + = = =
0,1,2,3,4,5,6,7,8,9 E 0,1,2,3,4,5,6,7,8,9 D 0,1,2,3,4,5,6,7,8,9 C 0,1,2,3,4,5,6,7,8,9 B 0,1,2,3,4,5,6,7,8,9 A D+1=D D=D AllDiff(A,B,C,D,E) 2C+1=D 2C=D E+A=A+10 E+A=A A+1=C A=C A+C+1=D A+C=D B+A=E+10 B+A=E
CS 195 - Intro to CO 30
Who Owns the Fish?
1. The Brit lives in the red house. 2. The Swede keeps dogs as pets. 3. The Dane drinks tea. 4. The green house is on the left of the white house. 5. The green house's owner drinks coffee. 6. The person who smokes Pall Mall rears birds. 7. The owner of the yellow house smokes Dunhill. 8. The man living in the center house drinks milk. 9. The Norwegian lives in the first house. 10. The man who smokes Blends lives next to the one who keeps cats. 11. The man who keeps the horse lives next to the man who smokes Dunhill. 12. The owner who smokes Bluemasters drinks beer. 13. The German smokes Prince. 14. The Norwegian lives next to the blue house. 15. The man who smokes Blends has a neighbor who drinks water.
CS 195 - Intro to CO 31
Constraint Programming
- Model a combinatorial problem through
– Variables X with Domains D(X) – Constraints
X2 X3 X1