© J. Christopher Beck 20081 Lecture 5: Graph Theory and Longest Paths.
© J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.
-
Upload
osborn-henderson -
Category
Documents
-
view
216 -
download
0
Transcript of © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.
![Page 1: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/1.jpg)
© J. Christopher Beck 2008 1
Lecture 13:Modeling inConstraint Programming
![Page 2: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/2.jpg)
© J. Christopher Beck 2008 2
Outline Introduction
The Crystal Maze Heuristics, Propagation, B&B
Modeling in CP
![Page 3: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/3.jpg)
© J. Christopher Beck 2008 3
Readings
P Ch 5.5, D.2, D.3
B.M. Smith, “Modelling”, The Handbook of Constraint Programming, 2006.
![Page 4: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/4.jpg)
© J. Christopher Beck 2008 4
Crystal Maze Place the numbers 1 through 8 in the
nodes such that: Each number appears exactly once
?
?
?
?
?
?
??
– No connected nodes have consecutive numbers
You have 5 minutes!
![Page 5: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/5.jpg)
© J. Christopher Beck 2008 5
Modeling
Each node a variable {1, …, 8} values in the domain of
each variable No consecutive numbers a
constraint (vi, vj) |vi – vj| > 1
All values used all-different constraint
![Page 6: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/6.jpg)
© J. Christopher Beck 2008 6
Heuristic Search
?
?
?
?
?
?
?? 1 8
{1, 2, 3, 4, 5, 6, 7, 8}
![Page 7: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/7.jpg)
© J. Christopher Beck 2008 7
Inference/Propagation
?
?
?
?
?
?
?? 1 8
{1, 2, 3, 4, 5, 6, 7, 8}
{1, 2, 3, 4, 5, 6, 7, 8}
![Page 8: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/8.jpg)
© J. Christopher Beck 2008 8
Inference/Propagation
?
?
?
?
?
?
?? 1 8
{3, 4, 5, 6}
7 2
{3, 4, 5, 6}
{3, 4, 5, 6} {3, 4, 5, 6}
64
3 5
{3, 4, 5, 6, 7} {2, 3, 4, 5, 6}
![Page 9: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/9.jpg)
© J. Christopher Beck 2008 9
Generic CP Algorithm
AssertCommitment
Propagators
Start
SuccessSolution?
MakeHeuristicDecision
BacktrackTechnique
Failure
Nothing toretract?
Dead-end?
![Page 10: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/10.jpg)
© J. Christopher Beck 2008 10
With CP You Are …
Guaranteed to find a solution if one exists If not you can prove there is no solution
But you need to have enough time! On average, for many problems you can
find a solution within a reasonable time CP is commercially successful for
scheduling and other applications
Questions?
![Page 11: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/11.jpg)
© J. Christopher Beck 2008 11
The Core of CP
Modeling How to represent the problem
Heuristic search How to branch How much effort to find a good branch
Inference/propagation How much effort
Backtracking
![Page 12: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/12.jpg)
© J. Christopher Beck 2008 12
Constraint Satisfaction Problem (CSP)
Given: V, a set of variables {v0, v1, …, vn} D, a set of domains {D0, D1, …, Dn} C, a set of constraints {c0, c1, …, cm}
Each constraint, ci, has a scope ci(v0, v2, v4, v117, …), the variables that it constrains
![Page 13: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/13.jpg)
© J. Christopher Beck 2008 13
Constraint Satisfaction Problem (CSP)
A constraint, ci, is a mapping from the elements of the Cartesian product of the domains of the variables in its scope to {T,F} ci(v0, v2, v4, v117, …) maps:
(D0 X D2 X D4 X D117 X … ) {T,F}
A constraint is satisfied if the assignment of the variables in its scope are mapped to T
![Page 14: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/14.jpg)
© J. Christopher Beck 2008 14
Constraint Satisfaction Problem (CSP)
In a solution to a CSP: each variable is assigned a value
from its domain: vi = di, di є Di
each constraint is satisfied
![Page 15: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/15.jpg)
© J. Christopher Beck 2008 15
Variables & Constraints
Variables can be anything colors, times, countries, … often integer valued or binary
Constraints are not limited to linear constraints extensional: list of acceptable value-
combinations intensional: mathematical expression
![Page 16: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/16.jpg)
© J. Christopher Beck 2008 16
Examples
V = {v1, v2, …, vn} Di = {1, 2, …, n} all-diff(v1, v2, …, vn)
each of the variables must take on a different value
v1 > v2 + v4
v4 = v5 * v6
![Page 17: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/17.jpg)
© J. Christopher Beck 2008 17
n-Queens Problem
Place n-Queens on the chess board so that no queen can attack any other
![Page 18: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/18.jpg)
© J. Christopher Beck 2008 18
n-Queens Problem
Variables? Constraints?
![Page 19: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/19.jpg)
© J. Christopher Beck 2008 19
n-Queens Problem
How about a different model?
![Page 20: © J. Christopher Beck 20081 Lecture 13: Modeling in Constraint Programming.](https://reader036.fdocuments.in/reader036/viewer/2022082518/56649ed35503460f94be33db/html5/thumbnails/20.jpg)
© J. Christopher Beck 2008 20
Why Do We Care About Modeling?
You need to represent your problem!
As in MIP/LP different models are harder or easier to solve
We will return to CP modeling (in a big way) in a few weeks