Resource Scheduling Constraints - Uppsala UniversityResource scheduling • Problem: tasks subject...

Post on 06-May-2020

8 views 0 download

Transcript of Resource Scheduling Constraints - Uppsala UniversityResource scheduling • Problem: tasks subject...

Resource Scheduling Constraints

Nicolas BeldiceanuSICS

Lägerhyddsvägen 5SE-75237 Uppsala,

Sweden(nicolas@sics.se)

Resource scheduling constraints

1. Overview2. Cumulative3. Cumulatives

Resource scheduling

• Problem: tasks subject to temporal andresource constraints

• Most successful area of CP• LP is usually poor on this type of problems• Two main categories of resources:

- renewable- non-renewable

Resource scheduling constraints

1. Overview2. Cumulative3. Cumulatives

ARGUMENTS :ctr_arguments(cumulative,

[TASKS-collection(origin-dvar, duration-dvar, end-dvar, height dvar),LIMIT-int]).

PURPOSE :The cumulative constraint enforces that at each point in time,the cumulated height of the set of tasks that overlap that point,does not exceed a given limit.

ORIGIN : [AggounBeldiceanu93]

EXAMPLE :cumulative([[origin-1, duration-3 , end-4 , height-1],

[origin-2, duration-9 , end-11, height-2],[origin-3, duration-10, end-13, height-1],[origin-6, duration-6 , end-12, height-1],[origin-7, duration-2 , end-9 , height-3]],8)

Cumulative

Cumulative

INITIAL GRAPH

Cumulative

1 2 3 4 5 6 7 8 9101112

≤≤≤≤ 8

( 3+1+1+2 ≤≤≤≤ 8 )

7

ARGUMENTS :ctr_arguments(coloured_cumulative,

[TASKS-collection(origin-dvar, duration-dvar, end-dvar, colour-dvar),LIMIT-int]).

PURPOSE :The coloured_cumulative constraint enforces that at each point intime, the number of distinct colours of the set of tasks that overlapthat point, do not exceed a given limit.

ORIGIN : Derived from cumulative and nvalues.

EXAMPLE :coloured_cumulative([[origin-1, duration-2 , end-3 , colour-1],

[origin-2, duration-9 , end-11, colour-2],[origin-3, duration-10, end-13, colour-3],[origin-6, duration-6 , end-12, colour-2],[origin-7, duration-2 , end-9 , colour-3]],2)

Coloured_cumulative

Coloured_cumulative

INITIAL GRAPH

Coloured_cumulative

1 2 3 4 5 6 7 8 9101112

≤≤≤≤ 2

3 2 3 2 1

nvalues([3,2,3,2],≤≤≤≤,2)

7

Definition of cumulative

cumulative(Origins,Durations,Heights,Limit)ListDvars ListDvars ListDvars Int

time

quantityof resource

Limit

task

origin

height

duration

Example of cumulative

O1 in 1..2, O2 in 3..3, D1 in 2..3, D2 in 2..2, H1 in 1..4, H2 in 2..3

cumulative([O1,O2],[D1,D2],[H1,H2],4),

labeling([leftmost,up],[O1,D1,H1,O2,D2,H2]).

[1,2,1,3,2,2] [1,3,1,3,2,3][1,2,1,3,2,3] [1,3,2,3,2,2][1,2,2,3,2,2] [2,2,1,3,2,2][1,2,2,3,2,3] [2,2,1,3,2,3][1,2,3,3,2,2] [2,2,2,3,2,2][1,2,3,3,2,3] [2,3,1,3,2,2][1,2,4,3,2,2] [2,3,1,3,2,3][1,2,4,3,2,3] [2,3,2,3,2,2][1,3,1,3,2,2]

Main applications of cumulative

1 2 3

1

Renewable resource

• disjunctive scheduling

• cumulative scheduling

Non renewable resource

• producer consumer

Bin-packing

Necessary condition for placement

Producer-Consumer

Final Stock

Consumed Quantity C

Stock production task

Consumer task

Initial stock

Produced Quantity P

Cumulative for placement

We want to place the 8 followings rectangles in a 12 x 4 rectangle :R1(5×2), R2(8×3), R3(6×1), R4(5×1), R5(2×1), R6(3×1), R7(2×2), R8(1×2) .

There exists a cumulative solution (by cutting R8 into two pieces) but there is no solution with a non-overlapping constraint on rectangles.(proof : M. Hujter, On the dynamic storage allocation problem, Manuscript, Computer and Automation Institute Hung. Acad. Sci. (1990))

4

3

2

1

00 1 2 3 4 5 6 7 8 9 10 11 12

R8

R1 : 5 × 2

R2 : 8 × 2

R1 : 6 × 1

R8

R4 : 5 × 1

R5

R6:3 × 1

R2 : 2 ×××× 2

Resource scheduling constraints

1. Overview2. Cumulative3. Cumulatives

The cumulatives constraint

The original cumulative constraint:

Restrict the resource consumptionat each point in time.

The generalized cumulatives constraint:

A pool of cumulative resources ,Height of a task can be negative ,Maximum or minimum resource consumption ,Holds for time-points crossed byat least one task.

1 2 3 4 5 601234

12

3 4

time

resource consumption ≤≤≤≤ 4

time

resource consumption

1 2 3 4 5 6-2-1012-101

Cumulatedprofiles

2

13

45

76 ≥≥≥≥ 0

≥≥≥≥ 0

Parameters• Tasks:

• Origin• Duration• End• Height• Machine

1 2 3 4 5 601231

time

Origin EndDuration

HeightMachine

ConsumptionResource 2

Resource 1

Origin+Duration=End

0 0

• Constraint:

• upper• lower 1

231

≤ 1231

• MachineId• Limit

01231

LimitIdentifier

• Resources:

task(O,D,E,H,M)

machine(M,L)

bound(Ctr)

DEFINITION

For all tasks :

For all time-points crossed by task :

Let be the machine where task is assigned ,

For all tasks which both cross point , and are assigned to :

The sum of the height of tasks is not greater (less)

than the capacity of machine .

tt

ti

ms i m

ms

time

resource consumption

-2-1012-101

3

5

76 ≥≥≥≥ 0

≥≥≥≥ 0

Machine 1

Machine 2

1

2

4

1 2 3 4 5 6

EXAMPLE

Original cumulative constraint

1 2 3 4 5 6

01234

12

3 4

time

resource consumption

Maximum capacity

({machine-1 origin-2 duration-2 height-2machine-1 origin-4 duration-2 height-1machine-1 origin-3 duration-1 height-1machine-1 origin-5 duration-1 height-3},{id-1 capacity-4},

≤≤≤≤)

cumulatives

cumulative constraint withmachine choice

({machine-1 origin-2 duration-3 height-1,machine-1 origin-3 duration-2 height-2,machine-2 origin-2 duration-4 height-1,machine-1 origin-6 duration-1 height-2},{id-1 capacity-3,id-2 capacity-1},

≤)

cumulatives

resource consumption

Machine 2 with capacity 1

Machine 1 with capacity 3

1 2 3 4 5 601231

time

1

2

3

4

Uninterupted minimum levelof resource consumption

({machine-1 origin-2 duration-4 height-0,machine-1 origin-2 duration-4 height-1,machine-1 origin-2 duration-2 height-1,machine-1 origin-4 duration-2 height-2,machine-1 origin-4 duration-1 height-1},{id-1 capacity-2},≥≥≥≥)

cumulatives

1 2 3 4 5 601234

time

resource consumption

23

45

1

Minimum consumption is 2

First use Last use

Minimum level ofresource consumption

({machine-1 origin-2 duration-2 height-1,machine-1 origin-2 duration-1 height-2,machine-1 origin-3 duration-1 height-1,machine-1 origin-5 duration-2 height-2},{id-1 capacity-2},≥≥≥≥)

cumulatives

1 2 3 4 5 601234

time

resource consumption

No constraint at this point

31

2

4

Minimum consumption is 2

Producer-consumer

cumulatives machine-1 origin-1 duration-3 height-2,machine-1 origin-1 duration-4 height-3,machine-1 origin-1 duration-6 height-1,machine-1 origin-5 duration-2 height-4},

({

{id-1 capacity-7},

≤)

time

resource consumption

No negative stock

1 2 3 4 5 601234567

1 4

2

3

Stock at thispoint in time

Producer-Consumer withmultiple resources

cumulatives

{id-1 capacity-4,id-2 capacity-3},≤ )

time

resource consumption

No negative stock on resource 2

1 2 3 4 5 601234123

Stocks at thispoints in time

3

1

2

4

5 No negative stock on resource 1

machine-1 origin-1 duration-1 height-1,machine-1 origin-1 duration-3 height-2,

machine-2 origin-1 duration-3 height-1,

machine-2 origin-3 duration-4 height-2}

machine-1 origin-3 duration-4 height-1,

,

({

Workload covering

cumulatives

{id-1 capacity-0},≥)

time

resource consumption

Green tasks”cover” yellow tasks

1 2 3 4 5 6-4-3-2-10123

Cumulatedprofile

machine-1 origin-2 duration-2 height-(-2),machine-1 origin-4 duration-2 height-(-3),

({

1

3

2

45

6

machine-1 origin-1 duration-4 height-1,machine-1 origin-5 duration-2 height-1,machine-1 origin-2 duration-4 height-1,machine-1 origin-3 duration-3 height-1},

Workloads covering

cumulatives

{id-1 capacity-0,id-2 capacity-0}≥ )

({

time

resource consumption

1 2 3 4 5 6-2-1012-101

Cumulatedprofiles

2

13

45

76

machine-1 origin-2 duration-2 height-(-2),

machine-1 origin-1 duration-4 height-1,

machine-1 origin-4 duration-2 height-(-1),

machine-1 origin-2 duration-3 height-2,machine-1 origin-5 duration-2 height-2,

machine-2 origin-3 duration-2 height-(-1),

machine-2 origin-1 duration-4 height-1},

Green tasks”cover” yellow tasks on

both resources

Exercise: project scheduling

Each task requires a given number of persons.Knowning that you have at most 7 persons,find the earliest end.

T12-1

T21-3

T34-3

T42-2

T53-4

T61-6

T70-0

Exercise: project scheduling (load)

Each task requires a given load (duration x needed resource).Knowning that you have at most 7 persons, modify your previous programin order to find the earliest end.

T11

T23

T312

T44

T512

T66

T70

Exercise: perfect square

Write a program for finding a solution for placing21 squares of respective size [50,42,37,35,33,29,27,25,24,19,18,17,16,15,11,9,8,7,6,4,2]) into asquare of size 112 without overlap.

Exercise: machine scheduling

Each task has to run on a given machinechosen from a set of machines. Each machinecan only run one task at a time and each taskshould not be interrupted. Find the earliest end.

T12-{1,2}

T21-{1,3}

T34-{1,3}

T42-{2,3}

T53-{1}

T61-{1,3}

T70-{}

Exercise: machine scheduling(quotient labeling)

Create a specialized labeling which, for eachtask, creates a compulsory part (intersection of the task positioned at its earliest start andof the task positioned at its latest start) ofsize 1. Justify the use of this heuristics.

Exercise: machine scheduling(variable speed)

The effective duration of a task is now computedby multiplying the ”duration” by a fixed coefficient(2 of M1, 1 of M2, 3 for M3).Modify your program to handle this factor.

The Sweep Algorithm: Fixed Tasks

resource

timeEvent pointsMinimum level to reach

for those instants wherethere is at least one task

Current positionof the sweep line: 3

Sweep-linestatus

01234

Task 1

Task 2 Task 3

• nb_task=1• sum_height=2

1 2 4 5

Sweep line status:number of tasks

sum of the height

•which overlap the sweep line

Event points:start of each task

end of each task

• nb_task=2• sum_height=3

•••• nb_task=0•••• sum_height=0

• nb_task=1• sum_height=4

• nb_task=0• sum_height=0

Not Yet Fixed Tasks

Preconditions for a Check Event

max(origin[t])<min(end[t])

min(machine[t])=max(machine[t])=r

max(height[t])<max(0,Limit[m])

machine[t]

: nb_task=nb_task+1

: nb_task=nb_task−−−−1

Start

End

QUESTIONANSWER

ACTION

: which instants to check ?: those instants for which there is a task which can cause a problem

: count the number of such tasks which overlap the sweep line

Not Yet Fixed Tasks (continued)

Preconditions for a Bad Profile Event

max(origin[t]) < min(end[t])

min(machine[t]) = max(machine[t]) = r

max(height[t]) < 0

r

: sum_height=sum_height+max(height[t])

: sum_height=sum_height −−−−max(height[t])

Start

End

QUESTIONANSWER

ACTION

: how to build an ”optimistic” resource consumption profile ?: consider the ”bad” and ”good” tasks

: sum up the height of such tasks which overlap the sweep line

Preconditions for a Good Profile Eventr ∈∈∈∈ dom(machine[t])

max(height[t]) > 0

r

: sum_height=sum_height+max(height[t])

: sum_height=sum_height −−−−max(height[t])

Start

End

10. if nb_task≠0 and sum_height<limit to reach then return fail

1. Scan the tasks and generate the check and profile events

2. Sort the events in increasing order

3. Set nb_task and sum_height to 0 and d to the smallest date

The Sweep Algorithm: Main Loop(simplified version: one resource, no pruning)

4. while there still exist an event E do

9. Extract the next event E (if it exists)

INITIALIZATION

CHECK

MODIFY SWEEP STATUS

CHECK

5. if d≠date of E then

6. if nb_task≠0 and sum_height<limit to reach then return fail

7. Set d to date of E

8. if type of E=check then add E.inc to nb_task else add E.inc to sum_height

Principle of the Generalization Algorithm

1 2 3 4 5 60

1

2

3

1

time

1

2

3

4

Machine 1

Machine 2

1 2 3 4 5 6

?

?

Removes 3,4 from origin of task 4

Task Interval

DEFINITION: At each instant: ΣΣΣΣ heigths ≥≥≥≥ Capacity

NECESSARY CONDITION: ΣΣΣΣ surfaces ≥≥≥≥ utilisation of interval x Capacity

IDEA: sum up over each instant where we have at least one task

time1 2 3 4 5 6-4-3-2-10123

≥≥≥≥ 1

time

resource consumption

1 2 3 4 5 6-4-3-2-10123

13

2

456

≥≥≥≥ 1

interval ≥≥≥≥ (1+1+1)X1(3-1)+(1+1+1-2)+(1+1+1-2)

Task Interval (atleast case)

• For tasks with negative height

• For tasks with positive height

• If non-negative capacity

• If negative capacity

: minimum intersection with interval

: maximum intersection with interval

: minimum utilization in time of interval

: maximum utilization in time of interval

CHECKING THE NECESSARY CONDITION

• Forbid to cover more than a given surface in an interval

• Force to cover at least a given surface in an interval

PRUNING ACCORDING TO THE NECESSARY CONDITION

Minimum Intersection of a Task with an Interval

interval

T at its earliest startand minimum duration

T at its latest endand minimum duration

2 1

Compute the size of the intersection withthe interval of these two instances,

and take the minimum

Result is 1

Key ideas of most algorithms forresource scheduling: compulsory part

DEFINITION : The Compulsory Part CP (A. Lahrichi PhDthesis 1979) is the intersection of all feasibleinstances of the task T

INTEREST : No need to wait until all the variables(start, duration, resource consumption) of task T are fixed to deduce some information about resource consumption of T over time.The other tasks will not have access to that resource amount � pruning

MAIN QUESTION : How to efficiently compute the CP?

To compute CP, we need to compute only the intersection of the two followings instances of the rectangle task :

Imin= task at its earliest date with minimum duration Imax= task at its latest date

Compulsory part

Startmin Startmax Startmin + Durationmin

Durationmin

Durationmax

CP of a rectangle task

3TTT CPCPCP21

∪∪Startmax

Startmin

T1 T2T3

T1 T2T3

321 TTTCP ∪∪

∅=1TCP

∅=2TCP

CP of the “global” task

CP of a sequence of rectangles

Scheduling Problem under Labour Constraints

resource

time0 1 2 3 4 5 6 7 8 9 10 11 12

6543210

Compulsory part of T2

� T1 can not start at positions 0,1,2 and 6

T2T1• Starting time of of T2 within [1, 3]

• No restriction on the starting time of T1

• Resource capacity equal to 6

Use of CP for pruning

Plane task (LT)

Smax Emin

Smin Smax Emin Emax

Earliest startImin

Latest endImax

Task

CP of a task with valleys

CP = Imin∩ Imax ∩ LT

Key ideas of most algorithms forresource scheduling: task interval

IDEA : Compute the intersection of all feasible instancesof a task T with a given interval and take the minimum.Repeat the previous step for all tasksCumulate all the minimum intersections and checkthat it does not exceed the available surface

MAIN QUESTION : How to efficiently compute the minimumintersection with an interval?

Exercise: maximum intersection

Consider a cumulative scheduling problem where one needs to use almostall the resource availability (i.e. the sum of the surface of the tasks is almostequal to the resource availability).

Question 1: consider a fixed interval low..up and a task t characterizedby its origin, duration and end (3 domain variables).Come up with a method for computing the maximum intersectionin surface (or a lower approximation) of task t with intervallow..up.

Question 2: how could you use the result of question 1 to perform somepruning in the context of the cumulative constraint ?