23mst368book B Unit b2 Vle
23mst368book B Unit b2 Vle
Unit B2
Optimal paths, packing and
scheduling
Contents
Introduction 119
4 Scheduling 163
4.1 Scheduling a project for a given number of workers 163
4.2 Algorithms with protection schemes 172
Index 200
Introduction
Introduction
The mathematical concept of a path in a network is a powerful tool in
enabling a wide range of problems to be represented and solved. Typical
examples include finding an appropriate route through a road system, or
scheduling a building project by ordering related activities as a path in
time from the commencement to the completion of the project.
Often we want to choose the ‘best’, or ‘optimal’, path. Finding paths
involves the following four types of combinatorial problem.
Existence problem Does a path exist between two given
vertices?
Construction problem Can we construct a path?
Enumeration problem How many paths are there?
Can we list them all?
Optimisation problem Can we find the ‘best’ path(s) available?
Situations in which we wish to find optimal paths are often naturally
modelled using networks. Usually the arc appropriately models the
transition from one state or position to another, and the optimisation
problem is in terms of weights attached to the arcs and/or the vertices
(capacities, lengths, costs, times). Network theory enables us to define
optimal for particular situations, and gives methods for finding the optimal
paths. These methods are often expressed as algorithms that find the
desired optimal paths by construction.
In this unit we show how various situations can be modelled by networks,
and we present several algorithms for finding different types of optimal
path.
In Section 1 Optimal path algorithms, we describe two algorithms: a
shortest path algorithm and a longest path algorithm. Finding the shortest
path has applications in areas such as road, rail and air transport
planning. The shortest path problem can also appear in many other guises,
such as geographical mapping software and computer networks. The
longest path problem plays an important role in Section 3.
In Section 2 Activity networks, we construct networks (known as activity
networks) representing the various stages in the completion of a project
that involves a number of related activities.
Then, in Section 3 Critical path analysis, we consider the problem of
finding optimal paths in activity networks. An optimal path represents an
optimum schedule for the project. We study these schedules further in
Section 4. Within such networks, some activities are critical in the sense
that any delay in completing them delays the completion of the whole
project. Critical path analysis identifies these activities and finds paths
with the minimum completion time for the project, given a sufficient
number of workers, thus establishing the optimum time that can be
achieved in the given circumstances.
119
Unit B2 Optimal paths, packing and scheduling
120
1 Optimal path algorithms
S T
Figure 1
We claim that the potential of each vertex W gives the length of a shortest
path from S to that vertex. This is clearly true when W = S, since the
algorithm gives S a potential of 0. Also, if this statement is true for all the
potentials assigned so far, then it is true for all potentials assigned at the
next stage since, in assigning a potential to a vertex W , the algorithm tells
us to consider all paths through vertices with known potentials (which we
know to be lengths of shortest paths) and to add on the distance from such
a vertex to W , taking the smallest such value; any path involving vertices
121
Unit B2 Optimal paths, packing and scheduling
Example B2.1
Find the shortest path(s) from S to T in the given network.
1 6
7 B
4
3
S 9 C 3 T
7 1 4
122
1 Optimal path algorithms
Solution
We use the shortest path algorithm. We start by giving S zero potential.
First iteration
We label the vertices that can be reached directly from S. The smallest
vertex label is 4, and so we assign potential 4 to B. We put a box around
the vertex label 4 to show that it is the potential assigned to B.
7
A
1 6
7 B
4
4
3
S 9 C 3 T
0 9
7 1 4
D
7
Second iteration
We label the vertices that can be reached directly from B, crossing out
larger vertex labels from previous iterations. The smallest vertex label is 5,
and so we assign potential 5 to A.
123
Unit B2 Optimal paths, packing and scheduling
7 5
A
1 6
7 B
4
4
3
S 9 C 3 T
0
97
7 1 4
D
7
Third iteration
We label the vertices that can be reached directly from A. The smallest
vertex label is 7, and so we assign potential 7 to C and also to D.
7 5
A
1 6
7 B
4
4
3
S 9 C 3 T
0 11
9 7
7 1 4
D
7
Although T now has a label, it has not yet been assigned a potential,
and so we carry on with further iterations of the algorithm.
124
1 Optimal path algorithms
Fourth iteration
We label the vertices that can be reached directly from C or D. The
smallest vertex label is 10, and so we assign potential 10 to T . We put the
symbol ∗ in columns C and T in the final row, to show that, while C
and T can be reached directly from D, the resulting vertex labels would be
greater than ones already assigned to C and T , respectively.
7 5
A
1 6
7 B
4
4
3
S 9 C 3 T
0 ⇢ 10
⇢
11
9 7
7 1 4
D
7
The final table in Example B2.1 provides full information about the labels
and potentials assigned at each stage. So, in answer to an exercise that
asks you to find a shortest path, it is enough to give just the final table,
together with the shortest path and its length. You might find the
following observations about the structure of the table helpful.
125
Unit B2 Optimal paths, packing and scheduling
• Each row should contain a vertex label or asterisk (∗) for each vertex
joined to the origin vertex for that row, by an arc directed away from
the origin vertex.
• A potential is assigned during each iteration, and if the smallest label
occurs multiple times, a potential is assigned to each occurrence.
• If you assigned multiple potentials during the preceding iteration, then
the next iteration must have the corresponding number of rows in the
table; each newly assigned potential will give rise to an origin vertex.
• Look for the lowest temporary label across all table entries to identify
the next potential; the assigned potential may not appear in the row(s)
for the current iteration.
• Going down each column, the entries decrease in size, with the smallest
value in a box, to show that it is the assigned potential for that vertex.
Any further entries below the boxed one consist of asterisks or repeat
the boxed entry. Two such boxed entries in a column mean that there
are two shortest paths from S to that column’s vertex.
Exercise B2.2
Find the shortest path from S to T in the following network. Give the
table of labels, the shortest path and its length.
A
25
7 D
4 5
13 B
S 6 10 T
5 12
28 E
3
C
126
1 Optimal path algorithms
The following observations explain why the longest path algorithm works.
The algorithm is designed so that, at each stage, the vertex labels will give
the length of the longest path from S to the relevant vertex using only
vertices with known potentials to reach that vertex. A vertex W is
assigned a potential only when all the vertices from which W can be
reached directly have known potentials. The longest path from S to W
will need to go through one of these vertices just before reaching W . The
label of W is chosen to be as large as possible; hence it will give the length
of the longest path from S to W . As for the shortest path algorithm, this
argument can be formalised using mathematical induction.
We now consider an example.
127
Unit B2 Optimal paths, packing and scheduling
Example B2.3
Find the longest path(s) from S to T in the given network.
1 6
7 B
4
3
S 9 C 3 T
7 1 4
Solution
We use the longest path algorithm. We start by giving S zero potential.
First iteration
We label the vertices that can be reached directly only from S; that is,
we label the vertices B and D. We don’t label A or C since both A and C
can also be reached from B, which does not yet have a potential. As B
and D can be reached only from S, we assign potential 4 to B and
potential 7 to D, marked by placing these numbers inside boxes.
1 6
7 B
4
4
3
S 9 C 3 T
0
7 1 4
D
7
128
1 Optimal path algorithms
Second iteration
We label the vertices that can be reached directly only from S, B
and/or D; that is, we label the vertices A and C. We don’t label T as it
can be reached from A and C, which do not yet have potentials. The
largest vertex label for A is 7, and so we assign potential 7 to A. The
largest vertex label for C is 9, and so we assign potential 9 to C.
5 7
A
1 6
7 B
4
4
3
S 9 C 3 T
0
78 9
7 1 4
D
7
Third iteration
We label the vertices that can be reached directly only from any
of S, A, B, C and D. The largest vertex label for T is 13, and so we assign
potential 13 to T .
129
Unit B2 Optimal paths, packing and scheduling
5 7
A
1 6
7 B
4
4
3
S 9 C 3 T
0 ⇢⇢
⇢
11 ⇢ 13
12
78 9
7 1 4
D
7
The final table in Example B2.3 provides full information about the labels
and potentials assigned at each stage. So, in answer to an exercise that
asks you to find a longest path, it is enough to give just the final table,
together with the longest path and its length. You might find the following
observations about the structure of the table helpful.
• The table will contain one row per vertex, with the exception of S, and
in each row a potential is assigned to the vertex listed in the column
‘vertices assigned labels’.
• Each row concerns one vertex that is being assigned a label. The row
shows a label for that vertex arising from each arc directed towards the
vertex in question from another vertex in the network.
• A potential is assigned by selecting the largest vertex label in a row; if
the largest label occurs multiple times in that row, a potential is
assigned to each occurrence. This can give rise to more than one option
for a longest path.
130
2 Activity networks
Exercise B2.4
Find the longest path from S to T in the following network. Give the table
of labels, the longest path and its length.
A
25
7 D
4 5
13 B
S 6 10 T
5 12
28 E
3
C
Learning outcomes
After studying this section, you should be able to:
• apply the shortest path algorithm to find the shortest path(s)
between two vertices in a network
• apply the longest path algorithm to find the longest path(s)
between two vertices in a network without cycles.
2 Activity networks
In Sections 2, 3 and 4 we describe the use of network analysis in planning
and scheduling the activities involved in large-scale projects such as those
occurring in industry. The methods of solution to these problems are given
as algorithms.
These network problems are, in general, considerably more complex than
those we have studied earlier. Due to this complexity, it may not be
possible to find optimum scheduling solutions, but instead we try to find
near-optimum solutions.
Any project that can be broken down into separate activities interrelated
in time can be represented by a network called an activity network. An
example is shown in Figure 2, which is an activity network for the
construction of a small building such as a garage. We use this building
construction as an illustrative example throughout the unit.
131
Unit B2 Optimal paths, packing and scheduling
A G H
5
1 6 8
7 10
E
0 5 8
4
2 10
B D F I J
0 8 2 2 3
start 2 5 7 9 10 finish
0 15
C
3
The vertices represent separate activities involved in the project, and are
numbered as well as being labelled with the letter used to denote the
activity. (We explain the significance of the numbers on the vertices
shortly.) The number next to each arc is the duration of the activity
represented by the vertex at the beginning of that arc.
A full list of the activities in this project is given at the beginning of
Subsection 2.1. For example, vertex 1 (also referred to as activity A) in
Figure 2 represents the preparation of the foundations, vertex 2 (that is,
activity B) represents the making and positioning of the door frame and
vertex 4 (that is, activity E) is the erecting of the walls. The activity
network shows arcs from vertex 1 to vertex 4 and from vertex 2 to
vertex 4. This indicates that activities A and B (corresponding to
vertices 1 and 2) must precede activity E (corresponding to vertex 4).
Hence activity E cannot start until activities A and B have both been
completed. The arcs in this type of activity network give the precedence
relations, showing that certain activities can only be started once other
activities have been completed.
In Section 3 we will show how the minimum completion time for the whole
project can be determined by finding a longest path, called a critical path,
through the corresponding activity network.
Many companies use network analysis as an aid to the planning and
control of large-scale projects. The first forms of network analysis were
devised and used in the USA in the late 1950s. Since that time, many
different systems of network analysis have been developed which use the
same basic techniques. An essential part of these systems is the use of an
activity network to represent a project.
Two types of activity network are in common use. Our main focus is the
type in which each vertex represents an activity (as in Figure 2); we study
such networks in detail in Subsection 2.1. In Subsection 2.2 we describe
132
2 Activity networks
the other type, in which each vertex represents an event (a stage in the
process corresponding to the start or finish of one or more activities), and,
in Subsection 2.3, we give a brief comparison of the two types.
activity duration
(in days)
A prepare foundations 7
B make and position door frame 2
C lay drains, floor base and screed 15
D install services and fittings 8
E erect walls 10
F plaster ceiling 2
G erect roof 5
H install doors and windows, and paint outside 8
I fit gutters and pipes 2
J paint inside 3
133
Unit B2 Optimal paths, packing and scheduling
134
2 Activity networks
135
Unit B2 Optimal paths, packing and scheduling
Example B2.5
Construct an activity network for the building construction example, using
the preceding algorithm. The activities and precedence relations are given
in the following table.
A prepare foundations 7
B make and position door frame 2
C lay drains, floor base and screed 15
D install services and fittings 8 E
E erect walls 10 A, B
F plaster ceiling 2 D, G
G erect roof 5 E
H install doors and windows, and paint outside 8 G
I fit gutters and pipes 2 C, F
J paint inside 3 I
Solution
original shadow
vertices vertices We apply the activity network construction algorithm.
A A Part A: procedure for numbering the vertices
Start We draw a bipartite graph with a vertex in each set
B B
corresponding to each activity – the original vertex in one set and a
corresponding shadow vertex in the other set.
C C
We draw an edge joining an original vertex to one of the shadow vertices if
D D the activity corresponding to the shadow vertex must precede the activity
represented by the original vertex.
E E We obtain the bipartite graph in Figure 5.
This represents the following precedence relations.
F F
D must follow E
G G E must follow A and B
F must follow D and G
H H G must follow E
I I H must follow G
I must follow C and F
J J J must follow I
Figure 5
136
2 Activity networks
First iteration
Step 1 The original vertices that have no edges incident with them
are A, B and C. Thus we assign the number 1 to vertex A, 2 to vertex B,
and 3 to vertex C, as shown on the left in Figure 6 and recorded in the
following table.
iteration 1
vertices A1
numbered B2
C 3
2 B B
3 C C
D D D D
E E E E
F F F F
G G G G
H H H H
I I I I
J J J J
step 1 step 2
Figure 6
137
Unit B2 Optimal paths, packing and scheduling
Second iteration
Step 1 The only original vertex that has no edge incident with it is
vertex E, so we number this vertex 4 as shown on the left in Figure 7. We
record this in our table.
iteration 1 2
vertices A1 E4
numbered B2
C 3
Step 2 We delete vertex E, its shadow vertex and the edges incident
with it. We are left with the graph shown on the right in Figure 7.
D D D D
4 E E
F F F F
G G G G
H H H H
I I I I
J J J J
step 1 step 2
Figure 7
Third iteration
Step 1 We number vertices D and G as shown on the left in
Figure 8. We record this in our table.
iteration 1 2 3
vertices A1 E4 D5
numbered B2 G6
C 3
138
2 Activity networks
5 D D
F F F F
6 G G
H H H H
I I I I
J J J J
step 1 step 2
Figure 8
Fourth iteration
Step 1 We number the vertices F and H as shown on the left in
Figure 9. We record this in our table.
iteration 1 2 3 4
vertices A1 E4 D5 F 7
numbered B2 G6 H 8
C 3
7 F F
8 H H
I I I I
J J J J
step 1 step 2
Figure 9
139
Unit B2 Optimal paths, packing and scheduling
Fifth iteration
Step 1 We number vertex I and record this in our table.
iteration 1 2 3 4 5
vertices A1 E4 D5 F 7 I 9
numbered B2 G6 H 8
C 3
Step 2 We delete vertex I, its shadow vertex and the remaining edge.
We are left with only vertex J.
9 I I
J J J J
step 1 step 2
Figure 10
Sixth iteration
Step 1 We number the remaining vertex J and record this in our
table.
iteration 1 2 3 4 5 6
vertices A1 E4 D5 F 7 I 9 J 10
numbered B2 G6 H 8
C 3
10 J J
step 1 step 2
Figure 11
140
2 Activity networks
A G H
5
1 6 8
7 10
E
0 5 8
4
2 10
B D F I J
0 8 2 2 3
start 2 5 7 9 10 finish
0 15
C
3
Iteration: 1 2 3 4 5 6
Figure 12
This is the activity network that we gave at the start of this section in
Figure 2. We have drawn the columns to help us in our construction; each
column contains the vertices obtained in that iteration.
We now give the details of the construction of this network.
Step 3 We draw the start vertex, and the vertices numbered in the first
iteration: A, B and C. We then draw arcs from the start vertex to A, B
and C, assigning a zero weight to each.
Step 4 In the second iteration we numbered vertex E, so we add vertex
E to the activity network.
From the table showing the precedence relations, we see that A and B
must precede E, so we draw arcs:
from A to E, with weight 7 (the duration of A)
from B to E, with weight 2 (the duration of B).
Step 4 In the third iteration we numbered vertices D and G, so we add
vertices D and G to the activity network. We have placed vertex G above
vertex D to avoid later arcs of the network crossing. (When drawing
similar diagrams, you may wish to do a rough drawing first, if time
permits.)
Activity E must precede D and G, so we draw arcs:
from E to D, with weight 10 (the duration of E)
from E to G, with weight 10 (the duration of E).
141
Unit B2 Optimal paths, packing and scheduling
142
2 Activity networks
Step 1, it is always worth checking your working, just to make sure that
you have not made an error.
Exercise B2.6
The process of assembling a bicycle is divided into the activities shown in
the following table. The precedence relations between the activities are
also shown in the table.
A C
Figure 15
Exercise B2.7
The activity network you constructed in Exercise B2.6 contains some
redundant arcs. Which are they and which are the redundant precedence
relations?
143
Unit B2 Optimal paths, packing and scheduling
Figure 16
You may be wondering why the vertices of the activity network are
numbered with such large numbers. The reason is that during the planning
stage, or later, it may be necessary to include additional activities. The
style of numbering adopted allows additional vertices to be conveniently
numbered in the correct sequence.
Vertices 10 and 20 represent the start and finish of activity A. The
event 20 is also the start event for activities B and C. Activities are
commonly referred to by quoting their start and finish event numbers; so,
for example, activity C is referred to as activity 2040.
In the numbering procedure no vertex V is numbered until all the vertices
incident to each arc pointing towards V have been numbered.
With this type of activity network, it is sometimes necessary to introduce
dummy activities. For example, if activity C must follow activity A, and
activity D must follow activities A and B, then we draw the activity
network as follows.
Figure 17
The dummy activity 3050, represented by the dashed line in Figure 17, is
introduced to show that activity D cannot start until activity A has been
completed. Dummy activities have no time duration associated with them.
144
2 Activity networks
Note that the activity network in Figure 17 is not the same as the network
in Figure 18; in the latter case, both C and D must follow both activities
A and B.
Figure 18
Dummy activities are also used when two activities have the same start
and end events. This is done so that each activity can be referred to by a
different number. An example is given in Figure 19.
Figure 19
Figure 20
145
Unit B2 Optimal paths, packing and scheduling
The dummy activity 2030 is required to ensure that not just activity A
(preparing the foundations) but also activity B (making and positioning
the door frame) is completed before the start of activity E (erecting the
walls). Similarly, the dummy activity 5060 is required to ensure that
activity G (erecting the roof) is completed as well as activity D (installing
services and fittings) before the start of activity F (plastering the ceiling).
146
3 Critical path analysis
147
Unit B2 Optimal paths, packing and scheduling
Convention
Suppose that the network involves n activities. We regard the start
vertex as the 0th vertex and the finish vertex as the (n + 1)th vertex.
We denote the weight of arc ij by ci,j ; this represents the duration of
Figure 21 activity i (see Figure 21).
The algorithm assigns labels pj and ej to each vertex j for
j = 0, 1, . . . , n + 1. When the algorithm has been completed then, for
j > 0:
• ej is the length of the longest path from the start vertex to
vertex j
• pj is the number of the preceding vertex on this longest path.
We will see later that ej is the ‘earliest starting time’ of the activity
represented by vertex j; that is, the earliest time at which the activity
can be started.
148
3 Critical path analysis
149
Unit B2 Optimal paths, packing and scheduling
Example B2.8
Find a critical path in the following activity network for the building
construction example, using the critical path construction algorithm.
A G H
5
1 6 8
7 10
E
0 5 8
4
2 10
B D F I J
0 8 2 2 3
start 2 5 7 9 10 finish
0 15
C
3
Solution
We begin by applying Part A of the algorithm.
150
3 Critical path analysis
e4 = 7
p4 = 1.
e5 = e4 + c4,5 = 7 + 10 = 17
p5 = 4.
e6 = e4 + c4,6 = 7 + 10 = 17
p6 = 4.
The labelling of vertices 4, 5 and 6 is shown on the following
diagram.
p1 = 0 p6 = 4
e1 = 0 e6 = 17
1 6
A 7 10 G
E
0 5
4
2 p4 = 1 10
B e4 = 7 D F
0 8
start 2 5 7
p0 = 0 p2 = 0 p5 = 4
e0 = 0 e2 = 0 e5 = 17
0
C
3
p3 = 0
e3 = 0
151
Unit B2 Optimal paths, packing and scheduling
e7 = 25
p7 = 5.
j i ei ci,j ei + ci,j ej pj
0 – – – – 0 0
1 0 0 0 0 0 0
2 0 0 0 0 0 0
3 0 0 0 0 0 0
4 1 0 7 7 7 1
4 2 0 2 2 – –
5 4 7 10 17 17 4
6 4 7 10 17 17 4
7 5 17 8 25 25 5
7 6 17 5 22 – –
8 6 17 5 22 22 6
9 3 0 15 15 – –
9 7 25 2 27 27 7
10 9 27 2 29 29 9
11 8 22 8 30 – –
11 10 29 3 32 32 10
152
3 Critical path analysis
p1 = 0 p6 = 4 p8 = 6
e1 = 0 e6 = 17 e8 = 22
5
1 6 8
A 7 10 G H
E
0 5 8
4
2 p4 = 1 10 p5 = 4 p7 = 5
B e4 = 7 e5 = 17 e7 = 25 I J
0 8 2 2 3
start 2 5 7 9 10 finish
p0 = 0 p2 = 0 D F p9 = 7 p10 = 9 p11 = 10
e0 = 0 e2 = 0 e9 = 27 e10 = 29 e11 = 32
0 15
C
3
p3 = 0
e3 = 0
153
Unit B2 Optimal paths, packing and scheduling
5
1 6 8
A 7 10 G H
E
0 5 8
4
2 10
B I J
0 8 2 2 3
start 2 5 7 9 10 finish
D F
0 15
C
3
Figure 25
154
3 Critical path analysis
Exercise B2.9
The activity network for the process of assembling a bicycle is reproduced
here.
A J
7
1 10
0 7 18
3 7
B C
0 3
START 2 4 6 FINISH
2 E 8
3 I
0 2 2 3
9
2
F 2 8
2
3 5 7
2
D G
2 H
2 8
Use the critical path construction algorithm to find a critical path in the
activity network, and calculate the minimum completion time of the
project.
155
Unit B2 Optimal paths, packing and scheduling
Exercise B2.10
What is the effect on the completion time of a project of a delay in the
completion of an activity that is not on any critical path?
156
3 Critical path analysis
Exercise B2.11
In the following activity network, the critical path is indicated by thick
lines, and the duration times are in days.
3
1 4 6
0 5 4 2
2
start 3 7 finish
0 4 4 7
2 5
157
Unit B2 Optimal paths, packing and scheduling
Note that ℓ0 must be zero – if we do not obtain this value, then we know
that we have made a mistake somewhere.
We illustrate this procedure by applying it to the activity network and
critical path for the building construction example. The detailed
explanation given here is not required in the solution to an exercise.
Example B2.12
Use the algorithm to find the latest starting times for the building
construction example. Hence find the float of each activity. The activity
network and critical path are shown in the following diagram.
5
1 6 8
A 7 10 G H
E
0 5 8
4
2 10
B I J
0 8 2 2 3
start 2 5 7 9 10 finish
D F
0 15
C
3
Solution
The minimum completion time is equal to the length of a critical path, so
in this case it is 32 days.
We now apply the algorithm.
Step 1 For vertex 11 (the finish vertex), we set ℓ11 equal to the
minimum completion time:
ℓ11 = 32 days.
158
3 Critical path analysis
Vertex 6 There are two arcs incident from this vertex. For the arc
joining vertex 6 to vertex 8, the difference is
ℓ8 − c6,8 = 24 − 5 = 19,
and for the arc joining vertex 6 to vertex 7, the difference is
ℓ7 − c6,7 = 25 − 5 = 20.
The smaller of these differences is the first, so
ℓ6 = 19.
Vertex 5 Only one arc is incident from this vertex, so
ℓ5 = ℓ7 − c5,7 = 25 − 8 = 17.
Vertex 4 Two arcs are incident from this vertex. For the arc joining
vertex 4 to vertex 6, the difference is
ℓ6 − c4,6 = 19 − 10 = 9,
and for the arc joining vertex 4 to vertex 5, the difference is
ℓ5 − c4,5 = 17 − 10 = 7.
The smaller of these differences is the second, so
ℓ4 = 7.
Vertex 3 Only one arc is incident from this vertex, so
ℓ3 = ℓ9 − c3,9 = 27 − 15 = 12.
Vertex 2 Only one arc is incident from this vertex, so
ℓ2 = ℓ4 − c2,4 = 7 − 2 = 5.
Vertex 1 Only one arc is incident from this vertex, so
ℓ1 = ℓ4 − c1,4 = 7 − 7 = 0.
Vertex 0 This is the start vertex. Three arcs are incident from this
vertex. For the arc joining vertex 0 to vertex 3, the difference
is
ℓ3 − c0,3 = 12 − 0 = 12,
for the arc joining vertex 0 to vertex 2, the difference is
ℓ2 − c0,2 = 5 − 0 = 5,
and for the arc joining vertex 0 to vertex 1, the difference is
ℓ1 − c0,1 = 0 − 0 = 0.
The smallest of these differences is the last, so
ℓ0 = 0,
as expected.
159
Unit B2 Optimal paths, packing and scheduling
i j ℓj ci,j ℓj − ci,j ℓi
11 – – – – 32
10 11 32 3 29 29
9 10 29 2 27 27
8 11 32 8 24 24
7 9 27 2 25 25
6 8 24 5 19 19
6 7 25 5 20 –
5 7 25 8 17 17
4 6 19 10 9 –
4 5 17 10 7 7
3 9 27 15 12 12
2 4 7 2 5 5
1 4 7 7 0 0
0 3 12 0 12 –
0 2 5 0 5 –
0 1 0 0 0 0
Notice that ℓ0 = 0.
The following table shows the earliest and latest starting times and the
float of each activity in the building project. We calculated the earliest
starting times and the critical path (shown in the first column) in
Example B2.8.
start 0 0 0 0
A 1 0 0 0
B 2 0 5 5
C 3 0 12 12
E 4 7 7 0
D 5 17 17 0
G 6 17 19 2
F 7 25 25 0
H 8 22 24 2
I 9 27 27 0
J 10 29 29 0
finish 11 32 32 0
160
3 Critical path analysis
Exercise B2.13
The activity network for the process of assembling a bicycle is reproduced
in the following diagram. The critical path is indicated by bold lines; the
minimum completion time is 30 minutes.
A J
7
1 10
0 7 18
3 7
B C
0 3
start 2 4 6 finish
2 E 8
3 I
0 2 2 3
9
2
F 2 8
2
3 5 7
2
D G
2 H
2 8
(a) Apply the algorithm for finding the latest starting times.
(b) Calculate the float for each activity, using your solution to
Exercise B2.9.
161
Unit B2 Optimal paths, packing and scheduling
Exercise B2.14
A project consists of ten activities A–J. The duration of each activity and
the activities that must precede each of them are as follows.
Learning outcomes
After studying this section, you should be able to:
• explain the terms precedence relations, activity network, critical
path, minimum completion time, earliest starting time, latest
starting time and float
• distinguish between the two types of activity network
162
4 Scheduling
4 Scheduling
In the previous section we saw that the minimum completion time for a
project is given by the length of a critical path in the corresponding
activity network. This is the shortest time in which the project can be
completed if there is no restriction on the number of workers available.
However, if there is a limit on the number of workers available, it may not
be possible to achieve this minimum completion time. The product of the
minimum completion time (measured in hours say) and the number of
workers available gives the number of person-hours that can be worked
during the minimum completion time. If this product is less than the sum
of the durations of all the activities, then it is obviously impossible to
finish in the minimum completion time. Even if the product is not less
than the sum of the durations, the precedence relations may be such that
some workers will have idle periods, so that it is again impossible to finish
in the minimum completion time.
In this section we investigate the problem of scheduling the activities of a
project for a given number of workers in the shortest possible time.
163
Unit B2 Optimal paths, packing and scheduling
network was constructed in Exercise B2.6 and the critical path was
determined in Exercise B2.9; this is shown in Figure 27.
A J
7
1 10
0 7 18
3 7
B C
0 3
start 2 4 6 finish
2 E 8
3 I
0 2 2 3
9
2
F 2 8
2
3 5 7
2
D G
2 H
2 8
Figure 27
time 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34
worker 1 D E C J
worker 2 A B F G H I
completion
time
Figure 28
164
4 Scheduling
Note that worker 1 is idle for 2 minutes before starting activity J, because
activity J cannot be started until activity B has been completed.
As it happens, this schedule does take 34 minutes – the minimum possible
time we calculated for this way of assigning activities. We notice that
worker 1 is idle for two time intervals each of 2 minutes.
This schedule violates factory rule 1, since worker 1 could begin activity F
as soon as they finish activity C. (It may also violate factory rule 3, since
the completion time with two workers might be as low as
64/2 = 32 minutes.)
We can improve on the preceding schedule by assigning activity F to
worker 1 as soon as they complete activity C. We thus obtain the
following schedule.
time 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32
worker 1 D E C F J
worker 2 A B G H I
completion
time
Figure 29
165
Unit B2 Optimal paths, packing and scheduling
166
4 Scheduling
Example B2.15
Apply the critical path scheduling algorithm to the bicycle assembly
project for two workers. The activity network for this project, and a list of
the latest starting times and durations (in minutes) are as follows.
A J
7
1 10
0 7 18
3 7
B C
0 3
start 2 4 6 finish
2 E 8
3 I
0 2 2 3
9
2
F 2 8
2
3 5 7
2
D G
2 H
2 8
vertex number i 1 2 3 4 5 6 7 8 9 10
activity A B D E F C G H I J
duration 7 7 2 3 2 7 2 8 8 18
ℓi 5 5 0 2 18 5 20 22 22 12
Solution
We apply the critical path scheduling algorithm.
We use the activity network precedence relations to determine which
activities can be started at each stage.
Start Set the project clock to 0.
Activities A, B and D are available to start.
167
Unit B2 Optimal paths, packing and scheduling
time 0 2 4 6
time on
project clock
time 0 2 4 6 8
time on
project clock
168
4 Scheduling
time 0 2 4 6 8 10 12 14 16
time on
project clock
169
Unit B2 Optimal paths, packing and scheduling
time 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32
worker 1 D E C F J
worker 2 A B G H I
completion
time
The schedule is the same as the one we obtained by trial and error. In
other words, the algorithm produces an optimum schedule in this case.
Exercise B2.16
Use the critical path scheduling algorithm to schedule the building
construction project for two workers. Do you obtain an optimum schedule?
The activity network, and the latest starting times and durations (in days)
are as follows.
A G H
5
1 6 8
7 10
E
0 5 8
4
2 10
B D F I J
0 8 2 2 3
start 2 5 7 9 10 finish
0 15
C
3
170
4 Scheduling
vertex number i 1 2 3 4 5 6 7 8 9 10
activity A B C E D G F H I J
duration 7 2 15 10 8 5 2 8 2 3
ℓi 0 5 12 7 17 19 25 24 27 29
In the next exercise we consider a case in which the algorithm does not
produce an optimum schedule.
Exercise B2.17
(a) For the project represented by the following activity network, find the
critical path(s) and the latest starting times by inspection. The
durations of the activities are in minutes. (Here the vertices are
numbered in alphabetical order, so we have omitted the numbers.)
H
2 5
2 I 5
A 2 5 L
2 J 5
B
K
0 10
0 2
C
0 2
0 2
start D finish
0 10
0 10
E
0 10
(b) Write down the schedule obtained when the critical path scheduling
algorithm is applied to this project with four workers.
171
Unit B2 Optimal paths, packing and scheduling
time 0 2 4 6 8 10 12 14 16 18 20 22 24
worker 1 A H I C L
worker 2 E J
worker 3 F K
worker 4 G B D
completion
time
Figure 30
time 0 2 4 6 8 10 12 14 16
worker 1 A H E
worker 2 B I F
worker 3 C J G
worker 4 D K L
completion
time
Figure 31
172
4 Scheduling
activity i A B C D E F G H I J K L
ei 0 0 0 0 0 0 0 2 2 2 2 7
ℓi 0 15 15 15 7 7 7 2 2 2 2 7
sum ei + ℓi 0 15 15 15 7 7 7 4 4 4 4 14
Next we rank the activities according to the values of these sums as shown
in the following table.
sum ei + ℓi 0 4 4 4 4 7 7 7 14 15 15 15
activity i A H I J K E F G L B C D
duration 2 5 5 5 5 10 10 10 10 2 2 2
173
Unit B2 Optimal paths, packing and scheduling
time 0 2 4 6 8 10 12 14 16 18
worker 1 A H E B
worker 2 I F C
worker 3 J G D
worker 4 K L
completion
time
Figure 32
Exercise B2.18
A project consists of ten activities A–J and has the following activity
network and critical path. (These were constructed in Exercise B2.14.)
A G H
10 10
1 8 10
6
0 B C D J 2
4 8 6
0 2 5 7 9 10
5
start finish
0 F
4
3
0 8
I E
4
4 6
174
5 Bin packing
The duration of each activity, and the earliest and latest starting times (in
days) are as follows.
activity i A B C D E F G H I J
duration 10 4 8 6 8 5 10 2 4 10
ei 0 0 4 12 4 0 18 28 0 18
ℓi 8 0 4 12 22 15 18 28 16 20
(a) Write down the schedule obtained when the critical path scheduling
algorithm is applied to this project, given that two workers are
available.
(b) Write down a suitable ranking of the activities and the schedule
obtained when the modified scheduling algorithm incorporating a
protection scheme is applied to this project, given that two workers
are available.
Learning outcomes
After studying this section, you should be able to:
• explain the terms factory rules and protection scheme
• use the critical path scheduling algorithm and the modified
scheduling algorithm incorporating a protection scheme to schedule
activities for a number of workers.
5 Bin packing
In the previous section we discussed scheduling problems in which we wish
to schedule the activities of a project for a given number of workers so that
the project is completed in the shortest possible time. We now turn the
problem around, and ask for the minimum number of workers required to
complete the project within a given period (which must, of course, be
greater than or equal to the length of a critical path in the activity
network for the project).
Suppose, for example, that a project consists of 11 activities A–K with the
following durations (in days). There are no precedence relations.
activity A B C D E F G H I J K
duration 8 8 2 9 6 9 5 4 6 9 7
175
Unit B2 Optimal paths, packing and scheduling
15
E G
10
activity C
duration
I
(days)
5
A B D F J
K
H
0
b1 b2 b3 b4 b5 b6 b7
Figure 33
This packing scheme uses 7 bins so, in terms of our original problem, this
scheme uses 7 workers to complete the project in 15 days.
Clearly, this algorithm is not very good because, once a bin cannot
accommodate a particular item, that bin is never used again, even though
a smaller item that could fit into it may appear later in the list. However,
for any problem, this simple algorithm uses no more than twice the
number of bins actually required.
To see this, suppose that n is the minimum number of bins needed
according to the next-fit algorithm, and that each bin has capacity k.
176
5 Bin packing
Let c(bi ) denote the content of bin bi packed according to the next-fit
algorithm. The content of two successive bins bi and bi+1 must be greater
than k, otherwise bin bi+1 would not have been used. So we have
c(bi ) + c(bi+1 ) > k, for i = 1, . . . , n − 1.
Thus, if n is even,
[c(b1 ) + c(b2 )] + · · · + [c(bn−1 ) + c(bn )] > 12 n × k.
So the total content needing to be packed is greater than 12 n × k. Since
each bin has capacity k, an optimum packing needs at least 12 n + 1 bins.
And, if n is odd,
[c(b1 ) + c(b2 )] + · · · + [c(bn−2 ) + c(bn−1 )] + c(bn ) > 21 (n − 1) × k + c(bn )
> 12 (n − 1) × k.
Since each bin has capacity k, an optimum packing needs at least
1 1 1
2 (n − 1) + 1 bins = 2 n + 2 bins.
Thus the next-fit packing with n bins uses at most twice the optimum
number of bins. Note that the upper bounds quoted in this section are
theoretical bounds; in practice, the algorithms give much better results in
many cases.
A better method is first-fit packing, in which the items are packed
according to the following rule.
It can be shown that the number of bins used in first-fit packing is at most
17
10 times the optimum number of bins.
If we pack the activities given earlier according to the first-fit packing
algorithm, we obtain the following packing. This packing uses only 6 bins,
so it gives a better solution to our problem than the one that we obtained
using the next-fit packing algorithm.
177
Unit B2 Optimal paths, packing and scheduling
15
G I
E H
10
activity C
duration
(days)
5
A B D F J
K
0
b1 b2 b3 b4 b5 b6
Figure 34
Notice that, in each of the preceding packings, the sum of the unfilled
capacities of all the bins except the last is greater than the duration of
activity K packed in the last bin. We might suspect that there is a better
packing scheme that uses only 5 bins, but we have no means of finding out
whether such a scheme exists, apart from trying other packing methods.
How can we improve on the first-fit method? Intuitively, it seems better to
pack the activities with the longest durations first, so that we can use
activities with smaller durations to fill the spaces in the bins already
partially occupied. This idea is the basis of the first-fit decreasing
algorithm, in which we fill the bins according to the following method.
It can be shown that the number of bins used in first-fit decreasing packing
is at most 11
9 times the optimum number of bins.
Let us apply this algorithm to our example.
First, we reorder the activities in decreasing order of duration (in days) as
follows.
activity D F J A B K E I G H C
duration 9 9 9 8 8 7 6 6 5 4 2
178
5 Bin packing
15
C
E I G K
10 H
activity
duration
(days)
5
D F J A B
0
b1 b2 b3 b4 b5
Figure 35
This packing scheme uses only 5 bins, so this problem requires the use of
only 5 workers to complete the project within the given time period.
In this case, the first-fit decreasing algorithm has produced an optimum
packing (that is, one using the fewest possible bins), but there are other
cases where it will not produce an optimum packing. However, the first-fit
decreasing algorithm is better than the first-fit algorithm, in the sense that
it usually produces a packing with fewer bins.
The bin-packing problem occurs in many different practical situations,
such as the following.
• A factory worker needs to pack items of various sizes into boxes as they
come off a production line in no particular order.
• A plumber wishes to minimise the number of pipes of a standard length
needed in order to produce (by making cuts) a given number of pieces of
pipe of specified lengths. In this case, the ‘bins’ are the standard-length
pipes, and the problem is to ‘pack’ the required lengths of pipe into the
smallest number of the standard-length pipes.
• A commercial television company that broadcasts with standard-length
breaks between programmes wishes to allocate advertisements. In this
case, the ‘bins’ are the breaks between programmes, and the problem is
to ‘pack’ advertisements into the smallest possible number of such
breaks.
In the first situation, the items are available only one at a time, so no
reordering of items is possible. In this case, an algorithm such as the
next-fit algorithm or the first-fit algorithm must be used. These algorithms
are called on-line algorithms.
In the other two situations, it is possible to reorder the items before
starting the packing process so the first-fit decreasing algorithm can be
used. Such an algorithm involving reordering is called an off-line
algorithm.
179
Unit B2 Optimal paths, packing and scheduling
Exercise B2.19
A carpenter has some planks of wood, each 12 feet long, and wishes to cut
sections from these planks of the following lengths (in feet).
section A B C D E F G H I J K L
length 6 2 3 3 3 3 4 4 5 2 8 5
Exercise B2.20
A project consists of twelve activities A–L with the following durations (in
days).
activity A B C D E F G H I J K L
duration 6 2 6 2 6 2 6 2 6 2 6 2
Learning outcomes
After studying this section, you should be able to:
• explain what is meant by the terms bin-packing problem, on-line
algorithm and off-line algorithm
• state and use the next-fit, first-fit and first-fit decreasing packing
algorithms.
180
Solutions to exercises
Solutions to exercises
Solution to Exercise B2.2
We apply the shortest path algorithm to the network that we are given,
shown in the following diagram.
A
25
7 D
4 5
13 B
S 6 10 T
5 12
28 E
3
C
We give the final table arising from the algorithm, having assigned S zero
potential at the start.
A
25
7 D
4 5
13 B
S 6 10 T
5 12
28 E
3
C
181
Unit B2 Optimal paths, packing and scheduling
We give the final table arising from the algorithm, having assigned S zero
potential at the start.
182
Solutions to exercises
2 B B
C C C C 6 C C
3 D D
E E 4 E E
F F 5 F F
G G G G 7 G G
H H H H H H 8 H H
I I I I I I 9 I I
J J J J J J 10 J J
In addition to giving the bipartite graphs, you may find it helpful to record
this information in a table as follows.
iteration 1 2 3 4
vertices A1 E4 C 6 H 8
numbered B2 F 5 G7 I 9
D3 J 10
183
Unit B2 Optimal paths, packing and scheduling
A J
7
1 10
0 7
7 18
3
B C
0 3
start 2 4 6 finish
2 E 8
3 I
0 2 2 3
9
2
F 8
2 2
3 5 7
2
D G
2 H
2 8
We now give the details of the construction of this network. These are not
required as part of the solution.
184
Solutions to exercises
A J
7
1 10
0 7
7 18
3
B C
0 3
start 2 4 6 finish
2 E 8
3 I
0 2 2 3
9
2
F 8
2 2
3 5 7
2
D G
2 H
2 8
185
Unit B2 Optimal paths, packing and scheduling
186
Solutions to exercises
A J
7
1 10
0 7 18
3 7
B C
0 3
start 2 4 6 finish
2 E 8
3 I
0 2 2 3
9
2
F 2 8
2
3 5 7
2
D G
2 H
2 8
187
Unit B2 Optimal paths, packing and scheduling
(b) The earliest starting time of activity 4 is equal to the length of the
longest path from the start vertex to vertex 4. This longest path
passes through vertices 1 and 3, and its length is 0 + 5 + 4 = 9 days, so
e4 = 9.
Activity 6 cannot start until activity 4 has been completed, and the
duration of activity 4 is 3 days; thus the earliest starting time for
activity 6 is 9 + 3 = 12 days, so
e6 = 12.
(c) We can find the latest starting time for activity 6 by working
backwards from the finish vertex. The minimum completion time is
18 days, so activity 7 must begin after 18 − 2 = 16 days, and hence
activity 6 must begin at the latest after 16 − 2 = 14 days, so
ℓ6 = 14.
Activity 4 must begin not later than 3 days before the latest starting
time of activity 6; thus the latest starting time for activity 4 is
14 − 3 = 11 days, so
ℓ4 = 11.
188
Solutions to exercises
i j ℓj ci,j ℓj − ci,j ℓi
11 – – – – 30
10 11 30 18 12 12
9 11 30 8 22 22
8 11 30 8 22 22
7 8 22 2 20 20
7 9 22 2 20 –
6 10 12 7 5 5
5 7 20 2 18 18
5 8 22 2 20 –
5 9 22 2 20 –
4 6 5 3 2 2
4 8 22 3 19 –
4 9 22 3 19 –
4 10 12 3 9 –
3 4 2 2 0 0
3 5 18 2 16 –
3 6 5 2 3 –
3 10 12 2 10 –
2 10 12 7 5 5
1 10 12 7 5 5
0 1 5 0 5 –
0 2 5 0 5 –
0 3 0 0 0 0
(b) The earliest and latest starting times and the floats are given in the
following table. (The earliest starting times and the critical path were
calculated in the solution to Exercise B2.9.)
189
Unit B2 Optimal paths, packing and scheduling
start 0 0 0 0
A 1 0 5 5
B 2 0 5 5
D 3 0 0 0
E 4 2 2 0
F 5 2 18 16
C 6 5 5 0
G 7 4 20 16
H 8 6 22 16
I 9 6 22 16
J 10 12 12 0
finish 11 30 30 0
A G H
10 10
1 8 10
6
0 B C D J 2
4 8 6
0 2 5 7 9 10
5
start finish
0 F
4
3
0 8
I E
4
4 6
190
Solutions to exercises
191
Unit B2 Optimal paths, packing and scheduling
A G H
10 10
1 8 10
6
0 B C D J 2
4 8 6
0 2 5 7 9 10
5
start finish
0 F
4
3
0 8
I E
4
4 6
(c) Applying the algorithm for finding the latest starting times, we obtain
the following table.
i j ℓj ci,j ℓj − ci,j ℓi
11 – – – – 30
10 11 30 2 28 28
9 11 30 10 20 20
8 10 28 10 18 18
7 8 18 6 12 12
9 20 6 14
6 11 30 8 22 22
5 7 12 8 4 4
4 6 22 4 18
9 20 4 16 16
3 9 20 5 15 15
2 5 4 4 0 0
1 8 18 10 8 8
0 1 8 0 8
0 2 0 0 0 0
0 3 15 0 15
0 4 16 0 16
The earliest and latest starting times and the floats are given in the
following table.
192
Solutions to exercises
start 0 0 0 0
A 1 0 8 8
B 2 0 0 0
F 3 0 15 15
I 4 0 16 16
C 5 4 4 0
E 6 4 22 18
D 7 12 12 0
G 8 18 18 0
J 9 18 20 2
H 10 28 28 0
finish 11 30 30 0
193
Unit B2 Optimal paths, packing and scheduling
time 0 2 4 6 8 10 12 14 16 18 20 22 24 26
worker 1 A E D
worker 2 B C G H
time on
project clock
time 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32
worker 1 A E D F I J
worker 2 B C G H
completion
time
194
Solutions to exercises
activity i A B C D E F G H I J K L
duration 2 2 2 2 10 10 10 5 5 5 5 10
ℓi 0 15 15 15 7 7 7 2 2 2 2 7
time 0 2 4 6 8 10 12 14 16 18 20 22 24
worker 1 A H I C L
worker 2 E J
worker 3 F K
worker 4 G B D
completion
time
time 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36
worker 1 B C D G E
worker 2 A F I J H
completion
time
195
Unit B2 Optimal paths, packing and scheduling
(b) We find the value of the sum of the earliest and latest starting times
for each activity, and rank the activities according to the values of
these sums, as shown in the following table.
sum ei + ℓi 0 8 8 15 16 24 26 36 38 56
activity i B A C F I D E G J H
duration 4 10 8 5 4 6 8 10 10 2
time 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34
worker 1 B C I E J
worker 2 A F D G H
completion
time
12
C
9
F
plank B
length 6 H J
(feet)
E
K
3 A
I L
G
D
0
1 2 3 4 5 6
plank
196
Solutions to exercises
(b) Using the first-fit algorithm, we obtain the following plan requiring
5 planks.
12
J
C
9
F L
plank B
length 6 H
(feet)
E
K
3 A
I
G
D
0
1 2 3 4 5
plank
(c) Using the first-fit decreasing algorithm, we first order the sections in
decreasing size.
section K A I L G H C D E F B J
length 8 6 5 5 4 4 3 3 3 3 2 2
12
C
G B
9
I
F
plank H
length 6
(feet)
E
K
3 A
L
D
J
0
1 2 3 4 5
plank
197
Unit B2 Optimal paths, packing and scheduling
(d) By trial and error, we obtain the following optimum plan requiring
only 4 planks. Other optimum plans can be obtained by interchanging
sections of the same lengths.
12
D
G
L
9
K
C
plank
F
length 6 J
(feet)
E
3 A
I
H
B
0
1 2 3 4
plank
12
activity B D F H J L
duration 6
(days)
3 A C E G I K
0
1 2 3 4 5 6
worker
198
Solutions to exercises
12
F L
9 D E J K
activity B H
duration 6
(days)
3 A C G I
0
1 2 3 4
worker
(c) Using the first-fit decreasing algorithm, we first order the activities in
decreasing order of duration.
activity A C E G I K B D F H J L
duration 6 6 6 6 6 6 2 2 2 2 2 2
12
L
9 C G K J
activity H
duration 6
(days) F
3 A E I D
B
0
1 2 3 4
worker
199
Index
Index
activity 131, 132 on-line algorithm 179
dummy 144 optimum schedule 165
activity network 131 original vertex 134
vertex represents activity 133
vertex represents event 144 path 119
algorithms critical 147
activity network construction 134 longest 120, 127, 147
critical path construction 149 shortest 121
critical path scheduling 166 PERT, Program Evaluation and Review
first-fit decreasing packing 178 Technique 146
first-fit packing 177 potential 120, 121, 126
latest starting times 157 longest path algorithm 126
longest path 127 shortest path algorithm 120
next-fit packing 176 precedence relations 132, 133
shortest path 121 inconsistencies in 142
project clock 166
bin packing 176 protection scheme 172
200