Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

IBM ILOG CP Optimizer Tutorial

A Robust Approach for Generating Detailed Schedules

Didier Vidal Product Manager dvidal@ilog.fr


ILOG, All rights reserved

Presenter
Didier Vidal
Senior Product Manager dvidal@ilog.fr

ILOG, All rights reserved

The limit of fine grained time


(thousands) Purchase Produce Store January I1 50 P1 40 I1 0 I2 75 P2 30 I2 30 February I1 60 I2 45 March I1 40 P1 20 I1 0 I2 0 P2 20 I2 0 April I1 40 P1 30 I1 0 I2 10 P2 40 I2 0

P1 35 P2 10 I1 0 I2 20

2 P1-40 P2-35

3 P1-10 P2-45

4 P1-20 P2-35

5 P1-50 P2-65

6 P1-10 P2-45

7 P1-50 P2-65

8 P1-10 P2-45

9 P1-50 P2-65

10 P1-50 P2-65

Plant 1 Plant 2 Warehouse 1

P1-50 P2-65 P1 - 20

Assembly line Packaging 1 Packaging 2 Stock

C1

C2

C3 C1 C2

C4
Setup product 2

C3

C4

Deliver C1 and C2
ILOG, All rights reserved

Deliver C3 and C4

The limit of fine grained time


(thousands) Purchase Produce Store January I1 50 P1 40 I1 0 I2 75 P2 30 I2 30 February I1 60 I2 45 March I1 40 P1 20 I1 0 I2 0 April I1 40 I2 10

P1 35 P2 10 I1 0 I2 20

Time bucket P2 20 P1 30 view. P2 40


I2 0 Main decisions I1 0 I2 0 time bucket per

2 P1-40 P2-35

3 P1-10 P2-45

4 P1-20 P2-35

5 P1-50 P2-65

6 P1-10 P2-45

Quantities Flow between time period


8 9 10 P1-10 P2-45 P1-50 P2-65 P1-50 P2-65

Plant 1 Plant 2 Warehouse 1

P1-50 P2-65 P1 - 20

P1-50 P2-65

Assembly line Packaging 1 Packaging 2 Stock

C1

C2

C3 C1 C2

C4
Setup product 2

Time line view.


C3 C4

Main decisions per time line Selection of tasks Sequence of tasks


Deliver C1 and C2
ILOG, All rights reserved

Deliver C3 and C4

Detailed Scheduling and Math Programming Use case


Single machine with capacity M A job scheduling problem
Each job requires w[j] resources Has a due date s[j] Has a duration d[j]

Schedule all tasks to minimize tardiness costs

ILOG, All rights reserved

Detailed Scheduling and Math Programming


An ILOG CPLEX formulation
// x is 1 if job j starts at time t dvar boolean x[1..nbJobs][0..maxTime]; // w[j] number of resources used by job k - s[j] due date minimize sum(j in 1..nbJobs, t in s[j]..maxTime) x[j][t]*w[j]*(t-s[j]); constraints { forall(j in 1..nbJobs) sum(t in 0..maxTime) x[j][t] == 1; forall(t in 0..maxTime) sum(j in 1..nbJobs, t2 in maxl(0, t - d[j] + 1)..t) x[j][t2]*w[j] <= 2; }

Number of x variables depends on time granularity

How can we express this problem without enumerating time ?

IBM ILOG CP Optimizer

ILOG, All rights reserved

CP Optimizer modeling concepts


Data structure Variable/expression Constraint No-overlap constraint Sequencing constraints Transition distance Piecewise function Stepwise function Sequence variable Constraints on function value (alwaysIn, ) Constraints on function value (alwaysIn)

State function

Cumul function

Basic expressions over interval variable (startOf, startEval, ) Interval variable

Unary constraints (forbidXXX)

Precedence constraints (endBeforeStart, )

Logical constraints (presenceOf)

Composition constraints (alternative, span)

ILOG, All rights reserved

A production problem
Step 1 Prepare Step 1
Duration 30

Step 2 Prepare Step 2


Duration 30

Manufacturing process

Heat treating
Duration D1 Temperature T1

Heat treating
Duration D2 Temperature T2

4 possible temperature levels

Product Steps
1 2 3 4 5 T1 30 T2 30 - T3 30 T2 45 T3 45 T4 45 T1 45 T1 30 T4 30 T3 30 T4 45 T1 45 T2 45 T4 30 T3 30 T2 30

Orders
12 16 14 18 13

Oven 1 Capacity 4

Oven 2 Capacity 4

Define a production plan that minimizes the oven usage time


ILOG, All rights reserved

Oven 3 Capacity 4

A production plan
T2 Oven 1 Capacity 4
P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1

T1
P3-S1 P3-S1 P3-S1 P3-S1 P3-S1 P3-S1 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2

T2 Oven 2 Capacity 4
P2-S1 P2-S1 P2-S1 P2-S1

T4
P4-S1 P4-S1 P4-S1 P4-S1

T3
P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S3 P2-S3 P2-S3 P2-S3

T4
P2-S3 P2-S3 P3-S2 P3-S2 P3-S2 P3-S2 P3-S2 P3-S2

T2 Oven 3 Capacity 4
P2-S1 P2-S1 P2-S1 P2-S1

T1
P3-S1 P3-S1 P3-S1 P3-S1

T3
P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S3 P2-S3 P2-S3 P2-S3

T4
P2-S3 P2-S3 P3-S2 P3-S2 P3-S2 P3-S2 P3-S2 P3-S2

ILOG, All rights reserved

CP Optimizer modeling concepts


Data structure Variable/expression Constraint No-overlap constraint Sequencing constraints Transition distance Piecewise function Stepwise function Sequence variable Constraints on function value (alwaysIn, ) Constraints on function value (alwaysIn)

State function

Cumul function

Basic expressions over interval variable (startOf, startEval, ) Interval variable

Unary constraints (forbidXXX)

Precedence constraints (endBeforeStart, )

Logical constraints (presenceOf)

Composition constraints (alternative, span)

ILOG, All rights reserved

10

Modeling step 1
P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P4-S1 P4-S1 P4-S1 P4-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P3-S1 P3-S1 P1-S1 P3-S1 P3-S1 P1-S1 P3-S1 P4-S2 P1-S1 P3-S1 P4-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2 P2-S3 P2-S3 P2-S3 P2-S3

P2-S3 P2-S3 P3-S2 P3-S2

P3-S2 P3-S2 P3-S2 P3-S2

Atomic decisions:
Start date and end date of each heating task (product, step, order number) Modeled as intervals

Temporal relation
Step n+1 starts at least 30 minutes after step n
ILOG, All rights reserved

11

Model step 1
dvar interval stepHeatingInt[a in allTasks] size a.ovenDuration; minimize max(a in allTasks) endOf(stepHeatingInt[a]); constraints { forall(t in allTasks : t.stepCount == 1) { startOf(stepHeatingInt[t]) >= preparationTime; }

forall(t1,t2 in allTasks : t1.processId == t2.processId && t1.stepCount + 1 == t2.stepCount && t1.commandId == t2.commandId) { endBeforeStart(stepHeatingInt[t1], stepHeatingInt[t2], preparationTime); } }

ILOG, All rights reserved

12

Solution step 1

ILOG, All rights reserved

13

Solution Step 1

Oven 1 Capacity 4

P1-S1 P1-S1 P1-S1

P1-S2 P1-S2 P1-S2 P1-S2

P1-S3 P1-S3 P1-S3 P1-S3

P1-S1

P2-S1 P2-S1 P2-S1

P2-S2 P2-S2 P2-S2 P2-S2

P2-S3 P2-S3 P2-S3 P2-S3

P2-S4 P2-S4 P2-S4 P2-S4

Oven 2 Capacity 4
P2-S1 P3-S1 P3-S1 P3-S1 P3-S2 P3-S2 P3-S2 P3-S2 P3-S3 P3-S3 P3-S3 P3-S3

P3-S1

Oven 3 Capacity 4

P4-S1 P4-S1 P4-S1

P4-S2 P4-S2 P4-S2 P4-S2

P4-S3 P4-S3 P4-S3 P4-S3

P4-S1

ILOG, All rights reserved

14

Step 2: modeling the capacity


At any point in time, the number of heating tasks must be smaller than the available oven capacity (3 ovens of capacity 4 each) The CP Optimizer concept to model this constraint without enumerating time is a cumulative function

ILOG, All rights reserved

15

Step 2: modeling the capacity


P1-S1-C1 P1-S1-C2

1
Pulse(p1-s1-c1, 1)

0 1

Pulse(p1-s1-c2, 1)

Pulse(p1-s1-c1, 1) 2 + Pulse(p1-s1-c2, 1) 1

Cumulative functions and pulse operators


ILOG, All rights reserved

16

Model step 2
dvar interval stepHeatingInt[a in allTasks] size a.ovenDuration;

cumulFunction heatingUsage = sum(a in allTasks) pulse(stepHeatingInt[a], 1);

minimize max(a in allTasks) endOf(stepHeatingInt[a]); constraints { forall(t in allTasks : t.stepCount == 1) { startOf(stepHeatingInt[t]) >= preparationTime; }

forall(t1,t2 in allTasks : t1.processId == t2.processId && t1.stepCount + 1 == t2.stepCount && t1.commandId == t2.commandId) { endBeforeStart(stepHeatingInt[t1], stepHeatingInt[t2], preparationTime); }

heatingUsage <= sum(o in ovens) ovenCapacity[o]; }

ILOG, All rights reserved

17

Solution Step 2

ILOG, All rights reserved

18

Solution Step 2

Oven 1 Capacity 4

Oven 2 Capacity 4

P1-S1 P2-S1 P1-S2 P2-S1 P1-S1 P2-S1 P2-S1 P1-S1 P2-S1 P2-S1 P2-S1 P1-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P3-S1 P1-S1 P5-S2 P2-S2 P4-S1 P4-S1 P4-S1 P4-S1 P4-S1 P5-S1 P4-S1 P5-S1 P2-S1 P4-S1 P5-S1 P2-S2 P5-S1 P2-S1 P5-S1

Oven 3 Capacity 4

ILOG, All rights reserved

19

Step 3: selecting the oven


Prerequisite for temperature management
Selecting the oven for each heating task

Each heating task can be performed on one of the 3 ovens The CP Optimizer concept to model this is an alternative statement

ILOG, All rights reserved

20

Step 3: Selecting the oven


Min 30 minutes
P1-S1 P1-S2

Min 30 minutes
P1-S3

Alternative

Alternative

P1-S1 on O2

P1-S2 on O2

Alternative

P1-S1 on O1

P1-S2 on O1

P1-S3 on O1

P1-S3 on O2

P1-S1 on O3

P1-S2 on O3

P1-S3 on O3

Oven 1 Capacity 4

P1-S1-C1 on O1 P1-S1-C2 on O1 P1-S1-C3 on O1 P1-S1-C4 on O1

P2-S1-C1 on O1 P2-S1-C2 on O1 P2-S1-C3 on O1 P2-S1-C4 on O1

ILOG, All rights reserved

21

Model step 3
dvar interval stepHeatingInt[a in allTasks] size a.ovenDuration; dvar interval stepOvenInt[a in allTasks][f in ovens] optional; cumulFunction ovenUsage[f in ovens] = sum(a in allTasks) pulse(stepOvenInt[a][f], 1); minimize max(a in allTasks) endOf(stepHeatingInt[a]); constraints { forall(t in allTasks : t.stepCount == 1) { startOf(stepHeatingInt[t]) >= preparationTime; } [...] forall(t in allTasks) alternative(stepHeatingInt[t], all (f in ovens) stepOvenInt[t][f]);

forall(f in ovens) ovenUsage[f] <= ovenCapacity[f]; }

ILOG, All rights reserved

22

Solution Step 3

ILOG, All rights reserved

23

Solution Step 3

Oven 1 Capacity 4

P1-S1 P2-S1 P1-S2 P2-S1 P1-S1 P2-S1 P2-S1 P1-S1 P2-S1 P2-S1 P2-S1 P1-S1

Oven 2 Capacity 4

P2-S1 P2-S1 P2-S1 P2-S1 P3-S1 P1-S1 P5-S2 P4-S1 P4-S1

P2-S1 P2-S1 P2-S2 P4-S1

Oven 3 Capacity 4

P4-S1 P4-S1 P5-S1 P4-S1 P5-S1 P2-S1 P4-S1 P5-S1 P2-S2 P5-S1 P2-S1 P5-S1

ILOG, All rights reserved

24

Step 4: Managing the temperature


For each oven, at any point in time, all heating tasks are done at the same temperature. For each oven, the minimum delay between two tasks at different temperature is given by a transition matrix
T1 T2 T3 T1 T2 T3 T4 0 5 10 15 5 0 5 10

T4 10 5 0 5 15 10 5 0

The CP Optimizer concept to model this is state function

ILOG, All rights reserved

25

Step 4: modeling the temperature


Interval requiring T1 Interval requiring T1
T1 T1 T2 T3 T4 0 5 10 15 T2 5 0 5 10 T3 10 5 0 5 T4 15 10 5 0

Interval requiring T2 Interval requiring T2

4
State function for oven 1

3 2 1 0
Only intervals requiring T1 allowed

5 minutes min
Only intervals requiring T2 allowed

-1 (undefined)

State function
ILOG, All rights reserved

26

Model step 4
dvar interval stepHeatingInt[a in allTasks] size a.ovenDuration; dvar interval stepOvenInt[a in allTasks][f in ovens] optional; cumulFunction ovenUsage[f in ovens] = sum(a in allTasks) pulse(stepOvenInt[a][f], 1); stateFunction ovenTemperatureCode[f in ovens] with transitionTimes;

minimize max(a in allTasks) endOf(stepHeatingInt[a]); constraints { forall(t in allTasks : t.stepCount == 1) { startOf(stepHeatingInt[t]) >= preparationTime; } [...] forall(t in allTasks) alternative(stepHeatingInt[t], all (f in ovens) stepOvenInt[t][f]); forall(t in allTasks, f in ovens) alwaysEqual(ovenTemperatureCode[f], stepOvenInt[t][f], t.ovenTemperatureCode); forall(f in ovens) ovenUsage[f] <= ovenCapacity[f]; }
ILOG, All rights reserved

27

Solution Step 4
T2 Oven 1 Capacity 4
P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P2-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1 P1-S1

T1
P3-S1 P3-S1 P3-S1 P3-S1 P3-S1 P3-S1 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2 P4-S2

T2 Oven 2 Capacity 4
P2-S1 P2-S1 P2-S1 P2-S1

T4
P4-S1 P4-S1 P4-S1 P4-S1

T3
P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S3 P2-S3 P2-S3 P2-S3

T4
P2-S3 P2-S3 P3-S2 P3-S2 P3-S2 P3-S2 P3-S2 P3-S2

T2 Oven 3 Capacity 4
P2-S1 P2-S1 P2-S1 P2-S1

T1
P3-S1 P3-S1 P3-S1 P3-S1

T3
P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S2 P2-S3 P2-S3 P2-S3 P2-S3

T4
P2-S3 P2-S3 P3-S2 P3-S2 P3-S2 P3-S2 P3-S2 P3-S2

ILOG, All rights reserved

28

Solution Step 4 (time limit 2 minutes)

ILOG, All rights reserved

29

Solution Step 4 (time limit 2 minutes)


An aggregate view, per batch

oven 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3

startTime endTime duration temperatureCode label 30 120 90 2 P2S1: 8 125 680 555 1 P1S1: 12 - P2S4: 16 - P3S1: 10 - P4S2: 18 685 775 90 2 P1S2: 1 - P4S3: 4 - P5S3: 5 780 810 30 3 P1S3: 3 30 75 45 2 P2S1: 4 85 130 45 4 P4S1: 4 135 225 90 3 P2S2: 8 230 485 255 4 P2S3: 5 - P3S2: 7 - P4S1: 9 - P5S1: 6 490 580 90 3 P3S3: 6 - P5S2: 6 585 735 150 2 P1S2: 7 - P4S3: 4 - P5S3: 6 740 800 60 3 P1S3: 5 - P3S3: 3 30 75 45 2 P2S1: 4 80 110 30 1 P3S1: 4 120 210 90 3 P2S2: 8 215 500 285 4 P2S3: 11 - P3S2: 7 - P4S1: 5 - P5S1: 7 505 595 90 3 P3S3: 5 - P5S2: 7 600 770 170 2 P1S2: 4 - P4S3: 10 - P5S3: 2 775 805 30 3 P1S3: 4

usage 100.00% 98.65% 100.00% 75.00% 100.00% 100.00% 100.00% 100.00% 100.00% 95.00% 100.00% 100.00% 100.00% 100.00% 100.00% 100.00% 92.65% 100.00%

ILOG, All rights reserved

30

CP Optimizer modeling concepts - review


Data structure Variable/expression Constraint No-overlap constraint Sequencing constraints Transition distance Piecewise function Stepwise function Sequence variable Constraints on function value (alwaysIn, ) Constraints on function value (alwaysIn)

State function

Cumul function

Basic expressions over interval variable (startOf, startEval, ) Interval variable

Unary constraints (forbidXXX)

Precedence constraints (endBeforeStart, )

Logical constraints (presenceOf)

Composition constraints (alternative, span)

ILOG, All rights reserved

31

Project Scheduling: Work Breakdown Structure

ILOG, All rights reserved

32

Project Scheduling: Work Breakdown Structure

forall(t in tasks : t.isSubdivided == 1) { span(taskInt[t], all(s in tasks : s.parentId == t.taskId && s.projectId == t.projectId) taskInt[s]); } forall(t in dependencies) endBeforeStart(taskInt[<t.projectId, t.beforeTid>], taskInt[<t.projectId, t.afterTid>]);

ILOG, All rights reserved

33

Various costs
int n = 100; int horizon = 500; int capMax = 500; dvar interval cover in 0..horizon size horizon; dvar interval a[i in 1..n] optional in 0..horizon size i; cumulFunction free = pulse(cover, 0, capMax); cumulFunction level = sum(i in 1..n) pulse(a[i],n-i) + free; Requires n-i resources

dexpr int peak = capMax - heightAtStart(cover, free); dexpr int makespan = max(i in 1..n) endOf(a[i]); dexpr int nbTasks = sum(i in 1..n) presenceOf(a[i]); int mpeak = 1; int mmakespan = 0; int mnbTasks = 0; Size i

minimize mpeak*peak + mmakespan*makespan - mnbTasks*nbTasks; subject to { forall(i in 1..n) presenceOf(a[i]) + mnbTasks >= 1; level <= capMax - 200*mnbTasks; heightAtStart(cover, free) <= mpeak*capMax; }

Cap max
10 40 90

Horizon (500)

Free

ILOG, All rights reserved

34

Various costs
600 500

400 minimize makespan Minimize peak Maximize task count with cap 300 200

Requires n-i resources

300

100

Size i
0 1 38 75 112 149 186 223 260 297 334 371 408 445 482

Cap max
10 40 90

Horizon (500)

Free

ILOG, All rights reserved

35

CP Optimizer modeling concepts - review


Data structure Variable/expression Constraint No-overlap constraint Sequencing constraints Transition distance Piecewise function Stepwise function Sequence variable Constraints on function value (alwaysIn, ) Constraints on function value (alwaysIn)

State function

Cumul function

Basic expressions over interval variable (startOf, startEval, ) Interval variable

Unary constraints (forbidXXX)

Precedence constraints (endBeforeStart, )

Logical constraints (presenceOf)

Composition constraints (alternative, span)

ILOG, All rights reserved

36

Modeling with IBM ILOG CP Optimizer


To learn how to model scheduling problems without enumerating time
CP Optimizer modeling concepts for scheduling
30 pages

CP Optimizer tutorial
54 pages

Resources at cpoptimizer.ilog.com

ILOG, All rights reserved

37

Thank You!

You might also like