Download - Constraint Programming II
![Page 1: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/1.jpg)
Constraint Programming II
March 15, 2001
Martin Henz, School of Computing, NUSwww.comp.nus.edu.sg/~henz
![Page 2: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/2.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 2
Today
Search Components in OPL Case study: ACC 97/98 Basketball Constraint programming techniques
![Page 3: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/3.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 3
Review
Constraint programming is a framework for integrating three families of algorithms
Propagation algorithms Branching algorithms Exploration algorithms
![Page 4: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/4.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 4
S E N D+ M O R E
= M O N E Y
S {9}E {4..7}N {5..8}D {2..8}M {1}O {0}R {2..8}Y {2..8}
S {9}E {5..7}N {6..8}D {2..8}M {1}O {0}R {2..8}Y {2..8}
E = 4 E 4
S {9}E {6..7}N {7..8}D {2..8}M {1}O {0}R {2..8}Y {2..8}
E = 5 E 5S {9}E {5}N {6}D {7}M {1}O {0}R {8}Y {2}
E = 6 E 6
![Page 5: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/5.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 5
Using OPL Syntax
enum Letter {S,E,N,D,M,O,R,Y};var int l[Letter] in 0..9;solve { alldifferent(l); l[S] <> 0; l[M] <> 0; l[S]*1000 + l[E]*100 + l[N]*10 + l[D] + l[M]*1000 + l[O]*100 + l[R]*10 + l[E] = l[M]*10000 + l[O]*1000 + l[N]*100 + l[E]*10 + l[Y] };search { forall(i in Letter ordered by increasing dsize(l[i])) tryall(v in 0..9) l[i] = v; };
All Solutions; Execution Run
![Page 6: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/6.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 6
Today
Search Components in OPL Propagation Algorithms Programming Branching Programming Exploration
Case study: ACC 97/98 Basketball Constraint programming techniques
![Page 7: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/7.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 7
Constraint Solving
Given: a satisfiable constraint C and a new constraint C’.
Constraint solving is deciding whether C C’ is satisfiable.
Example: C: n > 2C’: an + bn = cn
![Page 8: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/8.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 8
Constraint Solving
Clearly, constraint solving is not possible for general constraints.
Constraint programming separates constraints into Basic constraints: constraint solving Non-basic constraints: propagation (incomplete)
![Page 9: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/9.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 9
Basic Constraints in Constraint Programming
Basic constraints are conjunctions of constraints of the form X S, where S is a finite set of integers.
Constraint solving is done by intersecting domains.
Example:
C = X{1..10}, Y{9..20}, C’ = X{9..15}, Y{14..30}. In practice, we keep a solved form, storing the
current domain of every variable.
![Page 10: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/10.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 10
Basic Constraints and Propagators
S {1..9}E {0..9}N {0..9}D {0..9}M {1..9}O {0..9}R {0..9}Y {0..9}
all different(S,E,N,D, M,O,R,Y)
1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E= 10000*M + 1000*O + 100*N + 10*E + Y
![Page 11: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/11.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 11
Basic Constraints and Propagators
S {1..9}E {0..9}N {0..9}D {0..9}M {1}O {0..9}R {0..9}Y {0..9}
all different(S,E,N,D, M,O,R,Y)
1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E= 10000*M + 1000*O + 100*N + 10*E + Y
![Page 12: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/12.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 12
Basic Constraints and Propagators
S {2..9}E {0,2..9}N {0,2..9}D {0,2..9}M {1}O {0,2..9}R {0,2..9}Y {0,2..9}
all different(S,E,N,D, M,O,R,Y)
1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E= 10000*M + 1000*O + 100*N + 10*E + Y
![Page 13: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/13.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 13
Basic Constraints and Propagators
S {2..9}E {0,2..9}N {0,2..9}D {0,2..9}M {1}O {0}R {0,2..9}Y {0,2..9}
all different(S,E,N,D, M,O,R,Y)
1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E= 10000*M + 1000*O + 100*N + 10*E + Y
and so on and so on
![Page 14: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/14.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 14
Basic Constraints and Propagators
S {9}E {5..7}N {6..8}D {2..8}M {1}O {0}R {2..8}Y {2..8}
all different(S,E,N,D, M,O,R,Y)
1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E= 10000*M + 1000*O + 100*N + 10*E + Y
![Page 15: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/15.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 15
Completeness of Propagation
Given: Basic constraint C and propagator P. Propagation is complete, if for every
variable x and every value v in the domain of x, there is an assignment in which x=v that satisfies C and P.
Complete propagation is also called
domain-consistency or arc-consistency.
![Page 16: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/16.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 16
All Different: Example 1
C: v {1,2} w {1,2,3,4,5} x {1,2,3,4,5} y {1,2,3} z {4,5}
P: alldifferent(w,x,y,z)
![Page 17: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/17.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 17
All Different: Example 2
C: v {1} w {1,2,3,4,5} x {1,2,3,4,5} y {1,2,3} z {5}
P: alldifferent(w,x,y,z)
![Page 18: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/18.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 18
All Different: Example 2
C: v {1} w {1,2,3,4,5} x {1,2,3,4,5} y {1,2,3} z {5}
P: alldifferent(w,x,y,z) onValue
![Page 19: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/19.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 19
All Different: Example 3
C: v {1,2,3,4,5} w {1,2,3,4,5} x {1,2,3} y {1,2,3} z {1,2,3}
P: alldifferent(w,x,y,z) onValue
![Page 20: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/20.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 20
All Different: Example 3
C: v {1,2,3,4,5} w {1,2,3,4,5} x {1,2,3} y {1,2,3} z {1,2,3}
P: alldifferent(w,x,y,z) onDomain
![Page 21: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/21.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 21
All Different: Example 3
C: v {1,2,3,4,5} w {1,2,3,4,5} x {1,2,3} y {1,2,3} z {1,2,3}
P: alldifferent(w,x,y,z) onDomain
![Page 22: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/22.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 22
Complete All Different Constraint
v
z
y
w
x
1
5
4
2
3
![Page 23: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/23.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 23
Complete All Different Constraint
Remove all edgesthat do not belongto a maximum matching in bipartite graph[Regin 94]
v
z
y
w
x
1
5
4
2
3
![Page 24: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/24.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 24
Complete All Different Constraint
...by applyingmaximum matching algorithm in bipartite graphs[Hopcroft, Karp 1973]
O(|X|2 dmax2)
v
z
y
w
x
1
5
4
2
3
![Page 25: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/25.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 25
Today
Search Components in OPL Propagation Algorithms Programming Branching Programming Exploration
Case study: ACC 97/98 Basketball Constraint programming techniques
![Page 26: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/26.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 26
Review: Branching for MONEY enum Letter {S,E,N,D,M,O,R,Y};var int l[Letter] in 0..9;solve { alldifferent(l); l[S] <> 0; l[M] <> 0; l[S]*1000 + l[E]*100 + l[N]*10 + l[D] + l[M]*1000 + l[O]*100 + l[R]*10 + l[E] = l[M]*10000 + l[O]*1000 + l[N]*100 + l[E]*10 + l[Y] };search { forall(i in Letter ordered by increasing dsize(l[i])) tryall(v in 0..9) l[i] = v; };All Solutions; Execution Run
![Page 27: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/27.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 27
Domain Splitting in OPL
search { forall(i in Letter) while not bound(l[i]) do let m = dmid(l[i]) in try l[i] <= m | l[i] > m endtry;};
![Page 28: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/28.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 28
Today
Search Components in OPL Propagation Algorithms Programming Branching Programming Exploration
Case study: ACC 97/98 Basketball Constraint programming techniques
![Page 29: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/29.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 29
Optimization in OPL enum Letter {S,E,N,D,M,O,T,Y};var int l[Letter] in 0..9;maximize money subject to { money = l[M]*10000+l[O]*1000+l[N]*100+l[E]*10+l[Y] alldifferent(l); l[S] <> 0; l[M] <> 0; l[S]*1000 + l[E]*100 + l[N]*10 + l[D] + l[M]*1000 + l[O]*100 + l[S]*10 + l[T] = l[M]*10000 + l[O]*1000 + l[N]*100 + l[E]*10 + l[Y] };search { forall(i in Letter ordered by increasing dsize(l[i])) tryall(v in 0..9) l[i] = v; };
All Solutions; Execution RunMOST MONEY
![Page 30: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/30.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 30
Review: Depth-first Search in OPL enum Letter {S,E,N,D,M,O,T,Y};var int l[Letter] in 0..9;solve { alldifferent(l); l[S] <> 0; l[M] <> 0; l[S]*1000 + l[E]*100 + l[N]*10 + l[D] + l[M]*1000 + l[O]*100 + l[S]*10 + l[T] = l[M]*10000 + l[O]*1000 + l[N]*100 + l[E]*10 + l[Y] };search { forall(i in Letter ordered by increasing dsize(l[i])) tryall(v in 0..9) l[i] = v; };
If nothing else specified, depth-first search is used.
![Page 31: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/31.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 31
Built-in Explorations in OPL Depth-first search (OPL default) Best-first search
choose the node first that has maximal (minimal) lower bound for optimization function
OPL: BFSearch(money) Limited discrepancy search
explore search tree in order of increasing “discrepancies” OPL: LDSearch(4)
![Page 32: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/32.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 32
Best-first Search for Money enum Letter {S,E,N,D,M,O,T,Y};var int l[Letter] in 0..9;maximize money subject to { money = l[M]*10000+l[O]*1000+l[N]*100+l[E]*10+l[Y] alldifferent(l); l[S] <> 0; l[M] <> 0; l[S]*1000 + l[E]*100 + l[N]*10 + l[D] + l[M]*1000 + l[O]*100 + l[S]*10 + l[T] = l[M]*10000 + l[O]*1000 + l[N]*100 + l[E]*10 + l[Y] };search { BFSearch(money) forall(i in Letter ordered by increasing dsize(l[i])) tryall(v in 0..9) l[i] = v; };
![Page 33: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/33.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 33
Programming Explorations in OPL
Works on nodes of search tree Uses priority queue for order of nodes Parameterized by user-defined components
![Page 34: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/34.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 34
The Exploration Algorithm of OPL Boolean explore(PriorityQueue Q) { if Q.empty() { return false; } else { Node a := Q.pop(); return exploreActiveNode(a,Q); } }
Boolean exploreActiveNode a, PriorityQueue Q) { if a.isFailNode() { return explore(Q); } else if a.isLeafNode() { return true; } else if a.mustBePostponed(Q) { Q.insert(a); return explore(Q); } else { Q.insert(a.getRight()); a := a.getLeft(); return exploreActiveNode (a,Q); }}
![Page 35: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/35.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 35
Example: Implementing Depth-FirstSearchStrategy myDFS() {
evaluated to - OplSystem.getDepth();
postponed when
OplSystem.getEvaluation()
>
OplSystem.getBestEvaluation();
}
![Page 36: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/36.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 36
Applying User-defined Explorationenum Letter {S,E,N,D,M,O,R,Y};var int l[Letter] in 0..9;solve { alldifferent(l); l[S] <> 0; l[M] <> 0; l[S]*1000 + l[E]*100 + l[N]*10 + l[D] + l[M]*1000 + l[O]*100 + l[R]*10 + l[E] = l[M]*10000 + l[O]*1000 + l[N]*100 + l[E]*10 + l[Y] };search { applyStrategy myDFS() forall(i in Letter ordered by increasing dsize(l[i])) tryall(v in 0..9) l[i] = v; };
![Page 37: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/37.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 37
Combining Branching and Explorationsearch { applyStrategy myDFS() forall(i in 1..3) ordered by increasing dsize(l[i])) tryall(v in 0..9) l[i] = v; LDSearch(4) forall(i in 4..8) tryall(v in 0..9) l[i] = v;};
![Page 38: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/38.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 38
Today
Search Components in OPL Case study: ACC 97/98 Basketball Constraint programming techniques
![Page 39: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/39.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 39
ACC 1997/98: A Success Story of Constraint Programming
Integer programming + enumeration, 24 hoursNemhauser, Trick: Scheduling a Major College
Basketball Conference, Operations Research, 1998, 46(1)
Constraint programming, less than 1 minute.Henz: Scheduling a Major College Basketball
Conference - Revisited, Operations Research, 2001,
49(1)
![Page 40: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/40.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 40
Round Robin Tournament Planning Problems
n teams, each playing a fixed number of times r against every other team
r = 1: single, r = 2: double round robin. Each match is home match for one and
away match for the other Dense round robin:
At each date, each team plays at most once. The number of dates is minimal.
![Page 41: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/41.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 41
The ACC 1997/98 Problem
9 teams participate in tournament Dense double round robin:
there are 2 * 9 dates at each date, each team plays either home, away
or has a “bye” Alternating weekday and weekend matches
![Page 42: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/42.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 42
The ACC 1997/98 Problem (cont’d) No team can play away on both last dates. No team may have more than two away matches
in a row. No team may have more than two home matches
in a row. No team may have more than three away
matches or byes in a row. No team may have more than four home matches
or byes in a row.
![Page 43: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/43.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 43
The ACC 1997/98 Problem (cont’d) Of the weekends, each team plays four at home,
four away, and one bye. Each team must have home matches or byes at
least on two of the first five weekends. Every team except FSU has a traditional rival.
The rival pairs are Clem-GT, Duke-UNC, UMD-UVA and NCSt-Wake. In the last date, every team except FSU plays against its rival, unless it plays against FSU or has a bye.
![Page 44: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/44.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 44
The ACC 1997/98 Problem (cont’d) The following pairings must occur at least once
in dates 11 to 18: Duke-GT, Duke-Wake, GT-UNC, UNC-Wake.
No team plays in two consecutive dates away against Duke and UNC. No team plays in three consecutive dates against Duke UNC and Wake.
UNC plays Duke in last date and date 11. UNC plays Clem in the second date. Duke has bye in the first date 16.
![Page 45: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/45.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 45
The ACC 1997/98 Problem (cont’d) Wake does not play home in date 17. Wake has a bye in the first date. Clem, Duke, UMD and Wake do not play away
in the last date. Clem, FSU, GT and Wake do not play away in
the fist date. Neither FSU nor NCSt have a bye in the last
date. UNC does not have a bye in the first date.
![Page 46: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/46.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 46
Nemhauser/Trick Solution Enumerate home/away/bye patterns
explicit enumeration (very fast) Compute pattern sets
integer programming (below 1 minute) Compute abstract schedules
integer programming (several minutes) Compute concrete schedules
explicit enumeration (approx. 24 hours)
Schreuder, Combinatorial Aspects of Construction of Competition Dutch Football Leagues, Discr. Appl. Math, 35:301-312, 1992.
![Page 47: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/47.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 47
Modeling ACC 97/98 as Constraint Satisfaction Problem
Variables 9 * 18 variables taking values from {0,1} that
express which team plays home when. Example: HUNC, 5=1 means UNC plays home on date 5.
away, bye similar, e.g. AUNC, 5 or BUNC, 5
9 * 18 variables taking values from {0,1,...,9} that express against which team which other team plays. Example: UNC, 5 =1 means UNC plays team 1 (Clem) on date 5
![Page 48: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/48.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 48
Modeling ACC 97/97 as Constraint Satisfaction Problem (cont’d)
Constraints
Example: No team plays away on both last dates.
AClem,17 + AClem,18 < 2, ADuke,17 + ADuke,18 < 2, ...
All constraints can be easily formalized in this manner.
![Page 49: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/49.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 49
First Step: Use Nemhauser/Trick Idea Constraint programming for generating all
patterns. CSP representation straightforward. computing time below 1 second (Pentium II,
233MHz) Constraint programming for generating all
pattern sets. CSP representation straightforward. computing time 3.1 seconds
![Page 50: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/50.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 50
Back to Schreuder Constraint programming for abstract schedules
Introduce variable matrix for “abstract opponents” similar to in naïve model
there are many abstract schedules runtime over 20 minutes
Constraint programming for concrete schedules model somewhat complicated, using two levels of
the “element” constraint runtime several minutes
![Page 51: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/51.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 51
Cain’s Model Alternative to last two phases of
Nemhauser/Trick Assign teams to patterns in a given pattern set. Assign opponent teams for each team and date.
W.O. Cain, Jr, The computer-assisted heuristic approach used to schedule the major league baseball clubs, Optimal Strategies in Sports, North-Holland, 1977
![Page 52: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/52.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 52
Dates 1 2 3 4 5 6
Pattern 1 H A B A H BPattern 2 B H A B A HPattern 3 A B H H B A
Cain 1977 Schreuder 1992
Dates 1 2 3 4 5 6
Dynamo H A B A H BSparta B H A B A HVitesse A B H H B A
Dates 1 2 3 4 5 6
Team 1 3H 2A B 3A 2H BTeam 2 B 1H 3A B 1A 3HTeam 3 1A B 2H 1H B 2A
Dates 1 2 3 4 5 6
Dynamo VH SA B VA SH BSparta B DH VA B DA VHVitesse DA B VH DH B VA
![Page 53: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/53.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 53
Cain’s Model in CP: main idea Remember: matrices H, A, B represent patterns
and matrix represents opponents Given: matrices H, A, B of 0/1 values
representing given pattern set. Vector p of variables ranging from 1 to n; pGT
identifies the pattern for team GT. Team GT plays according to pattern indicated
by p on date 2: HpGT,2=HGT,2
Implemented: element(pGT,H2 , HGT,2 )
![Page 54: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/54.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 54
Using Cain’s Model in CP
Model for Cain simpler than model for Schreuder Runtimes:
patterns to teams: 33 seconds opponent team assignment: 20.7 seconds overall runtime for all 179 solutions: 57.1 seconds
![Page 55: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/55.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 55
Friar Tuck Constraint programming tool for sport
scheduling, ACC 97/98 just one instance Convenient entry of constraints through GUI Friar Tuck is distributed under GPL Friar Tuck 1.1 available for Unix and
Windows 95/98 (www.comp.nus.edu.sg/~henz/projects/FriarTuck)
Implementation language: Oz using Mozart (see www.mozart-oz.org)
![Page 56: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/56.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 56
Today
Search Strategies in OPL Case study: ACC 97/98 Basketball Constraint programming techniques
![Page 57: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/57.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 57
Constraint Programming Techniques
Symmetry Breaking Redundant Constraints Global Constraints
![Page 58: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/58.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 58
Symmetry Breaking
Often, the most efficient model admits
many different solutions that are essentially
the same (“symmetric” to each other).
Symmetry breaking tries to improve the
performance of search by eliminating
such symmetries.
![Page 59: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/59.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 59
Redundant Constraints
Pruning of original model is often not sufficient
Adding redundant constraints sometimes helps
![Page 60: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/60.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 60
Example: Grocery Puzzle
A kid goes into a grocery store and buys four items. The cashier charges $7.11, the kid pays and is about to leave when the cashier calls the kid back, and says “Hold on, I multiplied the four items instead of adding them; I’ll try again… Gosh, with adding them the price still comes to $7.11”! What were the prices of the four items?
![Page 61: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/61.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 61
Model for Grocery Puzzle
Variables A, B, C, D represent prices of items in cents.
Constraints: A + B + C + D = 711 A * B * C * D = 711 * 100 * 100 * 100
![Page 62: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/62.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 62
Additional Constraints
B C D
79 is prime factor of 711.
Thus without loss of generality:
A divisible by 79
Redundant constraint
Symmetries
![Page 63: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/63.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 63
Solution to Grocery Puzzle
Grocery Grocery plus Redundancy
Grocery plus Redundancyplus Symmetry
![Page 64: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/64.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 64
Example: Fractions
Find distinct non-zero digits such that the following equation holds:
A D G
+ + = 1
B C E F H I
![Page 65: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/65.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 65
Model for Fractions
One variable for each letter, similar to MONEY Constraint
A*E*F*H*I + D*B*C*H*I + G*B*C*E*F
= B*C*E*F*H*I
![Page 66: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/66.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 66
Additional Constraints
A D G B C E F H I
A 3 * 1 B C
G 3 * 1 H I
Symmetries
Redundant constraints
![Page 67: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/67.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 67
Constraint
A*E*F*H*I +
D*B*C*H*I +
G*B*C*E*F = B*C*E*F*H*I Symmetries
A*E*F >= D*B*C
D*H*I >= G*E*F Redundant Constraints
3*A >= B*C
3*G =< H*I
Fractions Fractions plus Symmetries
Fractions plus Symmetries
plus Redundancies
![Page 68: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/68.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 68
Redundant Constraints
Adding redundant constraints sometimes results in dramatic performance improvements.
![Page 69: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/69.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 69
Performance of Symmetry Breaking
All solution search: Symmetry breaking usually improves performance; often dramatically
One solution search: Symmetry breaking may or may not improve performance
![Page 70: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/70.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 70
“Global” Constraints: Hamiltonian Path
range ChessBoard 1..64;
{ChessBoard} Knightmove[ i in ChessBoard] = { j | j in ChessBoard : ... };var ChessBoard jump[ChessBoard];
solve { forall(p in ChessBoard) jump[p] in Knightmove[p]; circuit(jump); forall(p in ChessBoard) sum(c in Knightmove[p]) (jump[c] = p) = 1; };
Hamilton
![Page 71: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/71.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 71
Assessment: Don’t Use It!Don’t use constraint programming for: Problems for which there are known efficient algorithms
or heuristics. Example: Traveling salesman. Problems for which integer programming works well.
Example: Many discrete assignment problems. Problems with weak constraints and a complex
optimization function. Example: Timetabling problems.
![Page 72: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/72.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 72
Assessment: Do Use It!Use constraint programming for: Problems for which integer programming does not work
(linear models too large). Problems for which there are no efficient solutions
available. Problems with tight constraints, where propagation can be
employed. Example: ACC 97/98. Problems for which strong branching algorithms exist.
Example: Scheduling with unary resources.
![Page 73: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/73.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 73
Myths Debunked A fad! Constraint programming has been used successfully
in a number of application areas, most spectacularly in scheduling
Universal! More failure stories than success stories. All new! Many ideas come from AI search and Operations
Research. In particular, the important ideas for scheduling come from OR.
Artificial Intelligence! All quite earthly algorithms. Constraint programming systems provide framework for different kinds of algorithms to interact.
![Page 74: Constraint Programming II](https://reader036.vdocuments.us/reader036/viewer/2022062422/56813fea550346895daae285/html5/thumbnails/74.jpg)
SMA HPC (c) NUS 15.094 Constraint Programming 74
Perspective
Constraint programming will be added to the OR tool set as a standard technique for solving combinatorial problems, along with local search.
Constraint programming techniques will be tightly integrated with integer programming and local search.