0% found this document useful (0 votes)
24 views84 pages

23mst368book B Unit b2 Vle

The document outlines Unit B2 of MST368, focusing on optimal paths, packing, and scheduling within graph theory. It covers various algorithms for finding shortest and longest paths, activity networks, critical path analysis, and scheduling methods, emphasizing their applications in project management and resource allocation. Additionally, it introduces bin packing as a combinatorial problem related to project organization and resource optimization.

Uploaded by

Zeeshan Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views84 pages

23mst368book B Unit b2 Vle

The document outlines Unit B2 of MST368, focusing on optimal paths, packing, and scheduling within graph theory. It covers various algorithms for finding shortest and longest paths, activity networks, critical path analysis, and scheduling methods, emphasizing their applications in project management and resource allocation. Additionally, it introduces bin packing as a combinatorial problem related to project organization and resource optimization.

Uploaded by

Zeeshan Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

MST368

Graphs, games and designs

Unit B2
Optimal paths, packing and
scheduling
Contents
Introduction 119

1 Optimal path algorithms 120


1.1 The shortest path algorithm 120
1.2 The longest path algorithm 126

2 Activity networks 131


2.1 Activity networks using vertices to represent activities 133
2.2 Activity networks using vertices to represent events 144
2.3 Comparison of the two types of activity network 146

3 Critical path analysis 147


3.1 Critical paths 147
3.2 Earliest and latest starting times 156

4 Scheduling 163
4.1 Scheduling a project for a given number of workers 163
4.2 Algorithms with protection schemes 172

5 Bin packing 175

Solutions to exercises 181

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

In Section 4 Scheduling, we discuss the related problem of finding the


optimum schedule for the activities of a project when the number of
workers available is restricted. In this type of problem, the minimum
completion time for the project with no limit on the number of workers
cannot usually be achieved; however, it is still important to minimise the
completion time.
In practical situations involving the organisation of projects, the optimum
solution may not be the completion of the project in the minimum time,
but the completion of the project within an acceptable time with the
minimum number of workers or minimum resources. For example, we may
wish to determine how many workers or machines are needed to complete
an assembly task within a given number of days. This type of problem can
be represented as a combinatorial packing problem, and is discussed in
Section 5 Bin packing.

1 Optimal path algorithms


In this section we consider problems that involve finding the longest or
shortest paths in a network. In the first subsection we describe the shortest
path algorithm and in the second show how it can be modified to find the
longest path in a network without cycles. This longest path algorithm
forms the basis of the algorithm we will use in Section 3 to find a ‘critical
path’ in an ‘activity network’ for problems on scheduling.

1.1 The shortest path algorithm


Here we give an algorithm to find the shortest path in a directed network
from the source S to the sink T . The distance along an arc is taken to be
the weight of the arc. Working from S towards T , we assign a temporary
label to each vertex, giving the shortest distance from S to that vertex by
all paths so far considered. Eventually, each vertex acquires a permanent
label, called its potential, giving the shortest distance from S to that
vertex. When T has been assigned a potential, the shortest distance
from S to T has been found, and we can find the shortest path(s) from S
to T by tracing back from T to S using the potentials.
We present the steps of the shortest path algorithm, before working
through an example. As with all the algorithms in this unit, the process
described in the algorithm should become clearer as you work through the
example.

120
1 Optimal path algorithms

Shortest path algorithm


Start with a directed network with weighted arcs. Assign
potential 0 to the source S.
General Consider the vertex or vertices assigned a potential at the
step previous step. For each such vertex V , consider each
vertex W that can be reached from V along an arc V W ,
and assign W the temporary label
(potential of V ) + (distance V W )
unless W already has a smaller label, in which case leave
the label at W unchanged.
When all such vertices W have been labelled, choose the
smallest temporary vertex label in the network, and make
it a potential at each vertex where it occurs.
Repeat the General Step until the sink T has been assigned a
potential, then Stop:
• The shortest distance from S to T is the potential of T .
• To find a shortest path from S to T , trace backwards from T and
include an arc V W whenever
(potential of W ) − (potential of V ) = distance V W
until S is reached.

You may be wondering why the shortest path algorithm works. At an


intermediate stage, we have the situation shown in Figure 1.

S T

Vertices with Labelled Unlabelled


known potential vertices vertices

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

without potentials would necessarily be longer. This inductive argument


implies that, when we finally assign a potential to T , that potential is the
length of a shortest path from S to T .
During the application of the algorithm, it can occur that two or more
vertices have the same smallest temporary label when a potential next
needs to be assigned. In this case, all such vertices are assigned the value
of this smallest vertex label as their potential. During the next iteration of
the algorithm, all vertices reached directly from any of these vertices with
newly assigned potentials must be considered when updating the vertex
labelling.
We now illustrate the use of the algorithm. The detailed explanation and
diagrams that we give here are not required in solutions to exercises. We
will use a table to record the vertex labels at each stage of the algorithm
and this is a good way of presenting your solutions. At the end of the third
iteration of the general step in our example, two vertices are assigned a
potential. So, in the fourth iteration, two rows are added to our table,
ensuring that we record all the labelling that must be done at that stage.

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.

iteration origin vertices assigned labels potential assigned


vertex A B C D T to vertex
1 S 7 4 9 7 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.

iteration origin vertices assigned labels potential assigned


vertex A B C D T to vertex
1 S 7 4 9 7 B
2 B 5 7 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.

iteration origin vertices assigned labels potential assigned


vertex A B C D T to vertex
1 S 7 4 9 7 B
2 B 5 7 A
3 A 11 C, 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.

iteration origin vertices assigned labels potential assigned


vertex A B C D T to vertex
1 S 7 4 9 7 B
2 B 5 7 A
3 A 

11 C, D
4 C 10 T
D ∗ ∗

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

We now stop as T has been assigned a potential.


The shortest distance from S to T is the potential of T , which is 10.
To find a shortest path, we trace backwards from T , using the
potentials assigned as shown in the preceding table (numbers in boxes) and
the corresponding origin vertices, which are given in the same row as the
relevant potential.
We trace back from T to C, from C to B, and from B to S, and obtain the
shortest path SBCT of length 10.

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

1.2 The longest path algorithm


The algorithm for finding longest path(s) is similar to the shortest path
algorithm. Here the potential of a vertex gives the longest distance from
the source S to that vertex. For the shortest path, we look out from
vertices of known potential, whereas for the longest path, we look back to
vertices of known potential. If a network has a cycle then the longest path
algorithm does not terminate; there is no longest path since we could go
round the cycle an infinite number of times.

126
1 Optimal path algorithms

We present the steps of the longest path algorithm, before working


through an example.

Longest path algorithm


Start with a directed network with weighted arcs. Assign
potential 0 to the source S.
General Consider all vertices that can be reached directly only
step from vertices with known potentials.
For each such vertex W , consider each arc V W into W ,
and assign W the label
(potential of V ) + (distance V W )
unless W already has a larger label, in which case leave
the label at W unchanged.
When all such arcs V W have been considered, make the
vertex label at W a potential.
Repeat the General Step until the sink T has been assigned a
potential, then Stop:
• The longest distance from S to T is the potential of T .
• To find a longest path from S to T , trace backwards from T and
include an arc V W whenever
(potential of W ) − (potential of V ) = distance V W
until S is reached.
If the algorithm does not terminate then there is a cycle in the
network.

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.

iteration vertices origin vertices


assigned labels S A B C D
1 (S) B 4
D 7

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.

iteration vertices origin vertices


assigned labels S A B C D
1 (S) B 4
D 7
2 (S, B, D) A 7 5
C 9 7 8

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 .

iteration vertices origin vertices


assigned labels S A B C D
1 (S) B 4
D 7
2 (S, B, D) A 7 5
C 9 7 8
3 (S, A, B, C, D) T 13 12 11

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

We now stop as T has been assigned a potential.


The longest distance from S to T is the potential of T , which is 13.
To find a longest path, we trace backwards from T , using the potentials
assigned as shown in the preceding table (numbers in boxes) and the
corresponding origin vertices, which are given as column headings of the
relevant potential.
We trace back from T to A, and from A to S, and obtain the longest
path SAT of length 13.

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

Figure 2 Activity network for building construction

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.

2.1 Activity networks using vertices to


represent activities
We begin by considering the project to construct a garage. The separate
activities involved, and their estimated durations, are given in the
following table.

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

Clearly, some of these activities cannot be started until other activities


have been completed. For example, activity G (erect roof) cannot begin
until activity E (erect walls) has been completed.
The following list of precedence relations shows which activities must
precede which for the construction methods being used. In each of our
examples, we simply state a list of precedence relations. We do not discuss
the problem of actually obtaining a minimal list (that is, a list containing
no redundant information) of precedence relations for a given project. We
will see later in this subsection that redundancies in the precedence
relations lead to redundant arcs in the activity network.
D must follow E
E must follow A and B
F must follow D and G
G must follow E
H must follow G
I must follow C and F
J must follow I
We can represent this process of construction by the activity network given
in Figure 2.

133
Unit B2 Optimal paths, packing and scheduling

In this type of activity network, each activity is represented by a numbered


vertex. An arc joining a vertex X to a vertex Y indicates that the activity
represented by X must be completed before the activity represented by Y
can be started. The number associated with an arc is the duration of the
activity from which that arc is incident. For example, the arc joining A to
E indicates that activity E must follow activity A, and the number 7 next
to the arc is the duration (in days) of activity A. The activity network
thus represents the precedence relations in diagrammatic form.
Notice that the activity network has a start vertex and a finish vertex –
these do not represent any activities, but are included to complete the
network. Since the start vertex does not represent an activity, the
duration time associated with each arc leading from that vertex is zero.
An activity network can be used to find the minimum time necessary for
the completion of the project it represents. Before showing how this is
done, we present a systematic method for constructing an activity network
from a table of precedence relations.

Algorithm for constructing an activity network


The following algorithm is a systematic procedure for numbering the
activities and then drawing the activity network. One of the advantages of
using this method rather than drawing the activity network by trial and
error is that it produces a clear diagram in which the vertices are placed in
a logical order.
The algorithm is in two parts:
Part A of the algorithm is a procedure developed by D.R. Fulkerson for
numbering the activities and the corresponding vertices. The activities
are numbered in such a way that each activity is assigned a number
greater than the number assigned to any activity that must precede it.
Part B of the algorithm is a procedure for drawing the activity network.
original shadow
vertices vertices
Activity network construction algorithm
A A Part A: procedure for numbering the vertices
Start with a list of activities and associated precedence
B B
relations.
C C Represent each activity by a vertex.
For each vertex, create a shadow vertex, so that for
.. .. each activity there are two corresponding vertices – the
. .
original vertex and the shadow vertex.
N N Construct a bipartite graph in which one set of vertices
Figure 3 consists of the original vertices, and the other set consists
of the shadow vertices (see Figure 3).

134
2 Activity networks

If an activity Y must follow an activity X, draw an edge X X


joining the original vertex representing Y to the shadow
vertex representing X (see Figure 4). Y Y
Step 1 Number consecutively all the original vertices (chosen in Figure 4
any order) which have no edges incident with them.
Record the numbering, together with the current iteration
number of this step.
Step 2 Delete all numbered vertices, their corresponding shadow
vertices and all edges incident with these vertices.
If not all the vertices have been numbered, return to
Step 1.
If all the vertices have been numbered, go to Part B,
Step 3.

Part B: procedure for drawing the activity network


Step 3 Draw a start vertex, and the vertices numbered in the
first iteration of Step 1.
Draw an arc from the start vertex to each vertex which
was numbered in the first iteration of Step 1.
Assign a weight of zero to each of these arcs.
Step 4 Draw the vertices which were numbered in the next
iteration of Step 1.
To each such vertex Y , draw an arc from each previously
numbered vertex X if there is an edge joining the original
vertex Y to the shadow vertex X in the original bipartite
graph constructed in Part A.
Assign a weight to each arc XY equal to the duration of
the activity X.
Repeat Step 4 until all vertices have been included in the
activity network.
Step 5 Draw a finish vertex.
From each terminal vertex Z (that is, each vertex whose
out-degree is zero), draw an arc to the finish vertex.
Assign a weight to each such arc equal to the duration of
the corresponding activity Z. Stop:
The activity network has now been constructed.

We illustrate this procedure by using it to construct an activity network


for the building construction example. The detailed explanation given here
is not required in the solution to an exercise. It is sufficient to give the
bipartite graphs showing the numbering obtained by applying Part A of
the algorithm, together with the final activity network.

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.

activity duration preceding


(in days) activities

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

Step 2 We delete the numbered vertices, the corresponding shadow


vertices and all the edges incident with them. We are left with the graph
shown on the right in Figure 6.
original shadow
vertices vertices
1 A A

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

Step 2 We delete vertices D and G, their shadow vertices and the


edges incident with them. We are left with the graph shown on the right in
Figure 8.

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

Step 2 We delete vertices F and H, their shadow vertices and the


edge incident with F . We are left with the graph shown on the right in
Figure 9.

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

Step 2 This completes Part A of the algorithm, as all the vertices


have been numbered. We now proceed to Part B.

10 J J
step 1 step 2
Figure 11

140
2 Activity networks

Part B: procedure for drawing the activity network


Using the information recorded in our table when carrying out Part A, we
construct the following activity network.

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

Step 4 In the fourth iteration we numbered vertices F and H, so we add


vertices F and H to the activity network.
Activities D and G must precede F , and activity G must precede H, so we
draw arcs:
from D to F , with weight 8 (the duration of D)
from G to F , with weight 5 (the duration of G)
from G to H, with weight 5 (the duration of G).
Step 4 In the fifth iteration we numbered vertex I, so we add vertex I to
the activity network.
Activities C and F must precede I, so we draw arcs:
from C to I, with weight 15 (the duration of C)
from F to I, with weight 2 (the duration of F ).
Step 4 In the sixth iteration we numbered vertex J, so we add vertex J
to the activity network.
Activity I must precede J, so we draw an arc:
from I to J, with weight 2 (the duration of I).
All the activities have now been represented by vertices in the activity
network.
Step 5 We draw a finish vertex.
From the terminal vertices H and J, we draw arcs:
from H to finish, with weight 8 (the duration of H)
from J to finish, with weight 3 (the duration of J).
The activity network is now complete.

As well as ordering the activities, the procedure in Part A enables us to


detect any inconsistencies in the precedence relations. For example,
suppose that we are given the following precedence relations.
A must follow C
B must follow A
Figure 13 C must follow B
To start the algorithm, we construct the graph in Figure 13, but we cannot
proceed with Step 1, because there are no isolated vertices. The activities
form a cycle (see Figure 14), so it is impossible to schedule them, since
none of the activities can be started. If a cycle arises from a list of
precedence relations, then such relations are not compatible with a feasible
schedule. The presence of a cycle is revealed by the numbering procedure,
since no numbers can be assigned to any of the vertices representing
activities of the cycle. In general, the presence of a cycle may not become
apparent until you have completed several iterations of Step 1 of the
Figure 14 algorithm. If you do encounter a situation where you are unable to apply

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.

activity duration preceding


(in minutes) activities

A prepare frame, including front fork 7


B mount and align front wheel 7
C mount and align back wheel 7 D, E
D attach derailleur to frame 2
E install gear cluster 3 D
F attach chain wheel to crank 2 D
G attach crank and chain wheel to 2 F
frame
H mount right pedal 8 E, F , G
I mount left pedal 8 E, F , G
J make final attachments; fix and 18 A, B, C, D, E
adjust handlebars, saddle and
brakes

Use the algorithm to construct an activity network for this process.

Activity networks sometimes contain a redundant arc; that is, an arc


which can be deleted without removing any useful information. For
example, Figure 15 shows part of an activity network in which the arc AC
is redundant: it conveys the information that activity C must follow
activity A but it already follows from the other two arcs shown that C
must follow B and B must follow A and hence C must follow A.
B

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

2.2 Activity networks using vertices to


represent events
An alternative type of activity network uses arcs to represent activities and
vertices to represent events. An event is a stage in the process
corresponding to the start or finish of one or more activities. For example,
if activities B and C must follow activity A, this can be represented as
follows.

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

Here, activity A (also referred to as 1030) might be a rally driver driving a


car, whereas activity B (or 1020) might be a map reader giving
instructions to the driver. As another example, these activities might
represent the landing instructions from air traffic control and a pilot
carrying out the landing manoeuvre.
As an illustration of a complete activity network, we give an activity
network with vertices representing events for the building construction
example that we considered at the beginning of this section.

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).

2.3 Comparison of the two types of activity


network
Historical note
The first methods of network analysis that were developed used the
type of activity network in which vertices represent events. Two such
methods were developed at about the same time in the late 1950s and
were the first to be used in the planning of large-scale industrial
projects. These were Program Evaluation and Review Technique
(PERT) and Critical Path Method (CPM). PERT was used by the US
Navy to plan the Polaris missile project, where the main objective was
to complete the project in the shortest possible time. This was a
complex project involving activities whose times could not be
accurately predicted. CPM was developed by the DuPont de Nemours
Company; here the primary concern was to minimise the total cost of
a project. The most widely accepted distinction between PERT and
CPM concerns the performance times for the activities. CPM is used
for cases where these times can be predicted reasonably accurately.
The important distinctive feature of PERT is that the technique
permits probabilistic estimates of activity times, and so can
accommodate research and development projects in which times for
activities cannot be predicted with confidence. This means that it can
also be used for projects that may suffer disruption through strike
action or late delivery of materials.
The type of activity network in which vertices represent activities was
developed by Bernard Roy (1934–2017) who, at the time, was working
at Sema Metra International, a fairly recently established consultancy
company. Bernard Roy was a pioneer in applying Operational
Research to real-world problems and went on to have a highly
distinguished academic career recognised, for example, by the award
of the Gold Medal of the Association of European Operational
Research Societies.

The type of activity network in which vertices represent activities is easier


to understand and easier to construct than the type in which vertices
represent events. In particular, it does not require the use of dummy
activities. A disadvantage for some applications is that the events are not
included in the network, which makes it more difficult to plan a number of
concurrent projects.

146
3 Critical path analysis

In this unit we have chosen to introduce both types of activity network,


but to concentrate on the type of activity network in which vertices
represent activities, because its construction is more straightforward than
for the other type. The analysis of an activity network has the same
essential features, regardless of the type of network, and involves finding a
‘critical path’ in the network. Our aim is to explain the basic principles
and techniques on which practical methods of network analysis such as
PERT and CPM (described at the beginning of this subsection) are based.
However, both PERT and CPM involve complexities that cannot be
included here.
The algorithms we give are in a form suitable for the type of activity
network in which vertices represent activities. However, the same
algorithms can be adapted, with only minor modifications, for the other
type of activity network.

3 Critical path analysis


Once an activity network has been constructed, we can find a critical
path, which tells us the minimum completion time for the project: the
activities along the critical path must be completed in the given order to
satisfy the precedence relations. Therefore the project cannot be
completed any faster than the length of the critical path. We can then also
calculate the earliest and latest times by which each activity must begin if
the project is not to be delayed.
Throughout this section, we assume that there is no restriction on the
number of workers available. In Section 4 we investigate the problem of
scheduling activities for a given number of workers.

3.1 Critical paths


To find a critical path in an activity network we find a longest path from
the start vertex to the finish vertex. (Note that an activity network may
contain more than one critical path.) By a longest path we mean a path
for which the sum of the times associated with the arcs of the path (that
is, the length of the path) has the largest possible value. The minimum
completion time is equal to the length of a critical path.
To see that we are looking for a longest path when finding the minimum
completion time, remember that the activity network shows which
activities must precede which other activities. An arc, AB say, in the
activity network implies that activity A must be completed before
activity B can be started. More generally, all activities along any path
from the start vertex to an activity C must be completed before C can
start. It follows that the earliest start time for activity C corresponds to
the length of the longest path to C. As this will apply not only to all
activities but also to the finish vertex, the minimum completion time for
the project will be the length of the longest path in the activity network.

147
Unit B2 Optimal paths, packing and scheduling

A critical path can be found by inspection in a small activity network, but


for larger examples we need a systematic method. We could use the
longest path algorithm given in Section 1 to find a critical path in an
activity network. However, because of the special structure of an activity
network – namely, the way the vertices are numbered – we can improve on
this method. The algorithm we now give for finding a critical path is more
efficient than the longest path algorithm given in Section 1.

Algorithm for constructing critical paths


The algorithm for finding a critical path in an activity network is similar
to the longest path algorithm, except that we make use of the numbering
of the vertices in the activity network. We saw earlier that this numbering
is possible because an activity network contains no cycles.
The algorithm is in two parts:
Part A is a forward scan, in which vertices are labelled consecutively.
Part B is a backward scan, in which critical paths are identified.
We give a formal statement of the algorithm, and then illustrate its use
with an example. We adopt the following notation.

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

Critical path construction algorithm


In general, there may be more than one critical path. However, in each of
our examples there is only one.

Critical path construction algorithm


Start with an activity network involving n activities.

Part A: labelling procedure


Step 1 Assign to the start vertex (vertex 0) the labels p0 = 0
and e0 = 0. Move to vertex 1.
Step 2 For the current vertex j, calculate, for each arc ij incident
to vertex j, the sum ei + ci,j , where ci,j is the duration of
activity i as shown in Figure 22.
Figure 22
Choose the maximum value of these sums for all such arcs
ij, and set ej equal to this value.
Set pj equal to the value of i for which this sum is largest;
in the case of a tie, choose any of the appropriate values,
noting down alternatives in brackets, as these might lead
to alternative critical paths.
Repeat Step 2 for the next vertex j + 1, unless j is the finish vertex
in which case proceed to Step 3.

Part B: tracing back procedure


Step 3 Start with the finish vertex n + 1, and mark the arc
joining this vertex to the preceding vertex pn+1 .
Step 4 Consider the vertex j such that the last marked arc is
incident from j. Mark the arc joining this vertex to the
preceding vertex pj .
Repeat Step 4 until the start vertex is reached. Stop:
• The marked arcs form a critical path.
• The sum of the weights on the arcs of the critical path is the
minimum completion time, and is given by the value of en+1 .

We illustrate this procedure by an example. The detailed explanation and


diagrams given here are not required in the solution to an exercise.

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.

Part A: labelling procedure


Step 1
p1 = 0 Vertex 0 We label the start vertex with p0 = 0 and e0 = 0.
e1 = 0
Step 2 We consider each vertex in turn.
1 Vertex 1 There is only one arc incident to this vertex, so
A 7
E e1 = e0 + c0,1 = 0 + 0 = 0.
0
4
We set p1 equal to the number of the vertex from which the
2
B corresponding arc is incident, so
0
start 2 p1 = 0.
p0 = 0 p2 = 0
e0 = 0 e2 = 0
0 Vertex 2 The situation is the same for vertices 2 and 3 as for vertex 1,
as indicated in Figure 23.
C
Vertex 3 The current labels are shown in Figure 23.
3
p3 = 0
e3 = 0
Figure 23

150
3 Critical path analysis

Vertex 4 There are two arcs incident to this vertex:


for the arc joining vertex 1 to vertex 4,
e1 + c1,4 = 0 + 7 = 7;
for the arc joining vertex 2 to vertex 4,
e2 + c2,4 = 0 + 2 = 2.
The larger of these sums is the first, so

e4 = 7
p4 = 1.

Vertex 5 There is only one arc incident to vertex 5, from vertex 4, so

e5 = e4 + c4,5 = 7 + 10 = 17
p5 = 4.

Vertex 6 There is only one arc incident to vertex 6, from vertex 4, so

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

Vertex 7 There are two arcs incident to this vertex:


for the arc joining vertex 5 to vertex 7,
e5 + c5,7 = 17 + 8 = 25;
for the arc joining vertex 6 to vertex 7,
e6 + c6,7 = 17 + 5 = 22.
The larger of these sums is the first, so

e7 = 25
p7 = 5.

Continuing in this way, we assign labels to all the vertices.


We record our values in a table. Here j is the number of the vertex being
labelled, and i is the number of any vertex from which there is an arc to
vertex j. Furthermore, ci,j is the duration of activity i, as shown in
Figure 24 Figure 24.

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

This is illustrated in the following diagram.

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

We now apply Part B of the algorithm to find the critical path.

Part B: tracing back procedure


Step 3 The finish vertex is vertex 11.
Since p11 = 10, we mark the arc from vertex 10 to the finish
vertex.
Step 4 Since p10 = 9, we mark the arc from vertex 9 to vertex 10.
Step 4 Since p9 = 7, we mark the arc from vertex 7 to vertex 9.
Step 4 Since p7 = 5, we mark the arc from vertex 5 to vertex 7.
Step 4 Since p5 = 4, we mark the arc from vertex 4 to vertex 5.
Step 4 Since p4 = 1, we mark the arc from vertex 1 to vertex 4.
Step 4 Since p1 = 0, we mark the arc from the start vertex to
vertex 1.
The path we have obtained in Part B may also be obtained by tracing
back on the table from Part A as shown in the following table.

153
Unit B2 Optimal paths, packing and scheduling

j i ei ci,j ei + ci,j ej pj activity


numbered j
0 – – – – 0 0 start
1 0 0 0 0 0 0 A
2 0 0 0 0 0 0 B
3 0 0 0 0 0 0 C
4 1 0 7 7 7 1 E
4 2 0 2 2
5 4 7 10 17 17 4 D
6 4 7 10 17 17 4 G
7 5 17 8 25 25 5 F
7 6 17 5 22
8 6 17 5 22 22 6 H
9 3 0 15 15
9 7 25 2 27 27 7 I
10 9 27 2 29 29 9 J
11 8 22 8 30
11 10 29 3 32 32 10 finish

The critical path is via vertices A, E, D, F , I and J, as shown in thick


lines in Figure 25.

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

The length of the critical path is 0 + 7 + 10 + 8 + 2 + 2 + 3 = 32, the value


of e11 ; thus the minimum completion time is 32 days.
In this example there is only one critical path. If there were more than
one, this would be apparent from the pj column containing at least one
entry in brackets, which would need to lie on a critical path. For example,
if the duration of activity B had been 7 rather than 2, so that c2,4 = 7,
then there would have been two critical paths. In the preceding table, for
the two rows in which j = 4, we would have recorded ej = 7 in each row
and could then have chosen pj = 1 as before, but should also have recorded
a value in brackets of (2) in the second row in which j = 4, which would
allow us to trace the two alternative critical paths in Part B.

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

3.2 Earliest and latest starting times


The critical path construction algorithm assigns a label ei to each vertex i.
The value of ei is the length of the longest path from the start vertex to
the vertex i. In other words, ei is the earliest starting time of activity i,
since activity i cannot be started until all preceding activities have been
completed. We can also calculate for each activity i the latest starting
time ℓi , which is the latest time at which activity i can be started without
delaying the whole project.
For an activity i on a critical path we have ei = ℓi ; any delay in the
completion of the activity will delay the completion of the project by the
same amount.

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?

In the solution to the previous exercise we saw that an activity not on a


critical path may be delayed by a certain amount without delaying the
whole project. The maximum time by which an activity may be delayed
without delaying the project is called the float of that activity. The float
is the difference between the earliest and latest starting times:
float of activity i = ℓi − ei .
The float of an activity on the critical path is zero.
If a project is to be completed in the shortest possible time, then
particular attention must be paid to the activities on any critical path. For
other activities, there is some leeway in their starting time or duration –
the amount of leeway for such an activity is its float.

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

(a) What is the minimum completion time of the project?


(b) Calculate the earliest starting times for activities 4 and 6.
(c) Calculate the latest starting times for activities 4 and 6.
(d) Calculate the floats for activities 4 and 6.
(e) Can both activity 4 and activity 6 be delayed by their floats without
delaying the completion of the project?

The following algorithm is a systematic method for calculating latest


starting times for all the vertices. As in the solution to the preceding
exercise, we begin at the finish vertex and work back, vertex by vertex,
until all the vertices have been considered.

Algorithm for calculating latest starting times


Start with an activity network involving n activities, for which
the minimum completion time has been calculated.
Step 1 For vertex n + 1 (the finish vertex), set ℓn+1 equal to the
minimum completion time. Move to vertex n.
Step 2 For the current vertex i, calculate, for each arc ij incident
from vertex i, the difference ℓj − ci,j , where ci,j is the
duration of activity i (see Figure 26).
Figure 26
Choose the minimum value of these differences for all such
arcs ij, and set ℓi equal to this value.
If 1 ≤ i ≤ n, repeat Step 2 for the vertex i − 1.
If i = 0 (the start vertex), then stop:
For each vertex i, the value ℓi is the latest starting time.

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.

Step 2 We consider each vertex in turn.


Vertex 10 There is only one arc incident from this vertex, so
ℓ10 = ℓ11 − c10,11 = 32 − 3 = 29.
Similarly, we calculate the following latest starting times.
Vertex 9 ℓ9 = ℓ10 − c9,10 = 29 − 2 = 27
Vertex 8 ℓ8 = ℓ11 − c8,11 = 32 − 8 = 24
Vertex 7 ℓ7 = ℓ9 − c7,9 = 27 − 2 = 25

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

We record our results in the following table.

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.

activity vertex earliest starting latest starting float


numbered i number i time ei time ℓi ℓi − e i

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

As stated earlier, any activity that is on a critical path has a float of


zero – this must be so, since any delay in the completion of an activity on
a critical path must delay the project.

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.

activity duration preceding


(in days) activities
A 10
B 4
C 8 B
D 6 C
E 8 I
F 5
G 10 A, D
H 2 G
I 4
J 10 D, F , I

Use appropriate algorithms to do the following.


(a) Construct an activity network for this project. (In answer to this
part, you need only give the final activity network diagram.)
(b) Find a critical path and the minimum completion time.
(c) Find the latest starting time and the float for each activity.

Before leaving the subject of activity networks, we mention an important


difficulty which often arises in practice – namely that the estimated
durations of the activities may not be accurate, or may vary during the
planning and production stages. If estimates change, then the activity
network must be updated and, if necessary, the calculations of earliest and
latest starting times repeated. In particular, this may result in a different
set of activities forming the critical path. The advantage of PERT
(introduced at the start of Subsection 2.3) is that, at the planning stage,
three estimates of the time required would typically be specified for each
activity – the optimistic time, the most likely time and the pessimistic
time. Moreover, software packages are available which will handle PERT
calculations, thus facilitating the updating of the network, and the
monitoring and control of the project once it is underway.

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

• apply the algorithm to construct an activity network from a table of


precedence relations
• find a critical path in an activity network by using the critical path
construction algorithm, and calculate the minimum completion time
• apply the algorithm to find the latest starting times from an activity
network with a critical path, and calculate the float of each activity.

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.

4.1 Scheduling a project for a given number


of workers
We suppose that an ideal schedule satisfies the following conditions, which
we call the factory rules.
1. No worker may be idle if there is some activity that can be done.
2. Once a worker starts an activity, that activity must be continued by the
same worker until it is completed.
3. The project must be completed as soon as possible with the workforce
available.
These rules imply that the workers should have a minimum amount of idle
time, and that activities on a critical path should be started as soon as
possible.
Suppose, for example, that we wish to schedule the bicycle assembly
project for two workers according to the factory rules. This activity

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

As a first attempt at a schedule, let us assign all the activities on the


critical path to worker 1, and all the remaining activities to worker 2. In
doing this, we assign the activities in the order of the numbering scheme,
taking into account the precedence relations involving activities done by
both workers. In Exercise B2.9 we showed that the activities on the critical
path take a total of 30 minutes. Since the sum of the durations for all the
activities is 64 minutes, the activities assigned to worker 2 take a total of
34 minutes to complete. So, if the activities are scheduled in this way, the
shortest possible time for the completion of the project is 34 minutes. The
actual time may be greater because of the precedence relations; some
activities cannot be started until others have been completed.
The resulting schedule is the following.

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

This schedule has a completion time of 32 minutes – it is an optimum


schedule in the sense that it has the shortest possible completion time for
any schedule for the number of workers available. This schedule also
satisfies all the factory rules.
We arrived at this optimum solution by a trial-and-error method. Is it
possible to devise a systematic method that will produce an optimum
schedule for any activity network with a given number of workers?
Unfortunately, there is no known efficient algorithm for doing this. You
may argue that, in principle, we can use the exhaustion method : list all
possible schedules and choose one with a minimum completion time.
However, the number of possible schedules grows so rapidly with the
number of activities that it quickly becomes impractical to work through
them all as the number of activities grows. This is an example of
‘combinatorial explosion’.
Since there is no practical algorithm for this type of scheduling problem,
we use instead a heuristic method – that is, one depending on assumptions
based on past experience, giving a method that does not necessarily result
in an optimum solution, but usually gives a reasonable one.
The following heuristic algorithm, called the critical path scheduling
algorithm, has often been used in industry. It produces a schedule that
satisfies the first two factory rules, but not necessarily the third rule.

165
Unit B2 Optimal paths, packing and scheduling

Algorithm for scheduling activities


The algorithm assigns activities to a number of processors, which may be
people or machines. It is assumed that the activity network has been
constructed and the latest starting times calculated.
The algorithm makes use of a hypothetical clock to keep track of time. We
call this the project clock . At the end of each iteration, we advance the
project clock so that it records the time for which the project has been
running at this point.

Critical path scheduling algorithm


Start with an activity network for which the latest starting
times have been calculated.
Set the project clock to 0.
Step 1 If at least one processor is free, assign to any free
processor the most critical unassigned activity that can be
started, where the most critical activity is one with the
smallest latest starting time.
Repeat until no processor is free or until no unassigned
activity can be started.
Step 2 Advance the project clock until a time is reached when at
least one activity has been completed, so that at least one
processor is free.
If not all activities have been assigned, return to Step 1.
If all the activities have been assigned, advance the project
clock until all the activities have been completed. Stop:
• The final time on the project clock gives the minimum
completion time.
• The record of the timing and allocation of activities
obtained during Steps 1 and 2 gives a schedule for
achieving this time.

We illustrate this procedure by an example. This shows the level of


explanation required in the solution to an exercise. You should include this
detail (excluding the text inside the thinks bubbles) unless the question
just asks you to write down the final schedule.

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

Step 1 Of the available activities, the most critical is activity D,


since it has the smallest latest starting time.
We assign activity D to worker 1.
Activities A and B have the same latest starting time, so
either can be chosen for worker 2.
We assign activity A to worker 2.
Step 2 Advance the project clock to 2 minutes.
Activity D is completed, so worker 1 is free.
Activities B, E and F are now available to start.
The current state of the scheduling of the activities is as follows.

time 0 2 4 6

worker 1 D activities free


to be started:
worker 2 A B, E, F

time on
project clock

Step 1 Of the three available activities, E has the smallest latest


starting time.
We assign activity E to worker 1.
Step 2 Advance the project clock to 5 minutes.
Activity E is completed, so worker 1 is free.
Activities B, C and F are now available to start.
The current state of the scheduling of the activities is as follows.

time 0 2 4 6 8

worker 1 D E activities free


to be started:
worker 2 A B, C, F

time on
project clock

168
4 Scheduling

Step 1 Of the three available activities, B and C are the most


critical. Both have a latest starting time of 5 minutes. Since
the project clock is now at 5 minutes, and since we cannot
assign both activities B and C to workers at this point, there
will be a delay in the completion of the project – in other
words, the time taken with this schedule will be greater than
the length of the critical path.
We assign activity C to worker 1.
We have chosen C as it is on the critical path, but B
could have been chosen instead.
Step 2 Advance the project clock to 7 minutes.
Activity A is completed, so worker 2 is free.
No further activity is made free to be started by the
completion of activity A.
Activities B and F are now available to start.
Step 1 Of the available activities, B has the smaller latest
starting time.
We assign activity B to worker 2.
Step 2 Advance the project clock to 12 minutes.
Activity C is completed, so worker 1 is free.
No further activity is made free to be started by the
completion of activity C.
We just have activity F available to start.
Step 1 We assign activity F to worker 1.
The current state of the scheduling of the activities is as follows.

time 0 2 4 6 8 10 12 14 16

worker 1 D E C F activities free


to be started:
worker 2 A B none

time on
project clock

Step 2 Advance the project clock to 14 minutes.


Activities B and F are completed, so both workers are free.
Activities G and J are now available to start.
Step 1 Of the two available activities, J has the smaller latest
starting time.
We assign activity J to worker 1.
The only remaining activity that can be started is G.
We assign activity G to worker 2.
Step 2 Advance the project clock to 16 minutes.
Activity G is completed, so worker 2 is free.
Activities H and I are now available to start.

169
Unit B2 Optimal paths, packing and scheduling

Step 1 Both available activities have the same latest starting


time.
We assign activity H to worker 2.
Step 2 Advance the project clock to 24 minutes.
Activity H is completed and worker 2 is free.
Activity I is available to start.
Step 1 We assign activity I to worker 2.
Step 2 Advance the project clock to 32 minutes.
All activities have now been completed. Stop.
The resulting schedule is the following.

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

4.2 Algorithms with protection schemes


In Exercise B2.17 we obtained the following schedule.

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

This schedule is far from an optimum one, as can be seen by comparing it


with an optimum schedule such as the following.

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

In a situation like this, it is obviously desirable to produce a schedule that


has a shorter completion time than the one obtained by applying the
algorithm. To do this in industry, some form of protection scheme is
usually incorporated into an algorithm. Such a scheme permits, for
example, the use of precedence relations to override the ‘naive’ ranking
order under certain circumstances. There is no general protection scheme,
so a network analyst working in a particular situation must develop a
protection scheme that is appropriate for the type of scheduling problem
involved. For example, a protection scheme may be incorporated in the
algorithm as follows.

172
4 Scheduling

Outline of algorithm incorporating a protection scheme


Step 1 Compute for each activity the sum of the earliest starting
time and the latest starting time, and rank the activities
in ascending order according to the values of these sums.
Step 2 Assign activities successively to free workers according to
this ranking, taking into account the precedence relations.
If a preceding activity has not already been assigned,
break the ranking order when assigning the activities.

Applying this new algorithm to the project considered in Exercise B2.17,


we first identify the earliest and latest starting times for each activity, by
inspection of the activity network. We then calculate the sum of these
times as shown in the following table.

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

We now go to Step 2 of the algorithm, and assign each activity in turn to a


free worker. If an activity cannot be assigned immediately because of the
precedence relations, we wait until the appropriate previously assigned
activities have been completed. This procedure produces the schedule
shown in Figure 32.

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

This is close to an optimum schedule. This schedule does not satisfy


factory rule 1 (as each worker has some idle time), but it comes close to
satisfying factory rule 3 (as the schedule only takes two minutes longer
than the minimum possible time for four workers).
Once we have produced a schedule using such a protection scheme, we may
be able to improve it by moving activities to fill idle time intervals. For
example, in the preceding schedule, it is a simple matter to fill the initial
idle time intervals of workers 2, 3 and 4 with activities B, C and D. In this
way we arrive at the optimum schedule we gave earlier.

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

What is the minimum number of workers required to finish the project in


15 days?

175
Unit B2 Optimal paths, packing and scheduling

This problem is called a bin-packing problem, since it amounts to


trying to pack the activities into the minimum number of ‘bins’ b1 , b2 , . . . ,
each of specified capacity (in this case, 15 days).
There is no known algorithm that will always give an optimum solution to
the bin-packing problem. However, there are a number of simple heuristic
algorithms, which usually give near-optimum solutions.
One method is next-fit packing, in which the items (in this case, activities)
are packed in the order in which they occur. The order of occurrence is
often given in a table, such as the table at the start of this section, which
lists 11 activities in the order A to K. The items are packed according to
the following rule.

Next-fit packing algorithm


Always place the next item to be packed in the current bin if possible;
otherwise, place it in the next bin, which then becomes the current
bin.

If we pack the activities using the next-fit algorithm, we obtain the


following packing.

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.

First-fit packing algorithm


Always place the next item to be packed in the lowest numbered bin
that can accommodate that item.

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.

First-fit decreasing packing algorithm


Order the items in decreasing order of size, and apply the first-fit
packing procedure to this reordered list.

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

When we apply the first-fit algorithm, we obtain the following scheme.

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

It is required to find a way of cutting these sections so that the minimum


number of planks is used.
(a) Find a solution using the next-fit algorithm.
(b) Find a solution using the first-fit algorithm.
(c) Find a solution using the first-fit decreasing algorithm.
(d) By trial and error, find an optimum solution that uses fewer planks
than the solutions obtained in parts (a), (b) and (c).

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

It is required to find the minimum number of workers needed to complete


the project in 12 days.
(a) Find a solution using the next-fit algorithm.
(b) Find a solution using the first-fit algorithm.
(c) Find a solution using the first-fit decreasing algorithm.

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.

iteration origin vertices assigned labels potential assigned


vertex A B C D E T to vertex
1 S 7 

13 

28 A
2 A 11 

32 17 B
3 B 16 17 C
4 C ∗ D, E
5 D 22 T
E ∗

Having assigned potential 22 to T , we know that the length of the shortest


path from S to T is 22. We trace back from T to D, from D to B, from B
to A and from A to S, to get the shortest path SABDT .

Solution to Exercise B2.4


We apply the longest 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

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.

iteration vertices origin vertices


assigned labels S A B C D E
1 (S) A 7
2 (S, A) B 13 11
3 (S, A, B) C 28 18
D 32 19
4 (S, A, B, C, D) E 17 31
5 (S, A, B, C, D, E) T 37 43

Having assigned potential 43 to T , we know that the length of the longest


path from S to T is 43. We trace back from T to E, from E to C, and
from C to S, to get the longest path SCET .

Solution to Exercise B2.6


We apply the activity network construction algorithm.

Part A: procedure for numbering the vertices


We draw a bipartite graph representing the precedence relations which are
summarised in the following table. (These are listed in alphabetical order
for the right-hand column.)

activity preceding activities


J A, B, C, D, E
C D, E
E D
F D
H E, F , G
I E, F , G
G F

182
Solutions to exercises

The numbering of the vertices carried out in each successive iteration is


shown in the following diagrams.

first iteration second iteration third iteration fourth iteration


1 A A

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

We now construct the activity network following the procedure of Part B


of the algorithm. The resulting activity network is shown in the following
diagram.

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.

Part B: procedure for drawing the activity network


Step 3 We draw the start vertex, and the vertices numbered in the first
iteration: A, B and D. We then draw arcs from the start vertex to A, B
and D, assigning a zero weight to each.
Step 4 In the second iteration we numbered vertices E and F , so we add
vertices E and F to the activity network.
Activity D must precede E and F , so we draw arcs:
from D to E, with weight 2 (the duration of D)
from D to F , with weight 2 (the duration of D).
Step 4 In the third iteration we numbered vertices C and G , so we add
vertices C and G to the activity network.
Activities D and E must precede C, and activity F must precede G, so we
draw arcs:
from D to C, with weight 2 (the duration of D)
from E to C, with weight 3 (the duration of E)
from F to G, with weight 2 (the duration of F ).
Step 4 In the fourth iteration we numbered vertices H, I and J, so we
add vertices H, I and J to the activity network.

184
Solutions to exercises

Activities E, F and G must precede H and I, so we draw arcs:


from E to H and from E to I, with weight 3 (the duration of E)
from F to H and from F to I, with weight 2 (the duration of F )
from G to H and from G to I, with weight 2 (the duration of G).
Activities A, B, C, D and E must precede J, so we draw arcs:
from A to J, with weight 7 (the duration of A)
from B to J, with weight 7 (the duration of B)
from C to J, with weight 7 (the duration of C)
from D to J, with weight 2 (the duration of D)
from E to J, with weight 3 (the duration of E).
All the activities have now been represented by vertices.
Step 5 We draw a finish vertex. From the terminal vertices H, I and J,
we draw arcs:
from H to finish, with weight 8 (the duration of H)
from I to finish, with weight 8 (the duration of I)
from J to finish, with weight 18 (the duration of J).
The activity network is now complete.

Solution to Exercise B2.7


The activity network from Exercise B2.6 is as follows.

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

The arcs DJ and EJ are redundant, since activity J must follow


activity C which must follow activity E which must follow activity D.
Similarly, the arcs DC, F H and F I are redundant.

185
Unit B2 Optimal paths, packing and scheduling

The redundant precedence relations are given in the following table.

activity preceding activities


I F
J D, E
H F
C D

Solution to Exercise B2.9

j i ei ci,j ei + ci,j ej pj activity


numbered j
0 – – – – 0 0 start
1 0 0 0 0 0 0 A
2 0 0 0 0 0 0 B
3 0 0 0 0 0 0 D
4 3 0 2 2 2 3 E
5 3 0 2 2 2 3 F
6 3 0 2 2
6 4 2 3 5 5 4 C
7 5 2 2 4 4 5 G
8 4 2 3 5
8 5 2 2 4
8 7 4 2 6 6 7 H
9 4 2 3 5
9 5 2 2 4
9 7 4 2 6 6 7 I
10 1 0 7 7
10 2 0 7 7
10 3 0 2 2
10 4 2 3 5
10 6 5 7 12 12 6 J
11 8 6 8 14
11 9 6 8 14
11 10 12 18 30 30 10 finish

186
Solutions to exercises

Applying Part A of the critical path construction algorithm, we obtain the


vertex labels shown in the previous table.
The critical path is found using Part B, and is indicated on the table and
in the following activity network.
The critical path is via vertices D, E, C and J, as shown in the following
diagram in thick lines.

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

The length of the critical path is 0 + 2 + 3 + 7 + 18 = 30, the value of e11 .


Thus the minimum completion time is 30 minutes.

Solution to Exercise B2.10


Let us imagine that we steadily increase the delay in completing an
activity that is not on the critical path. To begin with, this delay will not
affect the time needed to complete the project. However, as the delay
increases, there will come a point when the delay becomes so large that the
activity becomes part of a new critical path, so delays larger than this will
delay the project.

187
Unit B2 Optimal paths, packing and scheduling

Solution to Exercise B2.11


(a) The minimum completion time is equal to the length of the critical
path, which is
0 + 5 + 4 + 7 + 2 = 18 days.

(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.

(d) The float of activity 4 is ℓ4 − e4 = 11 − 9 = 2 days.


The float of activity 6 is ℓ6 − e6 = 14 − 12 = 2 days.
(e) If activity 4 is delayed by 2 days, then the path through vertices 3, 4,
6 and 7 has the same length as the path through vertices 3, 5 and 7
and so becomes part of a new critical path, with the start time of
activity 6 delayed by 2 days. So if activity 6 is delayed by an
additional 2 days, this causes a delay of 2 days in the completion of
the whole project. In other words, the two activities cannot both be
delayed by their float times without delaying the whole project.

188
Solutions to exercises

Solution to Exercise B2.13


(a) 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 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

activity vertex earliest starting latest starting float


numbered i number i time ei time ℓi ℓi − e i

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

Solution to Exercise B2.14


(a) The activity network is as follows.

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

(b) Applying Part A of the critical path construction algorithm, we


obtain the following table. We have traced the critical path found in
Part B of the algorithm.

190
Solutions to exercises

j i ei ci,j ei + ci,j ej pj activity


numbered j
0 – – – – 0 0 start
1 0 0 0 0 0 0 A
2 0 0 0 0 0 0 B
3 0 0 0 0 0 0 F
4 0 0 0 0 0 0 I
5 2 0 4 4 4 2 C
6 4 0 4 4 4 4 E
7 5 4 8 12 12 5 D
8 1 0 10 10
8 7 12 6 18 18 7 G
9 3 0 5 5
9 4 0 4 4
9 7 12 6 18 18 7 J
10 8 18 10 28 28 8 H
11 6 4 8 12
11 9 18 10 28
11 10 28 2 30 30 10 finish

The critical path is via vertices B, C, D, G and H. The length of the


critical path is 0 + 4 + 8 + 6 + 10 + 2 = 30, the value of e11 ; thus the
minimum completion time is 30 days.

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

activity vertex earliest starting latest starting float


numbered i number i time ei time ℓi ℓi − ei

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

Solution to Exercise B2.16


We apply the critical path scheduling algorithm.
Start Set the project clock to 0.
Activities A, B and C are available to start.
Step 1 We assign activity A to worker 1.
We assign activity B to worker 2.
Step 2 Advance the project clock to 2 days.
Activity B is completed so worker 2 is free.
Activity C is available to start.
Step 1 We assign activity C to worker 2.
Step 2 Advance the project clock to 7 days.
Activity A is completed so worker 1 is free.
Activity E is available to start.
Step 1 We assign activity E to worker 1.
Step 2 Advance the project clock to 17 days.
Activities C and E are completed so both workers are free.
Activities D and G are available to start.
Step 1 We assign Activity D to worker 1.
We assign activity G to worker 2.
Step 2 Advance the project clock to 22 days.
Activity G is completed so worker 2 is free.
Activity H is available to start.

193
Unit B2 Optimal paths, packing and scheduling

Step 1 We assign activity H to worker 2.


Step 2 Advance the project clock to 25 days.
Activity D is completed so worker 1 is free.
Activity F is available to start.
The current state of the scheduling of activities is as follows. (This
diagram does not need to be presented as part of the solution but is given
to assist your understanding of the algorithm.)

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

Step 1 We assign activity F to worker 1.


Step 2 Advance the project clock to 27 days.
Activity F is completed so worker 1 is free.
Activity I is available to start.
Step 1 We assign activity I to worker 1.
Step 2 Advance the project clock to 29 days.
Activity I is completed so worker 1 is free.
Activity J is available to start.
Step 1 We assign activity J to worker 1.
Step 2 Advance the project clock to 30 days.
Activity H is completed so worker 2 is free.
Step 2 Advance the project clock to 32 days.
All activities have been completed. Stop.
The resulting schedule is the following, taking 32 days.

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

This is an optimum schedule – no other schedule has a shorter completion


time, as the length of the critical path is 32 days.

194
Solutions to exercises

Solution to Exercise B2.17


(a) By inspection, there are four critical paths from A to L via vertices
H, I, J or K. The minimum completion time is 17 minutes.
The latest starting times and durations (in minutes) for the activities
are given next.

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

(b) Applying the critical path scheduling algorithm, we obtain the


following schedule requiring 25 minutes for four workers.

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

This is not an optimum schedule, as discussed at the beginning of


Subsection 4.2.

Solution to Exercise B2.18


(a) Applying the critical path scheduling algorithm, we obtain the
following schedule requiring 36 days for two workers.

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

Applying the modified critical path scheduling algorithm with


protection scheme, we obtain the following schedule requiring 34 days
for two workers.

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

Solution to Exercise B2.19


(a) Using the next-fit algorithm, we obtain the following plan requiring
6 planks.

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

Then, applying the first-fit algorithm, we obtain the following plan


requiring 5 planks; in this plan only two feet of plank 5 are used and
one foot is unused in each of planks 2 and 4.

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

Solution to Exercise B2.20


(a) Using the next-fit algorithm, we obtain the following schedule
requiring 6 workers.

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

(b) Using the first-fit algorithm, we obtain the following schedule


requiring 4 workers, which is clearly an optimum schedule.

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

Then, applying the first-fit algorithm, we obtain the following schedule


requiring 4 workers, which is also clearly an optimum schedule.

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

combinatorial explosion 165 redundant arc 143


CPM, Critical Path Method 146 Roy, Bernard 146
critical path 147
construction algorithm 149 schedule 163
scheduling algorithm 166 scheduling 131, 163
heuristic method 165
dummy activity 144 shadow vertex 134
shortest path 121
earliest starting time 156 algorithm 121
event 144
exhaustion method 165 vertex
original 134
factory rules 163 representing activity 133
first-fit decreasing packing algorithm 178 representing event 144
first-fit packing algorithm 177 shadow 134
float 156, 161

heuristic method 165

inconsistencies in precedence relations 142

latest starting time 156


algorithm 157
longest path 120, 127, 147
algorithm 127

minimum completion time 147

next-fit packing algorithm 176

off-line algorithm 179

200

You might also like