Title: A Second Look at Constraint Programming
1A Second Look at Constraint Programming
2Today
- Fundamentals
- Case study ACC 97/98 Basketball
- Constraint programming techniques
3Thursday/Friday
- Applying constraint programming to job-shop and
other scheduling problems - Evaluation of constraint programming
4Review
- Constraint programming is a framework for
integrating three families of algorithms - Propagation algorithms
- Branching algorithms
- Exploration algorithms
5S 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
E 4
E ? 4
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
E 5
E ? 5
S ? 9 E ? 5 N ? 6 D ? 7 M ? 1 O ? 0 R
? 8 Y ? 2
S ? 9 E ? 6..7 N ? 7..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
E ? 6
E 6
6Using OPL Syntax
enum Letter S,E,N,D,M,O,R,Y var int lLetter
in 0..9 solve alldifferent(l) lS ltgt 0
lM ltgt 0 lS1000 lE100
lN10 lD lM1000
lO100 lR10 lE lM10000
lO1000 lN100 lE10 lY search
forall(i in Letter ordered by increasing
dsize(li)) tryall(v in 0..9)
li v ?All Solutions Execution ? Run
7Today
- Fundamentals
- Case study ACC 97/98 Basketball
- Constraint programming techniques
8Fundamentals
- Constraint solving
- Basic constraints and propagators
- Completeness of propagation
9Constraint Problems
- A constraint problem consists of
- number of variables n
- constraints c1,,cm ? ?n
- The problem is to find
- a (v1,,vn)? ?n such that
- a ? ci , for all 1 ? i ? m
10Constraint Solving
- Given a satisfiable constraint C and a new
constraint C. - Constraint solving is deciding whether C ? C is
satisfiable. - Example
- C n gt 2
- C an bn cn
11Constraint Solving
- Clearly, constraint solving is not possible for
general constraints. - Constraint programming separates constraints into
- Basic constraints constraint solving
- Non-basic constraints propagation (incomplete)
12Basic 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.
13Basic Constraints and Propagators
1000S 100E 10N D
1000M 100O 10R E 10000M 1000O
100N 10E Y
all different(S,E,N,D, M,O,R,Y)
S ? 1..9 E ? 0..9 N ? 0..9 D ? 0..9 M ?
1..9 O ? 0..9 R ? 0..9 Y ? 0..9
14Basic Constraints and Propagators
1000S 100E 10N D
1000M 100O 10R E 10000M 1000O
100N 10E Y
all different(S,E,N,D, M,O,R,Y)
S ? 1..9 E ? 0..9 N ? 0..9 D ? 0..9 M ?
1 O ? 0..9 R ? 0..9 Y ? 0..9
15Basic Constraints and Propagators
1000S 100E 10N D
1000M 100O 10R E 10000M 1000O
100N 10E Y
all different(S,E,N,D, M,O,R,Y)
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
16Basic Constraints and Propagators
1000S 100E 10N D
1000M 100O 10R E 10000M 1000O
100N 10E Y
all different(S,E,N,D, M,O,R,Y)
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
and so on and so on
17Basic Constraints and Propagators
1000S 100E 10N D
1000M 100O 10R E 10000M 1000O
100N 10E Y
all different(S,E,N,D, M,O,R,Y)
S ? 9 E ? 5..7 N ? 6..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
18Completeness of Propagation
- Given Basic constraint C and propagator P.
- Propagation is complete, if for every variable x
and every value v?domc(x), there is an assignment
in which xv that satisfies C and P. - Complete propagation is also called
- domain-consistency or arc-consistency.
19Example Complete All Different
- C w ? 1,2,3,4
- x ? 2,3,4
- y ? 2,3,4
- z ? 2,3,4
- P alldifferent(w,x,y,z)
20Example Complete All Different
- C w ? 1,2,3,4
- x ? 2,3,4
- y ? 2,3,4
- z ? 2,3,4
- P alldifferent(w,x,y,z)
- Most efficient known algorithm O(X2 dmax2)
- Regin 1994, using graph matching
21Today
- Fundamentals
- Case study ACC 97/98 Basketball
- Constraint programming techniques
22ACC 1997/98 A Success Story of Constraint
Programming
- Integer programming enumeration, 24 hours
- Nemhauser, 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, to
appear
23Round 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.
24The 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
25The ACC 1997/98 Problem (contd)
- 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.
26The ACC 1997/98 Problem (contd)
- 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.
27The ACC 1997/98 Problem (contd)
- 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.
28The ACC 1997/98 Problem (contd)
- 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.
29Nemhauser/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, 35301-312, 1992.
30Modeling 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, 51 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
31Modeling ACC 97/97 as Constraint Satisfaction
Problem (contd)
- Constraints
- Example No team plays away on both last dates.
- AClem,17 AClem,18 lt 2, ADuke,17 ADuke,18 lt
2, ... - All constraints can be easily formalized in this
manner.
32First Step Back to Nemhauser/Trick!
- 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
33Back 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
34Cains 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
35Cain 1977
Schreuder 1992
36Cains 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,2HGT,2 - Implemented element(pGT,H2 , HGT,2 )
37Using Cains 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
38Friar 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/FriarTuc
k) - Implementation language Oz using Mozart (see
www.mozart-oz.org)
39Today
- Fundamentals
- Case study ACC 97/98 Basketball
- Constraint programming techniques
40Constraint Programming Techniques
- Symmetry Breaking
- Redundant Constraints
- Global Constraints
41Symmetry 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.
42Redundant Constraints
- Pruning of original model is often not sufficient
- Adding redundant constraints sometimes helps
43Example 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 Ill try
again Gosh, with adding them the price still
comes to 7.11! What were the prices of the four
items?
44Model 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
45Additional Constraints
- Redundant constraint
- Symmetries
79 is prime factor of 711. Thus without loss of
generality A divisible by 79
B ? C ? D
46Solution to Grocery Puzzle
Grocery
Grocery plus Redundancy
Grocery plus Redundancy plus Symmetry
47Example Fractions
- Find distinct non-zero digits such that the
following equation holds - A D G
- 1
- B C E F H I
48Model for Fractions
- One variable for each letter, similar to MONEY
- Constraint
- AEFHI DBCHI GBCEF
-
- BCEFHI
49Additional Constraints
A D G ? ? B C E F H I
- Symmetries
- Redundant constraints
A 3 ? 1 B C
G 3 ? 1 H I
50Fractions
Fractions plus Symmetries
Fractions plus Symmetries plus Redundancies
- Constraint
- AEFHI
- DBCHI
- GBCEF BCEFHI
- Symmetries
- AEF gt DBC
- DHI gt GEF
- Redundant Constraints
- 3A gt BC
- 3G lt HI
51Redundant Constraints
- Adding redundant constraints sometimes results
in dramatic performance improvements.
52Performance of Symmetry Breaking
- All solution search Symmetry breaking usually
improves performance often dramatically - One solution search Symmetry breaking may or may
not improve performance
53Global Constraints Euler Tour
- range ChessBoard 1..64
- ChessBoard Knightmove i in ChessBoard
- j j in ChessBoard ...
- var ChessBoard jumpChessBoard
- solve
- forall(p in ChessBoard)
- jumpp in Knightmovep
- circuit(jump)
- forall(p in ChessBoard)
- sum(c in Knightmovep) (jumpc p) 1
Euler
54Today
- Fundamentals
- Case study ACC 97/98 Basketball
- Constraint programming techniques
55Thursday/Friday
- Applying constraint programming to job-shop and
other scheduling problems - Evaluation of constraint programming