Title: Scheduling with Constraint Programming
1Scheduling with Constraint Programming
2Today
- Optimization
- Scheduling
- Assessment
3Review
- Constraint programming is a framework for
integrating three families of algorithms - Propagation algorithms
- Branching algorithms
- Exploration algorithms
4S 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
5Using 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
6Today
- Optimization
- Scheduling
- Assessment
7Optimization
- 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
8Optimization Example
9SEND 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.
10Modeling
- 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.
11A 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
12A 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
13Propagation 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).
14Branching 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.
15Exploration Algorithms
- Modify exploration such that for each solution a,
corresponding optimization constraints are added. - Two strategies
- branch-and-bound continue as in original
exploration - restart optimization after each solution, start
from the root.
16Using OPL Syntax
enum Letter M,O,N,E,Y,S,D,T var int lLetter
in 0..9 minimize lM10000 lO1000
lN100 lE10 lY subject to
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) tryall(v in 0..9 ordered by
decreasing v) li v ?All
Solutions Execution ? Run
17Experiments with MONEY
MONEY Search
MONEY Optimization
18Today
- Optimization
- Scheduling
- Assessment
19Scheduling
- Scheduling Problems
- Propagation Algorithms for Resource Constraints
- Branching Algorithms
- Other Constraints
- Exploration Algorithms
- Literature
20Scheduling 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.
21Example 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
22Modeling
- Indices
- Task begin,a1,a2,a3,a4,a5,a6,p1,...,end
- Constants duration of tasks
- duration begin0, a14, a22,...
- Variables represent each task with a finite
domain variable representing its starting time. - Activity at in Task(durationt)
-
- at.start is finite domain variable
representing the starting time of at
23Precedence Constraints
- For each two tasks t1, t2, where t1 must precede
t2, introduce a constraint - at1.start at1.duration ? at2.start
- In OPL, just write
- at1 precedes at2
-
24Resource Constraints
- For each two tasks t1, t2 that require a unary
resource r, we have the constraint - at1.start at1.duration ?
- at2.start
- \/ at2.start at2.duration ?
- at1.start
-
- But many constraints and weak propagation.
- Thus, introduce global resource constraints.
25Scheduling
- Scheduling Problems
- Propagation Algorithms for Resource Constraints
- Branching Algorithms
- Other Constraints
- Exploration Algorithms
- Literature
26Global Resource Constraints in OPL
- Declare resource
- UnaryResource excavator
- Require resource
- aa1 requires excavator
- aa2 requires excavator...
- All requires constraints on a resource together
form a global resource constraint.
27Propagation Disjunctive Resource
- For all tasks t1, t2 using the same resource
- at1.start at1.duration ?
- at2.start
- \/ at2.start at2.duration ?
- at1.start
- Weakest but most efficient form of propagation
for unary resources.
28Propagation 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.
29Propagation 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.
30Task Intervals Example
A
B
C
D
I(A,B) A,B,C I(C,D) B,C,D
31Which Edge Finder?
- As usual, trade-off between run-time of
propagation algorithm and strength of
propagation. Edge finding can be expensive
depending on what 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 .
32Specifying Propagation Algorithms
- OPL fixes propagation for unary resources to an
(undisclosed) edge-finding algorithm. - For discrete (non-unary) resources, the user can
choose between default, disjunctive and
edgeFinder when declaring a resource - DiscreteResource
- crane(3) using edgeFinder
33Demo Propagation for Unary Resources
Bridge
34Scheduling
- Scheduling Problems
- Propagation Algorithms for Resource Constraints
- Branching Algorithms
- Other Constraints
- Exploration Algorithms
- Literature
35Branching Algorithms Serializers
- Simple enumeration techniques such as first-fail
are hopeless for scheduling. - Use unary resources to guide branching.
- For two tasks t1, t2 sharing the same resource,
use the constraints - t1.start t1.duration ? t2.start
- and
- t2.start t2.duration ? t1.start
- for branching.
36Which Tasks To Serialize?
- Resource-oriented serialization Serialize all
tasks of one resource completely, before tasks of
another resource are serialized. - Most-used-resource serialization
- Global slack
- Local slack
- Task-oriented serialization Choose two suitable
tasks at a time, regardless of resources. - Slack-based task serialization (see later)
37Most-used-resource Serialization
- Most-used-resource 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 t.duration
- Let S be the set of all tasks using resource r.
- demand(r) demand(S),
- Serialize the resource r with maximal demand(r)
first.
38Slack-based Resource Serialization
- Let T be a set of tasks running on resource r.
- supply(T) lct(T) - est(T)
- demand(T) ?t?T t.duration
- 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
39Local-Slack 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 tie-breaking.
40Which 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).
41Task-oriented 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 fine-grained control at the expense
of runtime for finding candidate task pairs among
all tasks.
42Programming Branching Algorithms in OPL
- Scheduling-specific try constructs
- tryRankFirst(u,a) activity a comes first
- tryRankLast(u,a) activity a comes last
- rank(u) serialize all tasks using u
- Reflective functions for unary resources
- isRanked(Unary) 1 if the resource is ranked
- nbPossibleFirst(Unary)
- number of activities that can
come first - globalSlack(Unary) global slack of u
- localSlack(Unary) local slack of u
43Example Task-oriented Serialization in OPL
- while not isRanked(tool) do
- select(r in Resources not isRanked(toolr))
- select(t in tasksr
- not isRanked(toolr,at)
- tryRankFirst(toolr,at)
44Demo Serialization Algorithms
Bridge
45Scheduling
- Scheduling Problems
- Propagation Algorithms for Resource Constraints
- Branching Algorithms
- Other Constraints
- Exploration Algorithms
- Literature
46Other Scheduling Constraints
- Discrete resources
- DiscreteResource crane(3)
- a requires(2) crane
- a consumes(1) crane
- Reservoirs
- Reservoir plumbing(3,1)
- a requires(2) plumbing
- a consumes(2) plumbing
- a provides(2) plumbing
- a produces(2) plumbing
47Exploration Algorithms
- Usually branch-and-bound using minimization of
the starting time of an end task - minimize aend.start subject to ...
- Lower-bounding Prove the non-existence of a
solution with aend.start ? n, add constraint
aend.start gt n increase n by ?. - Upper-bounding Find solution with aend.start
n, add constraint aend.startltn decrease n by
?.
48Literature
- Van Hentenryck The OPL optimization programming
language, 1999 - Constraint Programming Tutorial of Mozart, 2000
(www.mozart-oz.org) - Applegate, Cook A computational study of the
job-shop scheduling problem, 1991 - Carlier, Pinson An algorithm for solving the
job-shop scheduling problem, 1989 - Various papers by Laburthe, Caseau, Baptiste, Le
Pape, Nuijten, see Overview paper
49Today
- Optimization
- Scheduling
- Assessment
50Assessment 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.
51Assessment 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.
52Myths 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.
53The Future
- Constraint programming will be added in OR 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. - Look at the Workshop on Integration of AI and OR
Techniques for Combinatorial Optimization
Problems (www.uni-paderborn.de/CP-AI-OR)