Title: An Overview of Constraint Programming
1An Overview of Constraint Programming
 APORS 2000 Tutorial
 July 7, 2000
 Martin Henz, National University of Singapore
2Overview
 Constraint Programming in a Nutshell
 Elements of Constraint Programming
 Case study ACC 97/98 Basketball
 Constraint Programming Techniques
 Constraintbased Scheduling
3Overview
 Constraint Programming in a Nutshell
 Elements of Constraint Programming
 Case study ACC 97/98 Basketball
 Constraint Programming Techniques
 Constraintbased Scheduling
4Constraint Programming in a Nutshell
5Constraint Programming in a Nutshell
6SEND MORE MONEY
 Assign distinct digits to the letters
 S, E, N, D, M, O, R, Y
 such that S E N D
 M O R E

 M O N E Y
 holds.
7SEND MORE MONEY
 Assign distinct digits to the letters
 S, E, N, D, M, O, R, Y
 such that S E N D
 M O R E

 M O N E Y
 holds.
Solution 9 5 6 7 1 0 8
5 1 0 6 5 2
8Modeling
 Formalize the problem as a constraint problem
 number of variables n
 constraints c1,,cm ? ?n
 problem Find a (v1,,vn)? ?n such
 that a ? ci , for all 1 ? i ?
m
9A Model for MONEY
 number of variables 8
 constraints
 c1 (S,E,N,D,M,O,R,Y)? ?8 0 ? S,,Y ? 9
 c2 (S,E,N,D,M,O,R,Y)? ?8
 1000S 100E 10N D
 1000M 100O 10R E
 10000M 1000O 100N 10E Y
10A Model for MONEY (continued)
 more constraints

 c3 (S,E,N,D,M,O,R,Y)? ?8 S ? 0
 c4 (S,E,N,D,M,O,R,Y)? ?8 M ? 0
 c5 (S,E,N,D,M,O,R,Y)? ?8 SY all different
11Solution for MONEY
 c1 (S,E,N,D,M,O,R,Y)? ?8 0?S,,Y?9
 c2 (S,E,N,D,M,O,R,Y)? ?8
 1000S 100E 10N D
 1000M 100O 10R E
 10000M 1000O 100N 10E Y
 c3 (S,E,N,D,M,O,R,Y)? ?8 S ? 0
 c4 (S,E,N,D,M,O,R,Y)? ?8 M ? 0
 c5 (S,E,N,D,M,O,R,Y)? ?8 SY all
different  Solution (9,5,6,7,1,0,8,2)? ?8
12Elements of Constraint Programming
 Exploiting constraints during tree search
 Use propagation algorithms for constraints
 Employ branching algorithm
 Execute exploration algorithm
13S E N D M O R E M O N E Y
S ? ? E ? ? N ? ? D ? ? M ? ? O ? ? R ? ? Y ? ?
 0?S,,Y?9
 S ? 0
 M ? 0
 SY all different
 1000S 100E
10N D  1000M 100O 10R E
 10000M 1000O 100N 10E Y
14S E N D M O R E M O N E Y
Propagate
S ? 0..9 E ? 0..9 N ? 0..9 D ? 0..9 M ?
0..9 O ? 0..9 R ? 0..9 Y ? 0..9
 0?S,,Y?9
 S ? 0
 M ? 0
 SY all different
 1000S 100E
10N D  1000M 100O 10R E
 10000M 1000O 100N 10E Y
15S E N D M O R E M O N E Y
Propagate
S ? 1..9 E ? 0..9 N ? 0..9 D ? 0..9 M ?
1..9 O ? 0..9 R ? 0..9 Y ? 0..9
 0?S,,Y?9
 S ? 0
 M ? 0
 SY all different
 1000S 100E
10N D  1000M 100O 10R E
 10000M 1000O 100N 10E Y
16S E N D M O R E M O N E Y
Propagate
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
 0?S,,Y?9
 S ? 0
 M ? 0
 SY all different
 1000S 100E
10N D  1000M 100O 10R E
 10000M 1000O 100N 10E Y
17S 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
Branch
E ? 4
E 4
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
 0?S,,Y?9
 S ? 0
 M ? 0
 SY all different
 1000S 100E
10N D  1000M 100O 10R E
 10000M 1000O 100N 10E Y
18S 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
Propagate
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
 0?S,,Y?9
 S ? 0
 M ? 0
 SY all different
 1000S 100E
10N D  1000M 100O 10R E
 10000M 1000O 100N 10E Y
19S E N D M O R E M O N E Y
Branch
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..7 N ? 6..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
20S E N D M O R E M O N E Y
Propagate
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
21S E N D M O R E M O N E Y
Complete Search Tree
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
22Constraint Programming Systems
 Role support elements of
constraint programming  Provide propagation algorithms for constraints
 all different (e.g. wait for fixing)
 summation (e.g. interval consistency)
 Allow choice of branching algorithm
 (e.g. firstfail)
 Allow choice of exploration algorithm
 (e.g. depthfirst search)
23Using Oz
proc Money Root S E N D M O R Y in
Rootsol(sS eE nN dD mM oO rR yY) Root
09 FD.distinct Root S \ 0 M \
0 1000S 100E 10N D
1000M 100O 10R E 10000M
1000O 100N 10E Y FD.distribute ff
Root end ExploreAll Money
Modeling
Propagation
Branching
Exploration
MONEY Demo
24The Art of Constraint Programming
 Choose model
 Choose propagation algorithms
 Choose branching algorithm
 Choose exploration algorithm
25Programming Systems for Finite Domain Constraint
Programming
 Finite domain constraint programming library
 PECOS (Puget 1992)
 ILOG Solver (Puget 1993)
 Finite domain constraint programming languages
 CHIP (Dincbas, Hentenryck, Simonis, Aggoun 1988)
 SICStus Prolog (Haridi, Carlson 1995)
 Oz (Smolka and others 1995)
 OPL (van Hentenryck 1998)
26Overview
 Constraint Programming in a Nutshell
 Elements of Constraint Programming
 Case study ACC 97/98 Basketball
 Constraint Programming Techniques
 Constraintbased Scheduling
27Constraint Problems
 A finite domain 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
28Constraint Solving
 Given a satisfiable constraint C and a new
constraint C.  Constraint solving means deciding whether C ? C
is satisfiable.  Example
 C n gt 2
 C an bn cn
29Constraint Solving
 Constraint solving is not possible for general
constraints.  Constraint programming separates constraints into
 basic constraints complete constraint solving
 nonbasic constraints propagation (incomplete)
search needed
30Basic Constraints in Finite Domain 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.
31Basic 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
32Basic 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
33Basic 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
34Basic 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
35Basic 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
36Issues in Propagation
 Expressivity What kind of information can be
expressed as propagators?  Completeness What behavior can be expected from
propagation?  Efficiency How much computational resources does
propagation consume?
37Completeness 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 xv that satisfies C and P.  Complete propagation is also called
 domainconsistency or arcconsistency.
38Completeness of Propagation
 General arithmetic constraints are undecidable
(Hilberts Tenth Problem).  Propagation may not exhibit all inconsistencies.
 Example
 c1 n gt 2
 c2 an bn cn
39Example Complete All Different
 C w ? 1,2,3,4
 x ? 2,3,4
 y ? 2,3,4
 z ? 2,3,4
 P all_different(w,x,y,z)
40Example Complete All Different
 C w ? 1,2,3,4
 x ? 2,3,4
 y ? 2,3,4
 z ? 2,3,4
 P all_different(w,x,y,z)
 Most efficient known algorithm O(X2 dmax2)
 Regin 1994, using graph matching
41Basic Constraints vs. Propagators
 Basic constraints
 are conjunctions of constraints of the form
X ? S, where S is a finite set of integers  enjoy complete constraint solving
 Propagators
 can be arbitrarily expressive (arithmetic,
symbolic)  implementation typically fast but incomplete
42Propagation vs Branching
 Obvious tradeoff
 Complex propagation algorithms result in
fewer, but more expensive nodes in the search
tree.  Example MONEY with
alldiff and sum only test fixed assignment
alldiff wait for fixed variables sum interval
cons.
alldiff and sum domain consistency
43Some Propagator Classes
 Symbolic propagators
 Arithmetic propagators
 Scheduling propagators
 Reification
44Symbolic PropagatorsExample The Element
Propagator
 Oz FD.element I Vector X
 Meaning X is the Ith element of Array
 Example A 5 6 7 8
 I ? 0,9 X ? 0,9
 Propagation in both directions
 I ? 1,3 ? X ? 5,7
 X ? 7 ? I ? 4
45Arithmetic Propagators
 General arithmetic equations
 I1X11X1m1 InXn1Xnmn 0
 lt gt lt gt \
46Scheduling Propagators
 Details later.
 Scheduling constraint classes
 resource constraints
 precedence constraints
47Reified Constraints
 Reflecting the validity of a constraint in a
 0/1 variable
 Example Reified arithmetic equations
 X (I1X11X1m1 InXn1Xnmn 0)
 lt gt lt gt \
48Excursion From Propagation to Problem Solving
49Branching Algorithms
 Constraint programming systems provide
 libraries of predefined branching algorithms
 programming support for userdefined branching
algorithms
50Branching for MONEY
proc Money Root S E N D M O R Y in
Rootsol(sS eE nN dD mM oO rR yY) Root
09 FD.distinct Root S \ 0 M \
0 1000S 100E 10N D
1000M 100O 10R E 10000M
1000O 100N 10E Y FD.distribute ff
Root end ExploreAll Money
Modeling
Propagation
Branching
Exploration
51Basic Choice Points
x lt y
x gt y
52Choice Point Sequences
 choice x lt y x gt y end
 choice z 1 z 2 end
x lt y
x gt y
z 1
z 2
z 1
z 2
53Examples of Branching Algorithms
 Enumeration Choose variable, choose value
 naive enumeration
choose variables and values in
a fixed sequence  firstfail enumeration
choose a variable with minimal
domain size  Domainsplitting
 choice X lt Mid X gt Mid end
 Task sequencing for scheduling (later)
54Excursion Branching Algorithms in Oz
55Exploration Algorithms
 Combinations of aspects such as
 Order of exploration
 Interaction
 Optimization
 Visualization
56Exploration for MONEY
proc Money Root S E N D M O R Y in
Rootsol(sS eE nN dD mM oO rR yY) Root
09 FD.distinct Root S \ 0 M \
0 1000S 100E 10N D
1000M 100O 10R E 10000M
1000O 100N 10E Y FD.distribute ff
Root end ExploreAll Money
Modeling
Propagation
Branching
Exploration
57Order of Exploration
 Depthfirst search
 Iterative Deepening
 Limited discrepancy search Harvey/Ginsberg 95
58Interaction
 Firstsolution search
 All solution search
 Last solution search
 Search with user interaction
59Optimization
 Branchandbound
 Restart optimization
60Visualization
 Example Oz Explorer Schulte 1997.
 Oz Explorer combines
 visualization
 first/all solution / user interaction
 branchandbound optimization
 depthfirst search
61Excursion Exploration Algorithms in Oz
62Overview
 Constraint Programming in a Nutshell
 Elements of Constraint Programming
 Case study ACC 97/98 Basketball
 Constraint Programming Techniques
 Constraintbased Scheduling
63ACC 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
64Round 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.
65The 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
66The 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.
67The 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 ClemGT, DukeUNC, UMDUVA
and NCStWake. In the last date, every team
except FSU plays against its rival, unless it
plays against FSU or has a bye.
68The ACC 1997/98 Problem (contd)
 The following pairings must occur at least once
in dates 11 to 18 DukeGT, DukeWake, GTUNC,
UNCWake.  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.
69The 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.
70Nemhauser/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, 35301312, 1992.
71Modeling 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
72Modeling ACC 97/98 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.  But Search leads to huge search trees!
 No solutions can be found within
reasonable time!
73First 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
74Back 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
75Cains 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 computerassisted heuristic
approach used to schedule the major league
baseball clubs, Optimal Strategies in Sports,
NorthHolland, 1977
76Cain 1977
Schreuder 1992
77Cains 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 )
78Using 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
79Friar 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.mozartoz.org)
80Overview
 Constraint Programming in a Nutshell
 Elements of Constraint Programming
 Case study ACC 97/98 Basketball
 Constraint Programming Techniques
 Constraintbased Scheduling
81Constraint Programming Techniques
 Symmetry Breaking
 Redundant Constraints
 Parameterized Problems
82Symmetry 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.
83Redundant Constraints
 Pruning of original model is often not sufficient
 Adding redundant constraints sometimes helps
84Example 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?
85Model 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
86Additional Constraints
 Redundant constraint
 Symmetries
79 is prime factor of 711. Thus without loss of
generality A divisible by 79
B ? C ? D
87Solution to Grocery Puzzle
Grocery
Grocery plus Redundancy
Grocery plus Redundancy plus Symmetry
88Example Fractions
 Find distinct nonzero digits such that the
following equation holds  A D G
 1
 B C E F H I
89Model for Fractions
 One variable for each letter, similar to MONEY
 Constraint
 AEFHI DBCHI GBCEF

 BCEFHI
90Additional Constraints
A D G ? ? B C E F H I
 Symmetries
 Redundant constraints
A 3 ? 1 B C
G 3 ? 1 H I
91Fractions
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
92Redundant Constraints
 Adding redundant constraints sometimes results
in dramatic performance improvements.
93Performance of Symmetry Breaking
 All solution search Symmetry breaking usually
improves performance often dramatically  One solution search Symmetry breaking may or may
not improve performance
94Parameterized Problems
 Modeling facilities in Oz are embedded in
advanced programming language.  Problem scripts can be result of computation.
 Applications
 Embedding problem solving in complex applications
 Parameterized problems
Excursion N Queens
95Overview
 Constraint Programming in a Nutshell
 Elements of Constraint Programming
 Case study ACC 97/98 Basketball
 Constraint Programming Techniques
 Constraintbased Scheduling
96Review
 Constraint programming is a framework for
integrating three families of algorithms  Propagation algorithms
 Branching algorithms
 Exploration algorithms
97S 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
98Optimization
 Modeling define optimization function
 Propagation algorithms identify propagation
algorithms for optimization function  Branching algorithms identify branching
algorithms that lead to good solutions early  Exploration algorithms extend existing
exploration algorithms to achieve optimization
99Optimization Example
100SEND MOST MONEY
 Assign distinct digits to the letters
 S, E, N, D, M, O, T, Y
 such that
 S E N D
 M O S T

 M O N E Y holds and
 M O N E Y is maximal.
101Modeling
 Formalize the problem as a constraint
optimization problem  Number of variables n
 Constraints c1,,cm ? ?n
 Optimization constraints d1,,dm ? ?n ?2?n Given
a solution a, and an optimization constraint di ,
the constraint di(a)? ?n contains only those
assignments b for which b is better than a.
102A Model for MONEY
 number of variables 8
 constraints
 c1 (S,E,N,D,M,O,T,Y)? ?8 0 ? S,,Y ? 9
 c2 (S,E,N,D,M,O,T,Y)? ?8
 1000S 100E 10N D
 1000M 100O 10S T
 10000M 1000O 100N 10E Y
103A Model for MONEY (continued)
 more constraints
 c3 (S,E,N,D,M,O,T,Y)? ?8 S ? 0
 c4 (S,E,N,D,M,O,T,Y)? ?8 M ? 0
 c5 (S,E,N,D,M,O,T,Y)? ?8 SY all
different  optimization constraint
 d (s,e,n,d,m,o,t,y) ?
 (S,E,N,D,M,O,T,Y)? ?8
 10000m 1000o 100n 10e y
 lt 10000M 1000O 100N 10E Y
104Propagation Algorithms
 Identify a propagation algorithm to implement the
optimization constraints  Example SEND MOST MONEY
 d (s,e,n,d,m,o,t,y) ?
 (S,E,N,D,M,O,T,Y))? ?8??8
 10000m 1000o 100n 10e y
 lt 10000M 1000O 100N 10E Y
 Given a solution a, choose propagation algorithm
for d(a).
105Branching Algorithms
 Identify a branching algorithm that finds good
solutions early.  Example SEND MOST MONEY
 Idea Naïve enumeration in the order M, O,
N, E, Y.  Try highest values first.
106Exploration Algorithms
 Modify exploration such that for each solution a,
corresponding optimization constraints are added.  Two strategies
 branchandbound continue as in original
exploration  restart optimization after each solution, start
from the root.
107Using Oz
proc Money Root S E N D M O R Y in
Rootsol(sS eE nN dD mM oO rR yY) Root
09 FD.distinct Root S \ 0 M \
0 1000S 100E 10N D
1000M 100O 10R E 10000M
1000O 100N 10E Y FD.distribute ff
Root end proc OptimizationConstraint Old New
sol(sS1 eE1 nN1 dD1 mM1 oO1 tT1 yY1)
Old sol(sS2 eE2 nN2 dD2 mM2 oO2 tT2
yY2) New in 10000M1 1000O1 100N1
10E1 Y1 lt 10000M2 1000O2 100N2
10E2 Y2 end Explorer.object script(Money
OptimizationConstraint)
108Experiments with MONEY
MONEY Search
MONEY Optimization
109Scheduling
 Scheduling Problems
 Propagation Algorithms for Resource Constraints
 Branching Algorithms
 Other Constraints
 Exploration Algorithms
 Literature
110Scheduling Problems
 Assign starting times (and sometimes durations)
to tasks, subject to  resource constraints,
 precedence constraints,
 idiosyncratic and other constraints, and
 an optimization function, typically to minimize
overall schedule duration.
111Example Building a Bridge
Show Problem
Animate Solution
Gantt Chart
 Resource constraints
 Example a1 and a2 use excavator, cannot overlap
in time  Precedence constraints
 Example p1 requires a3, a3 must end before p1
starts
112Modeling
 Indices
 Tasks beg a1 a2 a3 a4 a5 a6 p1
 Constants duration of tasks
 Duration d(beg0 a14 a22...)
 Variables represent each task with a finite
domain variable representing its starting time.  Start FD.record start Tasks 0MaxTime

 Start.t is finite domain variable representing
the starting time of task t
113Precedence Constraints
 For each two tasks t1, t2, where t1 must precede
t2, introduce a constraint  Start.t1 Duration.t1 ? Start.t2
114Resource Constraints
 For each two tasks t1, t2 that require a unary
resource r, we have the constraint  Start.t1 Duration.t1 ? Start.t2
 ?
 Start.t2 Duration.t2 ? Start.t1

 But many constraints and weak propagation.
 Thus, introduce global resource constraints.
115Global Resource Constraints in Oz
 Schedule.serializedDisj
 a1 a2 a3 a4 a5 a6 excavator
 p1 p2 pile driver
 ...
 Start Duration
 User chooses among Schedule.serialized
 Schedule.serializedDisj
 Schedule.taskIntervals
116Propagation Using Disjunction
 For all tasks t1, t2 using the same resource
 Start.t1 Duration.t1 ? Start.t2
 ?
 Start.t2 Duration.t2 ? Start.t1
 Weakest but fastest form of propagation for unary
resources.
117Propagation Edge finding
 For a given task t and set of tasks S, all
sharing the same unary resource , find out
whether t can occur  before all tasks in S,
 after all tasks in S,
 between two tasks in S,
 and infer corresponding basic constraints.
118Propagation Task Intervals
 Notation est(t) earliest starting time
 lct(t) latest completion time
 For two tasks t1 and t2 where est(t1)?est(t2) and
lct(t1) ? lct(t2), the task interval I(t1,t2) is
defined  I(t1,t2) t est(t1) ? est(t) and
 lct(t) ? lct(t2)
 Perform edge finding on all task intervals.
119Task Intervals Example
A
B
C
D
I(A,B) A,B,C I(C,D) B,C,D
120Which Edge Finder?
 As usual, tradeoff between runtime of
propagation algorithm and strength of
propagation. Edge finding can be expensive
depending on which tasks are considered.  Recent edge finders have complexity n2 for one
propagation step, where n is the number of tasks
using the resource.  Edge finding based on task intervals can be
stronger than these, but typically have
complexity n3 .
121Demo Propagation for Unary Resources
Bridge
122Branching Algorithms Serializers
 Simple enumeration techniques such as firstfail
are hopeless for scheduling.  Use unary resources to guide branching.
 For two tasks t1, t2 sharing the same resource,
use the constraints  Start.t1 Duration.t1 ? Start.t2
 and
 Start.t2 Duration.t2 ? Start.t1
 for branching.
123Which Tasks To Serialize?
 Resourceoriented serialization Serialize all
tasks of one resource completely, before tasks of
another resource are serialized.  Mostusedresource serialization
 Global slack
 Local slack
 Taskoriented serialization Choose two suitable
tasks at a time, regardless of resources.  Slackbased task serialization (see later)
124Mostusedresource Serialization
 Mostusedresource serialization serialize
first the resource that is used the most.  Let T be a set of tasks running on resource r.
 demand(T) ?t?T Duration.t
 Let S be the set of all tasks using resource r.
 demand(r) demand(S),
 Serialize the resource r with maximal demand(r)
first.
125Slackbased Resource Serialization
 Let T be a set of tasks running on resource r.
 supply(T) lct(T)  est(T)
 demand(T) ?t?T Duration.t
 slack(T) supply(T)  demand(T)
 Let S be the set of all tasks using resource r.
 slack(r) slack(S), S is set of all task
running on r.  Global slack serialization Serialize resource
with smallest slack first
126LocalSlack Resource Serialization
 Let Ir be all task intervals on r. The local
slack is defined as min slack(I) I ? Ir  Local slack serialization Serialize resource
with smallest local slack first. Use global slack
for tiebreaking.
127Which Tasks Are Serialized?
 Ideas
 Use edge finding to look for possible first tasks
(and last tasks)  Choose tasks according to their est, lst

(lct, ect).
128Taskoriented Serialization
 Among all tasks using all resources, select a
pair of tasks according to local/global slack
criteria and other considerations, regardless
what resources are serialized already.  Provides more finegrained control at the expense
of runtime for finding candidate task pairs among
all tasks.
129Demo Serialization Algorithms
Bridge
130Exploration Algorithms
 Usually branchandbound using minimization of
the starting time of a last task  minimize aend.start subject to ...
 Lowerbounding Prove the nonexistence of a
solution with Start.last ? n, add constraint
Start.last gt n increase n by ?.  Upperbounding Find solution with Start.last
n, add constraint Start.last lt n decrease n by
?.
131Literature on CP Scheduling
 Van Hentenryck The OPL optimization programming
language, 1999  Constraint Programming Tutorial of Mozart, 2000
(www.mozartoz.org)  Applegate, Cook A computational study of the
jobshop scheduling problem, 1991  Carlier, Pinson An algorithm for solving the
jobshop scheduling problem, 1989  Various papers by Laburthe, Caseau, Baptiste, Le
Pape, Nuijten, see Overview paper
132Overview
 Constraint Programming in a Nutshell
 Elements of Constraint Programming
 Case study ACC 97/98 Basketball
 Constraint Programming Techniques
 Constraintbased Scheduling
 ???
133Assessment Dont Use It!
 Dont 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.
134Assessment 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.
135Myths 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! Mostly quite earthly
algorithms. Constraint programming systems
provide software framework for specialized
algorithms to interact.
136The Future
 Constraint programming will become a standard
technique in OR for solving combinatorial
problems, along with local search and integer
programming.  Constraint programming techniques will be tightly
integrated with integer programming and local
search.