constraint programming overview based on...
TRANSCRIPT
![Page 1: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/1.jpg)
DM841
Discrete Optimization
Part I
Lecture 2Constraint Programming Overview
based on Examples
Marco Chiarandini
Department of Mathematics & Computer ScienceUniversity of Southern Denmark
![Page 2: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/2.jpg)
Outline
1. An Initial Example
2. Constraint
3. Send More MoneyPoints to RememberModeling in MILP
2
![Page 3: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/3.jpg)
Put a different number in each circle (1 to 8) such that adjacent circles cannot take consecutive numbers
![Page 4: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/4.jpg)
Constraint Programming An Introduction
by example
Patrick Prosser with the help of Toby Walsh, Chris Beck,
Barbara Smith, Peter van Beek, Edward Tsang, ...
![Page 5: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/5.jpg)
A Puzzle
• Place numbers 1 through 8 on nodes – Each number appears exactly once
?
?
?
?
?
?
? ?
– No connected nodes have consecutive numbers
You have 8 minutes!
![Page 6: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/6.jpg)
Heuristic Search Which nodes are hardest to number?
?
?
?
?
?
?
? ?
![Page 7: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/7.jpg)
Heuristic Search
?
?
?
?
?
?
? ?
![Page 8: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/8.jpg)
Heuristic Search
?
?
?
?
?
?
? ?
Which are the least constraining values to use?
![Page 9: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/9.jpg)
Heuristic Search
?
1
?
?
8
?
? ?
Values 1 and 8
![Page 10: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/10.jpg)
Heuristic Search
?
1
?
?
8
?
? ?
Values 1 and 8
Symmetry means we don’t need to consider: 8 1
![Page 11: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/11.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
We can now eliminate many values for other nodes
![Page 12: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/12.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{1,2,3,4,5,6,7,8}
![Page 13: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/13.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{2,3,4,5,6,7}
![Page 14: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/14.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{3,4,5,6}
![Page 15: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/15.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{3,4,5,6}
By symmetry
{3,4,5,6}
![Page 16: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/16.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{3,4,5,6}
{3,4,5,6}
{1,2,3,4,5,6,7,8}
![Page 17: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/17.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{3,4,5,6}
{3,4,5,6}
{2,3,4,5,6,7}
![Page 18: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/18.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{3,4,5,6}
{3,4,5,6}
{3,4,5,6}
![Page 19: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/19.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{3,4,5,6}
By symmetry
{3,4,5,6}
{3,4,5,6}
{3,4,5,6}
![Page 20: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/20.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{3,4,5,6}
{3,4,5,6,7}
{3,4,5,6}
{3,4,5,6}
{3,4,5,6}
{2,3,4,5,6}
![Page 21: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/21.jpg)
Inference/propagation
?
1
?
?
8
?
? ?
{3,4,5,6}
{3,4,5,6,7}
{3,4,5,6}
{3,4,5,6}
{3,4,5,6}
{2,3,4,5,6}
Value 2 and 7 are left in just one variable domain each
![Page 22: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/22.jpg)
Inference/propagation
?
1
?
?
8
?
2 7
{3,4,5,6}
{3,4,5,6,7}
{3,4,5,6}
{3,4,5,6}
{3,4,5,6}
{2,3,4,5,6}
And propagate …
![Page 23: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/23.jpg)
Inference/propagation
?
1
?
?
8
?
2 7
{3,4,5}
{3,4,5,6,7}
{3,4,5}
{3,4,5,6}
{3,4,5,6}
{2,3,4,5,6}
And propagate …
![Page 24: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/24.jpg)
Inference/propagation
?
1
?
?
8
?
2 7
{3,4,5}
{3,4,5,6,7}
{3,4,5}
{4,5,6}
{4,5,6}
{2,3,4,5,6}
And propagate …
![Page 25: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/25.jpg)
Inference/propagation
?
1
?
?
8
?
2 7
{3,4,5}
{3,4,5}
{4,5,6}
{4,5,6}
Guess a value, but be prepared to backtrack …
![Page 26: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/26.jpg)
Inference/propagation
3
1
?
?
8
?
2 7
{3,4,5}
{3,4,5}
{4,5,6}
{4,5,6}
Guess a value, but be prepared to backtrack …
![Page 27: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/27.jpg)
Inference/propagation
3
1
?
?
8
?
2 7
{3,4,5}
{3,4,5}
{4,5,6}
{4,5,6}
And propagate …
![Page 28: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/28.jpg)
Inference/propagation
3
1
?
?
8
?
2 7
{4,5}
{5,6}
{4,5,6}
And propagate …
![Page 29: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/29.jpg)
Inference/propagation
3
1
?
?
8
?
2 7
{4,5}
{5,6}
{4,5,6}
Guess another value …
![Page 30: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/30.jpg)
Inference/propagation
3
1
?
5
8
?
2 7
{4,5} {4,5,6}
Guess another value …
![Page 31: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/31.jpg)
Inference/propagation
3
1
?
5
8
?
2 7
{4,5} {4,5,6}
And propagate …
![Page 32: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/32.jpg)
Inference/propagation
3
1
?
5
8
?
2 7
{4} {4,6}
And propagate …
![Page 33: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/33.jpg)
Inference/propagation
3
1
4
5
8
?
2 7
{4} {4,6}
One node has only a single value left …
![Page 34: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/34.jpg)
Inference/propagation
3
1
4
5
8
6
2 7
{6}
![Page 35: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/35.jpg)
Solution
3
1
4
5
8
6
2 7
![Page 36: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/36.jpg)
The Core of Constraint Computation
• Modelling – Deciding on variables/domains/constraints
• Heuristic Search • Inference/Propagation • Symmetry • Backtracking
![Page 37: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/37.jpg)
Hardness
• The puzzle is actually a hard problem – NP-complete
![Page 38: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/38.jpg)
Constraint programming
• Model problem by specifying constraints on acceptable solutions – define variables and domains – post constraints on these variables
• Solve model – choose algorithm
• incremental assignment / backtracking search • complete assignments / stochastic search
– design heuristics
![Page 39: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/39.jpg)
Example CSP • Variable, vi for each node • Domain of {1, …, 8} • Constraints
– All values used allDifferent(v1 v2 v3 v4 v5 v6 v7 v8) – No consecutive numbers for
adjoining nodes |v1 - v2 | > 1 |v1 - v3 | > 1 …
?
?
?
?
?
?
? ?
![Page 40: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/40.jpg)
Outline
1. An Initial Example
2. Constraint
3. Send More MoneyPoints to RememberModeling in MILP
3
![Page 41: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/41.jpg)
Constraint Programming - in a nutshell
I Declarative description of problems withI Variables which range over (finite) sets of valuesI Constraints over subsets of variables which restrict possible value
combinationsI A solution is a value assignment which satisfies all constraints
I Constraint propagation/reasoningI Removing inconsistent values for variablesI Detect failure if constraint can not be satisfiedI Interaction of constraints via shared variablesI Incomplete
I SearchI User controlled assignment of values to variablesI Each step triggers constraint propagation
I Different domains require/allow different methods
4
![Page 42: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/42.jpg)
Constraint Programming
Constraint Programming: an alternative approach to imperative programmingand object oriented programming.
I Variables each with a finite set of possible values (domain)
I Constraint on a sequence of variables: a relationship on their domains
Constraint Satisfaction Problem: finite set of constraints
5
![Page 43: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/43.jpg)
CP
Constraint Programming = model (representation) +propagation (reasoning, inference) +search (reasoning, inference)
6
![Page 44: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/44.jpg)
Basic Process
Problem
Human
Model
Constraint Solver/Search
Solution
Insight Centre for Data Analytics Slide 9June 20th, 2016
![Page 45: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/45.jpg)
More Realistic
Problem
Human
Model
Constraint Solver/Search
Hangs Solution Wrong Solution
Insight Centre for Data Analytics Slide 10June 20th, 2016
![Page 46: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/46.jpg)
Dual Role of Model
• Allows Human to Express Problem• Close to Problem Domain• Constraints as Abstractions
• Allows Solver to Execute• Variables as Communication Mechanism• Constraints as Algorithms
Insight Centre for Data Analytics Slide 11June 20th, 2016
![Page 47: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/47.jpg)
Modelling Frameworks
• MiniZinc (NICTA, Australia)
• NumberJack (Insight, Ireland)
• Essence (UK)
• Allow use of multiple back-end solvers
• Compile model into variants for each solver
• A priori solver independent model(CP, MIP, SAT)
Insight Centre for Data Analytics Slide 12June 20th, 2016
![Page 48: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/48.jpg)
Framework Process
Problem
Human
Model
Compile/Reformulate
CP MIP SAT Other
Solution Solution Solution Solution
Insight Centre for Data Analytics Slide 13June 20th, 2016
![Page 49: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/49.jpg)
Computational Models
Three main Computational Models to solve (combinatorial) constrainedoptimization problems:
I Mathematical Programming (LP, ILP, QP, SDP, ...)
I Constraint Programming (CSP as a model, SAT as a very special case)
I Local Search (... and Meta-heuristics)
I Others? Dynamic programming, dedicated algorithms, satisfiabilitymodulo theory, answer set programming, etc.
7
![Page 50: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/50.jpg)
Modeling
Modeling:
1. identify:I parametersI variablesI domainsI constraintsI objective function
that formulate the problem
2. express what in point 1) in a way that allows the solution by availablesoftware
8
![Page 51: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/51.jpg)
Variables
In MILP: real and integer (mostly binary) variables
In CP:
I finite domain integer (including Booleans),
I continuos with interval constraints
I structured domains: finite sets, multisets, graphs, ...
In LS: integer variables
9
![Page 52: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/52.jpg)
Constraint Programming vs MILP
I In MILP we formulate problems as a set of linear inequalities
I In CP we describe substructures (so-called global constraints) andcombine them with various combinators.
I Substructures capture building blocks often (but not always)comptuationally tractable by special-purpose algorithms
I CP models can:I be solved by the constraint engineI be linearized and solved by their MIP solvers;I be translated in CNF and solved by SAT solvers;I be handled by local search
I In MILP the solver is often seen as a black-boxIn CP and LS solvers leave the user the task of programming the search.
I CP = model + propagation + searchconstraint propagation by domain filtering inferencesearch = backtracking or branch and bound or local search
10
![Page 53: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/53.jpg)
Outline
1. An Initial Example
2. Constraint
3. Send More MoneyPoints to RememberModeling in MILP
11
![Page 54: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/54.jpg)
Aims
I Example of Finite Domain Constraint Problem
I Models and Programs
I Constraint Propagation and Search
I Some Basic Constraints:linear arithmetic, alldifferent, disequality
I A Built-in search
I Visualizers for variables, constraints and search
12
![Page 55: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/55.jpg)
Problem: Send + More = Money
Send + More = Money
You are asked to replace each letter by a different digit so that
S E N D +M O R E =
M O N E Y
is correct. Because S and M are the leading digits, they cannot be equal tothe 0 digit.
13
![Page 56: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/56.jpg)
Modelling
1. Parameters
2. Variables (ie, solution representation)
3. Domains (ie, allowed values for the variables)
4. Constraints
Later Objective Function
14
![Page 57: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/57.jpg)
Model
I Each character is a variable, which ranges over the values 0 to 9.
I An alldifferent constraint between all variables, which states that twodifferent variables must have different values. This is a very commonconstraint, which we will encounter in many other problems later on.
I Two disequality constraints (variable X must be different from value V )stating that the variables at the beginning of a number can not take thevalue 0.
I An arithmetic equality constraint linking all variables with the propercoefficients and stating that the equation must hold.
15
![Page 58: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/58.jpg)
Send More Money: CP model
SEND + MORE = MONEY
I Xi ∈ {0, . . . , 9} for all i ∈ I = {S ,E ,N,D,M,O,R,Y }
I Each letter takes a different digit 1 inequality constraint
alldifferent([X1,X2, . . . ,X8]).
(it substitutes 28 inequality constraints: Xi 6= Xj , i , j ∈ I , i 6= j)
I XM 6= 0, XS 6= 0
I Crypto constraint 1 equality constraint:103X1 +102X2 +10X3 +X4 +103X5 +102X6 +10X7 +X2 =
104X5 +103X6 +102X3 +10X2 +X8
16
![Page 59: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/59.jpg)
I This is one model, not the model of the problem
I Many possible alternatives
I Choice often depends on the constraint system availableConstraints availableReasoning attached to constraints
I Not always clear which is the best model
17
![Page 60: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/60.jpg)
Send More Money: CP modelGecode-python
from gecode import *
s = space()letters = s.intvars(8,0,9)S,E,N,D,M,O,R,Y = letterss.rel(M,IRT_NQ,0)s.rel(S,IRT_NQ,0)s.distinct(letters)C = [1000, 100, 10, 1,
1000, 100, 10, 1,-10000, -1000, -100, -10, -1]
X = [S,E,N,D,M,O,R,E,M,O,N,E,Y]
s.linear(C,X, IRT_EQ, 0)s.branch(letters, INT_VAR_SIZE_MIN, INT_VAL_MIN)for s2 in s.search():
print(s2.val(letters))
18
![Page 61: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/61.jpg)
Send More Money: CP modelMiniZinc
19
![Page 62: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/62.jpg)
Program Sendmory
:- module(sendmory).:- export(sendmory/1).:- lib(ic).sendmory(L):-
L = [S,E,N,D,M,O,R,Y],L :: 0..9,alldifferent(L),S #\= 0, M #\= 0,1000*S + 100*E + 10*N + D +1000*M + 100*O + 10*R + E #=10000*M + 1000*O + 100*N + 10*E + Y,labeling(L).
Insight Centre for Data Analytics Slide 21June 20th, 2016
![Page 63: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/63.jpg)
Question
But how did the program come up with this solution?
20
![Page 64: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/64.jpg)
Constraint Setup
I Domain Definition
I Alldifferent Constraint
I Disequality Constraints
I Equality Constraint
21
![Page 65: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/65.jpg)
The following slides are taken from H. Simonis: H. Simonis’ demo, slides33-134 and his tutorial at ACP2016.
22
![Page 66: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/66.jpg)
Domain Definition
L = [S,E,N,D,M,O,R,Y],L :: 0..9,
[S,E ,N,D,M,O,R,Y ] ∈ {0..9}
Insight Centre for Data Analytics Slide 31June 20th, 2016
![Page 67: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/67.jpg)
Domain Visualization
0 1 2 3 4 5 6 7 8 9SENDMORY
Insight Centre for Data Analytics Slide 32June 20th, 2016
![Page 68: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/68.jpg)
Domain Visualization
Rows =Variables
0 1 2 3 4 5 6 7 8 9SENDMORY
Insight Centre for Data Analytics Slide 32June 20th, 2016
![Page 69: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/69.jpg)
Domain Visualization
Columns = Values0 1 2 3 4 5 6 7 8 9
SENDMORY
Insight Centre for Data Analytics Slide 32June 20th, 2016
![Page 70: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/70.jpg)
Domain Visualization
Cells= State
0 1 2 3 4 5 6 7 8 9SENDMORY
Insight Centre for Data Analytics Slide 32June 20th, 2016
![Page 71: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/71.jpg)
Alldifferent Constraint
alldifferent(L),
• Built-in of ic library
• No initial propagation possible
• Suspends, waits until variables are changed
• When variable is fixed, remove value from domain ofother variables
• Forward checking
Insight Centre for Data Analytics Slide 33June 20th, 2016
![Page 72: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/72.jpg)
Alldifferent Visualization
Uses the same representation as the domain visualizer
0 1 2 3 4 5 6 7 8 9SENDMORY
Insight Centre for Data Analytics Slide 34June 20th, 2016
![Page 73: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/73.jpg)
Disequality Constraints
S #\= 0, M#\= 0,
Remove value from domain
S ∈ {1..9},M ∈ {1..9}
Constraints solved, can be removed
Insight Centre for Data Analytics Slide 35June 20th, 2016
![Page 74: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/74.jpg)
Domains after Disequality
0 1 2 3 4 5 6 7 8 9SENDMORY
Insight Centre for Data Analytics Slide 36June 20th, 2016
![Page 75: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/75.jpg)
Equality Constraint
• Normalization of linear terms• Single occurence of variable• Positive coefficients
• Propagation
Insight Centre for Data Analytics Slide 37June 20th, 2016
![Page 76: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/76.jpg)
Normalization
1000*S+ 100*E+ 10*N+ D+1000*M+ 100*O+ 10*R+ E
10000*M+ 1000*O+ 100*N+ 10*E+ Y
Insight Centre for Data Analytics Slide 38June 20th, 2016
![Page 77: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/77.jpg)
Normalization
1000*S+ 100*E+ 10*N+ D+1000*M+ 100*O+ 10*R+ E
10000*M+ 1000*O+ 100*N+ 10*E+ Y
Insight Centre for Data Analytics Slide 38June 20th, 2016
![Page 78: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/78.jpg)
Normalization
1000*S+ 100*E+ 10*N+ D+ 100*O+ 10*R+ E
9000*M+ 1000*O+ 100*N+ 10*E+ Y
Insight Centre for Data Analytics Slide 38June 20th, 2016
![Page 79: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/79.jpg)
Normalization
1000*S+ 100*E+ 10*N+ D+ 100*O+ 10*R+ E
9000*M+ 1000*O+ 100*N+ 10*E+ Y
Insight Centre for Data Analytics Slide 38June 20th, 2016
![Page 80: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/80.jpg)
Normalization
1000*S+ 100*E+ 10*N+ D+ 10*R+ E
9000*M+ 900*O+ 100*N+ 10*E+ Y
Insight Centre for Data Analytics Slide 38June 20th, 2016
![Page 81: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/81.jpg)
Normalization
1000*S+ 100*E+ 10*N+ D+ 10*R+ E
9000*M+ 900*O+ 100*N+ 10*E+ Y
Insight Centre for Data Analytics Slide 38June 20th, 2016
![Page 82: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/82.jpg)
Normalization
1000*S+ 100*E+ D+ 10*R+ E
9000*M+ 900*O+ 90*N+ 10*E+ Y
Insight Centre for Data Analytics Slide 38June 20th, 2016
![Page 83: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/83.jpg)
Normalization
1000*S+ 100*E+ D+ 10*R+ E
9000*M+ 900*O+ 90*N+ 10*E+ Y
Insight Centre for Data Analytics Slide 38June 20th, 2016
![Page 84: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/84.jpg)
Normalization
1000*S+ 91*E+ D+ 10*R
9000*M+ 900*O+ 90*N+ Y
Insight Centre for Data Analytics Slide 38June 20th, 2016
![Page 85: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/85.jpg)
Simplified Equation
1000∗S+91∗E +10∗R+D = 9000∗M +900∗O+90∗N +Y
Insight Centre for Data Analytics Slide 39June 20th, 2016
![Page 86: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/86.jpg)
Propagation
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9 =
9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9
Insight Centre for Data Analytics Slide 40June 20th, 2016
![Page 87: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/87.jpg)
Propagation
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸
1000..9918
=
9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸
9000..89919
Insight Centre for Data Analytics Slide 40June 20th, 2016
![Page 88: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/88.jpg)
Propagation
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸
9000..9918
=
9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸
9000..9918
Insight Centre for Data Analytics Slide 40June 20th, 2016
![Page 89: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/89.jpg)
Propagation
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸
9000..9918
=
9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸
9000..9918
Deduction:M = 1,S = 9,O ∈ {0..1}
Insight Centre for Data Analytics Slide 40June 20th, 2016
![Page 90: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/90.jpg)
Propagation
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸
9000..9918
=
9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸
9000..9918
Deduction:M = 1,S = 9,O ∈ {0..1}
Why? Skip
Insight Centre for Data Analytics Slide 40June 20th, 2016
![Page 91: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/91.jpg)
Consider lower bound for S
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸
9000..9918
= 9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸
9000..9918
• Lower bound of equation is 9000
• Rest of lhs (left hand side) (91 ∗ E0..9 + 10 ∗ R0..9 + D0..9)is atmost 918
• S must be greater or equal to 9000−9181000 = 8.082
• otherwise lower bound of equation not reached by lhs
• S is integer, therefore S ≥ d9000−9181000 e = 9
• S has upper bound of 9, so S = 9
Insight Centre for Data Analytics Slide 41June 20th, 2016
![Page 92: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/92.jpg)
Consider upper bound of M
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸
9000..9918
= 9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸
9000..9918
• Upper bound of equation is 9918
• Rest of rhs (right hand side) 900 ∗O0..9 + 90 ∗N0..9 + Y 0..9
is at least 0
• M must be smaller or equal to 9918−09000 = 1.102
• M must be integer, therefore M ≤ b9918−09000 c = 1
• M has lower bound of 1, so M = 1
Insight Centre for Data Analytics Slide 42June 20th, 2016
![Page 93: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/93.jpg)
Consider upper bound of O
1000 ∗ S1..9 + 91 ∗ E0..9 + 10 ∗ R0..9 + D0..9︸ ︷︷ ︸
9000..9918
= 9000 ∗M1..9 + 900 ∗O0..9 + 90 ∗ N0..9 + Y 0..9︸ ︷︷ ︸
9000..9918
• Upper bound of equation is 9918
• Rest of rhs (right hand side) 9000 ∗ 1 + 90 ∗ N0..9 + Y 0..9 isat least 9000
• O must be smaller or equal to 9918−9000900 = 1.02
• O must be integer, therefore O ≤ b9918−9000900 c = 1
• O has lower bound of 0, so O ∈ {0..1}
Insight Centre for Data Analytics Slide 43June 20th, 2016
![Page 94: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/94.jpg)
Propagation of equality: Result
0 1 2 3 4 5 6 7 8 9S - - - - - - - - Y
ENDM Y - - - - - - - -O 6 6 6 6 6 6 6 6
RY
Insight Centre for Data Analytics Slide 44June 20th, 2016
![Page 95: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/95.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9S - - - - - - - - Y
ENDM Y - - - - - - - -O 6 6 6 6 6 6 6 6
RY
Insight Centre for Data Analytics Slide 45June 20th, 2016
![Page 96: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/96.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9S Y
E |N |D |M Y
OR |Y |
Insight Centre for Data Analytics Slide 45June 20th, 2016
![Page 97: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/97.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SE |N |D |M Y
O |R |Y |
Insight Centre for Data Analytics Slide 45June 20th, 2016
![Page 98: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/98.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SENDMO Y
RY
Insight Centre for Data Analytics Slide 45June 20th, 2016
![Page 99: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/99.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SE |N |D |MO Y
R |Y |
Insight Centre for Data Analytics Slide 45June 20th, 2016
![Page 100: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/100.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SENDMORY
O = 0, [E ,R,D,N,Y ] ∈ {2..8}
Insight Centre for Data Analytics Slide 45June 20th, 2016
![Page 101: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/101.jpg)
Waking the equality constraint
• Triggered by assignment of variables
• or update of lower or upper bound
Insight Centre for Data Analytics Slide 46June 20th, 2016
![Page 102: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/102.jpg)
Removal of constants
1000 ∗ 9 + 91 ∗ E2..8 + 10 ∗ R2..8 + D2..8 =
9000 ∗ 1 + 900 ∗ 0 + 90 ∗ N2..8 + Y 2..8
Insight Centre for Data Analytics Slide 47June 20th, 2016
![Page 103: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/103.jpg)
Removal of constants
1000 ∗ 9 + 91 ∗ E2..8 + 10 ∗ R2..8 + D2..8 =
9000 ∗ 1 + 900 ∗ 0 + 90 ∗ N2..8 + Y 2..8
Insight Centre for Data Analytics Slide 47June 20th, 2016
![Page 104: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/104.jpg)
Removal of constants
91 ∗ E2..8 + 10 ∗ R2..8 + D2..8 = 90 ∗ N2..8 + Y 2..8
Insight Centre for Data Analytics Slide 47June 20th, 2016
![Page 105: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/105.jpg)
Propagation of equality (Iteration 1)
91 ∗ E2..8 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸
204..816
= 90 ∗ N2..8 + Y 2..8︸ ︷︷ ︸
182..728
Insight Centre for Data Analytics Slide 48June 20th, 2016
![Page 106: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/106.jpg)
Propagation of equality (Iteration 1)
91 ∗ E2..8 + 10 ∗ R2..8 + D2..8 = 90 ∗ N2..8 + Y 2..8︸ ︷︷ ︸
204..728
Insight Centre for Data Analytics Slide 48June 20th, 2016
![Page 107: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/107.jpg)
Propagation of equality (Iteration 1)
91 ∗ E2..8 + 10 ∗ R2..8 + D2..8 = 90 ∗ N2..8 + Y 2..8︸ ︷︷ ︸
204..728
N ≥ 3 = d204− 890
e,E ≤ 7 = b728− 2291
c
Insight Centre for Data Analytics Slide 48June 20th, 2016
![Page 108: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/108.jpg)
Propagation of equality (Iteration 2)
91 ∗ E2..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8
Insight Centre for Data Analytics Slide 49June 20th, 2016
![Page 109: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/109.jpg)
Propagation of equality (Iteration 2)
91 ∗ E2..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸
204..725
= 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸
272..728
Insight Centre for Data Analytics Slide 49June 20th, 2016
![Page 110: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/110.jpg)
Propagation of equality (Iteration 2)
91 ∗ E2..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸
272..725
Insight Centre for Data Analytics Slide 49June 20th, 2016
![Page 111: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/111.jpg)
Propagation of equality (Iteration 2)
91 ∗ E2..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸
272..725
E ≥ 3 = d272− 8891
e
Insight Centre for Data Analytics Slide 49June 20th, 2016
![Page 112: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/112.jpg)
Propagation of equality (Iteration 3)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8
Insight Centre for Data Analytics Slide 50June 20th, 2016
![Page 113: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/113.jpg)
Propagation of equality (Iteration 3)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸
295..725
= 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸
272..728
Insight Centre for Data Analytics Slide 50June 20th, 2016
![Page 114: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/114.jpg)
Propagation of equality (Iteration 3)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸
295..725
Insight Centre for Data Analytics Slide 50June 20th, 2016
![Page 115: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/115.jpg)
Propagation of equality (Iteration 3)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N3..8 + Y 2..8︸ ︷︷ ︸
295..725
N ≥ 4 = d295− 890
e
Insight Centre for Data Analytics Slide 50June 20th, 2016
![Page 116: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/116.jpg)
Propagation of equality (Iteration 4)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8
Insight Centre for Data Analytics Slide 51June 20th, 2016
![Page 117: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/117.jpg)
Propagation of equality (Iteration 4)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸
295..725
= 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸
362..728
Insight Centre for Data Analytics Slide 51June 20th, 2016
![Page 118: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/118.jpg)
Propagation of equality (Iteration 4)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸
362..725
Insight Centre for Data Analytics Slide 51June 20th, 2016
![Page 119: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/119.jpg)
Propagation of equality (Iteration 4)
91 ∗ E3..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸
362..725
E ≥ 4 = d362− 8891
e
Insight Centre for Data Analytics Slide 51June 20th, 2016
![Page 120: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/120.jpg)
Propagation of equality (Iteration 5)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8
Insight Centre for Data Analytics Slide 52June 20th, 2016
![Page 121: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/121.jpg)
Propagation of equality (Iteration 5)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸
386..725
= 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸
362..728
Insight Centre for Data Analytics Slide 52June 20th, 2016
![Page 122: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/122.jpg)
Propagation of equality (Iteration 5)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸
386..725
Insight Centre for Data Analytics Slide 52June 20th, 2016
![Page 123: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/123.jpg)
Propagation of equality (Iteration 5)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N4..8 + Y 2..8︸ ︷︷ ︸
386..725
N ≥ 5 = d386− 890
e
Insight Centre for Data Analytics Slide 52June 20th, 2016
![Page 124: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/124.jpg)
Propagation of equality (Iteration 6)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8
Insight Centre for Data Analytics Slide 53June 20th, 2016
![Page 125: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/125.jpg)
Propagation of equality (Iteration 6)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸
386..725
= 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸
452..728
Insight Centre for Data Analytics Slide 53June 20th, 2016
![Page 126: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/126.jpg)
Propagation of equality (Iteration 6)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸
452..725
Insight Centre for Data Analytics Slide 53June 20th, 2016
![Page 127: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/127.jpg)
Propagation of equality (Iteration 6)
91 ∗ E4..7 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸
452..725
N ≥ 5 = d452− 890
e,E ≥ 4 = d452− 8891
e
No further propagation at this point
Insight Centre for Data Analytics Slide 53June 20th, 2016
![Page 128: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/128.jpg)
Domains after setup
0 1 2 3 4 5 6 7 8 9SENDMORY
Insight Centre for Data Analytics Slide 54June 20th, 2016
![Page 129: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/129.jpg)
Outline
Problem
Program
Constraint Setup
SearchStep 1Step 2Further StepsSolution
Points to Remember
Insight Centre for Data Analytics Slide 55June 20th, 2016
![Page 130: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/130.jpg)
labeling built-in
labeling([S,E,N,D,M,O,R,Y])
• Try variable is order given
• Try values starting from smallest value in domain
• When failing, backtrack to last open choice
• Chronological Backtracking
• Depth First search
Insight Centre for Data Analytics Slide 56June 20th, 2016
![Page 131: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/131.jpg)
Search Tree Step 1
Variable S already fixed
S
E9
Insight Centre for Data Analytics Slide 57June 20th, 2016
![Page 132: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/132.jpg)
Step 2, Alternative E = 4
Variable E ∈ {4..7}, first value tested is 4
S
E4
9
Insight Centre for Data Analytics Slide 58June 20th, 2016
![Page 133: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/133.jpg)
Assignment E = 4
0 1 2 3 4 5 6 7 8 9SE Y - - -NDMORY
Insight Centre for Data Analytics Slide 59June 20th, 2016
![Page 134: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/134.jpg)
Propagation of E = 4, equality constraint
91 ∗ 4 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8
Insight Centre for Data Analytics Slide 60June 20th, 2016
![Page 135: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/135.jpg)
Propagation of E = 4, equality constraint
91 ∗ 4 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸
386..452
= 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸
452..728
Insight Centre for Data Analytics Slide 60June 20th, 2016
![Page 136: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/136.jpg)
Propagation of E = 4, equality constraint
91 ∗ 4 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸
452
Insight Centre for Data Analytics Slide 60June 20th, 2016
![Page 137: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/137.jpg)
Propagation of E = 4, equality constraint
91 ∗ 4 + 10 ∗ R2..8 + D2..8 = 90 ∗ N5..8 + Y 2..8︸ ︷︷ ︸
452
N = 5,Y = 2,R = 8,D = 8
Insight Centre for Data Analytics Slide 60June 20th, 2016
![Page 138: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/138.jpg)
Result of equality propagation
0 1 2 3 4 5 6 7 8 9SEN Y - - -D - - - - - - Y
MOR - - - - - - Y
Y Y - - - - - -
Insight Centre for Data Analytics Slide 61June 20th, 2016
![Page 139: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/139.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SEN Y - - -D - - - - - - Y
MOR - - - - - - Y
Y Y - - - - - -
Insight Centre for Data Analytics Slide 62June 20th, 2016
![Page 140: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/140.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SEN Y - -D - - - - - - Y
MOR - - - - - - Y
Y Y - - - - -
Alldifferent fails!
Insight Centre for Data Analytics Slide 62June 20th, 2016
![Page 141: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/141.jpg)
Step 2, Alternative E = 5
Return to last open choice, E , and test next value
S
E4
N5
9
Insight Centre for Data Analytics Slide 63June 20th, 2016
![Page 142: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/142.jpg)
Assignment E = 5
0 1 2 3 4 5 6 7 8 9SE - Y - -NDMORY
Insight Centre for Data Analytics Slide 64June 20th, 2016
![Page 143: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/143.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SE - Y - -NDMORY
Insight Centre for Data Analytics Slide 65June 20th, 2016
![Page 144: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/144.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SE Y
N |D |MOR |Y |
Insight Centre for Data Analytics Slide 65June 20th, 2016
![Page 145: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/145.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SENDMORY
N 6= 5,N ≥ 6
Insight Centre for Data Analytics Slide 65June 20th, 2016
![Page 146: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/146.jpg)
Propagation of equality
91 ∗ 5 + 10 ∗ R2..8 + D2..8 = 90 ∗ N6..8 + Y 2..8
Insight Centre for Data Analytics Slide 66June 20th, 2016
![Page 147: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/147.jpg)
Propagation of equality
91 ∗ 5 + 10 ∗ R2..8 + D2..8︸ ︷︷ ︸
477..543
= 90 ∗ N6..8 + Y 2..8︸ ︷︷ ︸
542..728
Insight Centre for Data Analytics Slide 66June 20th, 2016
![Page 148: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/148.jpg)
Propagation of equality
91 ∗ 5 + 10 ∗ R2..8 + D2..8 = 90 ∗ N6..8 + Y 2..8︸ ︷︷ ︸
542..543
Insight Centre for Data Analytics Slide 66June 20th, 2016
![Page 149: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/149.jpg)
Propagation of equality
91 ∗ 5 + 10 ∗ R2..8 + D2..8 = 90 ∗ N6..8 + Y 2..8︸ ︷︷ ︸
542..543
N = 6,Y ∈ {2,3},R = 8,D ∈ {7..8}
Insight Centre for Data Analytics Slide 66June 20th, 2016
![Page 150: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/150.jpg)
Result of equality propagation
0 1 2 3 4 5 6 7 8 9SEN Y - -D 6 6 6 6
MOR - - - - - Y
Y 6 6 6 6
Insight Centre for Data Analytics Slide 67June 20th, 2016
![Page 151: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/151.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SEN Y - -D 6 6 6 6
MOR - - - - - Y
Y 6 6 6 6
Insight Centre for Data Analytics Slide 68June 20th, 2016
![Page 152: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/152.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SEND |MOR Y
Y
Insight Centre for Data Analytics Slide 68June 20th, 2016
![Page 153: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/153.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SEND Y
MORY
Insight Centre for Data Analytics Slide 68June 20th, 2016
![Page 154: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/154.jpg)
Propagation of alldifferent
0 1 2 3 4 5 6 7 8 9SENDMORY
D = 7
Insight Centre for Data Analytics Slide 68June 20th, 2016
![Page 155: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/155.jpg)
Propagation of equality
91 ∗ 5 + 10 ∗ 8 + 7 = 90 ∗ 6 + Y 2..3
Insight Centre for Data Analytics Slide 69June 20th, 2016
![Page 156: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/156.jpg)
Propagation of equality
91 ∗ 5 + 10 ∗ 8 + 7︸ ︷︷ ︸542
= 90 ∗ 6 + Y 2..3︸ ︷︷ ︸
542..543
Insight Centre for Data Analytics Slide 69June 20th, 2016
![Page 157: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/157.jpg)
Propagation of equality
91 ∗ 5 + 10 ∗ 8 + 7 = 90 ∗ 6 + Y 2..3︸ ︷︷ ︸
542
Insight Centre for Data Analytics Slide 69June 20th, 2016
![Page 158: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/158.jpg)
Propagation of equality
91 ∗ 5 + 10 ∗ 8 + 7 = 90 ∗ 6 + Y 2..3︸ ︷︷ ︸
542
Y = 2
Insight Centre for Data Analytics Slide 69June 20th, 2016
![Page 159: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/159.jpg)
Last propagation step
0 1 2 3 4 5 6 7 8 9SENDMORY Y -
Insight Centre for Data Analytics Slide 70June 20th, 2016
![Page 160: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/160.jpg)
Further Steps: Nothing more to do
S
E4
N5
9
Insight Centre for Data Analytics Slide 71June 20th, 2016
![Page 161: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/161.jpg)
Further Steps: Nothing more to do
S
E4
N
D6
5
9
Insight Centre for Data Analytics Slide 71June 20th, 2016
![Page 162: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/162.jpg)
Further Steps: Nothing more to do
S
E4
N
D
M7
6
5
9
Insight Centre for Data Analytics Slide 71June 20th, 2016
![Page 163: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/163.jpg)
Further Steps: Nothing more to do
S
E4
N
D
M
O1
7
6
5
9
Insight Centre for Data Analytics Slide 71June 20th, 2016
![Page 164: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/164.jpg)
Further Steps: Nothing more to do
S
E4
N
D
M
O
R0
1
7
6
5
9
Insight Centre for Data Analytics Slide 71June 20th, 2016
![Page 165: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/165.jpg)
Further Steps: Nothing more to do
S
E4
N
D
M
O
R
Y8
0
1
7
6
5
9
Insight Centre for Data Analytics Slide 71June 20th, 2016
![Page 166: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/166.jpg)
Further Steps: Nothing more to do
S
E4
N
D
M
O
R
Y2
8
0
1
7
6
5
9
Insight Centre for Data Analytics Slide 71June 20th, 2016
![Page 167: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/167.jpg)
Complete Search Tree
S
E4
N
D
M
O
R
Y2
8
0
1
7
6
5 6 7
9
Insight Centre for Data Analytics Slide 72June 20th, 2016
![Page 168: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/168.jpg)
Solution
9 5 6 7+ 1 0 8 51 0 6 5 2
Insight Centre for Data Analytics Slide 73June 20th, 2016
![Page 169: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/169.jpg)
Outline
1. An Initial Example
2. Constraint
3. Send More MoneyPoints to RememberModeling in MILP
23
![Page 170: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/170.jpg)
Points to Remember
I Constraint models are expressed by:variables + constraints + parameters
I Problems can have many different models, which can behave quitedifferently. Choosing the best model is an art.
I Constraints can take many different forms.
I Propagation deals with the interaction of variables and constraints:It removes some values that are inconsistent with a constraint from thedomain of a variable.
I Constraints only communicate via shared variables.
24
![Page 171: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/171.jpg)
Points to Remember
I Propagation is data driven, and can be quite complex even for smallexamples.
I Propagation usually is not sufficient, search may be required to find asolution.
I The default search uses chronological depth-first backtracking,systematically exploring the complete search space.
I The search choices and propagation are interleaved,after every choice some more propagation may further reduce theproblem.
25
![Page 172: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/172.jpg)
Applications
I Operation research (optimization problems)I Graphical interactive systems (to express geometrical correctness)I Molecular biology (DNA sequencing, 3D models of proteins)I FinanceI Circuit verificationI Elaboration of natural languages (construction of efficient parsers)I Scheduling of activitiesI Configuration problem in form compilationI Generation of coerent music programs [Anders and Miranda [2011]].I Data basesI ...I http://hsimonis.wordpress.com/
26
![Page 173: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/173.jpg)
ApplicationsDistribution of technology used at Google for optimization applicationsdeveloped by the operations research team
[Slide presented by Laurent Perron on OR-Tools at CP2013]27
![Page 174: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/174.jpg)
List of Contents
I Modeling with Finite Domain Integer VariablesI Introduction to GecodeI Overview on global constraintsI Notions of local consistencyI Constraint propagation algorithmsI Filtering algorithms for global constraintsI SearchI Set variablesI Symmetries
28
![Page 175: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/175.jpg)
Outline
1. An Initial Example
2. Constraint
3. Send More MoneyPoints to RememberModeling in MILP
29
![Page 176: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/176.jpg)
Send More Money: ILP model 1
I xi ∈ {0, . . . , 9} for all i ∈ I = {S ,E ,N,D,M,O,R,Y }
I δij =
{0 if xi < xj
1 if xj < xi
I Crypto constraint:103x1 +102x2 +10x3 +x4 +103x5 +102x6 +10x7 +x2 =
104x5 +103x6 +102x3 +10x2 +x8
I Each letter takes a different digit:
xi − xj − 10δij ≤ −1, for all i , j , i < jxj − xi + 10δij ≤ 9, for all i , j , i < j
30
![Page 177: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/177.jpg)
Send More Money: ILP model 2
I xi ∈ {0, . . . , 9} for all i ∈ I = {S ,E ,N,D,M,O,R,Y }I yij ∈ {0, 1} for all i ∈ I , j ∈ J = {0, . . . , 9}I Crypto constraint:
103x1 +102x2 +10x3 +x4 +103x5 +102x6 +10x7 +x2 =
104x5 +103x6 +102x3 +10x2 +x8
I Each letter takes a different digit:∑
j∈J
yij = 1, ∀i ∈ I ,
∑
i∈I
yij ≤ 1, ∀j ∈ J,
xi =∑
j∈J
jyij , ∀i ∈ I .
31
![Page 178: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/178.jpg)
Send More Money: ILP model
The quality of these formulations depends on both the tightness of the LPrelaxations and the number of constraints and variables (compactness)
I Which of the two models is tighter?project out all extra variables in the LP so that the polytope for LP is inthe space of the x variables. By linear comb. of constraints:
Model 1
−1 ≤ xi − xj ≤ 10− 1
Model 2∑j∈J
xj ≥|J| (|J| − 1)
2, ∀J ⊂ I ,
∑j∈J
xj ≤|J| (2k − |J|) + 1
2, ∀J ⊂ I .
I Can you find the convex hull of this problem?Williams and Yan [2001] prove that model 2 is facet defining
Suppose we want to maximize MONEY, how strong is the upper boundobtained with this formulation? How to obtain a stronger upper bound?
32
![Page 179: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/179.jpg)
Send More Money: ILP model (revisited)
I xi ∈ {0, . . . , 9} for all i ∈ I = {S ,E ,N,D,M,O,R,Y }I Crypto constraint:
103x1 +102x2 +10x3 +x4 +103x5 +102x6 +10x7 +x2 =
104x5 +103x6 +102x3 +10x2 +x8
I Each letter takes a different digit:
∑
j∈J
xj ≥|J| (|J| − 1)
2, ∀J ⊂ I ,
∑
j∈J
xj ≤|J| (2k − |J|) + 1
2, ∀J ⊂ I .
But exponentially many!
33
![Page 180: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/180.jpg)
Send More Money: CP model (revisited)
I Xi ∈ {0, . . . , 9} for all i ∈ I = {S ,E ,N,D,M,O,R,Y }
I
103X1 +102X2 +10X3 +X4 +103X5 +102X6 +10X7 +X2 =
104X5 +103X6 +102X3 +10X2 +X8
I
alldifferent([X1,X2, . . . ,X8]).
I Redundant constraints (5 equality constraints)X4 + X2 = 10 r1 + X8,
X3 + X7 + r1 = 10 r2 + X2,
X2 + X6 + r2 = 10 r3 + X3,
X1 + X5 + r3 = 10 r4 + X6,
+r4 = X5.
Can we do better? Can we propagate something?
34
![Page 181: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/181.jpg)
Send Most Money: CP modelGecode-python
Optimization version:
max∑
i∈I ′CiXi , I ′ = {M,O,N,E ,Y }
from gecode import *
s = space()letters = s.intvars(8,0,9)S,E,N,D,M,O,T,Y = letterss.rel(M,IRT_NQ,0)s.rel(S,IRT_NQ,0)s.distinct(letters)C = [1000, 100, 10, 1,
1000, 100, 10, 1,-10000, -1000, -100, -10, -1]
X = [S,E,N,D,M,O,S,T,M,O,N,E,Y]
s.linear(C,X,IRT_EQ,0)money = s.intvar(0,99999)s.linear([10000,1000,100,10,1],[M,O,N,E,Y], IRT_EQ, money)s.maximize(money)s.branch(letters, INT_VAR_SIZE_MIN, INT_VAL_MIN)for s2 in s.search():
print(s2.val(money), s2.val(letters))
39
![Page 182: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/182.jpg)
Strengths
I CP is excellent to explore highly constrained combinatorial spaces quickly
I Math programming is particulary good at deriving lower bounds
I LS is particualry good at derving upper bounds
40
![Page 183: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/183.jpg)
Differences
I MILP modelsI impose modelling rules: linear inequalities and objectivesI emphasis on tightness and compactness of LP, strength of bounds
(remove dominated constraints)
I CP modelsI a large variety of algorithms communicating with each other: global
constraintsI more expressivenessI emphasis on exploiting substructres, include redundant constraints
41
![Page 184: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/184.jpg)
Resume
I Constraint Satisfaction Problem
I Modelling in CP
I Examples, Send More Money, Sudoku
42
![Page 185: Constraint Programming Overview based on Examplesmarco/Teaching/AY2016-2017/DM841/Slides/dm841-p1-lec2.pdfConstraint Programming An Introduction by example Patrick Prosser with the](https://reader033.vdocument.in/reader033/viewer/2022042103/5e80c96a50715d39754d01a2/html5/thumbnails/185.jpg)
References
Anders T. and Miranda E.R. (2011). Constraint programming systems for modelingmusic theories and composition. ACM Comput. Surv., 43(4), pp. 30:1–30:38.
Hooker J.N. (2011). Hybrid modeling. In Hybrid Optimization, edited by P.M.Pardalos, P. van Hentenryck, and M. Milano, vol. 45 of Optimization and ItsApplications, pp. 11–62. Springer New York.
Smith B.M. (2006). Modelling. In Handbook of Constraint Programming, edited byF. Rossi, P. van Beek, and T. Walsh, chap. 11, pp. 377–406. Elsevier.
Williams H. and Yan H. (2001). Representations of the all_different predicate ofconstraint satisfaction in integer programming. INFORMS Journal onComputing, 13(2), pp. 96–103.
43