scheduling - computing science - simon fraser … · 2006-09-05 · e.g. staff/employee/crew...

28
Simon Fraser University School of Computing Science October 10, 2004 Copyright © 1998 by Bill Havens 1 of 28 Scheduling Denition: Scheduling is the allocation of resources to activities over time. e.g. Time Tabling e.g. Staff/Employee/Crew Scheduling e.g. Job Shop/Production Scheduling e.g. Project Management e.g. Scheduling of Processes in an Operating System

Upload: lythuy

Post on 26-Aug-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 1 of 28

Scheduling

Definition

: Scheduling is the allocation of resources to activities over time.

e.g. Time Tabling

e.g. Staff/Employee/Crew Scheduling

e.g. Job Shop/Production Scheduling

e.g. Project Management

e.g. Scheduling of Processes in an Operating System

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 2 of 28

Scheduling is a CSP

The al location of resources is subject to various constraints.

e.g. Time tabling

room capacity

at most 1 course per room

AV requirements

e.g. Staff/Employee/Crew Scheduling

no double bookings

employee must be qualified for the activity

union regulations

company policies

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 3 of 28

e.g. Job Shop/Production Scheduling

due dates

resource constraints

e.g. Film Festival Schedule

artistic considerations

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 4 of 28

Scheduling as Optimization Problems

Often a number of, possibly conflicting, optimization criteria

The problems are usually NP-hard.

e.g. Time tabling

minimize the # of rooms used.

exam scheduling: minimize the # of conflicts

e.g. Staff/Employee/Crew Scheduling

minimize the # of employees

minimize the amount of overtime

maximize the “fairness” of the schedule

maximize the # of employee requests

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 5 of 28

e.g. Job Shop/Production Scheduling

minimize the # of tardy orders.

maximize machine utilization

minimize the amount of work in progress

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 6 of 28

Modelling Scheduling Problems as CSPs

The key questions are:

What are the domain variables?

What are the constraints?

What are the optimization criteria?

Sequence of examples:

1. Scheduling with precedence constraints2. Scheduling with precedence and resource constraints3. The bridge scheduling problem4. Scheduling with non-unit capacity resources5. Resource allocation

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 7 of 28

Scheduling with Precedence Constraints

Given:

Set of

n

tasks:

t

1

,

t

2

,...,

t

n

Durations:

d

1

,

d

2

,

...,

d

n

Set of precedence constraints: e.g.

t

i

before

t

j

Find: An assignment of start times (integers) to tasks that minimizes the duration of the project subject to the constraint that:

t

i

must end before

t

j

starts if there is a precedence constraint between

t

i

and

t

j

.

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 8 of 28

Often visualize as a graph:

Find the minimum start time for

t

end.

t1

t2 t3t5

t6

t4t7

t9t8 t10 tend8

8

8

11

1 2

1 3 2 1

1

3

7

7

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 9 of 28

As a CSPOne domain variable per task:

• Si represents the start time of the ith task.

• Initial domain is {0, 1,..., max_duration}

• The only constraints are the precedence relations:

ti before tj ≡ Si + di ≤ Sj

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 10 of 28

The task graph is the constraint graph:

S1

S2 S3

S5

S6

S4

S7

S9S8 S10 Send8

8

8

11

1 2

1 3 2 1

1

3

7

7

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 11 of 28

Propagation using Arc Consistency• Given a constraint Si + di ≤ Sj, how are the domains of Si and Sj

revised?

• Assume that we enforce arc-consistency.

• Propagation works in two directions:

1. Earlier Task to Later Task: Si + di ≤ Sj.

• from definition of arc consistency: eliminate s from dom(Sj) if

~ (∃ v ∈ dom(Si) s.t. v + di ≤ s )

• or min(dom(Si)) + di ≤ Sj

Si

Si + di

Sj

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 12 of 28

2. Later Task to Earlier Task: Si ≤ Sj - di

• or Si ≤ max(dom(Sj)) - di

Si

Si + di

Sj

Sj - di

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 13 of 28

Constraint Graph After PropagationPropagation finds the earliest possible start time for each task.

Now know that the earliest possible finish time for the project is 22.

S1

S2 S3

S5

S6

S4

S7

S9S8 S10 Send8

8

8

11

1 2

1 3 2 1

1

3

7

7

[0,8]

[7,15][15,23]

[15,23]

[15,27]

[16,24] [21,29]

[22,30]

[10,22]

[7,19]

[19,27]

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 14 of 28

To minimize the project’s duration:• assume that the project can finish as early as possible.

• change the domain of Send to be {22} and propagate.

S10 + 1 ≤ Send implies S10 + 1 ≤ 22 implies S10 ≤ 21

After propagation:

S1

S2 S3

S5

S6

S4

S7

S9S8 S10 Send8

8

8

11

1 2

1 3 2 1

1

3

7

7

[0,0]

[7,7][15,15]

[15,15]

[15,19]

[16,16] [19,19] [21,21]

[22,22]

[10,14]

[7,11]

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 15 of 28

Equivalent to the Critical Path Method (CPM):• Nodes on the critical path have singleton domains

• Cannot be delayed without delaying the project.

• There is one “unsolved” constraint: S2 + 3 ≤ S3

• Not every combination of values from dom(S2) and dom(S3) satisfies the constraint.

• Can be solved by setting dom(S2) to {7}

Note: the problem is easily solvable in polynomial time.

Note: the domains may be represented by intervals rather than sets.

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 16 of 28

Scheduling with Resource Constraints• Typically, activities require some resources in order to complete.

• e.g. people, machines, rooms

• Extend the previous problem to include unit-capacity resources.

Given:• Set of n tasks: t1,t2,..., tn

• Durations: d1, d2,..., dn

• Set of precedence constraints: e.g. ti before tj

• Resource requirements: r1, r2,..., rn

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 17 of 28

Find: An assignment of start times to tasks that minimizes the duration of the project subject to the constraints that:

1. ti must end before tj starts if there is a precedence constraint between ti and tj.

2. ti and tj cannot overlap in time if they must share a resource (i.e. if ri = rj).

Note: The problem is NP-hard.

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 18 of 28

Modelling as a CSPDomain Variables

• S1, S2,..., Sn - start times of the tasks (as before)

Constraints:

1. if ti before tj then Si + di ≤ Sj

2. If ri = rj then Si + di ≤ Sj or Sj + dj ≤ Si

Note: The second constraint is called a disjunctive constraint.

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 19 of 28

Disjunctive ConstraintsCan get domains with “holes”:

• e.g. dom(Si) = [0,30], dom(Sj ) = 10, durations dj = di = 5

Si ≤ 5 or Si ≥ 5 or dom( Si) = [0,5] ∪ [15,30]

• Can represent the domains as sets (bit-vectors)

• Use hierarchical arc consistency on reals (HACR)

Can be handled in different ways:1. Using the definition of arc consistency

2. Wait until singleton domains (delay operator)

3. Wait until one disjunct is true (cardinality constraint)

4. As a choice during search (Prolog approach)

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 20 of 28

Using the Defn of Arc Consistency• Remove a start time vi from dom(Si) if

~ (∃ vj ∈ dom(Sj) s.t. vi + di ≤ vj or vj + dj ≤ vi)

• May by time consuming.

• Or express using union (Cogdonet & Diaz clp(FD)):

Si in [0, max(dom(Sj))-di ] ∪ [min(dom(Sj))+dj, ∞]

Sj in [0, max(dom(Si))-dj ] ∪ [min(dom(Si))+di, ∞]

• These are interpreted as functions that refine the domain of the variable on the LHS when a variable on the RHS changes

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 21 of 28

Wait Until Singleton Domain Wait until one of the domain is a singleton and then revise the other.

e.g. if dom(Sj) = {vj} then eliminate [vj-di, vj+dj] from dom(Si).

Wait Until One Disjunct is True ( Nicolog & clp(BNR) )Propagate the disjunct/constraint Si + di ≤ Sj if:

• It is implied by the constraint graph

• Sj + dj > Si is implied by the constraint graph

• Similarly for the disjunct Si + di ≤ Sj .

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 22 of 28

As a Choice During SearchTraditionally, CSPs are solved by:

1. Setting up the constraint graph

2. Using a backtracking search algorithm to assign values to variables

Generalization: constraint posting• Initially, constraint graph contains only the precedence constraints.

• During search:

1. tentatively add one of the disjuncts to the constraint graph2. may have to backtrack and add the other disjunct instead

• In CLP, this corresponds to calling noOverlap predicate during search.

noOverlap(Si, Di, Sj, Dj) :- Si + Di ≤ Sj.noOverlap(Si, Di, Sj, Dj) :- Sj + Dj ≤ Si.

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 23 of 28

Least Commitment Principle• When making a choice, try to add a constraint that make less of a

commitment because it is less likely to be wrong.

• The above choice commits to putting one task before another rather than choosing a particular start time for a task.

Experimental Results on the Bridge Scheduling Problem:[Dincbas, Simonis, van Hentenryck] - #4 (as a choice) is best

Subsequently found that combining #4 can be used a search heuristic combined with #1 or #3 to give better results.

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 24 of 28

OptimizationCan optimize a CSP by solving a sequence of CSPs.

1. add a domain variable (CostVar) to represent the cost a solution

2. add constraint between the CostVar and existing vars

3. solve the CSP and find the cost of the solution

4. add a new constraint: CostVar < cost

5. solve the new CSP

6. repeat step 3-5 until no solution is possible.

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 25 of 28

Performance• Iteratively finds better-and-better solutions.

• Branch-and-bound like

• prune the current state if CostVar ≥ cost.

• may be necessary to program in special purpose bounding functions

• i.e. prune if lower_bound(partial_solution) ≥ cost.

• defined in the CHIP CLP language.

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 26 of 28

The Bridge Scheduling ProblemProblem from Bartusch’s Ph.D. thesis

<<< Diagram >>>

46 Tasks and 7 resources

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 27 of 28

Additional Constraints:1. Time between completion of a formwork and its corresponding

foundation is at most 4 days.

2. There are at most 3 days between the end of a particular excavation (or foundation piles) and the beginning of the corresponding formwork.

3. The formworks must start at least 6 days after the beginning of the erection of the temporary housing.

4. The removal of the temporary housing can start two days before the end of the last masonry work.

5. The delivery of the performed bearers occurs exactly 30 days after the beginning of the project.

Simon Fraser University School of Computing Science

October 10, 2004 Copyright © 1998 by Bill Havens 28 of 28

Summary of computational results:• Original solution using branch-and-bound took well over 20 mins.

• Chip on Sun-3 took 43 seconds.

• Nicolog on a Sparc IPX takes 3 seconds.