constraint programming peter van beek university of waterloo
TRANSCRIPT
![Page 1: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/1.jpg)
Constraint Programming
Peter van Beek
University of Waterloo
![Page 2: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/2.jpg)
Applications
Reasoning tasks: abductive, diagnostic, temporal, spatial
Cognitive tasks: machine vision, natural language processing
Combinatorial tasks: scheduling, sequencing, planning
![Page 3: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/3.jpg)
Constraint Programming
CP = solve problems by specifying
constraints on acceptable solutions
Why CP? constraints often a natural part of problems once problem is modeled using constraints, wide
selection of solution techniques available
![Page 4: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/4.jpg)
Constraint-based problem solving
Model problem specify in terms of constraints on acceptable solutions define variables (denotations) and domains define constraints in some language
Solve model define search space / choose algorithm
– incremental assignment / backtracking search
– complete assignments / stochastic search
design/choose heuristics
Verify and analyze solution
![Page 5: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/5.jpg)
Model problem specify in terms of constraints on acceptable solutions define variables (denotations) and domains define constraints in some language
Solve model define search space / choose algorithm
– incremental assignment / backtracking search
– complete assignments / stochastic search
design/choose heuristics
Verify and analyze solution
Constraint-based problem solving
ConstraintSatisfactionProblem
![Page 6: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/6.jpg)
Constraint satisfaction problem
A CSP is defined by a set of variables a domain of values for each variable a set of constraints between variables
A solution is an assignment of a value to each variable that
satisfies the constraints
![Page 7: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/7.jpg)
Model problem specify in terms of constraints on acceptable solutions define variables (denotations) and domains define constraints in some language
Solve model define search space / choose algorithm
– incremental assignment / backtracking search
– complete assignments / stochastic search
design/choose heuristics
Verify and analyze solution
Constraint-based problem solving
![Page 8: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/8.jpg)
Example: Assembly line sequencing
What order should the cars be manufactured?
Constraints: even distributions changes in colors run length constraints
![Page 9: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/9.jpg)
Example: Scheduling
Algy Bertie Charlie Digby1st FT 60 Guardian 75 Express 5 Sun 902nd Guardian 30 Express 3 Guardian 15 FT 13rd Express 2 FT 25 FT 10 Guardian 14th Sun 5 Sun 10 Sun 30 Express 1
What is the earliest that they can all set of for school?
Four students, Algy, Bertie, Charlie, and Digby share a flat.Four newspapers are delivered.Each student reads the newspapers in a particular order and for a specified amount of time.Algy arises at 8:30, Bertie and Charlie at 8:45, Digby at 9:30.
![Page 10: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/10.jpg)
Schedule
Sun
8 am 9 10 11
Express
Guardian
FT
![Page 11: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/11.jpg)
Example: Graph coloring
Given k colors, does there exist a coloring of the nodes such that adjacent nodes are assigned different colors
![Page 12: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/12.jpg)
Example: 3-coloring
Variables: v1, v2 , v3 , v4 , v5
Domains: {1, 2, 3}
Constraints: vi vj if vi and vj
are adjacent
v2
v3
v1
v5
v4
![Page 13: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/13.jpg)
Example: 3-coloring
One solution:
v1 1
v2 2
v3 2
v4 1
v5 3
v2
v3
v1
v5
v4
![Page 14: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/14.jpg)
Example: Boolean satisfiability
Given a Boolean formula, does there exist a satisfying assignment (an assignment of true or false to each variable such that the formula evaluates to true)
![Page 15: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/15.jpg)
Example: 3-SAT
Variables: x1, x2 , x3 , x4 , x5
Domains: {True, False}
Constraints: (x1 x2 x4), (x2 x4 x5), (x3 x4 x5)
(x1 x2 x4) (x2 x4 x5) (x3 x4 x5)
![Page 16: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/16.jpg)
Example: 3-SAT
One solution:x1 False
x2 False
x3 False
x4 True
x5 False
(x1 x2 x4) (x2 x4 x5) (x3 x4 x5)
![Page 17: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/17.jpg)
Example: n-queens
Place n-queens on an n n board so that no pair of queens attacks each other
![Page 18: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/18.jpg)
Example: 4-queens
4
3
2
1
x1 x2 x3 x4Variables: x1, x2 , x3 , x4
Domains: {1, 2, 3, 4}
Constraints: xi xj and | xi - xj | | i - j |
![Page 19: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/19.jpg)
Example: 4-queens
One solution:
x1 2
x2 4
x3 1
x4 3 4
3
2
1
x1 x2 x3 x4
Q
Q
Q
Q
![Page 20: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/20.jpg)
Search tree for 4-queens
x1
x2
x3
x4
1 2 3 4
(1,1,1,1) (4,4,4,4)(2,4,1,3) (3,1,4,2)
![Page 21: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/21.jpg)
Specification of forward checking
Invariant:1 i c,c j n,
(xj, xi) is arc-consistent
x1 xc-1 xc xc+1 xn
currentpast future
![Page 22: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/22.jpg)
Forward checking
{2} {5}Q
Q
Q
1
1
11
1
1
1
1
1
2
2
2
22
2
3
3 3
33
{3}
{1,4,6}
{1,3,4}
{3,4,6}
x1 x5
x6
x3
x4
x2
4321 5 6 x1
x5
x6
x3
x4
x2
1
![Page 23: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/23.jpg)
Enforcing arc-consistency
{a, b, c} {a, b, c}<
xi xj
![Page 24: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/24.jpg)
Enforcing path-consistency
<
{a, b, c}
xi
{a, b, c}
xj
{a, b, c}
xk
<
<
![Page 25: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/25.jpg)
Search graph for 4-queens
(1,1,1,1)(1,1,4,2)
(2,4,1,3)
(3,1,4,2)
(1,1,1,2)
(1,1,1,3)
(1,1,1,4)(1,4,1,3)
(4,1,4,2)
0
0
4
6
1
3
41
1
![Page 26: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/26.jpg)
Stochastic search
Q
Q
Q x1
Q
Initial assignment
x2
x3
x4
1 12
Pick queen in conflict
Q
Q
Q x1
Q
x2
x3
x4
Move to min. conflicts
Q
Q
Q x1
Q
x2
x3
x4
0 2
Pick queen in conflict
Q
Q
Q x1
Q
x2
x3
x4
2
![Page 27: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/27.jpg)
Tractability
NP
NP-Complete
P
(SAT, TSP, ILP, CSP, …)
![Page 28: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/28.jpg)
Reducibility
NP-Complete
3-SAT
ILP
CSP binary CSP
(0,1)-ILP
![Page 29: Constraint Programming Peter van Beek University of Waterloo](https://reader036.vdocuments.net/reader036/viewer/2022062417/5515ca4355034689058b49ab/html5/thumbnails/29.jpg)
CSP, binary CSP, SAT, 3-SAT, ILP, ...
Model and solve in one of these languages Model in one language, translate into
another to solve
Options