0% found this document useful (0 votes)
4 views

FM Modelling With Algorithms

The document describes the MEI AS and A Level Further Mathematics textbook, focusing on Modelling with Algorithms, which is available in both Whiteboard and Student eTextbook formats. It emphasizes the integration of algorithms, graph modeling, and linear programming, providing resources for teachers and students to enhance their learning experience. Additionally, it includes information on environmental policies, ordering details, and the structure of the textbook, which supports problem-solving and the use of technology in mathematics education.

Uploaded by

amsharma5078
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)
4 views

FM Modelling With Algorithms

The document describes the MEI AS and A Level Further Mathematics textbook, focusing on Modelling with Algorithms, which is available in both Whiteboard and Student eTextbook formats. It emphasizes the integration of algorithms, graph modeling, and linear programming, providing resources for teachers and students to enhance their learning experience. Additionally, it includes information on environmental policies, ordering details, and the structure of the textbook, which supports problem-solving and the use of technology in mathematics education.

Uploaded by

amsharma5078
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/ 117

MEI AS and A Level Further Mathematics - Modelling with Algorithms is available as a

Whiteboard eTextbook and Student eTextbook.


Whiteboard eTextbooks are online interactive versions of the printed textbook that enable teachers to:
• Display interactive pages to their c ass
• Add notes and highlight areas
• Add double-page spreads into lesson plans

Student eTextbooks are downloadable versions of the printed textbooks that teachers can assign to
students so they can:
• Download and view on any device or browser
• Add, edit and synchronise notes across two devices
• Access their personal copy on the move

To find out more and sign up for free trials visit: www.hoddereducation.co.uk/dynamiclearning
V

"integral integral A Level Mathematics online resources


Our eTextbooks link seamlessly with Integral A Level Mathematics online resources, allowing you to
move with ease between corresponding topics in the eTextbooks and Integral.
These online resources have been developed by MEI and cover the new OCR specifications, supporting
teachers and students with high quality teaching and learning activities that include dynamic resources and
self-marking tests and assessments.
Integral A Level Mathematics online resources are available by subscription to enhance your use of this
book. To subscribe to Integral visit wwwJntegralmaths.org
Jan Dangerfield
Series editor:
Catherine Berry
Series advisor:
Roger Porkess

AS and
A LEVEL
FURTHER
MATHEMATICS
Modelling with Algorithms

9781510403130.indb 1 20/03/18 7:48 AM


Hachette UK’s policy is to use papers that are natural, renewable and recyclable products and made from wood grown in sustainable
forests. The logging and manufacturing processes are expected to conform to the environmental regulations of the country of origin.
Orders: please contact Bookpoint Ltd, 130 Park Drive, Milton Park, Abingdon, Oxon OX14 4SE. Telephone: (44) 01235 827720.
Fax: (44) 01235 400401. Email [email protected] Lines are open from 9 a.m. to 5 p.m., Monday to Saturday, with a
24-hour message answering service.You can also order through our website: www.hoddereducation.co.uk
ISBN: 978 1 5104 0313 0
 Jan Dangerfield and MEI 2018
First published in 2018 by
Hodder Education,
An Hachette UK Company
Carmelite House
50 Victoria Embankment
London EC4Y 0DZ
www.hoddereducation.co.uk
Impression number 10 9 8 7 6 5 4 3 2 1
Year 2022 2021 2020 2019 2018
All rights reserved. Apart from any use permitted under UK copyright law, no part of this publication may be reproduced or transmitted
in any form or by any means, electronic or mechanical, including photocopying and recording, or held within any information storage
and retrieval system, without permission in writing from the publisher or under licence from the Copyright Licensing Agency Limited.
Further details of such licences (for reprographic reproduction) may be obtained from the Copyright Licensing Agency Limited,
www.cla.co.uk
Cover photo © sakkmesterke - 123RF.com
Illustrations by Integra Software Services Pvt. Ltd., Pondicherry, India
Typeset in Bembo Std, 11/13 by Integra Software Services Pvt. Ltd., Pondicherry, India
Printed in U.K.
A catalogue record for this title is available from the British Library.

9781510403130.indb 2 20/03/18 7:48 AM


Contents
Getting the most from this book iv 4 Further network problems 44
1 Algorithms 1 4.1 Critical path analysis 44
4.2 Network flows 52
1.1 What is an algorithm? 1
1.2 Algorithmic complexity 6 5 Linear programming 59
1.3 Packing 10 5.1 Formulating linear programming
1.4 Sorting 12 problems 59
5.2 Graphical solutions 63
2 Modelling with graphs and
networks 17 6 Simplex method 71
2.1 The language of graphs and 6.1 Using a simplex tableau 71
networks 17 6.2 Non-standard forms 77
2.2 Modelling with graphs 23 6.3 Use of technology 82
2.3 Modelling with networks 27
7 Reformulating network problems 
3 Network algorithms 32 as linear programming problems 86
3.1 Algorithms for minimum connector 7.1 Modelling paths and flows 86
problems 32
7.2 Modelling allocation problems 93
3.2 Finding the shortest path 39
3.3 Calculating algorithmic Answers 100
complexities  42

iii

9781510403130.indb 3 20/03/18 7:48 AM


Getting the most from this book
Mathematics is not only a beautiful and exciting subject in its own right but also one
that underpins many other branches of learning. It is consequently fundamental to our
national wellbeing.
This textbook covers the content of Y413/Y433 Modelling with Algorithms, one of the
options in the MEI AS and A Level Further Mathematics specification. Some students will
begin this course in year 12 alongside the A level course, whereas others only begin Further
Mathematics when they have completed the full A Level Mathematics and so have already
met some of the topics, or background to topics, covered in MEI A Level Mathematics (Year 2).
This book has been written with all these users in mind.
The journey through the content of this book is described in diagrammatic form at the
beginning of chapter one.
Between 2014 and 2016 A Level Mathematics and Further Mathematics were very
substantially revised, for first teaching in 2017. Changes include increased emphasis on
● Problem solving
● Mathematical rigour
● Use of ICT
● Modelling
This book embraces these ideas. A large number of exercise questions involve elements of
problem solving and require rigorous logical argument. Questions that invite the use of
spreadsheets, graphical calculators or LP solvers are indicated with a computer screen icon.
The use of software to solve LPs is crucial in the latter stages of the book, and there
are many other opportunities for the use of technology to aid understanding of the
concepts and methods.
Modelling pervades the whole of this book. Every aspect of the modelling cycle is
used. Real world problems are modelled as graph or network problems, as algorithms
or as LPs. The solution has to be interpreted carefully in context and then the
reasonableness of the answer checked.
Throughout the book the emphasis is on understanding and interpretation rather than
mere routine calculations, but the various exercises do nonetheless provide plenty of scope
for practising basic techniques. In addition, extensive online support, including further
questions, is available by subscription to MEI’s Integral website, http://integralmaths.org.
There are places where the work depends on knowledge from earlier in the book or
elsewhere and this is flagged up in the Prior knowledge boxes. This should be seen as
an invitation to those who have problems with the particular topic to revisit it. At the
end of each chapter there is a list of key points covered as well as a summary of the
new knowledge (learning outcomes) that readers should have gained.
Two common features of the book are Activities and Discussion points. These serve
rather different purposes. The Activities are designed to help readers get into the
thought processes of the new work that they are about to meet. The Discussion points
invite readers to talk about particular points with their fellow students and their teacher
and so enhance their understanding.
Answers to all exercise questions are provided at the back of the book, and also online
at www.hoddereducation.co.uk/MEIFurtherMathsModellingwithAlgorithms
This is a 4th edition MEI textbook so much of the material is well tried and tested.
However, as a consequence of the changes to A Level requirements in Further Mathematics,
large parts of the book are either new material or have been very substantially rewritten.
Catherine Berry
iv
Roger Porkess

9781510403130.indb 4 20/03/18 7:48 AM


1 Algorithms

The journey through Modelling with Algorithms is shown in this flowchart.


An algorithm must be
seen to be believed. Model a problem
Donald Knuth (1938– ) What problems can be with a network Different problems can be
modelled as a network? modelled with the same network

Algorithms for sorting and


Use an algorithm to packing
What is an algorithm? solve the problem and
Does the algorithm give an interpret the solution
optimal solution? How do you Finding the shortest path
know? or the maximum flow
What happens if the problem is through a network
bigger? How much longer will
For larger, authentic
the algorithm take to solve it?
problems, reformulate
Investigate LP
as a linear programming
problems graphically
(LP) problem
Integer variables

How does simplex work? Use simplex method


or simplex software
Interpret output

Figure 1.1

Discussion point
A friend asks you how to work out the perimeter of a triangle.
What information would you need to know about the triangle before you can give
an answer?

1 What is an algorithm?
An algorithm is a finite sequence of operations for carrying out a procedure or
solving a problem. Cooking recipes, knitting patterns and instructions for making
flat pack furniture are algorithms, but obviously these are not mathematical
algorithms.

9781510403130.indb 1 20/03/18 7:48 AM


What is an algorithm?

ACTIVITY 1.1
Do you know on which day of the week you were born? Zeller’s algorithm can be
used to work it out. Try the algorithm using your date of birth.

Example:
Zeller’s algorithm
29th Feb 2000
Let day number = D D = 29
This uses the current Let month number = M M=2
(new) value of Y. Let year number = Y Y = 2000
If M = 1 or 2, add 12 to M and subtract 1 from Y M = 14
Y = 1999
INT(N) is the integer part
of N. This is the largest Let C be the first two digits of Y and X be the last two digits of Y C = 19
integer that is less than or X = 99
equal to N. For example, Calculate INT(2.6M – 5.4) + INT(X ÷ 4) + INT(C ÷ 4) + D + X – 2C 31+24+4+29+99-38
INT(2.3) = 2, INT(6.7) = 6, = 149
INT(4) = 4 and INT(0) = 0.
The integer part of a
Find the remainder when this is divided by 7 2
negative number N is the If the remainder is 0 the day was Sunday, if it is 1 the day was Tuesday
negative of INT(−N), for Monday, and so on
example, INT(−1.7) = −1.

The remainder when N is


In mathematics an algorithm has an initial state and involves inputs, outputs and
divided by 7 is the same variables. The initial state is the ‘factory setting’ values of any variables that are not
as N – 7 × INT(N ÷ 7) defined within the algorithm. Usually this means that all variables have the value 0
until they are updated.
For Zeller’s algorithm as given above, the inputs are the initial values of D, M and Y;
the output is the day and the variables are C, D, M, X and Y.
The output may be printed or displayed.

Communicating an algorithm
How do you communicate an algorithm? The form of communication depends on
who (for example a seven-year-old) or what (for example a computer) will be using
the algorithm.
Whatever method is used to communicate the steps of an algorithm it must be:
l unambiguous, so the person or machine running the algorithm does not have
to make any choices
l deterministic, so there is no chance or randomness involved
l finite, so the algorithm stops.
This means that each time the algorithm is used with a certain input, it gives the
same output, and that it does this in a finite number of steps.
An algorithm may be communicated in ordinary language, in a flowchart or in
pseudocode. A flowchart was used to show the journey through Modelling with
Algorithms at the start of this chapter.

9781510403130.indb 2 20/03/18 7:48 AM


Zeller’s algorithm could be written in pseudocode as:
Step 1 Let D be day number
Let M be month number M = M + 12 means
1
Let Y be year number that the value of (old)
M + 12 becomes the
value of (new) M.

Chapter 1 Algorithms
Step 2 If M < 3 then M = M + 12 and Y = Y – 1

Step 3 Let C = INT(Y ÷ 100)


Let X = Y – (100 × C)

Step 4 Let S = INT(2.6M – 5.4) + INT(X ÷ 4) + INT(C ÷ 4) + D + X – 2C

Step 5 Let A = S – (7 × INT(S ÷ 7)) and display the value of A


Note that the output is the day number and not the name of the day.
Algorithms for mathematical processes can usually be broken up into a number of
Completing a pass means sequential steps. Sometimes an algorithm will involve decisions (‘if … then …’)
that you have worked and may loop back to an earlier step (‘go to step …’).
through the instructions
once, as far as either Algorithms may involve iterative processes. This means that after completing one
terminating or looping pass through the instructions a solution has been obtained that may only be part
back to an earlier step.
way to the answer to the problem. By going back and carrying out further passes
the solution can be improved.
For example, an algorithm for finding square roots is given below:
Step 1 Input a positive number N
 N
Step 2 Let A = 1 NA +
2 A
1 N
Step 3 Let B = 2  A + 
A
Step 4 If (A – B)2 < 0.001 then go to step 6
Step 5 Let A = B and then go to step 3
Step 6 Display the value of B and STOP

ACTIVITY 1.2
Work through this algorithm with N = 2. The algorithm loops back to step 3,
a pass occurs each time that step 3 is used. How many passes are carried out?

Example 1.1 The real roots of a quadratic equation


ax2 + bx + c = 0 (a ≠ 0)
can be found using the quadratic formula

−b ± b 2 − 4ac .
x=
2a
(i) Use a flowchart to represent an algorithm for solving a quadratic equation.
(ii) Write the algorithm in pseudocode.

3

9781510403130.indb 3 20/03/18 7:48 AM


What is an algorithm?

Solution This is one possible solution.

(i) Input a, b, c (ii) Step 1 Let d = b2 – 4ac


Step 2 If d < 0 print
d = b2 − 4ac ‘no real solutions’
and go to step 5
Print ‘No real No
solutions’
Is d ³ 0? −b + b 2 − 4ac
Step 3 Let x1 =
2a
Yes
x1 = (−b + Öd ) ÷ (2a) −b − b 2 − 4ac
Let x2 =
x2 = (−b − Öd ) ÷ (2a) 2a
Note Step 4 Print x1 and x2
The word ‘algorithm’ Print x1, x2 Step 5 STOP
Stop
has become more
commonplace since
the development of the Figure 1.2
computer. A computer
program is simply an An algorithm gives the logical structure that underlies a computer program for
algorithm written in such solving a problem. Modelling with algorithms has obvious connections with
a way that a machine can computer science but does not require programming skills or knowledge of any
carry it out.
specific computing language.

ACTIVITY 1.3
Below are two algorithms, one expressed in pseudocode and the other as a flowchart.
Russian algorithm for multiplying two Euclid’s method for finding the highest
integers common factor of two positive integers x
Step 1 Write the two numbers side and y
by side Input x, y
Step 2 Beneath the left number Subtract y from
write double that number x to get a new
Yes
Beneath the right number Is x > y ? value of x
write the integer part of half
No
that number
Step 3 Repeat step 2 until the right
number is 1 Yes Subtract x from
Is x < y ? y to get a new
Step 4 Delete those rows where the value of y
No
number in the right column
is even
Step 5 Add up the remaining No
Does x = y ?
numbers in the left column.
This is the result of multiplying Yes
the original numbers Output x
Figure 1.3

Work through the Russian algorithm with left number 13 and right number 37.
Work through the Euclidean algorithm with x = 6 and y = 15.
How could you represent these algorithms differently?
What different type of user might each representation be suitable for?

9781510403130.indb 4 20/03/18 7:48 AM


Proving that an algorithm does achieve what it is supposed to do is often quite tricky.
Note
Proving an algorithm
For example even if you believe that Zeller’s algorithm does what it is supposed to do,
it is quite a task to ‘unpick’ it and show that it does the right thing.You can probably 1
means showing that see that step 2 of Zeller’s algorithm deals with leap years by making the year run from
the correct output is the beginning of March (M = 3) to the end of February (M = 14), and that the
always achieved for any algorithm is about counting days from some starting point and then dealing with

Chapter 1 Algorithms
permitted input.
things like leap years.What may be less obvious is the calculation of INT(2.6M − 5.4).
If there are only a small
number of possible
inputs, or if they can Discussion point
be put into sets that all If you work out what this does for each month (from M = 3 to M = 14) you might start
behave similarly (such as to understand how Zeller’s algorithm works.
odd numbers and even
numbers) then it may
be possible to prove an
algorithm using proof by You need to be able to trace through an algorithm to find out what output it gives
exhaustion.
for certain inputs. Sometimes an algorithm is not ‘fit for task’ which means that it
does not always do what it is supposed to do. If you can find an input for which
the algorithm does not work then this immediately gives a counter-example and
disproves the algorithm. Sometimes a faulty algorithm can be repaired.
For example:
l you might need to build in a restriction on the inputs so that they cannot be 0,
or must be positive, or must be integers
l you might need to correct an error such as choosing the wrong variable, an
arithmetic slip or a ‘go to’ that loops back to the wrong step
l you might need to add a condition to deal with special cases.

In Example 1.1 the values of the inputs a, b and c should be real numbers. The
algorithm will not work when a has the value 0 so it has been disproved, unless the
value of a is restricted to be non-zero.
In Chapter 3 you will learn that algorithms can also be developed and adapted to
deal with variations on a standard problem.

Exercise 1.1

① Construct a flowchart that can be used to check


if a number N is prime, where N is a positive
Apply the algorithm with X = 62.
(i)
integer and N > 2.
(ii) Show that for all values of X between 1 and
② The following six steps define an algorithm:
99 the algorithm produces the same answer.
Step 1 Think of a positive whole number You may use the fact that, when written out,
and call it X numbers between 1 and 99 all have twelve or
Step 2 Write X in words (using letters) fewer letters.
Step 3 Let Y be the number of letters used [MEI]
Step 4 If Y = X then stop ③ The following algorithm is to be applied to the
Step 5 Replace X by Y positive integers from 2 to 99:
Step 6 Go to step 2 Step 1 Put a circle around 2 and then cross
out all remaining multiples of 2

9781510403130.indb 5 20/03/18 7:48 AM


Algorithmic complexity

Step 2 Put a circle around the next uncrossed To illustrate how this works, take the Roman
number and then cross out all numeral CIX as an example.
remaining multiples of that number. Always start by looking at row 1. Look at the row
Step 3 Repeat step 2 until all are either 1 entry in the column headed C (the first symbol
circled or crossed out. in the Roman numeral) to find 100 9. Add 100
(i) Draw a ten-by-ten grid. Shade out the first to the running total (which was 0 originally) and
two squares and let the remaining squares move to row 9.
represent the integers from 2 to 99. Now look at row 9 in the column headed I
(ii) Say what the algorithm finds. (the second symbol in the Roman numeral) to
[MEI] find 1 11. Add 1 to the running total and move
④ Table 1.1 can be used to convert a number from to row 11.
Roman numerals into ordinary base 10 numbers. Finally look at row 11 in the column headed
X (the third symbol in the Roman numeral) to
Row M D C L X V I
find 8 0. Add 8 to the running total. Since this
1 1000 2 500 3 100 9 50 5 10 10 5 7 1 11
was the last symbol in the Roman numeral the
2 1000 2 500 3 100 9 50 5 10 10 5 7 1 11 algorithm now stops.
3 100 9 50 5 10 10 5 7 1 11 CIX = 100 + 1 + 8 = 109
4 100 4 50 5 10 10 5 7 1 11 (i) Write this algorithm as a set of steps.
5 50 6 10 10 5 7 1 11 (ii) What are the limitations of the algorithm?
6 10 6 5 7 1 11 (iii) Write pseudocode instructions for
7 5 8 1 11 converting ordinary base 10 numbers into
8 1 8 Roman numerals.
 [MEI adapted]
9 800 5 300 5 100 4 50 6 10 10 5 8 1 11
10 80 7 30 7 10 6 5 8 1 11
11 8 0 3 0 1 8
Table 1.1

2 Algorithmic complexity
Most problems can be solved using a variety of algorithms, some of which might
be more efficient than others. By ‘efficient’ we usually mean using fewer operations
(which in turn means running more quickly and so taking less time). There might
be other considerations too, such as the amount of storage capacity needed if the
algorithm is to be run on a computer.
As a simple example of improving efficiency, look back to Example 1.1, where you
saw an algorithm to find the real roots of a quadratic equation. It is a good idea to
calculate the value of b2 − 4ac as a first step, because the sign of that value has to be
checked to see whether it is worth continuing with the calculation.
If an algorithm requires the evaluation of a quadratic expression, the way in which
the expression is written can make a difference to the efficiency.
For example, 3x2 + 2x + 9 can be written as (3x + 2)x + 9. This bracketed form is
called a nested form.

9781510403130.indb 6 20/03/18 7:48 AM


When x = 5, the evaluation with a calculator requires the following key presses:

3x2 + 2x + 9: 3 multiplications 1
and 2 additions

(3x + 2)x + 9: 2 multiplications

Chapter 1 Algorithms
and 2 additions
The nested form uses fewer operations (multiplications and additions) so it should
be quicker (albeit by the tiniest amount of time).
Comparing the number of operations for a general polynomial of degree n gives:

an x n + an − 1x n − 1 + … + a2 x 2 + a1x + a0  1
n (n + 1) × and n +
2

(((…((a x + a
n n −1 ) x + an − 2 ) x + an − 3 ) x + …) + a1 ) x + a0  n × and n +

The nested method has linear order complexity (or order n or O(n)) because
the time taken to run the calculation involves n1 as the highest power of n.The
expanded form has quadratic order complexity (or order n2 or O(n2)) because
the time taken to run the calculation will involve n2 as the highest power of n.

Note
If any of the coefficients happened to be 0 then some work would be saved. It
is usual to focus on the worst case situation (rather than the best case or an
average case). This is partly because then any predictions about run-times
will be ‘worst case scenarios’ but mainly because the worst case is usually the
easiest to consider.

The nested method is more efficient than the expanded form because O(n) is
a lower order complexity than O(n2). Irrespective of what the actual linear and
quadratic functions are that represent the run-time for the two methods for a
polynomial of degree n, a linear function will give lower values (smaller run-times)
than a quadratic function for realistic sized (huge) problems.
For example, if it takes M microseconds for a computer to multiply two numbers
and A microseconds for it to add two numbers then (once the programs have been
written) inputting the coefficients is the same for both methods and the run-time is
1
n(n+1)M + nA for the expanded form and nM + nA for the nested form.
2
Now, in this case, 1 n(n+1)M + nA is always bigger than nM + nA, but the details,
2
1
such as the and the (n+1) are irrelevant, if n is huge all that matters is that n2 is
2
much bigger than n.
O(n2) is always less efficient than O(n) once n becomes large. Similarly O(n3) is less
efficient than O(n2) and so on.

9781510403130.indb 7 20/03/18 7:48 AM


Algorithmic complexity

● If an algorithm has O(n) complexity then doubling the size of the problem will
roughly double the run-time, or tripling the size of the problem will roughly
triple the run-time. If the actual run-time is an + b then scaling the problem
size by a factor of k gives a run-time of akn + b. For large values of n, the run-
time akn (+ b) is roughly k times the original run-time an (+ b).
● If an algorithm has O(n2) complexity then doubling the size of the problem will
Note roughly quadruple the run-time, or tripling the size of the problem will scale
the run-time by a factor of about 9. If the actual run-time is an2 + bn + c then
Often a table is a useful scaling the problem size by a factor of k gives a run-time of ak2n2 + bkn + c. For
way to record the results,
with a column for each
large values of n, the run-time ak2n2 (+ bkn + c) is roughly k2 times the run-time
variable and using a an2 (+ bn + c).
new line each time any ● Similarly, ifan algorithm has O(nr) complexity, then scaling the problem size by
variable changes.
a factor k will scale the run-time by a factor of (approximately) kr.

Exercise 1.2

① The following flowchart defines an algorithm Work through the algorithm with x = 3,
(iii)
which operates on two inputs, x and y. y1 = 4 and y2 = 1. Keep a record of the
Input x and y
values of r, q1 and q2 each time they are
updated.
Let r = y and q = 0
The two algorithms achieve the same result.
(iv) Suggest the advantages and disadvantages of
each algorithm.
No Let r = r − x
Is r < x? [MEI]
Let q = q + 1
② Programmable calculators use a version of the
Yes
Basic programming language that, amongst other
Print q and r things, can perform repetitions using ‘for … next’.
To show how this works look at the following
Figure 1.4
programs and their printouts.
(i) Run the algorithm with inputs of x = 3
and y = 41. Keep a record of the values of r
and q each time they are updated.
(ii) Say what the algorithm achieves.

The following flowchart defines an algorithm


with three inputs, x, y1 and y2.

Input y1 and y2
Let r = 10r − y2
Let r = y1 and q1 = 0 Let q2 = 0

No Let r = r − x
Is r < x? No Let r = r − x
Let q1 = q1 + 1 Is r < x?
Let q2 = q2 + 1
Yes Yes
Print q1, q2 and r

Figure 1.5

9781510403130.indb 8 20/03/18 7:48 AM


FOR M = 1 TO 3 1 B

PRINT M 2
T = 0: S = 0 1
FOR J = 0 TO 9
NEXT M 3
FOR K = 0 TO 9

Chapter 1 Algorithms
FOR L = 0 TO 9
FOR M = 1 TO 3 1 1
FOR M = 0 TO 9
FOR N = 1 TO M 2 1
IF S = 21 THEN T = T + 1
PRINT M, N 2 2
S=S+1
NEXT N 3 1
NEXT M
NEXT M 3 2 S=S−9
3 3 NEXT L
In a certain town the bus tickets are numbered S=S−9
0000 to 9999. NEXT K
Some children are collecting the tickets whose S=S−9
digits add up to 21.
NEXT J
(i) How many such tickets will there be in the
tickets numbered from 0000 to 9999? PRINT T
Two algorithms for finding the number of tickets ③ The following algorithm finds the highest
whose digits add up to 21 are given as calculator common factor (HCF) of two positive integers.
programs below (A and B).You do NOT need to
1 Let A be the first integer and B be the
put these programs into your calculator to answer
second integer
this question.
2 Let Q = INT(B ÷ A)
(ii) Show that each algorithm achieves the
correct result. 3 Let R = B − (Q×A)
(iii) Compare the efficiency of the two
4 If R = 0 go to step 8
algorithms by counting the number of 5 Let the new value of B be A
additions/subtractions and the number of 6 Let the new value of A be R
comparisons used. 7 Go to step 2
8 Record the HCF as the value of A
A
9 STOP
T=0
(i) Work through the algorithm with A = 2520
FOR J = 0 TO 9 and B = 5940.
FOR K = 0 TO 9 (ii) What happens if the order of the input is

FOR L = 0 TO 9 reversed, so A = 5940 and B = 2520?


It has been claimed that the number of iterations
FOR M = 0 TO 9
of this algorithm is
S=J+K+L+M log(M ÷ 1.17)
approximately , where M is the
IF S = 21 THEN T = T + 1  1+ 5 
log 
NEXT M  2 
NEXT L larger of A and B.
(iii) Count the number of iterations of the loop
NEXT K
in the algorithm when A = 233 and B = 377.
NEXT J Compare this with the number claimed by
PRINT T the formula above.

9781510403130.indb 9 20/03/18 7:48 AM


Packing

3 Packing
One of the situations where an algorithmic approach is useful is for
one-dimensional bin-packing problems. Imagine having to send a number of
files as attachments to the same email address, but there is a limit on the total size
of the files attached to one email. How should the files be put together so that
the number of emails needed is as small as possible?
The classic bin-packing problem packs ‘boxes’ of given sizes into a number of
(equal sized) ‘bins’ of a fixed size.
Here are three methods that could be used:
1 First-fit algorithm
Take the boxes in the order listed and pack each box in the first bin that has
enough space for it (starting each time with the first bin).
2 First-fit decreasing algorithm
Reorder the boxes from the largest to the smallest, then apply the first-fit
method to this list.
3 Full-bin strategy
Look for combinations of boxes that will fill bins. Pack these boxes. Put the
rest together in combinations that result in bins that are as nearly full as
possible.

Example 1.2 The boxes A to K with masses in kilograms as shown in Table 1.2 are to be
packed into bins that can each hold a maximum of 15 kg. Apply each of the three
bin packing methods to this problem.
A B C D E F G H I J K
8 7 4 9 6 9 5 5 6 7 3
Table 1.2

Solution
A and B are put into bin 1,
First-fit: Bin 1 A(8) B(7) which is then full.

C and D are put into bin 2 but


Bin 2 C(4) D(9) there is not enough room for E.
Bin 2 has 2 kg of spare capacity.

The first bin with enough


Bin 3 E(6) F(9) capacity for E is bin 3.

Continue in this way.


Bin 4 G(5) H(5) K(3)
When K is reached, the
first bin with enough
Bin 5 I(6) J(7) capacity is bin 4.

10

9781510403130.indb 10 20/03/18 7:48 AM


First-fit decreasing:
First order the list D(9) F(9) A(8) B(7) J(7) E(6) I(6) G(5) H(5) C(4) K(3) 1
D is put into bin 1 leaving Bin 1 D(9) E(6)
6 kg spare in bin 1.

Chapter 1 Algorithms
Bin 2 F(9) I(6)
F is put into bin 2 leaving
6 kg spare in bin 2.
The first bin with enough
Bin 3 A(8) B(7) capacity for B is bin 3.
A is put into bin 3 leaving
7 kg spare. When K is reached, the
Bin 4 J(7) G(5) K(3) first bin with enough
Continue in this way. capacity is bin 4.

Bin 5 H(5) C(4)


Full-bin strategy:
For example
Bin 1 A(8) B(7) This is just one way to
make full bins (for bins
Bin 2 C(4) E(6) G(5) 1 to 4).
Discussion points
What does optimal mean Bin 3 D(9) I(6)
in this sense?
Why might some other Bin 4 J(7) H(5) K(3)
criterion be more
appropriate? Bin 5 F(9)
What are the problems
with using a complete The full-bin strategy is not an algorithm because there is no set way to make the
enumeration? full bins. It is probably evident that using the items with the largest weights to make
full bins is usually better than filling a bin with lots of smaller weight items.
The only known algorithm that will always find the optimal packing is to use a
complete enumeration (that is, try every possibility).
An algorithm that will usually find a good solution, although not necessarily an
optimal (best) solution to a problem is called a heuristic (or a heuristic algorithm).
A heuristic is a method that finds a solution efficiently, but with no guarantee
that the solution is optimal. This raises another issue in the consideration of what
constitutes an efficient algorithm. If you cannot guarantee getting the best solution
would you want the algorithm that got to its solution with the least expense (in
terms of time or money) or the one that consistently gave better solutions than the
others? The consistency with which an algorithm gives a good solution is therefore
another factor in its efficiency. Heuristics are important when classic methods fail,
for example when the only way to guarantee finding the optimal solution is a
complete enumeration.
The efficiency of different packing strategies could be compared by counting the
number of comparisons needed in the worst case for a list of n items.
In the worst possible case, both first-fit and first-fit decreasing algorithms
use 1 + 2 + … + (n – 1) = 21 (n – 1)n comparisons. Using this measure of complexity,
both first-fit and first-fit decreasing are quadratic order algorithms, O(n2).

11

9781510403130.indb 11 20/03/18 7:48 AM


Sorting

Exercise 1.3
① Sam wants to download the following videos onto four 16GB USB sticks.
Can this be done?
Program A B C D E F G H I
Size (GB) 4 3.2 2.4 2.6 4.4 1 2 2.4 3.6
Program J K L M N O P Q R
Size (GB) 5.6 3 4.8 3 4 2.8 8 4.8 1.6
Table 1.3
② A small car ferry has a number of lanes, each 20 m long. The following vehicles
are waiting to be loaded.
Petrol tanker 14 m Car 4 m Range rover 5m Car 4m
Car 3m Van 4 m Car and trailer 8 m Car 3m
Coach 12 m Lorry 11 m Car 4m Lorry 10 m

Table 1.4
How many lanes are needed to fit all the vehicles on the ferry at the same
time?
③ A plumber is using pipes that are 6 m long and needs to cut the following
lengths.

Length (m) 0.5 1 1.5 2 2.5 3 3.5


Number 0 2 4 3 0 1 2

Table 1.5
Use the first-fit decreasing algorithm to find a way to cut the lengths.
④ Six items with the masses given in Table 1.6 are packed into bags, each of
Discussion point which has a capacity of 10 kg.
How would you sort Item A B C D E F
a shuffled pack of
Weight (kg) 2 1 6 3 3 5
standard playing cards
into suits, in the order Table 1.6
clubs, diamonds, hearts,
spades, and within each (i) Use the first-fit algorithm to pack these items into bags, saying how
suit from ace to king? many bags are needed.
(ii) Give an optimal solution.
[MEI]

4 Sorting
The first step in the first-fit decreasing algorithm, considered above, involves
sorting the list of weights into decreasing order (largest to smallest). Sorting is used
to put a list of names into alphabetical order or to rank a list of universities on their
‘student satisfaction’ scores. Usually such tasks are done using a computer, but how
does a computer sort a list?
Sorting is an everyday activity in which the efficiency of the algorithm used is
important. There are many popular sorting algorithms for sorting a list of numbers
into ascending or descending order.
The sorting algorithm that will be used here is the quick sort algorithm.

12

9781510403130.indb 12 20/03/18 7:48 AM


At this stage the pivot Quick sort
is guaranteed to be in
its correct position in
To sort a list of numbers into ascending (increasing) order: 1
the final list and can 1 The first value in the list is the pivot.
be marked in some
Excluding the pivot, pass along the list and write down each value that is less
way to indicate this.
than or equal to the pivot value, then write the pivot value and then write

Chapter 1 Algorithms
The pivot splits the
list into two sublists: down the values that are greater than the pivot.
one containing the This concludes the first pass.
values that are less 2 Repeat step 1 on each sublist. If a sublist contains just one value this becomes
than or equal to the
pivot (excluding the
a pivot and is marked as being in its correct position in the final list. This
pivot itself) and the concludes the next pass.
other containing 3 Continue in this way until every value is marked as being in its correct
the values that are position in the final list.
greater than the pivot.
It is possible that one
of these sublists may
be empty.

Example 1.3 Use quick sort to sort this list into ascending order
7 5 2 4 10 1 6 3

Solution
Original list 7 5 2 4 10 1 6 3
Active pivots are
boxed and used pivots After 1st pass: 5 2 4 1 6 3 7 10
are underlined.
After 2nd pass: 2 4 1 3 5 6 7 10
After 3rd pass: 1 2 4 3 5 6 7 10
Discussion point After 4th pass: 1 2 3 4 5 6 7 10
 ow would you adapt
H
quick sort so that the After 5th pass: 1 2 3 4 5 6 7 10
pivot is still the first
value in the list (or Sorted list: 1 2 3 4 5 6 7 10
sublist) but the sort
is into descending
(decreasing) order? For a small example like this, writing down the sorted list is easy. The example is
used to illustrate how quick sort works when it is applied to a much longer list.
Other sorting algorithms can be used, such as bubble sort or shuttle sort. For
example, you may be asked to count the number of comparisons (or comparisons
and swaps) to compare the efficiency of two algorithms being used to sort a
Note particular list.
Sometimes the list to The worst case for quick sort, in terms of comparisons, is when the pivot at each
be sorted is written pass is the smallest or largest value in the sublist (so one of the new sublists is
vertically, then the two empty). This would be the case when the original list is already sorted (or sorted
sublists will be above
but in reverse). In the worst case, quick sort has quadratic complexity, O(n2).
and below the pivot
instead of to the left and
to the right of the pivot.

13

9781510403130.indb 13 20/03/18 7:48 AM


Sorting

Exercise 1.4
① Use quick sort to sort this list of numbers Second pass: In the revised list, compare the
into decreasing order. Record the number of second and third numbers and
comparisons made in each pass. swap if necessary.
6 8 3 2 4 7 7 If a swap was necessary then
② The instructions below describe the steps of a compare the first number with the
bubble sort algorithm applied to a list of K numbers. new second number and swap if
necessary.
Step 1 Let M = 1
Write down the remaining
Step 2 Let N = 1
numbers with their order
Step 3 If the Nth number in the list is greater unchanged.
than the (N + 1)th, then
Third pass: In the revised list, compare the
swap them
third and fourth numbers and swap
Step 4 Let N = N + 1 if necessary.
Step 5 If N < K + 1 – M go to step 3  If a swap was necessary then
Step 6 Let M = M + 1 compare the second number with
Step 7 If M < K go to step 2 the new third number and swap if
Step 8 Display list necessary.
(i) Apply the bubble sort algorithm to the list If both swaps were necessary then
of numbers compare the first number with the
new second number and swap if
7 9 5 1 11 3
necessary.
Record the list each time that step 2 is used.
Write down the remaining
Count the number of comparisons and the
numbers with their order
number of swaps in each of these passes
unchanged.
(from one use of step 2 to the next).
And so on until no further passes are possible.
The list is now split into two sublists:
(i) Use shuttle sort to sort the following list.
7 9 5 and 1 11 3
13 56 2 40 10 50 35
Bubble sort is applied to each sublist, which are
then merged back together. Write down the list at the end of each pass
and record the number of comparisons that
(ii) How many comparisons and how many
have been made in each pass.
swaps does each of these applications of
(ii) Explain why, in the worst case, shuttle sort
bubble sort use?
has quadratic complexity.
(iii) Describe how to merge the sorted sublists.
(iii) Sort the list
How many comparisons does the merge
involve? 13 56 2 40 10 50 35
 [MEI adapted] into ascending order using quick sort.
③ Shuttle sort is described below. Record the number of comparisons that are
First pass: Compare the first two numbers made.
and swap if necessary so that the (iv) Compare the efficiency of shuttle sort and
smaller is written first. quick sort for sorting this particular list into
Write down the remaining ascending order.
numbers with their order [MEI adapted]
unchanged.

14

9781510403130.indb 14 20/03/18 7:48 AM


LEARNING OUTCOMES 1
Now you have finished this chapter you should
➤ understand what an algorithm is and understand the meanings of the terms
‘finite’, ‘initial state’, ‘input’, ‘output’ and ‘variable’ in the context of algorithms

Chapter 1 Algorithms
➤ be able to interpret and apply algorithms presented in a variety of formats,
including written English, flowcharts and pseudocode
➤ understand and use loops (‘go to step …’), passes, decisions (‘if … then …’) and
the idea of an iterative process
➤ be able to repair, develop and adapt given algorithms

➤ understand the idea of algorithmic complexity as a way to compare different


algorithms
➤ understand that algorithms can sometimes be proved correct or incorrect

➤ know what a heuristic is

➤ be able to sort a list of values using quick sort or other sorting algorithms which
are specified
➤ be able to use and compare first-fit and first-fit decreasing bin packing
algorithms and full-bin strategy.

KEY POINTS
1 An algorithm is a finite sequence of operations for carrying out a procedure or
solving a problem.
2 An algorithm may be communicated in ordinary language, in a flowchart or in
pseudocode.
3 For large n, an algorithm with O(na) complexity is more efficient than an
algorithm with O(nb) complexity when a < b.
4 If an algorithm has O(nr) complexity then scaling the problem size by a factor k
will scale the run-time by a factor of (approximately) kr.
5 First-fit algorithm
Take the boxes in order listed and pack each box in the first bin that has enough
space for it (each time starting with the first bin).
First-fit decreasing algorithm
Reorder the boxes from the largest to the smallest, then apply the first-fit
method to this list.
Full-bin strategy
Look for combinations of boxes to fill bins. Pack these boxes. Put the remaining
boxes together in combinations that result in bins that are as nearly full as
possible.
6 A heuristic is a method that finds a solution efficiently, but with no guarantee
that the solution is optimal. Heuristics are important when classic methods fail,
for example when the only way to guarantee finding the optimal solution is a
complete enumeration.
7 The efficiency of different packing strategies could be compared by counting
the number of comparisons needed in the worst case for a list of n items. In the
worst case, first-fit and first-fit decreasing both have quadratic complexity, O(n2).

15

9781510403130.indb 15 20/03/18 7:48 AM


Sorting

8 Quick sort can be used to sort a list of numbers into ascending (increasing)
order:
The first value in the list is the pivot. Excluding the pivot, pass along the list and
write down each value that is less than or equal to the pivot value, then write the
pivot value and then write down the values that are greater than the pivot. The
pivot splits the list into two sublist.
Repeat the process on each sublist and continue in this way until every value has
been a pivot.
9 In the worst case, quick sort has quadratic complexity, O(n2).

16

9781510403130.indb 16 20/03/18 7:48 AM


Modelling with graphs and
2 networks

A picture is worth a Isaac Newton’s tree planting puzzle


thousand words. How can you plant nine trees so that there are ten different straight lines each
connecting three trees?
(1918 newspaper
advertisement)

1 The language of graphs and


networks
The utilities problem (or gas-water-electricity problem) is a version of an ancient
problem. Three houses (1, 2 and 3) need to be connected to the supplies of each of
three utilities (G, W and E). The problem is to f  ind a way to do this without having
any of the connecting pipes or cables crossing others.

G W E

1 2 3

Figure 2.1
The problem can be modelled by representing the houses and the utilities as points
and the connections between them as straight or curved lines. The points are called
nodes or vertices and the lines are called arcs or edges.

Figure 2.2

17

9781510403130.indb 17 20/03/18 7:48 AM


The language of graphs and networks

A collection of nodes (or vertices) connected by arcs (or edges) is known as a


graph. Graphs are used to show relationships between objects. Note that this is a
much more general use of the word graph than the Cartesian graphs that you met
at GCSE.
The graph connecting each of the houses to each of the utilities is a special graph
called a complete bipartite graph. The meanings of these terms will make more
sense when you have studied this chapter. The utilities problem is impossible in
2-dimensional space, no matter how sneakily you distort the arcs.

Note
The graph in this problem is a non-planar graph, which means that the arcs
cannot be drawn without crossings. The mathematician Kazimierz Kuratowski
studied planarity and showed there must always be at least two arcs that cross
over each other. Planarity might be important if there is a risk of contamination
between arcs when they cross (for example in a circuit board). Planarity is not
covered in this book.

Definitions
l A graph is a set of nodes (or vertices) together with a set of arcs (or edges).
An edge has a vertex at each end.

Figure 2.3

l An edge with the same vertex at both ends is called a loop.

Figure 2.4

l The order (sometimes called the degree) of a vertex is the number of edges
incident on it (the number of ends of edges at the vertex) (if you ‘zoom in’ and
ignore the rest of the graph).
Figure 2.5 shows a vertex of order 5.

Notice that the loop contributes


two ends towards the order of
the vertex.

Figure 2.5

Example 2.1 (i) Draw four vertices on a piece of paper and join them using five edges. Record
the order of each vertex of your graph and compare with other people.
(ii) What is the sum of the vertex orders (the total vertex order)?
(iii) What is the minimum possible vertex order and what is the maximum
possible vertex order?

18

9781510403130.indb 18 20/03/18 7:48 AM


(iv) What is the greatest possible number of vertices of order 1?
(v) What is the greatest possible number of vertices of order 4? 2
For any graph, there must always be an even number of vertices with an odd
vertex order.

Chapter 2 Modelling with graphs and networks


(vi) Verify that this is true for your graph.
(vii) Explain why there cannot be an odd number of vertices with an odd
vertex order.

Solution
(i) There are many possible graphs with four vertices and five edges.
Three examples are shown in Figure 2.6.
The vertex orders
of these graphs are (3) (2) (2) (4)
shown in brackets. (2) (2)

(3) (3)

(2) (3) (1) (3)


Figure 2.6
(ii) The sum of the vertex orders is always 10. The reason for this is
that each edge has two
(iii) The minimum possible vertex order is 0. This ends so it contributes 2 to
would be a vertex on its own not connected the total; the sum of the
to anything, not even connected to itself. vertex orders is twice the
number of edges.
The maximum possible vertex order is 10.
This would be a vertex with 5 loops (the
other three vertices have vertex order 0).
(iv) The greatest possible number of vertices of order 1 is 3. (Figure 2.7 shows
two ways of drawing such a graph.) If all four vertices had order 1, the sum
of the vertex orders cannot be 10.

Figure 2.7
(v) The greatest possible number of vertices of order 4 is 2. The total vertex
order is 10, so there cannot be more than 2 vertices of order 4. There are
various ways to draw such a graph, for example:

Figure 2.8

19

9781510403130.indb 19 20/03/18 7:48 AM


The language of graphs and networks

(vi) Each of the graphs in Figure 2.6 has two vertices with odd orders (1 or 3)
and two with even orders (0, 2 or 4). There could be no odd order vertices
or four odd order vertices but there cannot be one odd and three even or
three odd and one even.
(vii) The sum of the vertex orders is twice the number of edges, so the sum is
even. The sum of the vertex orders for any number of even order vertices
will be even. An odd number of vertices of odd order would make an odd
total, so there cannot be an odd number of vertices of odd order.

You may have thought that some of the graphs above were a bit ‘unfair’ because
one or more of the following occurred:
l a vertex of order 0 (or more than one such vertex)
l the four vertices are not all connected together as a single graph (the graph was
really two or more disconnected subgraphs)
l a loop (or more than one loop)
l ‘repeated’ edges where two vertices were connected by more than one edge.

The following definitions are useful for avoiding problems with these issues.
l A connected graph is one in which every vertex is joined, directly or indirectly,
to each of the other vertices.
l A simple graph is a graph with no loops and no ‘repeated’ edges.

l A simply connected graph is a graph that is both simple and connected.

Example 2.2 A simply connected graph is drawn with exactly five nodes.
(i) What is the minimum possible number of arcs?
(ii) What is the maximum possible number of arcs?

Solution
(i) The minimum is four arcs; any fewer than this and the graph is not
connected.
Figure 2.9 shows one example.

The minimum number of


arcs in a simply connected
graph with n nodes is n − 1.

Figure 2.9
(ii) The maximum is ten arcs; any more than this and the graph is not simple.
This is shown in Figure 2.10.

The maximum number of


arcs in a simply connected
graph with n nodes is
1 (n − 1)n.
2

Figure 2.10

20

9781510403130.indb 20 20/03/18 7:48 AM


The extreme cases of simply connected graphs have special names.
l A simply connected graph with the minimum possible number of arcs is called
a tree.
2
l A simply connected graph with the maximum possible number of arcs is called
a complete graph.

Chapter 2 Modelling with graphs and networks


The complete graph with n vertices is denoted Kn; the graph in Figure 2.10 is K5.
Sometimes the vertices naturally split into two sets with the edges joining a vertex
from one set to a vertex in the other, and no edges joining two vertices from the
same set. This happened with the utilities problem at the start of the chapter.
l A bipartite graph is one where the vertices partition into two sets and edges
cannot join vertices that are in the same set.
A simply connected bipartite graph with the maximum possible number of arcs is
called a complete bipartite graph.

This complete bipartite


graph has 3 × 2 = 6 arcs.

Figure 2.11
The arcs in a graph are usually undirected, but it may sometimes be appropriate to
use directed arcs. A directed arc is like a one-way street.
l A digraph is a graph with directed arcs.

Incidence matrices
Having to draw a graph is not always the easiest way to communicate its structure,
for example when a computer program needs to have a graph as its input. An
alternative way to describe a graph is by giving its incidence matrix.
An incidence matrix shows the number of edges between each pair of vertices.
The vertices need to have labels so that they can be identified.
The incidence matrix for an undirected graph will be symmetric about its lead
diagonal (the diagonal from top left to bottom right).

Example 2.3 (i) Draw the graph described by this incidence matrix.
A B C D
A  0 1 0 3 
 
B  1 2 0 2 
C  0 0 0 1 
D  3 2 1 0 

(ii) Write down the incidence matrix for the graph in Figure 2.12.
U W Y

V X Z
Figure 2.12 ➜

21

9781510403130.indb 21 20/03/18 7:48 AM


The language of graphs and networks

Solution
(i) Figure 2.13 shows one way of drawing the graph. Depending on how
you draw the graph, it may look different to this but the differences will
be superficial because there is only one way of connecting the vertices as
described by the incidence matrix.

A B Note the 2 connecting B to


itself in the incidence matrix;
this represents the two ends
of a loop.

C D

Figure 2.13

(ii) U V W X Y Z

U  0 1 0 1 0 0 
 
V  1 0 1 0 0 0 
W  0 1 0 1 0 1 
X  1 0 1 0 0 1 
 
Y  0 0 0 0 0 1 
Z  0 0 1 1 1 0 

Isomorphic graphs
Discussion point
What is the same about
these two graphs? What
is different about them?
Graph 1 Graph 2
Figure 2.14
Sometimes two graphs have the same structure, apart perhaps from being labelled
differently, although they may or may not look alike.
Two graphs are said to be isomorphic if they have the same structure, in the sense
that, ignoring any labelling, one can be stretched, twisted or otherwise distorted
into the other, without adding, removing or cutting any arcs. The two graphs in
Figure 2.14 are isomorphic. It is possible to label the vertices of two isomorphic
graphs so that they have the same incidence matrix.

ACTIVITY 2.1
Draw some trees with four vertices. How many possible non-isomorphic trees
with four vertices are there?

22

9781510403130.indb 22 20/03/18 7:48 AM


Exercise 2.1

① Draw three different (non-isomorphic) trees each ④ Figure 2.15 shows a printed circuit board with
2
with fives vertices and four edges. two points for external connections and three
② Table 2.1 below shows the number of vertices of internal points. Each of the connection points is

Chapter 2 Modelling with graphs and networks


orders 1, 2 and 3 in three graphs. to be wired to each of the internal points.

Order of vertex 1 2 3
Graph A 3 0 1
Graph B 2 2 0
Graph C 1 1 1
Key: internal point
Table 2.1
Write down the number of vertices and the
(i) connection point

number of edges in each of these graphs. Figure 2.15


(iI) Explain how you can find the number of (i) Show that the two connection points can
vertices and the number of edges without each be wired to each of the three internal
drawing the graphs. points without any wires crossing.
(iii) Draw an example of each graph. (ii) Show that two connection points can each
③ This is the incidence matrix for a graph. Draw be wired to each of four internal points
the graph it represents. without any wires crossing.
A B C (iii) Give the smallest number of connection
points and internal points for which at least
A  0 1 2 
one crossing will be required.
B  1 2 1 
  [MEI]
C  2 1 0 

2 Modelling with graphs


The utilities problem used a graph to model the connections between the six
locations. Many problems can be modelled using graphs.
The following is a medieval puzzle.
A showman needs to carry across a river his wolf, his goat and a sack of cabbages.
If the goat and the sack of cabbages are left together without the showman, the
goat would eat the cabbages. If the wolf and the goat are left together without the
showman, the wolf would eat the goat! There is a boat available, but it is small and
can only accommodate the showman (S) (who must row the boat) and one of the
other three items (W, G, C). The problem is to find a way to get all three items to
the other side of the river.
The problem can be modelled using a graph in which the vertices have labels such
as SWGC|– or WC|SG. The vertex labels show which of S, W, G, C are together
on the two sides of the river between each crossing. The boat is always with the
showman. A dash just means that S, W, G, C are all on the other side of the river.

23

9781510403130.indb 23 20/03/18 7:48 AM


Modelling with graphs

Each of the four symbols can appear on either side of the river, so there are 24 = 16
possible vertices; however six of these can be deleted because they involve GC without
S or WG without S.This leaves ten possible vertices, numbered 1 to 10 below:
1 SWGC|– 2 SWG|C 3 SWC|G 4 SGC|W 5 SG|WC
6 –|SWGC 7 C|SWG 8 G|SWC 9 W|SGC 10 WC|SG

Example 2.4 (i) Draw a graph showing the ten vertices, 1 to 10, and edges to represent
crossings that are possible.
(ii) Explain why this is a bipartite graph.
(iii) Describe how the graph can be used to find a way for the showman to get
the wolf, goat and sack of cabbages across the river.

Solution
1 2 3 4 5
(i)

6 7 8 9 10

Figure 2.16

(ii) Vertices 1 to 5 have the showman (and the boat) on the first side of the
river and vertices 6 to 10 have the showman (and the boat) on the other
side. Edges represent river crossings so must join one of {1, 2, 3, 4, 5} to
one of {6, 7, 8, 9, 10}.
(iii) You need to find a continuous path from 1 to 6.

The path needed to solve the problem in Example 2.4 is called an alternating path,
because it alternates between the two sets that make up the bipartite graph.
The possible journeys can be represented more usefully by rearranging the vertices.
1 10 2 8 5 6

3 9 4

Figure 2.17
The most efficient alternating paths are:
1 – 10 – 3 – 7 – 4 – 8 – 5 – 6 and 1 – 10 – 3 – 9 – 2 – 8 – 5 – 6

24

9781510403130.indb 24 20/03/18 7:48 AM


These represent the showman travelling backwards and forwards taking the
following with him:
G, –, W, G, C, –, G or G, –, C, G, W, –, G
2
The second solution is just the first one done in reverse order. The goat has to be
with the showman most of the time to avoid it eating the cabbages or being eaten

Chapter 2 Modelling with graphs and networks


by the wolf.
Alternating paths on bipartite graphs are also useful for matching problems.
Matching problems involve bipartite graphs where the two sets are the same size
and each vertex from one set needs to be paired with a vertex from the other set, so
that each vertex is used exactly once.
The emphasis in this chapter is on the modelling and not on using algorithms to
solve problems.

Example 2.5 Four people (A, B, C, D) are travelling in a car.


The car has four seats (W, X,Y, Z). The people need
to be allocated to the seats, so that each person gets
a seat and no two people share a seat, subject to the FRONT OF CAR
following restrictions:
l A wants to sit in one of the front seats
l B wants to either drive or sit behind the driver Seat W Seat X
(driving
l C does not want to drive seat)
l D wants to sit in seat Z.
Seat Y Seat Z
(i) Draw a graph to show which people can sit
in which seats.
(ii) Find a way to seat the four people. Figure 2.18

Solution
(i) A W (ii) C = Y Y is only
B X
D=Z connected to C.
B=X
C Y
A =W D is only
D Z connected
With C = Y and D = to Z.
Figure 2.19 Z matched, B can
only be matched to X,
leaving A= W.

25

9781510403130.indb 25 20/03/18 7:48 AM


Modelling with graphs

Exercise 2.2
① A 90 kg man (M), a 50 kg woman (W) and a ② Six tasks, A, B, C, D, E and F, are to be carried
40 kg child (C), together with a 30 kg sack of out by six people, 1, 2, 3, 4, 5 and 6. Each task
potatoes (P), are at the top of a building. The requires a different combination of people to
three people need to get to the ground using a carry it out; these people all need to work on the
pair of large buckets joined by a cable that passes task at the same time.
over a pulley. Each bucket can hold at most one Table 2.2 shows the tasks for which each person is
person and the sack of potatoes. required.

Person 1 2 3 4 5 6
A C A D B B
Tasks C D E E E C
F F F F F F
Table 2.2

Each person can only work on one task at a time,


so this constrains which tasks can happen at the
same time.
(i) Draw a graph to represent this situation. The
Figure 2.20 vertices should be the six tasks and an edge
Initially one bucket is on the ground and the should be drawn between two tasks if they
other is at the top of the building. When the have a person in common (so they cannot be
upper bucket has a larger load than the lower done at the same time). For example, A and
bucket, the upper bucket will descend to the C should be joined because they both need
ground and the lower bucket will rise to the top person 1.
of the building. For safety, if any of the people (ii) Draw the complement of the graph from
are in either bucket there must be no more than part [i], i.e. with the same vertices but using
a 10 kg difference between the loads in the two the edges that were not used in part [i].
buckets. (iii) Use the complement graph to organise the
(i) Use a 16 vertex digraph to model the tasks in an efficient way.
situation, where the vertices are labelled to [MEI]
show which of M, W, C, P are at the top of ③ A puzzle has four cubes with their faces painted
the building (and hence which are on the blue (B), green (G), red (R) or yellow (Y).
ground) and the directed edges show safe
The aim is to stack the cubes on top of one
transitions from one vertex to the next. So
another to form a tower in such a way that each
the vertices are MWCP, MWC, MCP, MW,
of the four tall faces of the tower uses all four
etc. and an arrow from MWCP to MWC
colours.
represents the potatoes being sent down in
the bucket; the child can then descend in The cubes are painted as follows:
the second bucket while the potatoes travel Cube 1 B opposite G R opposite R Y opposite B
to the top again which is shown by an Cube 2 B opposite G G opposite R B opposite Y
arrow from MWC to MWP. Cube 3 R opposite B R opposite Y G opposite Y
(ii) Where is the sack of potatoes when the last
Cube 4 Y opposite R Y opposite G B opposite G
person reaches the ground?

26

9781510403130.indb 26 20/03/18 7:48 AM


Draw a graph with four vertices, one for
(i) (ii) Find a suitable set of three subgraphs and
each colour. Connect two vertices by an
edge labelled (1) if those colours are opposite
explain how these can be used to give a
solution to the problem. 2
on cube 1, by an edge labelled (2) if they  [OCR adapted]
are opposite on cube 2, and so on. This will
result in 12 edges, three for each cube.

Chapter 2 Modelling with graphs and networks


To solve the puzzle, the graph needs to be split
into three subgraphs, each with the vertices B, G,
R,Y and each containing four edges, one each of
(1), (2), (3) and (4), so that each vertex has order 2.
Each of the twelve edges will be in exactly one of
the three subgraphs.

3 Modelling with networks


Problems involving distances/costs/time, etc. can be modelled as networks. Again,
the emphasis in this chapter is on the modelling and not on using algorithms to
solve problems.
When modelling a problem it is sometimes necessary to assign values to the arcs.
These values are called weights and may represent distances, times, costs, etc. The
graph then becomes a network, which may be directed or undirected.
l A network is a weighted graph.
A network may be represented using a distance, time or cost matrix. This is like an
incidence matrix except that the numbers give the weights on the arcs.
A cable TV company wants to connect 11 places as economically as possible. Laying
cables costs £1000 per mile. The distances (in miles) between the places are shown
in Figure 2.21.
Minehead
38
Barnstaple
24
50

35 Taunton
Bude 31 40
30 35
Okehampton
20
41 23 Exeter

31 46 22
Bodmin
31
31
26 Torbay
52
Plymouth
Truro
37

Land’s End

Figure 2.21

27

9781510403130.indb 27 20/03/18 7:48 AM


Modelling with networks

If the map of the coastline is removed, the information is summarised as a network.


Alternatively a distance table could be used.
LE Tr Bo Pl Bu Ok Ba Ex To Mi Ta
LE - 37 - - - - - - - - -
Tr 37 - 26 52 - - - - - - -
Bo - 26 - 31 20 41 - - - - -
Pl - 52 31 - - 31 - 46 31 - -
Bu - - 30 - - 30 35 - - - -
Ok - - 41 31 30 - 31 23 - - -
Ba - - - - 35 31 - 40 - 38 50
Ex - - - 46 - 23 40 - 22 - 35
To - - - 31 - - - 22 - - -
Mi - - - - - - 38 - - - 24
Ta - - - - - - 50 35 - 24 -
Table 2.3

The ‘least weight tree’ The cable TV company needs to f ind the least weight tree that connects all 11
means ‘the tree with places. A tree that reaches all the vertices is called a spanning tree, so the company
the least total weight’. needs to find a minimum spanning tree which is also known as a minimum
connector.
Other problems that could be asked about the distances are:
l Find the shortest distance from Minehead to Land’s End. This is called a shortest
path.
A good route from Minehead to Land’s End is:
Mi – Ta – Ex – Pl – Tr – LE
This route has length 194 miles. The shortest path from Minehead to Land’s End
has length 156 miles.

ACTIVITY 2.2
Find the route of this shortest path.

l Find the shortest delivery route, starting and ending at Truro and making
Discussion point deliveries at each of the other places. For a network on a complete graph this is
called a least weight cycle and the problem is called travelling salesperson.
Is there a shorter
delivery route? A possible delivery route is:
Tr – LE – Tr – Bo – Bu – Ba – Mi – Ta – Ex – To – Ex – Ok – Pl – Tr
This delivery route has length 402 miles.

28

9781510403130.indb 28 20/03/18 7:48 AM


l Find the shortest route that can be travelled to check every road. This problem is
Discussion point
The route need not start
called route inspection.
A possible route is:
2
and end at these places.
Is there a shorter route LE – Tr – Bo – Pl – Tr – Bo – Bu – Ok – Bo – Pl – Ok – Ex – Pl – To – Ex –
that uses every arc in the Ta – Mi – Ba – Ta – Ex – Ba – Ok – Bu – Ba

Chapter 2 Modelling with graphs and networks


network? This route has length 775 miles, starting at Land’s End and finishing at
Barnstaple.
For all three of these problems there are shorter routes, but they are not easy to
Discussion point find.
The arc weights need not
represent distances, but
There are algorithms for dealing with these kinds of network problems; some of
even when they do why these are covered in Chapter 3. In reality computer software would be used to
might finding a shortest tackle these problems.
route not give the best
A delivery company may need to find the cheapest way to deliver orders from a
answer?
number of warehouses to a number of shops. Suppose that there are four warehouses
and four shops and each warehouse can fill the order of any one shop, but the cost
of doing so depends on the distance between the warehouse and the shop.
The table shows the cost (in a suitable unit) for each warehouse to fulfil the order
of each shop. The warehouses need to be paired with the shops to give the least
cost allocation.
Shop
S1 S2 S3 S4
W1 60 62 61 64
Warehouse W2 65 63 60 60
W3 59 61 58 63
W4 60 60 62 60
Table 2.4
The least cost allocation uses W1 to supply S1, W2 to supply S4, W3 to supply S3 and
W4 to supply S2. This costs 60 + 60 + 58 + 60 = 238.
The allocation problem involves finding a least weight matching on a bipartite graph.
The allocation problem involves supplying 1 unit from each warehouse to shops
each with a demand of 1 unit. To make the problem more realistic, the supplies and
demands may be more than one unit and warehouses may be able to supply more
than one shop.
Suppose now that the costs in Table 2.4 represent unit costs, with availabilities at
the warehouses:
W1 = 15 units   W2 = 12 units   W3 = 8 units   W4 = 3 units
and demands at the shops:
S1 = 10 units   S2 = 10 units   S3 = 12 units   S4 = 6 units
Note that the total supply and the total demand balance one another.
Finding the cheapest way to allocate the goods from the warehouses to the shops
then becomes a transportation problem. In this case, the number of supply points
and the number of demand points are equal, but for a transportation problem, these
numbers could be different.

29

9781510403130.indb 29 20/03/18 7:48 AM


Modelling with networks

A possible way to fulfil the demands is:


W1 supplies 10 units to S1 and 5 units to S2
W2 supplies 5 units to S2 and 7 units to S3
W3 supplies 5 units to S3 and 3 units to S4
W4 supplies 3 units to S4.
This solution costs 2304, but cheaper solutions than this exist.
The allocation problem is a special case of the transportation problem when
the number of warehouses equals the number of shops, every supply availability
equals 1 and every demand equals 1.

Exercise 2.3

① Table 2.5 shows the direct road distances, in ② Six students are choosing rooms in a shared house.
miles, between five places, A, B, C, D and E. Each student has given a score (from 0 to 5) to
There is no road between A and E. each room. A score of 0 means that the student
does not want that room under any circumstances.
A B C D E
Room
A - 12 36 20 -
R1 R2 R3 R4 R5 R6
B 12 - 30 30 40
Alice 0 4 2 1 0 3
C 36 30 - 10 20
Beth 0 0 3 2 0 2
D 20 30 10 - 12
Student Cal 2 1 4 0 3 1
E - 40 20 12 -
Dan 0 2 0 3 5 4
Table 2.5
Ella 3 0 0 0 3 0
(i) Draw a network to represent this 1 3 3 1 1 0
Fred
information.
Table 2.6
The roads represented by the arcs BC and BD
are dual carriageways. The average travel speed (i) Draw a bipartite graph showing which
on the dual carriageways is 60 miles per hour. students do want which rooms.
The average travel speed on all other roads is (ii) Weight this graph to show the student’s scores
50 miles per hour. for the rooms they do want.
(ii) Construct a table to show the travel times (iii) Without using a formal algorithm, find a way
for these roads. to allocate the students to the rooms that has
(iii) Without using a formal algorithm, find the a total score of at least 17.
quickest route from A to E.

30

9781510403130.indb 30 20/03/18 7:48 AM


LEARNING OUTCOMES 2
Now you have finished this chapter you should
➤ understand the language of graphs, including the terms node/vertex, arc/edge

➤ understand the terms simple, connected, complete, bipartite, tree and digraph in

Chapter 2 Modelling with graphs and networks


the context of graphs
➤ be able to use incidence matrices to represent graphs

➤ be able to model problems using graphs

➤ understand that a network is a weighted graph

➤ be able to use distance matrices to represent directed and undirected networks

➤ be able to model problems using networks.

KEY POINTS
1. A graph is a set of nodes (or vertices) together with a set of arcs (or edges).
An edge has a vertex at each end. An edge with the same vertex at both ends is
called a loop.
2. The order of a vertex is the number of edges incident on it.
3. A connected graph is one in which every vertex is joined, directly or indirectly,
to each of the other vertices. A simple graph is a graph with no loops and no
‘repeated’ edges. A simply connected graph is a graph that is both simple and
connected.
4. A tree is a simply connected graph with the minimum possible number of arcs.
5. A complete graph is a simply connected graph with the maximum possible
number of arcs.
6. A bipartite graph is one where the vertices partition into two sets and edges
cannot join vertices that are in the same set.
7. A digraph is a graph with directed arcs.
8. Two graphs are said to be isomorphic if they have the same structure.
9. A network is a weighted graph.

31

9781510403130.indb 31 20/03/18 7:48 AM


3 Network algorithms

Artificial intelligence AI A simply connected graph connects six vertices. The vertex orders are 1, 2, 2, 2, 4
and 5. A network is formed by weighting each arc with the sum of the orders of the
uses a complex set of two vertices that it joins.
rules – algorithms – to
get to a conclusion. Find the total weight of the minimum spanning tree for this network.
A computer has to
calculate its way through
all those rules and that In the final section of Chapter 2 you modelled some problems using networks
takes a lot of processing. and found informal solutions to the problems. This chapter is about algorithmic
So AI works best when a methods for the minimum connector and shortest path problems.
small computer is using
it on a small problem
– your car’s anti-lock
1 Algorithms for minimum connector
brakes are based on AI, problems
for example. Or you need
to use a giant computer Recall that a minimum connector, or minimum spanning tree, is the least weight
connected graph that includes every vertex.
on a big problem – like
IBM using a room-size
machine to compete Kruskal's algorithm
against humans on Kruskal’s algorithm can be used to find a minimum connector for an undirected
Jeopardy in 2011. network given in graphical form.
Kevin Maney (1960 – ) Kruskal’s algorithm starts with the set of nodes and then adds in arcs, working
in increasing order of weight, provided the arc does not join two nodes that are
already linked (directly or indirectly). More formally, an arc is not used if it connects
two nodes that are already in the same connected subgraph. The effect of this is that
little trees are formed that join together to become bigger trees until eventually all
the vertices are connected as a single big tree.

Steps for Kruskal’s algorithm


To find a minimum connector for an undirected network, start with the set of
nodes, and select arcs to add as follows.
Strictly speaking this
makes the ‘algorithm’ l First select the shortest arc of the network.
ambiguous. This
would be important l At each subsequent stage choose an arc to add as follows:
when programming a the arc should not yet have been selected
computer to implement
it, but for using the adding the arc should not join nodes which are already linked
algorithm by hand it the arc should be the shortest arc which satisfies these conditions
makes no practical
difference. if at any stage there are two suitable arcs of equal weight then either can be
chosen.
32

9781510403130.indb 32 20/03/18 7:48 AM


Since a tree of n nodes has n – 1 arcs, Kruskal’s algorithm stops when n – 1 arcs
have been chosen. The nodes are all connected and any remaining arcs would
connect two nodes that are already linked. 3
It is useful to draw the nodes and show the arcs as they are added in.
For a small problem, sorting the weights can be done informally without needing

Chapter 3 Network algorithms


to use a sorting algorithm.

Historical note

The algorithm was published in 1956 by the American mathematician Joseph


Kruskal (1928–2010). It is an example of a ‘greedy’ algorithm. Greedy algorithms
essentially ‘grab what is best’ for the current state without regard to the bigger
picture. Surprisingly, greedy approaches can lead to optimal solutions for a
variety of different types of problem. It can be shown that Kruskal’s algorithm is
indeed optimal.

Example 3.1 The cable TV company problem is modelled using the network below.
LE 37 Tr 26 Bo 30 Bu 35 Ba 38 Mi

52 31 41 30 31
This problem was
introduced on page 27 Pl 31 Ok 40 50 24
31 46 23

To 22 Ex 35 Ta

Figure 3.1
Use Kruskal’s algorithm to find a minimum connector.

Solution
Ex – To 22 LE Tr Bo Bu Ba Mi

Ex – Ok 23
Mi – Ta 24
Pl Ok
Bo – Tr 26
Bo – Bu 30
To Ex Ta
Ok – Bu 30
Figure 3.2
Ba – Ok 31
List the arcs in Bo – Pl 31
increasing order of
weight and draw a graph Ok – Pl 31
that initially consists of
Pl – To 31
just the nodes. There are
11 nodes so we need at Ba – Bu 35
least 10 arcs in the list.
The order of the nodes Ex – Ta 35
does not matter, so, for
example, Ex – To is the LE – Tr 37
same as To – Ex.
Ba – Mi 38 etc.
33

9781510403130.indb 33 20/03/18 7:48 AM


Algorithms for minimum connector problems

Ex – To 22 LE Tr Bo Bu Ba Mi

Ex – Ok 23
Mi – Ta 24
Pl Ok
Bo – Tr 26
Bo – Bu 30
Work down the list and To Ex Ta
Ok – Bu 30
build trees by adding in
Figure 3.3
arcs. If an arc cannot be Ba – Ok 31
used cross it out.
Bo – Pl 31

This arc is not used,


Ok – Pl 31
since Ok and Pl are Pl – To 31
already connected via Bu
and Bo. Ba – Bu 35
Ex – Ta 35
LE – Tr 37
Finally add up the Ba – Mi 38 etc.
weights for the arcs that
were used. The total weight of the arcs used is 289 miles

By using the arcs of weight 31 in a different order a different minimum connector


can be found, but it will still have total weight 289.

Prim’s algorithm
An alternative to Kruskal’s algorithm is Prim’s algorithm. This is another greedy
Historical algorithm for finding a minimum connector for an undirected network, which can
note also be shown to be optimal.
Prim’s algorithm was Prim’s algorithm starts with a single node and builds a tree by successively adding
developed in 1930 by the
in the least weight arc that connects one of the vertices that is already in the tree to
Czech mathematician
Vojtch Jarnik and one of the vertices that is not yet in the tree.
later independently
rediscovered in 1959
by the American
Steps for Prim’s algorithm
mathematician Robert C To find a minimum connector for an undirected network, start with one node and
Prim (1921–2012). build a tree as follows.
l Connect the nearest node that is not yet connected to those already in the tree.
This ambiguity makes If there is more than one nearest node, choose any one of these to connect to
no practical difference the tree.
when implementing the
algorithm by hand. l Repeat until all nodes have been connected.
Since a tree on n nodes has n − 1 arcs, Prim’s algorithm stops when n − 1 arcs have
been chosen. The nodes are all connected and any remaining arcs would connect
two nodes that are already linked.
It is useful to draw the nodes and show the arcs as they are added in.

34

9781510403130.indb 34 20/03/18 7:48 AM


Example 3.2 Use Prim’s algorithm to find a minimum connector for the cable TV company
problem. Start building your tree from Barnstaple (Ba). 3
LE 37 Tr 26 Bo 30 Bu 35 Ba 38 Mi

52 31 41 30 31

Chapter 3 Network algorithms


Pl 31 Ok 40 50 24
31 46 23

Figure 3.4 To 22 Ex 35 Ta

Solution
The least weight arc from
Ba is Ba − Ok = 31. The Ba – Ok 31 LE Tr Bo Bu Ba Mi
tree then contains Ba
and Ok. Ok – Ex 23
Ex – To 22
Pl Ok
The least weight arc Ok – Bu 30
from Ba or Ok to one of
the other places is Bu – Bo 30
Ok − Ex = 23.
Bo – Tr 26 To Ex Ta
Figure 3.5
The least weight arc Bo – Pl 31
from Ba, Ex or Ok to one Ex – Ta 35
of the other places is
Ex − To = 22. Ta – Mi 24
LE – Tr 37
The least weight arc
from Ba, Ex, Ok or To to The total weight of the arcs used is 289 miles.
one of the other places
is
Ok − Bu = 30 and so on.
Note
Note that Prim’s algorithm builds a single tree from a little tree into a big tree,
whereas Kruskal’s algorithm often starts with a collection of little trees that
eventually join together to make a single tree.

Discussion point
 hich algorithm do you
W
think would be easier to For a small network given in graphical form, Prim’s algorithm is easy to apply, but
program a computer to for a large network Kruskal’s algorithm might be easier as the list can be sorted
carry out? Why? using quick sort.
However, Prim’s algorithm can easily be converted into a form that can be used when
the network is given in tabular form as a distance matrix. Rows will correspond to
nodes that are not yet joined to the tree and columns will be marked to indicate those
that are already in the tree. Choosing the next arc corresponds to looking down all the
marked columns and finding the least weight entry that is not crossed out. If there are
two possibilities that are of equal weight choose either one of them.
When applying this version of Prim’s algorithm by hand it is useful to record the
arcs as they are chosen and it may be useful to draw the tree as the arcs are chosen.

35

9781510403130.indb 35 20/03/18 7:48 AM


Algorithms for minimum connector problems

Prim’s algorithm in tabular form


Step 1 Delete the row corresponding to the starting node. Mark the column
corresponding to this node.
Step 2 Look down the marked column(s) and find the smallest value in that
column that is not already crossed out. Choose this entry by putting a
box round it.
Step 3 Delete the row that contains the entry that has just had a box put round
it. Mark the column corresponding to the node that was on the row that
has just been crossed out.
Step 4 If any row is not crossed out go back to step 2, otherwise stop.

Example 3.3 Use Prim’s algorithm in tabular form to find a minimum connector for the cable
TV company problem. Start building your tree from Barnstaple (Ba).

Solution
(11) (7) (6) (8) (5) (2) (1) (3) (4) (10) (9)
LE Tr Bo Pl Bu Ok Ba Ex To Mi Ta Arcs chosen
LE - 37 - - - - - - - - - Ba - Ok 31
Tr 37 - 26 52 - - - - - - - Ex - Ok 23
Bo - 26 - 31 30 41 - - - - - To - Ex 22
Pl - 52 31 - - 31 - 46 31 - - Bu - Ok 30
Bu - - 30 - - 30 35 - - - - Bo - Bu 30
Ok - - 41 31 30 - 31 23 - ∞ - Tr - Bo 26
Ba - - - - 35 31 - 40 - 38 50 Pl - Bo 31
Ex - - - 46 - 23 40 - 22 - 35 Ex - Ta 35
To - - - 31 - - - 22 - - - Ta – Mi 24
Mi - - - - - - 38 - - - 24 Tr - LE 37
Ta - - - - - - 50 35 - 24 - Total 289
Table 3.1
The total length of the arcs used in 289 miles.

Start by crossing out the row for Ba and marking the column for Ba. The labelling could
be marking the column for Ba to show that it was chosen first.
Looking down this column, the least weight is Ok – Ba = 31. Box this, cross out the rest
of the Ok row and mark the Ok column.
Now look down both of the marked columns: the least weight that is not crossed out is
Ex – Ok = 23. Box this, cross out the rest of the Ex row and mark the Ex column.
Continue in this way.

36

9781510403130.indb 36 20/03/18 7:48 AM


Exercise 3.1
① Use Kruskal’s algorithm to find a minimum ② Use Prim’s algorithm in graphical form, starting
3
connector for this network. List the arcs that are at Stratford-upon-Avon, to find a minimum
used in the order that they are included and give connector for this network. List the arcs that are
the total weight of the minimum spanning tree. used in the order that they are included and give

Chapter 3 Network algorithms


Swindon
the total weight of the minimum spanning tree.

Stoke-on-Trent Nottingham
41
49
37
40 34
50 25
44
Basingstoke
36 Shrewsbury Leicester
Warminster 21 Salisbury 45 39
31
23 Birmingham
41 49 30
43
Southampton 24
Yeovil 40 27 27
31
20 25 39 Northampton
Bournemouth
28 Worcester
Stratford-upon-Avon
Dorchester
39 40 42
25

52
Figure 3.6 Gloucester Oxford

Figure 3.7

③ Use Prim’s algorithm in tabular form, starting from Malvern, to find a


minimum connector for this network. List the arcs that are used in the order
that they are included and give the total weight of the minimum spanning tree.

Cheltenham
Tewksbury

Gloucester
Worcester

Hereford

Evesham
Malvern

Ross

Malvern – 8 19 ∞ 19 13 20 ∞
Worcester 8 – 25 16 ∞ 15 ∞ ∞
Hereford 19 25 – ∞ 14 ∞ 28 ∞
Evesham ∞ 16 ∞ – ∞ 13 ∞ 16
Ross 19 ∞ 14 ∞ – 24 16 ∞
Tewksbury 13 15 ∞ 13 24 – 10 9
The infinity symbol ∞ is Gloucester 20 ∞ 28 ∞ 16 10 – 9
often used in a table to
indicate that there is no Cheltenham ∞ ∞ ∞ 16 ∞ 9 9 –
direct connection between
Table 3.2
two nodes.

37

9781510403130.indb 37 20/03/18 7:48 AM


Algorithms for minimum connector problems

④ Use Prim’s algorithm, starting from Carlisle, to find a minimum connector for
this network.
Newcastle
Carlisle 57 upon Tyne
32 19
37 Penrith
Workington 41 34
Middlesbrough
50
28
59 26
Kendal Scotch Corner
34
50
Barrow-in-Furness 20 45
54
Lancaster 42 Skipton
22 28 24 York
Blackpool 35
17
Preston Leeds
31 40
30 33
35 38
Liverpool Manchester
Sheffield

Figure 3.8
⑤ Use Prim’s algorithm, starting from Dorchester, to find a minimum connector
for this network.

Lytchett Minster
Puddletown
Dorchester

Bere Regis
Wimborne

Weymouth

Warmwell
Blandford

Wareham

Swanage

Poole
Dorchester – 5 ∞ ∞ ∞ ∞ 8 5 ∞ ∞ ∞
Puddletown 5 – 12 ∞ 6 ∞ ∞ 9 14 ∞ ∞
Blandford ∞ 12 – 7 9 11 ∞ ∞ 16 ∞ ∞
Wimborne ∞ ∞ 7 – 8 7 ∞ ∞ ∞ ∞ 7
Bere Regis ∞ 6 9 8 – 8 19 11 8 ∞ ∞
Lytchett Minster ∞ ∞ 11 7 8 – 25 ∞ 5 ∞ 6
Weymouth 8 ∞ ∞ ∞ 19 25 – 7 ∞ ∞ ∞
Warmwell 5 9 ∞ ∞ 11 ∞ 7 – 13 ∞ ∞
Wareham ∞ 14 16 ∞ 8 5 ∞ 13 – 10 ∞
Swanage ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ 10 – ∞
Poole ∞ ∞ ∞ 7 ∞ 6 ∞ ∞ ∞ ∞ –
Table 3.3

38

9781510403130.indb 38 20/03/18 7:48 AM


⑥ Use Kruskal’s algorithm to find a minimum connector for this network.

Holyhead 3
38 47
Conwy Chester
43 19
50 Betws-y-Coed 23

Chapter 3 Network algorithms


Porthmadog 22
34 Llangollen
25 40 31
28
Dolgellau 38 19 Shrewsbury
Welshpool
34 56

Aberystwyth 48 53
45
56
Builth Wells 39
50 Hereford
Fishguard
51
35 33
43
22 45
37 Carmarthen
27 31 Merthyr Tydfil
Swansea 22 Chepstow
Milford Haven 29
40

Cardiff

Figure 3.9

2 Finding the shortest path


When you use a computerised route planner or a sat nav, you provide your starting
point and destination and the program produces a ‘best’ route together with
directions and distances.
At the heart of these systems is an algorithm for finding the shortest distance
between two nodes in an undirected network. The weights in such a network are
usually times to take account of dif ferent travel speeds on motorways, main roads
and minor roads.
Historical
note Imagine making the network from beads and strings, where the nodes are beads
and the arcs are strings, with the lengths of the strings representing the weights
The shortest path
algorithm was published
(distances between nodes). Hold the bead that represents the starting point and
in 1959 by the Dutch pick the network up, so that the other beads hang vertically below the first one,
mathematician Edsger because of gravity. The distance that each node hangs below the first one is limited
W. Dijkstra (1930–2002). by the lengths of the strings; these distances will be the shortest distances from the
starting point.
Dijkstra’s algorithm finds the shortest distances from a start node to each of the
other nodes by using a labelling method. At each node a box is drawn. These boxes
are used to record the working. They also give evidence that the algorithm is being
applied correctly.

39

9781510403130.indb 39 20/03/18 7:48 AM


Finding the shortest path

Note Order of (permanent) labelling Permanent label (shortest


distance from start node)
Do not cross out working
Temporary labels (working
values when they are
values)
updated.
Figure 3.10

Steps for Dijkstra’s algorithm


Step 1 Label the start node with permanent label 0 and order of labelling 1.
For each arc from this node, assign the arc weight as a temporary label at
the node that it connects to.
Look at all the temporary labels and find the smallest, make this value
into a permanent label and give the node order of labelling 2.
Step 2 Work from the node that has most recently been given a permanent
label.
For each arc from this node, add the arc weight to this permanent
label and record it as a temporary label at the node that it connects to
provided the value is less than the current best (i.e. least) temporary label
at that node. If the arc weight plus the permanent label is greater than or
equal to the current best temporary label do not record it.
Look at all the temporary labels at all nodes that do not yet have
permanent labels (not just the ones that have just been updated) and
find the smallest. Make this value permanent and give the node the next
order of labelling number.
Step 3 If the destination node does not yet have a permanent label go to Step 2
again.
If the destination node does have a permanent label, this value is the
length of the shortest path. To find the route of the shortest path, trace
back from the destination, including any arc for which the arc weight is
the dif ference between the permanent labels at the nodes at its two ends.
The order of labelling is useful if you are interrupted part way through applying the
algorithm. As a check, the permanent labels should come out in increasing order.
There is no need to keep a note of which arcs were used to achieve the various
temporary or permanent labels. This is dealt with in the trace-back in Step 3.

Example 3.4
Use Dijkstra’s algorithm to find the shortest path from A to F in this network.

B 5 D
7 4
A 10 F

4 3
C 12 E

Figure 3.11

40

9781510403130.indb 40 20/03/18 7:48 AM


Note Solution
Usually the working The iterations look like this:
3
would all be done on one A
C
diagram. 3 7
7 7 14
B 5 D B 5 D

Chapter 3 Network algorithms


7 4 7 4
Starting from vertex A 1 0 1 0 10
A 10 F A F
assign temporary labels
4 3 4 3
at vertices B and C, the
smallest temporary label C 12 E C C 12 E
A 2 4 32 74
is at C so C = 4 becomes
7 4 74 1416
the second permanent B 5 D B 5 D
label. C 4 4
7 7
1 0 3 7 1 0
10 F A 10 F
7 7A 14
B 5 D B 5 D
B 37 74 3 D 34 7 34 12
7 4
From C assign temporary 4 4 12
7 C 10 12 E14 12 7 C ED 14 12
10 labels 4 + 10 = F 14 at
1 0
2 4B 5 D F 2 4 B 512
A A
D and 4 + 12 = 16 at E. 47 4 7 16 4
4 3 4 34 1 0
The smallest temporary C 1 0 10
1012 F A
C 12 label (that
E is not already 3 A7 C E
2 4 2 4
7 permanent) is at B so 7 4 14 4 3
4 B 5 D 4 B 5 D 16 3
B = 7 becomes the third C 12 C 12 E
7 4 B 7 4E 32 74 4 12
permanent label. 1 0 32 74 4 12 D
10 F A 7 4 10 1416F 12 74 16 12
14
B 5 D B 5 D
4 3 4 3 7 4
3 7 D 3 7 7 4 4 12 1 0
C 12 E 4 12 1 0 C 12 E A 10
72 4 14 12 2A 7 4 B
10
5 D
14 12 F
4 B 5 D 4 16 4 3
7 4 74 43
1 0 C 10 12 E 5 16 C 12 E
10 F A 2 4 F 2 4
A 16
44 163 4 16
4 3
3 7 C 12 E4 12 D 3 7 C 12 E4 12
2 4 2 4
7 14 12 7 14 12
4 B 5 D 16 4 B 5 D 16

7 4 7 4 You could have


1 0 10 5 16
10 F A F made E the fifth
16
permanent label and
4 3 4 3
F the sixth, but there
C 12 E C 12 E is no advantage in
2 4 2 4
4 16 doing this.
4
Note 16
Figure 3.12
For AC 4 = 4 – 0 but you
only trace back along a Tracing back from F gives the arcs FD (4 = 16 – 12), DB (5 = 12 – 7) and BA
route, so C was never (7 = 7 – 0)
reached.
This gives the route A – B – D – F = 16.

Exercise 3.2
① Use Dijkstra’s algorithm to find a shortest path from S to T for each of the networks.
(i) Q 2 (ii) D
P 5 R 1
8 1 T
2 4 7 6 4
1 6 E
S X Y T A 4
1 6 3 1
3 5 6
8 1
1 3
U 3 W F 2
4 4 B 2
V S C
6
Figure 3.13
Figure 3.14
41

9781510403130.indb 41 20/03/18 7:48 AM


Calculating algorithmic complexities

(iii) A 2 E 5 I (iii) If you can travel by road from El Paso to


6 4 7 Santa Fe in 5 hours and from Santa Fe to
2 B F 3
2 J Denver in 5 hours, would you save time on
1 6
S 4 5 T
1 C 3 G 2 K
7 journey (i) or (ii) by using a mix of road and
3 1 1 5 rail? (You should neglect connection times.)
2 3 Salt Lake City
D H L 15 18 Omaha 5
San Francisco if ic Chicago
P a c 9
Figure 3.15 Union 12
gto
n
7
u rlin
B
② The map shows the main railway lines across the 4 Denver
USA and gives the approximate times in hours for Atchison, 18 Kansas
Topeka & 17
Los Angeles Santa Fe City
the various journeys. 20
20 Santa Fe n d
Find the quickest route from Los Angeles to sla
(i) 17 c kI
Chicago. RoSou
thern Pac
El Paso ific
(ii) Find the quickest route from New Orleans 21
New Orleans
to Denver. Figure 3.16

3 Calculating algorithmic
complexities
As with any algorithm, the small examples used to show how Kruskal, Prim and
Dijkstra work are not of the scale of a practical problem. When a sat nav finds a
shortest route it will typically analyse thousands or even millions of possible routes.
Understanding how the algorithms work is important for creating computer
programs and also for dealing with variations on the standard problems. For
example, how could you change Dijkstra’s algorithm to deal with a directed
network?
You may have wondered why you learn about both Kruskal and Prim as ways to
find a minimum connector. In some situations one will be better than the other,
but often it is just a matter of preference.
Prim’s algorithm is usually best when the network is given in tabular form, but
Kruskal’s algorithm is useful when you want to answer questions about things like
whether the least weight arc is always part of a minimum connector or whether the
greatest weight arc is ever part of a minimum connector.
Considering the complexity of these three algorithms, in the worst case, brings
up an issue relating to how you measure the size of a network.You could use the
number of nodes or the number of arcs.
Kruskal’s algorithm needs the arc weights to be sorted. The number of comparisons
used will be a quadratic function of the number of arcs or a cubic function of the
number of nodes.
Similarly, each iteration of Prim’s algorithm involves comparing a number of arc
weights. The number of comparisons at each iteration will be a linear function. It
follows that the total number of comparisons used will be a quadratic.
For large-scale problems, both Kruskal’s algorithm and Prim’s algorithm can be
programmed so that in the worst case they have quadratic complexity as a function
of the number of vertices.

42

9781510403130.indb 42 20/03/18 7:48 AM


For Dijkstra’s algorithm, the work involved at each stage is approximately
proportional to the number of nodes which have not yet been permanently
labelled, so the total work involved is approximately proportional to 3
(n – 1) + (n – 2) + … + 3 + 2 + 1, where n is the number of nodes. This is a
quadratic function of the number of nodes, so Dijkstra has quadratic complexity.

Chapter 3 Network algorithms


Exercise 3.3
① A computer takes 0.02 seconds to solve a long would you expect the student to take to
minimum connector problem. Roughly how long solve a shortest path problem on a network with
will it take for a problem that is ten times bigger? 30 vertices?
② A student takes 20 seconds to solve a shortest ③ Calculate the maximum possible number of
path problem on a network with 12 vertices comparisons and the maximum possible number
using Dijkstra’s algorithm. Approximately how of additions used when Dijkstra’s algorithm is
applied on a network with n = 5 vertices.

LEARNING OUTCOMES
Now you have finished this chapter you should
➤ be able to use Kruskal’s algorithm to solve minimum connector problems in
graphical form
➤ be able to use Prim’s algorithm to solve minimum connector problems in
graphical or tabular form
➤ be able to model shortest path problems and solve them using Dijkstra’s
algorithm
➤ know that Kruskal, Prim and Dijkstra all have quadratic complexity in relation to
the number of arcs.

KEY POINTS
1 Kruskal’s algorithm starts with the set of nodes and then adds in arcs, working
in increasing order of weight, provided the arc does not join two nodes that are
already linked (directly or indirectly).
2 Prim’s algorithm starts with a single node and builds a tree by successively
adding in the least weight that connects one of the vertices that is already in the
tree to one of the vertices that is not yet in the tree.
If the network is given in tabular form, when a node is chosen its row is crossed
out and the column for that node is marked. The tree is built by looking down all
the marked columns, putting a box round the smallest value that is not crossed
out and choosing the node for the row containing this box.
3 Dijkstra’s algorithm starts by labelling the start with permanent label 0 and
order of labelling 1.
Temporary labels are updated by working from the node that has most recently
been given a permanent label, adding this permanent label to the arc weight for
each arc that is incident on the node and recording this at the node that the arc
connects to whenever it is smaller than the best temporary label at that node.
The smallest of the temporary labels at the nodes that do not yet have
permanent labels becomes the next permanent label and the order of labelling
for that node is recorded. When the destination has a permanent label, the
route is found by tracing back and recording arcs for which the arc weight is the
difference between the permanent labels at the nodes at its two ends.

43

9781510403130.indb 43 20/03/18 7:48 AM


4 Further network problems

There cannot be a crisis Each morning Paul makes toast using a grill. The grill can take two slices of bread
at a time and takes 1 minute to toast each side of the bread. How long does it take
next week, my schedule Paul to toast three slices of bread?
is already full.
Henry Kissinger (1923–)

1 Critical path analysis


In most situations, time can be saved by careful planning. Large-scale construction
problems, maintenance problems and scheduling use critical path analysis
techniques to enable complex projects to be planned, monitored and adjusted if
delays occur.
Think about the following scenario.
Jane, Sue and Meena share a flat. Jane has an interview at 9 a.m. and is panicking
because it is 8.10 already and she thinks that she won’t get there on time.
‘Don’t worry,’ says Sue, ‘I’m already dressed so I’ll go and get your car from the
lock-up and Meena will iron your clothes while you shower and get ready.’
To decide whether Jane can get to her interview within 50 minutes, when Sue and
Meena help her, the project is broken up into activities.

Activity Duration (minutes) Immediate predecessors


A Shower 3 –
B Dry hair 8 A
C Fetch car 7 –
D Iron clothes 12 –
E Get dressed 10 B, D
F Drive to interview 20 C, E
Table 4.1
Some of the activities can only be done by Jane (A, B, E, F); Sue will do activity C
and Meena will do activity D. The column labelled ‘Immediate predecessors’ shows,
for each activity, which other activities have to be completed before the activity
can begin. Jane cannot dry her hair (B) until after she has showered (A), so A is an
immediate predecessor for B. She cannot get dressed (E) until she has showered (A),

44

9781510403130.indb 44 20/03/18 7:48 AM


dried her hair (B) and her clothes have been ironed (D). However, since B must
follow A, only the immediate predecessors B and D need to be recorded. Similarly,
F cannot start until C and E are both complete. 4
If Sue sets off immediately she can be back with the car by 8.17. Jane takes
11 minutes to shower and dry her hair so she is ready to get dressed at 8.21.

Chapter 4 Further network problems


Meena can have Jane’s clothes ready by 8.22 and Jane can then get dressed and set
off at 8.32. Unless she gets held up, she will arrive at the interview at 8.52, with
8 minutes to spare thanks to her flatmates.
Sue could wait until 8.05 to go for the car but it may be safer to set off
immediately in case she is delayed. If Meena takes longer than 12 minutes to
iron the clothes it will delay Jane’s arrival time at her interview.

Activity networks
For a complicated project, the precedences may be represented using an activity
network.
l Arcs represent activities and the arc weights show the durations of the activities.
l Vertices represent events (moments in time between completion of one activity
and the start of another). Some events are fixed points in time and some can
move around within a ‘window’ of time.
l The network must have a single start event and a single finish event.
The project above can be represented as shown in Figure 4.1.
D(12)

A(3) B(8) E(10)


F(20)

C(7) .
Figure 4.1
Sometimes the events are numbered and then activities can be referred to by giving
the events that they connect. For this to be possible, the network must be a simple
digraph that has been weighted.

Dummy activities
Dummy activities may be needed to form a simple digraph.
l A dummy activity is an activity that has duration 0.
l Dummy activities are shown as dashed lines.
l Dummy activities may also be needed to establish precedences when the
relationship between activities is more complicated.
It is good practice to have as few dummies as possible.

45

9781510403130.indb 45 20/03/18 7:48 AM


Critical path analysis

Example 4.1 Figure 4.2 shows an activity network in which three dummy activities have been
used.

Activity Preceding activities


A –
B –
C A
D A, B
E C, D
F C, D
G D
H E, F

Table 4.2

C E
2 5 7

F H
A
6

1 8

B
G
D
3 4

Figure 4.2

Explain the purpose of each dummy activity.

Solution
The dummy from event 2 to event 3 is needed because D is preceded by A and
B, but C is preceded by A only.
The dummy from event 4 to event 5 is needed because E and F are preceded by
C and D, but G is preceded by D only.
The dummy from event 6 to event 7 is needed because otherwise E and F would
both join event 5 to event 7 and the graph would not be simple. Activity E is
(5, 7) and F is (5, 6), so there is no ambiguity.

Identifying a critical path


l The minimum time in which a project can be completed, assuming no
unexpected delays, is called the minimum project completion time.
l The minimum project completion time is the length of the longest path in the
(directed) activity network. There may be more than one longest path.
l Any activity on a longest path is called a critical activity. A delay in a critical
activity will delay the entire project.
A forward pass is made through the network, from the start to the finish, to find
the earliest event times.

46

9781510403130.indb 46 20/03/18 7:48 AM


l The earliest time at any event is the earliest time at which the activities leading
into the event can be completed. Some of these activities may be completed
before this time, but the event cannot occur until they are all completed. 4
l The earliest time for the start event is set as 0.
l The earliest time for the finish event is the minimum project completion time.

Chapter 4 Further network problems


Figure 4.3 shows the earliest event times for Jane’s problem.
iron clothes (12)

0 22 42
shower (3) dry hair (8) dress (10) drive to interview (20)
1 2 3 4 5
3 12

fetch car (7)

The earliest time ‘dry hair’ Although Jane can have


can begin is after 3 minutes, showered and dried her hair in
since ‘shower’ comes first 11 minutes, her clothes will not
be ready until 12 minutes, so
the earliest time ‘dress’ can
begin is after 12 minutes

Figure 4.3
A backward pass is then made through the network, from the finish to the start,
to find the latest event times.
l The latest time at any event is the latest time at which the activities coming
from the event can be started for the project to finish in the minimum project
completion time.
l The latest event time for the finish event is the project completion time.
l The latest event time for the start event is 0.
The earliest and latest event times are shown at the events in a double box, with
the earliest time in the first box and the latest time in the second box. If the earliest
time and latest time at an event are the same, then the event is a fixed point in time
and is said to be a critical event.

The latest event time for event 4 is 22,


as Jane cannot start driving any later
if she is to be on time. Similarly, the
iron clothes (12) latest event time for event 3 is 12

0 0 22 22 42 42
Note 1
shower (3)
2
dry hair (8)
3
dress (10)
4 5
On the forward pass, 3 4 12 12 drive to interview (20)
when there is a choice,
fetch car (7)
the largest time is
needed.
On the backward pass, The latest time for event 2 will be 4,
when there is a choice, because Jane could leave drying her
the smallest time is hair until time 4 without delaying the
needed. start of dressing

Figure 4.4
47

9781510403130.indb 47 20/03/18 7:48 AM


Critical path analysis

The critical activities can be identified as follows.


l The event at the start of the activity is a critical event.
l The event at the end of the activity is a critical event.
l The difference between the event times at the start and end of the activity is
equal to the activity duration.
For the activity network in Figure 4.4, the critical activities are iron clothes, dress
and drive to interview.

Float
Non-critical activities have float. This is the amount of time by which the duration
of the activity can be extended without having any effect on the minimum project
completion time.
l The float (or total float) for activity (i, j) is given by
(latest event time at j – earliest event time at i) – duration
The float may be divided into independent float (which is unique to this activity)
and interfering float (which has an impact on the float of other activities).
l Independent float for activity (i, j) is given by
(earliest event time at j – latest event time at i) – duration
or 0 if this calculation gives a negative answer
l Interfering float = total float – independent float.
The float for a critical activity is 0.
Float is useful for making adjustments when an activity is delayed, for scheduling a
project between a number of workers or when other resourcing restrictions apply.

Example 4.2 (i) Calculate the float for each non-critical activity in Jane’s problem.
(ii) If Meena is away, so that Jane only has Sue to help her, can Jane still get to
her interview on time?

Solution
(i)
Activity Duration Float Independent float Interfering float
A 3 (4 – 0) – 3 = 1 (3 – 0) – 3 = 0 1–0=1
B 8 (12 – 3) – 8 = 1 (12 – 4) – 8 = 0 1–0=1
C 7 (22 – 0) – 7 = 15 (22 – 0) – 7 = 15 15 – 15 = 0
Table 4.3
(ii) Meena had been doing activity D, which was a critical activity.
If Sue does D instead and then does activity C, while Jane does activities A,
B and E as before, Sue will be back with the car 19 minutes after the start
(at 8.29) and Jane can still leave the flat at the same time as before and get to
the interview with 8 minutes to spare.

48

9781510403130.indb 48 20/03/18 7:48 AM


Resourcing and scheduling
Computer software is usually used to carry out critical path analysis for a large
project. The software will usually print out a cascade chart, showing when each
4
activity can happen.

Chapter 4 Further network problems


l A cascade chart has a horizontal time scale, a row showing the critical activities
and a row for each non-critical activity.
l Non-critical activities are shown starting at their earliest possible start times and
the float is shown at the end of the activity.
l Any dummy activities are not shown on the cascade chart.
Computer software may also produce a resource histogram showing how many
workers are needed at each time, with each activity starting at its earliest possible
time, and a schedule (or timetable) showing which activity each worker needs
to be doing at each time. The usual convention is that once an activity has been
started by a worker, then that worker continues with it until it is completed.
These charts are useful for assigning workers to activities and for resource
levelling, that is, using the floats in activities so that fewer workers are required.

Example 4.3 Construct a cascade chart and a resource histogram for Jane’s problem.

Solution
A
B
C
The dotted lines show the D E F
floats for activities A, B 0 10 20 30 40 time (mins)
and C.
Figure 4.5
Workers

3
2
1
0 10 20 30 40 time (mins)

Figure 4.6

A cascade chart and resource histogram, together with the activity network or table
showing the precedences, can be used to carry out resource levelling. Resource
levelling may be needed to enable the project to be completed by a fixed maximum
number of workers in the minimum time, or at minimum cost, or by making the
most sensible use of the resources (e.g. if a specialist worker or special equipment is
needed for some activities, these could be scheduled to follow straight on from one
another).
In Jane’s problem, the cascade chart shows that activity C can be moved to start
after B ends, so that only two people are needed for the project.

49

9781510403130.indb 49 20/03/18 7:48 AM


Critical path analysis

Exercise 4.1 ① Draw an activity network to represent this project.


Activity Duration Immediate predecessors
A 5 –
B 2 A
C 8 –
D 12 A, C
E 6 B, C
Table 4.4
② Find the total float for each activity in this project.
Activity Duration Immediate predecessors
A 2 –
B 1 –
C 1 A
D 3 A, B
 [MEI adapted]
Table 4.5
③ The activities involved in cooking a meal of toad-in-the-hole, potatoes and
cabbage, followed by apple pie and custard, are shown in the table below.
Immediate
Activity Duration (mins)
predecessors
A Grill sausages 8 –
B Make batter 6 –
C Make apple pie 15 –
D Prepare potatoes 6 –
E Prepare cabbage 4 –
F Cook sausages and batter together 35 A, B
G Cook potatoes 25 D
H Cook cabbage 8 E
I Cook apple pie 30 C
J Make custard 8 –
Table 4.6
(i) Draw an activity network to represent this project.
(ii) Find the minimum project completion time, assuming that there are
enough people available to carry out the activities.
(iii) Which activities are critical?

PS ④ Harry wants to decorate a room. The activities involved are given in the table,
together with their durations and immediate predecessors.
Activity Duration (days) Immediate predecessors
A Remove old wallpaper 1 –
B Prepare wooden surfaces 0.25 –
C Paint ceiling 0.75 A
D Apply undercoat 1 A, B
E Apply gloss paint 1 D
F Paper walls 1 C, E
Table 4.7
50

9781510403130.indb 50 20/03/18 7:48 AM


(i) Represent the project as an activity network.
Harry decides to decorate three rooms. The activities, durations and
predecessors for each room are as in the table above. Harry will be helped by
4
his friend Nisha, but activities cannot be shared between Harry and Nisha.
(ii) Show how Harry and Nisha can decorate the three rooms when they only

Chapter 4 Further network problems


have 8 days available. [MEI, adapted]
PS ⑤ The activities involved in a project are shown in the table below.

Activity A B C D E F G H I J K L M N
Duration (days) 1 2 4 3 14 14 16 12 14 10 5 4 6 3
Immediate – A B A C C C DG DG DG H I J EFKLM
predecessors
Number of workers 1 1 1 1 1 2 2 2 3 1 1 2 1 2
Table 4.8
(i) Calculate the minimum time in which this project can be completed and
determine which activities are critical.
(ii) Calculate the float on the non-critical activities, distinguishing between
the independent and the interfering float.
(iii) Draw a cascade chart for the project.

(iv) Describe, in detail, the effect on the project if only five workers are
available, each of whom can carry out any of the activities.
PS ⑥ A project is described in the table below.
Activity Duration (days) Immediate predecessors
A 8 –
B 4 –
C 2 A
D 10 A
E 5 B
F 3 C, E
Table 4.9
The duration of any of the activities can be reduced at a cost, as given in the
table below.
Cost (£) for each day by which duration
Activity Maximum reduction
is reduced
A 2 50
B 2 100
C 1 40
D 5 60
E 4 25
F 2 10
Table 4.10
Which activity durations should be reduced, and by how many days, to reduce
the minimum project completion time by
(i) 2 days (ii) 7 days

at minimum cost?

51

9781510403130.indb 51 20/03/18 7:48 AM


Network flows

2 Network flows
There are many situations in which something has to be transported from one place
to another along alternative routes: water through pipes, electricity through cables,
goods along roads, people by trains, and so on.
When a continuous flow is required, the problem can be modelled as a network
flow, where the weights on the arcs show capacities and the maximum continuous
flow from the start to the finish is required.
l The flow along any arc cannot exceed the capacity of the arc.
l All flows start from the source vertex.
There are no flows into the source.
In some situations, there may be multiple sources (for example, there may be
several warehouses supplying goods to shops) and then a single supersource is
used to supply the sources.
The source is sometimes denoted by S.
l All flows end at the sink vertex.
There are no flows from the sink.
If a flow has multiple sinks (for example, there may be several shops receiving
the goods from warehouses), then a single supersink is used that all the sinks
drain into.
The sink is sometimes denoted by T (for terminus).
l At all other vertices, flow passes through the vertex. The flow that enters the
vertex must be equal to the flow that leaves the vertex.
In some cases, the flow in an arc will be directed; this is the case for the arcs from
the source and the arcs into the sink. There may be other directed arcs if there are
valves or other reasons why the flow can only be in one direction.

Example 4.4 The network below shows the capacities of the arcs in a network with source S
and sink T.
A 10 C

13 5 13

S T

12 5 12
5
B D

Figure 4.7

(i) Explain why the flow along SB cannot exceed 10 units.


(ii) Show that the flow SACT = 8, SADT = 5, SBCT = 5, SBDT = 5 is feasible.
‘SACT = 8’ means that
there is a flow of 8 units
along the route SACT.

52

9781510403130.indb 52 20/03/18 7:48 AM


Solution
(i) The capacities of the arcs leaving B are BC = 5 and BD = 5, so at most
4
10 units can leave B. Therefore no more than 10 units can enter B, so the
8 from SACT and 5 from flow in SB cannot exceed 10.
SADT.

Chapter 4 Further network problems


(ii)
Arc Flow Capacity Vertex Flow in Flow out
SA 8 + 5 = 13 13 S – 23
To show that the flow is SB 5 + 5 = 10 12 A 13 13
feasible, you need to show AC 8 10 B 10 10
that the total flow along
AD 5 5 C 13 13
each arc does not exceed
its capacity and that, at BC 5 5 D 10 10
each vertex, the flow in is BD 5 5 T 23 –
equal to the flow out.
CT 8 + 5 + 13 13
DT 5 + 5 = 10 12

Table 4.11 Table 4.12

For each arc, flow ⩽ capacity  Flow in = flow out at each vertex
(apart from the source and sink)

In Example 4.4, the flow through the network was 23 units, but is this the
maximum possible flow from S to T?
One way to find a maximum flow is to consider making ‘cuts’ through the
network.
l A cut is a partition of the vertices into two sets so that one set contains the
The capacity of a cut is
sometimes called the source and the other contains the sink.
value of the cut, but note l Any arc from a vertex in the source set to a vertex in the sink set is a cut arc.
that it is calculated using
the capacities of the arcs l The capacity of a cut is the maximum possible flow across the cut, from
not the values of any given S to T, without any regard to the rest of the network. This is the sum of the
flow. capacities of the cut arcs that can flow from S to T. If a cut arc can only flow
from T to S, then it contributes 0 to the capacity of the cut.
The capacity (or value) of a cut is the maximum flow that would spill out if the
arcs actually were cut.

Example 4.5 There are 16 possible cuts for the network in Example 4.5.
List these cuts and find the capacity of each.

53

9781510403130.indb 53 20/03/18 7:48 AM


Network flows

Solution
Cut Capacity Cut Capacity
{S}{ABCDT} 13 + 12 25 {SBC}{ADT} 13 + 5 + 10 + 13 41
{SA}{BCDT} 12 + 10 + 5 27 {SBD}{ACT} 13 + 5 + 5 + 12 35
{SB}{ACDT} 13 + 5 + 5 23 {SCD}{ABT} 13 + 12 + 10 + 5 + 13 + 5 + 5 + 12 75
{SC}{ABDT} 13 + 12 + 10 + 5 + 13 53 {SABC}{DT} 5 + 5 + 13 23
{SD}{ABCT} 13 + 12 + 5 + 5 +12 47 {SABD}{CT} 10 + 5 + 12 27
{SAB}{CDT} 10 + 5 + 5 + 5 25 {SACD}{BT} 12 + 5 + 5 + 13 + 12 47
{SAC}{BDT} 12 + 5 + 5 + 13 35 {SBCD}{AT} 13 + 10 + 5 + 13 + 12 53
{SAD}{BCT} 12 + 10 + 5 + 12 39 {SABCD}{T} 13 + 12 25

The minimum cut forms a ‘bottleneck’ that restricts the amount that can flow from
S to T.
For the cuts in Example 4.6, the minimum cuts are {SB}{ACDT} and {SABC}
{DT} = 23, so 23 is the maximum flow.
When the maximum flow happens, the arcs in these cuts are saturated (full to
capacity).
The maximum flow/minimum cut theorem says that
the maximum flow through a network equals the minimum cut.
Checking every possible cut is not usually a practical way to find a maximum flow.
However, if a flow can be found with the same value as a cut, then this must be a
maximum flow and a minimum cut. There are algorithms for finding a minimum
cut, but these are not considered in this book. A different approach, using software,
is used in Chapter 7.

Exercise 4.2 ① B 12 E 12
G

10 3 5
8 10
C
5 F
A 5
10 H
10 10
D cut

Figure 4.8
(i) In the transmission network shown above, identify the source and the sink.
(ii) Find the capacity of the indicated cut.

54

9781510403130.indb 54 20/03/18 7:48 AM


② The network in Figure 4.9 shows a system of pipes through which fluid flows
from S to T. The numbers represent the capacities of the pipes.
A 3 B
4
4 12

Chapter 4 Further network problems


S 8 T

10 11

C 6 D

Figure 4.9
(i) Explain why only arcs AB and AD need to be directed.
(ii) Explain why arc AD cannot be full to capacity.
(iii) Find a flow of 19 from A to T in which the flow from A to B is 3.
(iv) Find a cut that shows that 19 is the maximum flow.
(v) If pipe AB is installed the wrong way round, so the flow is from B to A,
does the maximum flow change?
③ (i) Find minimum cuts for each of these networks.

(a) (b)
A A

2 2
5 5
4 4
D D
5 8 5 8
6 T 6 T
S S
B B
5 8 5 8
E E
2 2
8 8
7 7

C C

Figure 4.10
Confirm that your cuts are minimum cuts by finding a flow of the same
(ii)
value in each network.
④ Gas is supplied to three locations, T1, T2 and T3, from two sources S1 and S2.
The rate of supply from S1 cannot exceed 20 units. The rate of supply from S2
cannot exceed 30 units. There are no constraints on the rate of flow into T1, T2
and T3. The transmission network is shown in Figure 4.11, with pipe capacities
giving the maximum permissible rates of flow.

55

9781510403130.indb 55 20/03/18 7:48 AM


Network flows

A 5 D
10
15

15 10 10 T1
S1
15
12
10
C
10
S2 T2
10 15
B
10
T3

10

Figure 4.11
(i) Add a supersource together with appropriate capacitated edges to model
the supply constraints.
(ii) Add a supersink together with appropriate edges.
(iii) Find the maximum flow and find a cut that has the same value.
⑤ The matrix in Figure 4.12 represents capacities of roads (thousands of cars per
hour) in a road network.
A B C D E F G
A − 3 3 − − 2 −
B 3 − − 5 1 − −
C 3 − − 2 − 3 −
D − 5 2 − − 1 2
E − 1 − − − − 1
F 2 − 3 1 − − 2
G − − − 2 1 2 −

Figure 4.12
Draw the network.
(i)

(ii) Find the maximum hourly flow of cars from B to F, showing how this may
be achieved. Prove that this is a maximum.
⑥ Figure 4.13 shows a fuel distribution system. Fuel is delivered to supply points
at A, B and C. It passes from the supply points through monitoring points J, K,
L and M and on to delivery points at P and Q. The arc weights show capacities
in litres per second.
J 8

A 6 P

4 K 5

B 8 4

4 L 3

C Q

5 M 7

Figure 4.13

56

9781510403130.indb 56 20/03/18 7:48 AM


A supersource S is introduced, with pipelines connecting S to A, B and C.
Pipelines connect P and Q to a supersink T.
(i) Without reference to the flow through J, K, L and M, what are the minimum
4
feasible capacities, in litres per second, of the arcs from the supersource?
(ii) Without reference to the flow through J, K, L and M, what are the

Chapter 4 Further network problems


minimum feasible capacities, in litres per second, of the arcs to the supersink?
(iii) What is the maximum possible flow, in litres per second, through each of
the monitoring points J, K, L and M?
(iv) Deduce the maximum flow from S to T.

LEARNING OUTCOMES
Now you have finished this chapter you should
➤ be able to model precedence problems using activity-on-arc networks
➤ understand the use of dummy activities
➤ be able to carry out a forward pass to find the minimum project completion time
➤ be able to carry out a backward pass to find the critical activities
➤ be able to calculate float and understand what independent float and interfering
float mean
➤ be able to schedule projects with resource restrictions
➤ be able to model a transmission system as a network flow problem
➤ be able to use a supersource or supersink
➤ be able to specify a cut and calculate its capacity
➤ be able to use the maximum flow/minimum cut theorem.

KEY POINTS
1 A precedence problem may be represented using an activity network. Activities
are represented by arcs, durations by arc weights and events by vertices.
2 An activity network must have a single start and a single finish.
3 A dummy activity may be needed so that an arc can be uniquely labelled using
the events at its ends.
A dummy activity may be needed to establish a precedence.
Dummy activities have duration 0 and are shown as dashed lines.
4 The minimum time in which a project can be completed, assuming no
unexpected delays, is called the minimum project completion time. This is the
length of the longest path.
5 Any activity on a longest path is called a critical activity. A delay in a critical
activity will delay the entire project.
6 A forward pass is made through the network, from the start to the finish, to find
the earliest time for each event.
The earliest time at any event is the earliest time at which the activities leading
into the event can be completed. Some of these activities may be completed
before this time but the event cannot occur until they are all completed.
7 A backward pass is made through the network, from the finish to the start, to
find the latest time for each event.
The latest time at any event is the latest time at which the activities coming
from the event can be started for the project to finish in the minimum project
completion time.

57

9781510403130.indb 57 20/03/18 7:48 AM


Network flows

8 The float (or total float) for activity (i, j) is given by


(latest event time at j – earliest event time at i) – duration
Independent float for activity (i, j) is given by
(earliest event time at j – latest event time at i) – duration
or 0 if this calculation gives a negative answer
Interfering float = total float – independent float.
9 A cascade chart has a horizontal time scale, a row showing the critical activities
and a row for each non-critical activity.
Non-critical activities are shown starting at their earliest possible start time and
the float is shown at the end of the activity.
10 A resource histogram shows how many workers are needed at each time, with
each activity starting at its earliest possible time.
11 A schedule (or timetable) shows which activity each worker needs to be doing at
each time.
12 In a network flow problem, the weights on the arcs show capacities and the
maximum continuous flow from the start to the finish is required.
The flow along any arc cannot exceed the capacity of the arc.
13 If there are multiple sources, then a single supersource is used to supply the
sources.
If there are multiple sinks, then a single supersink is used that all the sinks
drain into.
14 At every vertex, apart from the source and sink, the flow that enters the vertex
must be equal to the flow that leaves the vertex.
15 A cut is a partition of the vertices into two sets, so that one set contains the
source and the other contains the sink.
Any arc from a vertex in the source set to a vertex in the sink set is a cut arc.
The capacity (or value) of a cut is the maximum possible flow across the cut,
from S to T. This is the sum of the capacities of the cut arcs that can flow from
S to T. If a cut arc can only flow from T to S, then it contributes 0 to the capacity
of the cut.
16 The maximum flow through a network equals the minimum cut.

58

9781510403130.indb 58 20/03/18 7:48 AM


5 Linear programming

You don’t get any points Think about a product that you might make to sell at a fundraising event. What
factors affect how much profit you can make?
in life for doing things
the hard way.
Tim Fargo
1 Formulating linear programming
problems
Linear programming was developed in the Second World War to solve logistical
problems.
A linear programming (LP) problem is an optimisation problem that requires the
maximum or minimum value of some linear function of some variables, subject to
some constraints that are also linear functions of the variables.
Formulating a problem means translating the problem into a mathematical form
using equations and inequalities.
● First, you need to identify the variables (the quantities that can take different
values) and their units, where appropriate. The variables are usually defined
using ‘Let x = …, let y = …’, etc.
● Next, determine what factors restrict the values of the variables and formulate
the constraints algebraically.
● Finally, the objective needs to be identified; this consists of an objective
function together with a statement of whether this is to be maximised or
minimised.

59

9781510403130.indb 59 20/03/18 7:48 AM


Formulating linear programming problems

Example 5.1 A factory produces two types of drink – an ‘energy’ drink and a ‘refresher’ drink.
Each drink requires syrup, vitamin supplements and flavouring, as shown in
Table 5.1. The final row of the table shows how much of each ingredient is
available for a day’s production.
Syrup Vitamin Flavouring
(litres) supplement (units) (cm3)
5 litres of energy drink 1.25 2 30
5 litres of refresher drink 1.25 1 20
Amount available 250 300 4800
Table 5.1
The manager wants to plan how much of each drink to make to maximise the
profit from the day’s production. The manager knows that all the drink produced
can be sold to give a profit of £1 per litre for the energy drink and 80p per litre
for the refresher drink.
(i) Define suitable variables for this problem.
(ii) Write the constraints algebraically.
(iii) State the objective.

Solution
(i) The manager can vary the amount of each type of drink that is made, so the
variables are
x = amount of energy drink made, in litres
y = amount of refresher drink made, in litres.
(ii) The constraints come from the amount of each ingredient needed.
Every 5 litres of energy drink uses 1.25 litres of syrup, so 1 litre of energy drink
uses 0.25 litres of syrup and x litres of energy drink uses 0.25x litres of syrup.
Similarly, y litres of refresher drink uses 0.25y litres of syrup.
To make x litres of energy drink and y litres of refresher drink,
0.25x + 0.25y litres of syrup are needed.
There are 250 litres of syrup available, so 0.25x + 0.25y ⩽ 250. This may be
divided through to simplify the coefficients: x + y ⩽ 1000
A similar argument for the vitamin supplements gives the constraint
0.4x + 0.2y ⩽ 300, which can be simplified to give 2x + y ⩽ 1500.
The flavouring gives the constraint 6x + 4y ⩽ 4800 or 3x + 2y ⩽ 2400.
Additionally, the variables x and y cannot be negative, so there will be non-
negativity constraints x ⩾ 0 and y ⩾ 0.
(iii) The objective is to maximise the profit. The profit (in £) is given by
P = x + 0.8y. This is the objective function.
This completes the formulation of the problem.
Maximise P = x + 0.8y
subject to x + y ⩽ 1000
Sometimes these non- 2x + y ⩽ 1500
negativity constraints are 3x + 2y ⩽ 2400
assumed.
and x ⩾ 0, y ⩾ 0.

60

9781510403130.indb 60 20/03/18 7:48 AM


Standard linear programming form is when a problem has been formulated
in terms of non-negative variables as a linear objective to be maximised subject to
linear constraints, each of which is less than or equal to a non-negative constant. 5
If the information about the constraints is given in ‘ratio form’ (as in Example 5.2)
it may be useful to try out some numerical values first.

Chapter 5 Linear programming


Example 5.2 Tammy makes tanning lotions which she sells to beauty salons. She makes three
different lotions using the same basic ingredients but in different proportions.
These lotions are called amber, bronze and copper.
To make one litre of tanning lotion she needs one litre of fluid; this can either be
water or water mixed with hempseed oil. One litre of amber lotion uses one litre
of water, one litre of bronze lotion uses 0.8 litres of water and one litre of copper
lotion uses 0.5 litres of water; any remainder is made up of hempseed oil. Tammy
has 40 litres of water and 7 litres of hempseed oil available.
(i) By defining appropriate variables, show that the constraint on the amount of
water used can be written as 10a + 8b + 5c ⩽ 400.
(ii) Find a similar constraint on the amount of hempseed oil used.
There is enough of the tanning ingredient to make 20 litres of amber lotion or
40 litres of bronze lotion or 100 litres of copper lotion.
(iii) Form constraints on the amount of tanning ingredient available.
(iv) What other constraints are there on the values of a, b and c?
[OCR, GCE Mathematics, Paper 4736/01, June 2014 adapted]

Solution
(i) Let a = amount of amber lotion made, in litres.
The variables may need Let b = amount of bronze lotion made, in litres.
to be adjusted to give Let c = amount of copper lotion made, in litres.
the required constraint,
but this seems to be a The amount of water needed is 1a + 0.8b + 0.5c litres and this cannot
sensible starting point. exceed 40 litres. This confirms that
This gives the constraint a + 0.8b + 0.5c ⩽ 40, the choices for the
variables, and their
which scales up to give 10a + 8b + 5c ⩽ 400. units, were right.

(ii) The amber lotion uses no hempseed oil. Each litre of bronze lotion uses
0.2 litres of hempseed oil and each litre of copper lotion uses 0.5 litres of
hempseed oil.
The amount of hempseed oil needed is 0.2b + 0.5c litres and this cannot
exceed 7 litres.
This gives the constraint 0.2b + 0.5c ⩽7
which scales up to give 2b + 5c ⩽ 70.
(iii) There is enough of the tanning ingredient to make 20 litres of amber lotion
or 40 litres of bronze lotion or 100 litres of copper lotion. This means that
a ⩽ 20, b ⩽ 40 and c ⩽ 100. But if a = 20, then this uses all of the tanning
ingredient, leaving none for the other two types of lotion.

61

9781510403130.indb 61 20/03/18 7:48 AM


Formulating linear programming problems

Suppose that there are 200 units of the tanning ingredient available (200
has been chosen because it is a multiple of 20, 40 and 100). Then 20 litres
of amber lotion uses 200 units of the tanning ingredient, so 1 litre of amber
lotion uses 10 units of the tanning ingredient and a litres of amber lotion
uses 10a units of the tanning ingredient.
Similar reasoning for the other two lotions leads to the following constraint
10a + 5b + 2c ⩽ 200
(iv) The variables a, b and c must be non-negative
a ⩾ 0, b ⩾ 0 and c ⩾ 0

Integer programming
In the problems in Examples 5.1 and 5.2, the variables were continuous, but
sometimes the variables are restricted to take integer values. This leads to an
integer linear programming problem (ILP). An ILP problem is exactly the
same as a linear programming problem except that it has the additional restriction
that the variables are integer-valued. This restriction would usually be stated at the
end of the formulation (after the non-negativity constraints).

Exercise 5.1 ① There are two processes involved in making cards: printing and folding. There
is a time of 6000 seconds available for each process. The printing must be done
in the morning and the folding in the afternoon.
Two types of cards are available. Table 5.2 shows the number of seconds that a
card of each type takes to print and to be folded. The profit on a card of each
type is also shown.
Printing time per Folding time per Profit per
Type of card
card (seconds) card (seconds) card (pence)
X 1 3 2
Y 2 1 5
Table 5.2
Let x be the number of cards of type X and y be the number of cards of type Y.
The values of x and y that give the maximum profit are required.
Formulate this as an integer programming problem in standard linear
programming form.
② The contract conditions imposed by a coach company on hiring out a minibus
are as follows:
The total number of passengers must not exceed 14.
The total number of passengers must be at least 10.
There must be at least one adult for each child.
The cost of hiring the minibus is £10 for each adult and £5 for each child.
Formulate the problem of finding the minimum amount that the coach
company can receive for the hire of its minibus.
③ A car park has a usable area of 300 m2 which is to be marked out for small cars and
large cars. A small car space uses 10 m2 and a large car space uses 12 m2.The number
of spaces for large cars must be at least 1.5 times the number of spaces for small cars.
All other considerations, such as the shape of the car park and allowing room
to manoeuvre into the spaces, may be ignored.
62

9781510403130.indb 62 20/03/18 7:49 AM


The owner of the car park wants to know how many spaces should be marked
out for small cars and how many for large cars to maximise the number of cars
that can be parked. 5
Formulate this as an integer linear programming problem.
④ A robot can walk at 1.5 m s–1 or run at 4 m s–1. The batteries hold enough

Chapter 5 Linear programming


charge for the robot to walk 9000 metres or run 3000 metres.
Let x be the time (in seconds) for which the robot walks and y be the time
(in seconds) for which the robot runs.
(i) Find the maximum values of x and y.
The problem is to find the greatest distance that the robot can travel in half an hour.
(ii) Formulate the problem in standard linear programming form.

2 Graphical solutions
When a problem has just two variables it can be illustrated graphically.

Drawing the feasible region


The first step in constructing a graphical solution is to draw the feasible region
(FR). This is the set of points that satisfy all the constraints.
To graph a constraint, the boundary line (where the inequality becomes an =) is
drawn. This is done for each constraint.
When all the boundary lines have been drawn, you need to indicate the feasible
region. One way to do this is to shade the side of each line for which the constraint
is not true so that, at the end, the unshaded region is the feasible region. This is
illustrated in Example 5.3.

Example 5.3 Draw a graph to show the feasible region for the problem from Example 5.1.

Solution
The line 2x + y = 1500
cuts the axes at (750, 0)
and (0, 1500); the side
containing (0, 0) is not
shaded
The line x + y = 1000 y
cuts the axes at 1500
(1000, 0) and (0, 1000); The line 3x + 2y = 2400
the side containing 1000 cuts the axes at (800, 0)
(0, 0) is not shaded and (0, 1200); the side
500 containing (0, 0) is not
shaded

O 500 1000 x

The non-negativity
constraints mean that
the region to the left of
the y-axis and the region
below the x-axis are shaded

Figure 5.1

63

9781510403130.indb 63 20/03/18 7:49 AM


Graphical solutions

Finding the optimal solution


The optimal solution then needs to be found. One way to find the optimal solution
is to draw some lines corresponding to certain values of the objective function and
deduce where the objective is maximised (or minimised). This method is called
using a profit line.
In Example 5.1, the objective function was given by P = x + 0.8y.
Figure 5.2 shows the feasible region for this problem, found in Example 5.3, and
two lines which represent P = 400 and P = 800, respectively.

y
1500 x + 0.8y = 800 is
the line through
1000 (800, 0), (0, 1000)
x + 0.8y = 400
is the line through
(400, 0), (0, 500) 500

O 500 1000 x

Figure 5.2

The profit lines are parallel and the direction of increasing profit is shown by the
arrow. By sliding the profit lines, the last point in the feasible region is where the
line x + y = 1000 cuts the line 3x + 2y = 2400.
The optimum value will always occur at a vertex of the feasible region (it may
occur at two vertices and then the whole of the line between these points will also
give optimal points). This means that another way to locate the optimum point is to
check the value of P at the vertices (or at least at some of the vertices). This method
is called vertex checking.
The coordinates of the vertices of the feasible region are found by solving pairs of
simultaneous equations.
Often a combination of the two methods is used, particularly when changes are
made to the coefficients after the feasible region has been drawn.

Example 5.4 For the problem in Example 5.1:


(i) Calculate the vertices of the feasible region.
(ii) Calculate the value of P at each vertex.
(iii) Deduce the solution to the problem.

Solution
(i) x + y = 1000 and 3x + 2y = 2400.
Solving simultaneously gives x = 400, y = 600.
2x + y = 1500 and 3x + 2y = 2400.
Solving simultaneously gives x = 600, y = 300.
The vertices of the feasible region are
(0, 0), (750, 0), (600, 300), (400, 600), (0, 1000).

64

9781510403130.indb 64 20/03/18 7:49 AM


(ii) P = x + 0.8y
x y P 5
0 0 0
750 0 750
600 300 840

Chapter 5 Linear programming


400 600 880
0 1000 800
Table 5.3
(iii) The maximum value of P is 880, when x = 400 and y = 600.
Always give the solution The manager should choose to make 400 litres of energy drink and 600
in the context of the
original problem. litres of refresher drink for a profit of £880.

Using technology
Small linear programming problems can be investigated using a spreadsheet solver.
Consider again the energy drink problem from Example 5.1.
Maximise P = x + 0.8y
subject to x + y ⩽ 1000
2x + y ⩽ 1500
3x + 2y ⩽ 2400
and x ⩾ 0, y ⩾ 0.
This can be set up on a spreadsheet as follows.

Figure 5.3

By putting values into cells C3 and D3, the value of P is calculated in cell E4 and
the values of the left-hand side of each constraint is calculated in cells E6 to E8 and
compared with the upper limits in cells F6 to F8.
The calculation of the formulae for cells E4 and E6 to E8 can be done easily using
the SUMPRODUCT function. Alternatively, the use of $ enables the formulae to
TECHNOLOGY be copied from cell E4 into cells E6 to E8.
Set up a spreadsheet Different values can be tried out in cells C3 and D3. This approach could also be
as shown in figure 5.3. used for a three-variable problem. Some spreadsheets have a linear programming
Experiment with different
values in cells C3 and D3.
solver which solves linear programming problems set out in this format.

65

9781510403130.indb 65 20/03/18 7:49 AM


Graphical solutions

Linear programming problems in augmented form


At the optimum point, two of the constraints will be at their maximum values but
the other constraints will have some slack.
The linear programming formulation can be rewritten in augmented form by
introducing non-negative slack variables. The constraints then become equations
and the boundary lines of the feasible region each correspond to a variable (or slack
variable) being 0.
This formulation enables the variables and slack variables all to be regarded in the
same way. This is used to explain what the terms non-basic and basic variables mean
(see below), which is useful for the geometrical interpretation of the feasible region.
The augmented form is also needed for the simplex algorithm in Chapter 6.
The vertices of the feasible region are called basic feasible solutions and are
where two boundary lines intersect. These will correspond to two of the variables
(or slack variables) being 0; these are called the non-basic variables. The other
variables are called the basic variables at that point.

Example 5.5
The line 2x + y = 1500
cuts the axes at (750, 0)
and (0, 1500); the side
containing (0, 0) is not
shaded
The line x + y = 1000 y
cuts the axes at 1500
(1000, 0) and (0, 1000); The line 3x + 2y = 2400
the side containing 1000 cuts the axes at (800, 0)
(0, 0) is not shaded and (0, 1200); the side
500 containing (0, 0) is not
shaded

O 500 1000 x

The non-negativity
constraints mean that
the region to the left of
the y-axis and the region
below the x-axis are shaded

Figure 5.4
(i) Reformulate the problem in Example 5.1 in augmented form.
(ii) Interpret the boundaries of the feasible region in terms of variables or slack
variables being 0.
(iii) Write down which variables are non-basic at the vertices of the feasible
region and find the values of the basic variables at each vertex.
(iv) Interpret the values of the basic and non-basic variables at the optimum point.

66

9781510403130.indb 66 20/03/18 7:49 AM


Solution
(i) Introduce non-negative slack variables s, t and u to take up the slack in the
5
inequalities that define the constraints.
Maximise P = x + 0.8y

Chapter 5 Linear programming


subject to x + y + s = 1000
2x + y + t = 1500
3x + 2y + u = 2400
and x ⩾ 0, y ⩾ 0, s ⩾ 0, t ⩾ 0, u ⩾ 0.

(ii) Working anticlockwise around the feasible region starting from the origin,
the boundaries of the feasible region are y = 0, t = 0, u = 0, s = 0, x = 0.
(iii)
Vertex Non-basic variables Basic variables
(0, 0) x = 0, y = 0 s = 1000, t = 1500, u = 2400
(750, 0) t = 0, y = 0 x = 750, s = 250, u = 150
(600, 300) t = 0, u = 0 x = 600, y = 300, s = 100
(400, 600) u = 0, s = 0 x = 400, y = 600, t = 100
(0, 1000) s = 0, x = 0 y = 1000, t = 500, u = 400
Table 5.4
(iv) At the optimum point, x = 400, y = 600, s = 0, t = 100, u = 0.
Make 400 litres of energy drink and 600 litres of refresher drink. This
uses all the syrup and flavouring. There are 100 ÷ 5 = 20 units of vitamin
supplement that are unused (the division being needed because the
constraint 0.4x + 0.2y ⩽ 300 was scaled by a factor of 5 to simplify the
coefficients).

Notes
● For an ILP problem, the optimum will be at a grid point within the feasible region.
A heuristic approach is to solve the LP problem (for non-negative real variables) and
then investigate integer-valued feasible points near the solution. If the gradient of
the objective function is similar to the gradient of a boundary of the feasible region,
then it is possible that the optimum for the ILP problem is a long way from the
optimum for the LP problem.
● For a minimisation problem, the profit line slides the other way and the feasible
region may be unbounded.
● In some situations, the variables may be permitted to take negative values. Such a
problem can be reformulated in standard form by redefining the variables.

Linear programming in three dimensions


A linear programming problem with three variables will be represented in
3 dimensions by intersecting planes that define a convex polyhedron. Each
boundary plane will correspond to a variable (or slack variable) being 0, the edges
to pairs of variables being 0 and the vertices to triples of variables being 0.

67

9781510403130.indb 67 20/03/18 7:49 AM


Graphical solutions

ACTIVITY 5.1
(i) Use a 3-dimensional graph plotter to represent the feasible region for the
following linear programming problem given in augmented form.
Maximise P = 9x + 10y + 6z
subject to 2x + 3y + 4z + s = 3
6x + 6y + 2z + t = 8
and x ⩾ 0, y ⩾ 0, z ⩾ 0, s ⩾ 0, t ⩾ 0.
(ii) Find the coordinates of each vertex of the feasible region by setting, in turn,
three of the variables to zero and by considering all possible combinations of
three variables.
(iii) Find the vertex which maximises the objective function.

For a 3-dimensional problem, one of the constraints may give an equation that
enables the problem to be reduced to a 2-dimensional problem in two variables.

Exercise 5.2 ① Solve the following linear programming problem.


Maximise P = x + 2y
subject to 4x + 5y ⩽ 45
4x + 11y ⩽ 44
x+y⩽6
and x ⩾ 0, y ⩾ 0.
② A manufacturer has to decide how much of each of two types of cloth to
produce each day.
Each metre of cloth A requires 2 kg of wool, 21 litre of dye, 4 minutes of
preparation time and 5 minutes of loom time. The profit on each metre of
cloth A is £3.
Each metre of cloth B requires 1 kg of wool, 13 litre of dye, 5 minutes of
preparation time and 4 minutes of loom time. The profit on each metre of
cloth B is £2.50.
Each day, the manufacturer has 100 kg of wool and 28 litres of dye. There are
6 hours of preparation time available in the morning and 6 hours of loom time
available in the afternoon.
(i) Formulate the constraints on the amount of each type of cloth produced,
apart from non-negativity.
(ii) Show that the constraint on loom time is redundant.

(iii) Find how much of each type of cloth the manufacturer should produce
each day to maximise the profit.
③ Solve the following integer linear programming problem.
Maximise P=x+y
subject to 3x + 4y ⩽ 12
2x + y ⩽ 4
and x ⩾ 0, y ⩾ 0
with x and y integers.
④ An airline operator needs to decide how many rows of seats in its new plane
will be club class and how many will be economy class. The plane can have up

68

9781510403130.indb 68 20/03/18 7:49 AM


to 30 rows of seats in total. Each club class row has 4 seats and each economy
class row has 6 seats.
The operator believes that at most 40 club class tickets will be sold. Club class
5
tickets cost 25% more than economy class tickets.
On long haul flights the plane must not carry more than 150 passengers.

Chapter 5 Linear programming


The operator wants to maximise the income from ticket sales.
(i) Explain why this can be formulated as the following integer linear
programming problem.
Maximise 5x + 6y
subject to x + y ⩽ 30
4x + 6y ⩽ 150
x ⩽ 10
and x ⩾ 0, y ⩾ 0
with x and y integers.
(ii) Solve the problem graphically.

On short flights less fuel is needed and the plane can carry more passengers.
(iii) What must the capacity of the plane be if the constraint x + y ⩽ 30 is not
redundant?
[MEI]
⑤ A chef has 2000 g of lentils, 10 000 g of potatoes and 3000 g of carrots, together
with store-cupboard basics such as onions, stock, crème fraiche, herbs and
spices with which to make some soup.
Table 5.5 shows the quantities of lentils, potatoes and carrots used to make 12
portions of each of the three soups, together with the profit if all the portions sell.

Soup (recipe for


Lentils (g) Potatoes (g) Carrots (g) Profit (£)
12 portions)
Lentil and potato 200 1600    0 3.00
Spiced carrot and lentil 420    0 1800 3.60
Winter warmer   0 1800 1200 6.00
Table 5.5

The chef makes 12x portions of lentil and potato soup, 12y portions of spiced
carrot and lentil soup and 12z portions of winter warmer soup.
(i) Write down and simplify constraints on the values of x, y and z from the
quantities of lentils, potatoes and carrots available.
(ii) What is the maximum possible value of x?

The chef wants to use all the carrots.


(iii) Write z as a function of y and hence reduce the non-trivial constraints to
two constraints in x and y only.
(iv) Formulate the problem of finding the values of x and y that maximise the
profit, assuming that all the soup sells.
The optimal solution is to make 75 portions of lentil and potato soup, 20
portions of spiced carrot and lentil soup and no winter warmer soup.
(v) What quantity of lentils remains unused?

69

9781510403130.indb 69 20/03/18 7:49 AM


Graphical solutions

LEARNING OUTCOMES
Now you have finished this chapter you should
➤ be able to formulate a linear programming problem in standard form
➤ be able to use slack variables to convert a linear programming problem in
standard form to augmented form
➤ recognise when a problem requires integer solutions
➤ be able to solve a 2-dimensional linear programming problem graphically
➤ be able to consider the effect of modifying coefficients in the constraints or the
objective function
➤ understand how a 3-dimensional linear programming problem can be reduced
to a 2-dimensional linear programming problem when one constraint is an
equality.

KEY POINTS
1 Formulating a problem involves identifying the variables and then formulating
algebraic constraints and an objective.
2 Standard linear programming form is when a problem has been formulated in
terms of non-negative variables as a linear objective to be maximised subject
to linear constraints, each of which is less than or equal to a non-negative
constant.
3 An integer linear programming (ILP) problem is the same as a linear
programming problem except that it has the additional restriction that the
variables are integer-valued.
4 The feasible region (FR) is the set of points that satisfy all of the constraints.
5 The optimal solution can be found by using a profit line or by vertex checking.
6 Non-negative slack variables can be used to rewrite a standard linear
programming formulation in augmented form. The constraints become
equations and the boundaries of the feasible region each correspond to a
variable (or slack variable) being 0.
7 The vertices of the feasible region are called basic feasible solutions. At a basic
feasible solution, two of the variables will be 0; these are called the non-basic
variables. The other variables are called the basic variables at that point.
8 For an integer linear programming problem, the optimum solution will be at a
grid point within the feasible region.
9 Linear programming problems with three variables are represented in
3-dimensions but it may be possible to reduce them to 2-dimensional problems
and solve them graphically.

70

9781510403130.indb 70 20/03/18 7:49 AM


6 Simplex method

Simplex munditiis (so What is the maximum value of P = x + 2y + 3z where x, y and z are integers with
x ⩾ 1, y ⩾ 2, z ⩾ 3 and 2x + 3y + z ⩽ 25?
simple, so neat).
Horace (65−27bc)

1 Using a simplex tableau


Linear programming problems with two variables can be solved graphically but
most realistic problems have far more than two variables. The graphical method
can be set up algebraically, using simultaneous equations, but it becomes difficult to
keep track of what is happening. A simplex tableau is a way of recording the results.
Using this method, a linear programming problem is stated in augmented form
with the objective function rewritten so that it has the same form as the constraints,
with all the variables on the left-hand side and a constant on the right-hand side.
A simplex tableau has a column for the objective variable (P ) followed by columns
for the variables (x, y, …) and then the slack variables (s, t, …). There is a final
column for the right-hand side (RHS). The first row shows the coefficients in
the objective function, which is to be maximised, and the other rows show the
coefficients in the constraints (in the order corresponding to the slack variables).
This is essentially a matrix representation of the linear programming problem with
the objective rewritten to match the form of the constraints.

71

9781510403130.indb 71 20/03/18 7:49 AM


Using a simplex tableau

The initial tableau


Example 6.1 The drinks manufacturer problem from Chapter 5 gave this linear programming
problem in augmented form.
Maximise P = x + 0.8y The variables s, t and u are
subject to x + y + s = 1000 slack variables.

2x + y + t = 1500
3x + 2y + u = 2400
and x ⩾ 0, y ⩾ 0, s ⩾ 0, t ⩾ 0, u ⩾ 0.
Represent this problem as an initial simplex tableau.

Solution
The objective function is written as P − x − 0.8y (+ 0s + 0t + 0u) = 0, and
similarly for the constraints, to give this initial simplex tableau.
P x y s t u RHS
1 −1 −0.8 0 0 0 0
0 1 1 1 0 0 1000
0 2 1 0 1 0 1500
0 3 2 0 0 1 2400

Table 6.1

The basic variables are shown by columns consisting of all 0s apart from a single 1
(basis columns); the non-basic variables are shown by columns that do not have this
form (non-basis columns).
The value of each non-basic variable is 0.
The value of each basic variable (and the objective) is found by reading down its
basis column to the 1 and then across to the value in the RHS column.

Example 6.2 Write down the values of the variables at the basic feasible solution represented
by the initial simplex tableau in the solution to Example 6.1.

Solution
x and y are non-basic and have the value 0.
s, t and u are the basic variables with values s = 1000, t = 1500, u = 2400.
The value of the objective is P = 0.
P x y s t u RHS
1 −1 −0.8 0 0 0 0
0 1 1 1 0 0 1000
0 2 1 0 1 0 1500
0 3 2 0 0 1 2400
Table 6.2
The initial basic feasible solution is the point (0, 0)
72

9781510403130.indb 72 20/03/18 7:49 AM


Choosing a pivot
The simplex algorithm is used to move from one basic feasible solution to another 6
where the objective is either greater or the same. Each iteration requires a suitably
chosen pivot; the pivot will determine a basic variable and a non-basic variable that
exchange roles. The other basic variables remain basic, although their values will

Chapter 6 Simplex method


change, and the other non-basic variables remain non-basic.
l The first step of the algorithm is to choose a pivot column. The pivot column
is chosen to correspond to a non-basic variable so that, when this variable
becomes positive, the objective function will increase in value. This requires a
column for which the entry in the objective row is negative.
Although it is not always the case that the most negative entry will give the
biggest increase in the value of P, it is not unusual for this to be the case. When
there is a choice of pivot column, unless instructed otherwise, choose the one
with the most negative entry in the objective row (or the first of these if there is
more than one with the same value).
l The second step is to choose a pivot row. This involves finding a row for which
entry in RHS column
the entry in the pivot column is positive and the ratio is
entry in pivot column
minimised.

Example 6.3 (i) Find the pivot element for the initial simplex tableau in the solution to
Example 6.1.
(ii) By referring to the feasible region in Example 5.3, interpret the pivot choice
geometrically.

Solution
(i) The most negative entry in the objective row is −1 in the x column.
For positive entries in the pivot column, the ratios are
1000 ÷ 1 = 1000
1500 ÷ 2 = 750
2400 ÷ 3 = 800
The minimum ratio is 750 so the pivot row is the third row (which
previously corresponded to the basic variable t).
The pivot element is the 2 in the third row of the x column.
x will become basic and t will become non-basic.
(ii) Geometrically, this corresponds to moving along the edge y = 0 and checking
where it meets s = 0, t = 0 and u = 0. In this case, these points are (1000, 0),
(750, 0) and (800, 0), respectively. The first of these to be reached is (750,
0) and that becomes the next basic feasible solution.

73

9781510403130.indb 73 20/03/18 7:49 AM


Using a simplex tableau

Carrying out an iteration


The system of equations is now manipulated to exchange the roles of the basic and
non-basic variable that are determined by the pivot. This is called an iteration of the
tableau.
l Each entry in the pivot row is divided by the value of the pivot element.
l Each of the other rows is replaced by
current row ± multiple of pivot row
where the multiple is chosen to make the entry in the pivot column become 0.

Example 6.4 Carry out an iteration of the initial simplex tableau from Example 6.1 and
interpret the resulting tableau.

Solution
The pivot entry is 2, so each element in the pivot row is divided by 2.
This gives 1 in the pivot cell.
For each of the other rows, k times the new pivot row is then subtracted from
the row, where k is the entry in the pivot column of that row.
This gives the value 0 in the pivot column of that row.
Initial tableau
P x y s t u RHS
If necessary, use fractions 1 −1 −0.8 0 0 0 0
to ensure that rounding 0 1 1 1 0 0 1000
errors do not creep in. 0 2 1 0 1 0 1500
0 3 2 0 0 1 2400
Table 6.3
After 1st iteration
P x y s t u RHS
1 0 −0.3 0 0.5 0 750 Row 1 + new pivot row
0 0 0.5 1 −0.5 0 250 Row 2 − new pivot row
As a check, there should
be the same number of 0 1 0.5 0 0.5 0 750 New pivot row
basis columns as in the 0 0 0.5 0 −1.5 1 150 Row 4 − 3 × new pivot row
initial tableau, the entries
in the right-hand column Table 6.4
should still be non-
negative and the value of P
The resulting tableau has P = 750, x = 750, y = 0, s = 250, t = 0, u = 150.
should have increased (or It corresponds to the basic feasible solution (750, 0) with P = 750.
stayed the same if the ratio
was 0). This is the vertex where the edge y = 0 meets t = 0.

74

9781510403130.indb 74 20/03/18 7:49 AM


In the activity below, you will carry out the algebraic manipulations that lead to the
solution given in Example 6.4.
6
ACTIVITY 6.1

Chapter 6 Simplex method


In the example, the pivot element is in the x column of the row corresponding to
the constraint 2x + y + t = 1500.
Rearrange this constraint to make x the subject.
Substitute for x in the objective function and each of the other constraints.
Compare your results with the tableau after the first iteration given in Example 6.4.

Finding the optimal solution


l If there are no negative entries of the objective row of the resulting tableau, then an
optimal solution has been found. Otherwise, further iterations can be carried out.

Example 6.5 Complete the application of the simplex algorithm for the problem from
Example 6.1, interpreting the result of each tableau.

Solution
The next pivot is chosen from the y column (because of the −0.3 in the
objective row).
P x y s t u RHS
1 0 −0.3 0 0.5 0 750
0 0 0.5 1 −0.5 0 250 250 ÷ 0.5 = 500
0 1 0.5 0 0.5 0 750 750 ÷ 0.5 = 1500
0 0 0.5 0 −1.5 1 150 150 ÷ 0.5 = 300
Table 6.5

The next pivot is from row 4 of the y column.


P x y s t u RHS
1 0 0 0 −0.4 0.6 840 Row 1 + 0.3 × new pivot row
0 0 0 1 1 −1 100 Row 2 − 0.5 × new pivot row
0 1 0 0 2 −1 600 Row 3 − 0.5 × new pivot row
0 0 1 0 −3 2 300 New pivot row
Table 6.6

The resulting tableau has P = 840, x = 600, y = 300, s = 100, t = 0, u = 0.


It corresponds to the basic feasible solution (600, 300) with P = 840.
This is the vertex where the edge t = 0 meets u = 0.
The next pivot is from row 2 of the t column.

75

9781510403130.indb 75 20/03/18 7:49 AM


Using a simplex tableau

P x y s t u RHS
1 0 0 0.4 0 0.2 880 Row 1 + 0.4 × new pivot row
0 0 0 1 1 −1 100 New pivot row
0 1 0 −2 0 1 400 Row 3 − 2 × new pivot row
0 0 1 3 0 −1 600 Row 4 + 3 × new pivot row
Table 6.7

The resulting tableau has P = 880, x = 400, y = 600, s = 0, t = 100, u = 0.


It corresponds to the basic feasible solution (400, 600) with P = 880.
This is the vertex where the edge u = 0 meets s = 0.
There are no more negative values in the objective row so this is an optimal
solution.

Example 6.6 Use the simplex method to find an optimal solution of the following problem.
Maximise P=a+b+c
subject to 10a + 8b + 5c ⩽ 400
2b + 5c ⩽ 70
10a + 5b + 2c ⩽ 200
and a ⩾ 0, b ⩾ 0, c ⩾ 0.

Solution
Initial tableau
P a b c s t u RHS
1 −1 −1 −1 0 0 0 0
0 10 8 5 1 0 0 400
0 0 2 5 0 1 0 70
0 10 5 2 0 0 1 200
Table 6.8
Pivot on the 10 in row 4 of column a.
P a b c s t u RHS
1 0 −0.5 −0.8 0 0 0.1 20
0 0 3 3 1 0 −1 200
0 0 2 5 0 1 0 70
0 1 0.5 0.2 0 0 0.1 20
Table 6.9
Pivot on the 5 in row 3 of column c.
P a b c s t u RHS
1 0 −0.18 0 0 0.16 0.1 31.2
0 0 1.8 0 1 −0.6 −1 158
0 0 0.4 1 0 0.2 0 14
0 1 0.42 0 0 −0.04 0.1 17.2
Table 6.10
76

9781510403130.indb 76 20/03/18 7:49 AM


Pivot on the 0.4 in row 3 of column b.
P a b c s t u RHS 6
1 0 0 0.45 0 0.25 0.1 37.5
0 0 0 −4.5 1 −1.5 −1 95

Chapter 6 Simplex method


0 0 1 2.5 0 0.5 0 35
0 1 0 −1.05 0 −0.25 0.1 2.5
Table 6.11
The optimum has been achieved at a = 2.5, b = 35, c = 0 with P = 37.5.

A degenerate linear programming problem is one in which more than one vertex is
optimal (and all points between these vertices).With a degenerate linear programming
problem, the simplex method will find the optimal value and will reach one of the
optimal solutions. Although the final tableau has no negative values in the objective
row, there will be at least one non-basic column with a 0 in the objective row.
Iterating on a pivot from this column will give a different optimal solution.

Exercise 6.1 ① Use the simplex algorithm to solve the following linear programming problem.
Maximise P = 16x + 24y
subject to 2x + 3y ⩽ 24
2x + y ⩽ 16
y⩽6
and x ⩾ 0, y ⩾ 0.
② Use the simplex algorithm to solve the following linear programming problem.
Maximise P = 9x + 10y + 6z
subject to 2x + 3y + 4z ⩽ 3
6x + 6y + 2z ⩽ 8
and x ⩾ 0, y ⩾ 0, z ⩾ 0.
③ Use the simplex algorithm to solve the following linear programming problem.
Maximise P = 3w + 2x
subject to w + x + y + z ⩽ 150
2w + x + 3y + 4z ⩽ 200
and w ⩾ 0, x ⩾ 0, y ⩾ 0, z ⩾ 0.
④ Use the simplex algorithm to solve the following linear programming problem.
Maximise P = 3w + 2x
subject to w + x + y + z ⩽ 150
2w + x + 3y + 4z ⩽ 200
w⩾x
and w ⩾ 0, x ⩾ 0, y ⩾ 0, z ⩾ 0.

2 Non-standard forms
A problem may be presented in a form that cannot be rearranged into standard
linear programming form.
Sometimes a simple substitution can resolve this issue.
77

9781510403130.indb 77 20/03/18 7:49 AM


Non-standard forms

Example 6.7 A problem is given as follows.

This is the problem


Maximise P = x + 2y +3z
given at the start of this subject to 2x + 3y + z ⩽ 25
chapter, ignoring the
integer constraint.
and x ⩾ 1, y ⩾ 2, z ⩾ 3.
Reformulate the problem in standard linear programming form by letting
X = x − 1, Y = y − 2, Z = z − 3 and Q = P − 14.

Solution
X = x − 1, Y = y − 2 and Z = z − 3, so x ⩾ 1, y ⩾ 2, z ⩾ 3 become
X ⩾ 0, Y ⩾ 0, Z ⩾ 0.
Substituting x = X + 1, y = Y + 2, z = Z + 3 in the objective and the other
constraint gives
P = (X + 1) + 2(Y + 2) + 3(Z + 3) = X + 2Y + 3Z + 14 ⇒ Q = X + 2Y + 3Z
and 2(X + 1) + 3(Y + 2) + (Z + 3) ⩽ 25 ⇒ 2X + 3Y + Z ⩽ 14.
The problem is reformulated as
Maximise Q = X + 2Y +3Z
subject to 2X + 3Y + Z ⩽ 14
and X ⩾ 0, Y ⩾ 0, Z ⩾ 0.

A similar approach can work with variables that can take negative values or form
problems that require the objective to be minimised.
If the inequality in a constraint is ⩾ rather than ⩽, and this cannot be resolved by a
simple substitution, the two-stage simplex method may be used.
The two-stage simplex method is needed because the problem cannot be
formulated with the origin as a basic feasible solution, so the origin cannot be used
as the starting point.
In the two-stage simplex method, instead of adding a non-negative slack variable to
a ⩽ constraint, a non-negative surplus variable is subtracted from a ⩾ constraint.
The column corresponding to the surplus variable will consist of 0s and −1, and
this is resolved by using a non-negative artificial variable (which will eventually
take the value 0).
The artificial variable will need to be minimised.

Example 6.8 Use a surplus variable and an artificial variable to produce an initial simplex
tableau for the following linear programming problem.
Note Maximise P = x + 0.8y
In this case, there are subject to x + y ⩽ 1000
only two variables and a
graphical method could
2x + y ⩽ 1500
be used to show that the 3x + 2y ⩽ 2400
fourth constraint has no
effect on the solution,
x + y ⩾ 800
which is the same as in and x ⩾ 0, y ⩾ 0.
Example 6.5.
Use the two-stage simplex method to solve the problem.

78

9781510403130.indb 78 20/03/18 7:49 AM


Solution
Non-negative slack variables s1, s2, s3 are added to the first three constraints and a 6
non-negative surplus variable is subtracted from the fourth constraint to give
Maximise P = x + 0.8y

Chapter 6 Simplex method


subject to x + y + s1 = 1000
2x + y + s2 = 1500
3x + 2y + s3 = 2400
x + y − s4 = 800
and x ⩾ 0, y ⩾ 0, s1 ⩾ 0, s2 ⩾ 0, s3 ⩾ 0, s4 ⩾ 0.
Then add a non-negative artificial variable a4 to the fourth constraint to make it
into
x + y − s4 + a4 = 800   a4 ⩾ 0.
This gives the following initial simplex tableau.

P x y s1 s2 s3 s4 a4 RHS
1 −1 −0.8 0 0 0 0 0 0
0 1 1 1 0 0 0 0 1000
0 2 1 0 1 0 0 0 1500
0 3 2 0 0 1 0 0 2400
0 1 1 0 0 0 −1 1 800
Table 6.12
There is now an obvious solution, namely, x = 0, y = 0, s4 = 0 (s1 = 1000,
s2 = 1500, s3 = 2400, a4 = 800). However, this artificial solution does not
represent a solution to the original problem, without the artificial variable.
This is resolved by adding a new objective.
The first row represents Minimise A = a4 = 800 − x − y + s4
the new objective, to be
used in the first stage ⇒ A + x + y − s4 = 800
of the simplex method.
It gives the sum of the The resulting initial tableau for the two-stage simplex method is then as follows.
artificial variables (in
this case a4 = 800). A P x y s1 s2 s3 s4 a4 RHS
1 0 1 1 0 0 0 −1 0 800
The second row gives the
0 1 −1 −0.8 0 0 0 0 0 0
original objective, which
will come into action in 0 0 1 1 1 0 0 0 0 1000
the second stage (once 0 0 2 1 0 1 0 0 0 1500
a basic feasible solution
for the original problem 0 0 3 2 0 0 1 0 0 2400
has been found). 0 0 1 1 0 0 0 −1 1 800
Table 6.13
The remaining rows are The iterations will be exactly as before, except that, because the first stage
the constraints.
requires a minimisation, the pivot column must have a positive entry in the
first objective row.

79

9781510403130.indb 79 20/03/18 7:49 AM


Non-standard forms

First stage
Using the x column as the first pivot column, the ratios (for positive entries in the
x column) are 1000 ÷ 1 = 1000, 1500 ÷ 2 = 750, 2400 ÷ 3 = 800,
800 ÷ 1 = 800.
Pivot on the 2 in row 4 of the x column.

A P x y s1 s2 s3 s4 a4 RHS
1 0 0 0.5 0 −0.5 0 −1 0 50
0 1 0 −0.3 0 0.5 0 0 0 750
0 0 0 0.5 1 −0.5 0 0 0 250
0 0 1 0.5 0 0.5 0 0 0 750
0 0 0 0.5 0 −1.5 1 0 0 150
0 0 0 0.5 0 −0.5 0 −1 1 50
Table 6.14
Pivot on the 0.5 in row 6 of the y column.

A P x y s1 s2 s3 s4 a4 RHS
1 0 0 0 0 0 0 0 −1 0
0 1 0 0 0 0.2 0 −0.6 0.6 780
0 0 0 0 1 0 0 1 −1 200
0 0 1 0 0 1 0 1 −1 700
0 0 0 0 0 −1 1 1 −1 100
0 0 0 1 0 −1 0 −2 2 100
Table 6.15
This gives the solution A = 0 and
P = 780, x = 700, y = 100, s1 = 200, s2 = 0, s3 = 100, s4 = 0, a4 = 0.
This can be used as a starting point for the second stage.
Second stage
The first objective row and columns corresponding to A and a4 are removed and
the simplex method is applied as before.

P x y s1 s2 s3 s4 RHS
1 0 0 0 0.2 0 −0.6 780
0 0 0 1 0 0 1 200
0 1 0 0 1 0 1 700
0 0 0 0 −1 1 1 100
0 0 1 0 −1 0 −2 100
Table 6.16

80

9781510403130.indb 80 20/03/18 7:49 AM


Pivot on the 1 in row 4 of the s4 column.

P x y s1 s2 s3 s4 RHS 6
1 0 0 0 −0.4 0.6 0 840
0 0 0 1 1 −1 0 100

Chapter 6 Simplex method


0 1 0 0 2 −1 0 600
0 0 0 0 −1 1 1 100
0 0 1 0 −3 2 0 300
Table 6.17
Pivot on the 1 in row 2 of the s2 column.

P x y s1 s2 s3 s4 RHS
1 0 0 0.4 0 0.2 0 880
0 0 0 1 1 −1 0 100
0 1 0 −2 0 1 0 400
0 0 0 1 0 0 1 200
0 0 1 3 0 −1 0 600
Table 6.18
The optimum has been achieved.
P = 880, x = 400, y = 600, s1 = 0, s2 = 100, s3 = 0, s4 = 200.

Equality constraints are sometimes used to reduce the number of variables (as when
a 3-dimensional problem is reduced to 2 dimensions). The simplex algorithm can
be used with a problem that has an equality constraint by writing it as a pair of
inequalities.
For example, the constraint
x + 2y − z = 3
can be replaced by the pair of inequalities
x + 2y − z ⩽ 3, x + 2y − z ⩾ 3.

Exercise 6.2 ① Use two-stage simplex to solve the following linear programming problem.
Maximise P = 16x + 24y
subject to 2x + 3y ⩽ 24
2x + y ⩽ 16
y⩽6
y⩾2
and x ⩾ 0, y ⩾ 0

81

9781510403130.indb 81 20/03/18 7:49 AM


Use of technology

② Use two-stage simplex to solve the following linear programming problem.


Maximise P = 9x + 10y + 6z
subject to 2x + 3y + 4z ⩽ 3
6x + 6y + 2z ⩽ 8
x+y+z⩾1
y⩾2
and x ⩾ 0, y ⩾ 0, z ⩾ 0
③ Use two-stage simplex to solve the following linear programming problem.
Maximise P = 3w + 2x
subject to w + x + y + z ⩽ 150
2w + x + 3y + 4z ⩽ 200
y + z ⩾ 50
and w ⩾ 0, x ⩾ 0, y ⩾ 0, z ⩾ 0
④ Use two-stage simplex to solve the following linear programming problem.
Maximise P = 3w + 2x
subject to w + x + y + z ⩽ 150
2w + x + 3y + 4z ⩽ 200
x−w⩽0
y + z ⩾ 50
and w ⩾ 0, x ⩾ 0, y ⩾ 0, z ⩾ 0

3 Use of technology
Although small linear programming problems may be solved graphically or using
the simplex algorithm by hand, for a large-scale problem, computer software would
be used to carry out the simplex algorithm.
A spreadsheet can be used to carry out the iterations of the simplex algorithm for a
medium-sized problem.

Example 6.10 A spreadsheet is set up with the initial tableau below. What formulae are
appropriate for the cells A5 to A8?

Figure 6.1

Solution
It may be a good idea to
put the column headings The pivot cell is B3 so A7 = A3/2 and then A5 = A1+3*A7, A6 = A2−A7,
in the first row and to A8 = A4−2*A7
leave a gap between
each tableau. These formulae can then be copied across cells B5 to B8.

82

9781510403130.indb 82 20/03/18 7:49 AM


Spreadsheets can also be used to try out values for the variables or solve a linear
TECHNOLOGY
Set up the spreadsheet
programming problem by trial and error. Most spreadsheets also have a linear
programming solver.You may need to give the reports from online solvers or 6
shown in figure 6.1 and other linear programming software along with their interpretation, but detailed
carry out one iteration knowledge of any particular software will not be expected.
using the method

Chapter 6 Simplex method


shown in the solution to
Example 6.10.

Exercise 6.3 ① Use a linear programming solver to find the solution to the following linear
programming problem.
Maximise 3x + y
Subject to x + 2y ⩽ 6
2.5x + 4y ⩽ 8.5
−x + 6y ⩽ 10
② A computer prints the following solution to a linear programming problem.
MAX = 25 * x1 + 30 * x2;
ST 20 * x1 + 30 * x2 <= 690
5 * x1 + 4 * x2 <= 120
x1 >= 0; x2 >= 0;
END
LP OPTIMUM FOUND AT STEP 2
OBJECTIVE FUNCTION VALUE
1) 750.0000

VARIABLE VALUE REDUCED COST


X1 12.0000 0.0000
X2 15.0000 0.0000
Interpret the output, ignoring the reduced costs.
③ A simplex tabulation is represented in a spreadsheet as follows.

Figure 6.2
(i) Complete the missing row 7 and column F.
(ii) Interpret the entry 2.25 in cell G9.

83

9781510403130.indb 83 20/03/18 7:49 AM


Use of technology

④ Table 6.19 shows the answer report from a linear programming solver.

Objective Cell (Max)


Cell Name Original Value Final Value
$E$5 5x + 8y 21 69.5862069

Variable Cells
Cell Name Original Value Final Value Integer
$C$4 x 1 3.103448276 Contin
$D$4 y 2 6.75862069 Contin

Constraints
Cell Name Cell Value Formula Status Slack
$E$7 7x + 3y 42 $E$7 <=$F$7 Binding 0
$E$8 2x + 5y 40 $E$8 <= $F$8 Binding 0
Table 6.19

Interpret the answer report.


⑤ Sam makes some small pots and some coin trays to sell at a fundraising event.
Sam makes x pots and y coin trays. Restrictions from Sam’s time, the materials
available and anticipated demand give the following constraints on the values
of x and y.
124x + 91y ⩽ 650
2y ⩽ 3x + 4
5y ⩾ x
and x ⩾ 0, y ⩾ 0
If all the pots and coin trays sell, the profit will be P = 13x + 10y pence. Sam
wants to maximise the profit.
Assume that Sam can sell everything that has been made.
(i) Use a linear programming solver to find the optimal values of x and y,
ignoring the fact that x and y must be integers.
(ii) Find the optimal solution when both x and y are integers.

LEARNING OUTCOMES
Now you have finished this chapter you should
➤ be able to formulate a linear programming problem as an initial simplex tableau
➤ be able to choose a pivot and carry out an iteration of the simplex algorithm
➤ recognise when an optimal solution has been achieved
➤ understand the geometrical basis for the simplex method
➤ be able to deal with negative variables
➤ understand how to use the two-stage simplex method to deal with ⩾ constraints
and equality constraints
➤ be able to interpret the output from computer software or a spreadsheet.

84

9781510403130.indb 84 20/03/18 7:49 AM


KEY POINTS 6
1 To be able to formulate an initial simplex tableau, the linear programming
problem must be stated in augmented form with the objective function rewritten
so that it has the same form as the constraints, with all the variables on the left-

Chapter 6 Simplex method


hand side and a constant on the right-hand side.
2 A simplex tableau has a column for the objective variable followed by columns
for the variables and slack variables and then a column for the right-hand side.
The first row shows the coefficients in the objective function and the other rows
show the coefficients in the constraints.
3 The basic variables are shown by columns consisting of all 0s apart from a single
1. The non-basic variables are shown by columns that do not have this form.
The value of each non-basic variable is 0.
The value of each basic variable (and the objective) is found by reading down to
the 1 and then across to the value in the right-hand column.
4 The first step of the algorithm is to choose a pivot column; this is a column for
which the entry in the objective row is negative. The entry with the most negative
entry in the objective row is usually chosen.
The second step is to choose a pivot row; this involves finding a row for which
entry inRHS column
the entry in the pivot column is positive and the ratio is
entry in pivot column
minimised.
The system of equations is now manipulated to exchange the roles of the
basic and non-basic variable that are determined by the pivot. This is called an
iteration of the tableau.
l Each entry in the pivot row is divided by the value of the pivot element.
l Each of the other rows is replaced by
current row ± multiple of pivot row
where the multiple is chosen to make the entry in the pivot column 0.
5 With a degenerate linear programming problem, where more than one vertex
is optimal (and all points between these vertices), the simplex method will find
the optimal value and will reach one of the optimal solutions. Although the final
tableau has no negative values in the objective row, there will be at least one row
with a 0 in the right-hand column leading to a pivot choice where the value in
the objective row is 0 and the ratio is 0. This iteration will give a different optimal
solution.
6 In the two-stage simplex method, instead of adding a non-negative slack variable
to each ⩽ constraint, a non-negative surplus variable is subtracted from each
⩾ constraint. The column corresponding to a surplus variable will consist of 0s
and −1, however, and this is resolved by adding non-negative artificial variables
(which will eventually take the value 0).
The sum of the artificial variables will need to be minimised by introducing a new
objective A. In the first stage, A is minimised by choosing a pivot column with a
positive entry in the objective row.
The first objective row, the columns for A and any artificial variables are then
removed and the remaining problem is dealt with as a maximisation in the
second stage.

85

9781510403130.indb 85 20/03/18 7:49 AM


Reformulating network problems
7 as linear programming problems

Wisdom denotes the List all the possible paths from A to D in the network shown in Figure 7.1.
pursuing of the best ends B
by the best means. 4 5
Francis Hutcheson
2 D
(1694–1746) A
1
6
C

Figure 7.1

1 Modelling paths and flows


The network problems considered in Chapters 2, 3 and 4 can be reformulated
as linear programming (LP) problems. Sometimes this requires the use of an
indicator variable. This is a variable which only takes the value 0 or 1.

In different contexts, an indicator variable might be used to indicate


●● whether a switch is off or on
●● whether a statement is false or true
●● whether a spreadsheet cell is empty or not
●● whether an arc is not used or is used in a path.

Referring to Figure 7.1, each arc has two indicator variables associated with it.
The arc AB has associated indicator variables AB and BA, arc BD has associated
indicator variables BD and DB, and so on.

Note that AB refers both to an arc and to a variable.

The variable AB takes the value 1 if the arc from A to B is being used; otherwise
it is 0. So the path A to B to C to D can be described by setting the variables
AB = BC = CD = 1 and the other seven variables equal to 0.
In a directed network, some variables will not be needed.

There are five arcs, so there are 10 variables. It makes sense not to have variables BA,
CA, DB, DC if you are only considering the path from A to D, since the arcs will not be
used in those directions.

86

9781510403130.indb 86 20/03/18 7:49 AM


Example 7.1 (i) How would you know whether a set of indicator variables define a path in a
network? 7
(ii) If a set of arcs in Figure 7.1 define a path from A to D, write a set of
constraints using the indicator variables representing AB, AC, BC, BD, CB
and CD.

Chapter 7 Reformulating network problems as linear programming problems


Solution
(i) Exactly one of the arcs from the start vertex has the value 1; the others have
the value 0.
Exactly one of the arcs to the finish vertex has the value 1; the others have
the value 0.
At each of the other vertices either all the arcs have value 0 or two arcs have
value 1 (one entering the vertex and one leaving it) and the others have
value 0.
(ii) AB + AC = 1
AB + CB = BC + BD = 0 or 1
AC + BC = CB + CD = 0 or 1
BC + CB = 0 or 1
BD + CD = 1,
where each of AB, AC, BC, BD, CB, CD takes the value 0 or 1.

This can be written as


AB + AC = 1
AB + CB − BC − BD = 0
AC + BC − CB − CD = 0
BC + CB ⩽ 1
BD + CD = 1
where each of AB, AC, BC, BD, CB, CD takes the value 0 or 1.

Example 7.2 The set of indicator variables {AB, AC, BC, BD, CB, CD} define a path from A
to D in the network in Figure 7.1. What does 4AB + 6AC + 2BC + 5BD +
2CB + CD represent?

Solution
This is the sum of the arc weights for the arcs that have indicator value 1. In
other words, it is the total weight of the arcs in the path or the length of the
path.

87

9781510403130.indb 87 20/03/18 7:49 AM


Modelling paths and flows

Example 7.3 (i) What does the following linear programming problem find on the network
in Figure 7.1?
Minimise 4AB + 6AC + 2BC + 5BD + 2CB + CD
subject to AB + AC = 1,
AB + CB − BC − BD = 0,
AC + BC − CB − CD = 0,
BD + CD = 1,
and each of AB, AC, BC, BD, CB, CD takes the value 0 or 1.
(ii) Why is the constraint BC + CB ⩽ 1 not needed?

Solution
(i) This finds the length of the shortest path from A to D. The indicator
variables define the shortest path.
(ii) If both BC and CB are included in a route, then the route can be made
shorter by not using either of these. Because the objective is to minimise,
there is no need for this restriction (the minimum route will also be the
minimum path).

Using linear programming to solve shortest path problems is not a practical method
for longhand calculations, but can be effective if computer software is used to solve
the linear programming problem.
Checking that the indicator variables define a path involves checking that, at each
vertex, there are either zero arcs entering the vertex and zero arcs leaving, or there
is one arc entering the vertex and one leaving. It is sufficient to check that the
number of arcs entering the vertex equals the number leaving the vertex, since
cycles can be removed as they will not give a shortest route.
These vertex checks are the same as those used to check network flows, except that
with indicator variables the ‘flow’ in each arc will be either 0 or 1.
If the variables AB, AC etc. are not restricted to being indicator variables, and
instead are assigned the value of the flow in the arc, the maximum flow from the
start to the finish can be found.

Example 7.4 Formulate a linear programming problem to find the maximum flow from S to T
in Figure 7.2.
A

5 6

3 T
S

2 4

Figure 7.2

88

9781510403130.indb 88 20/03/18 7:49 AM


Solution
The variables SA, SB, AB, BA, AT and BT will be assigned the value of the
7
(directed) flow in the arc.
The flow in each arc cannot exceed the capacity of the arc (and cannot be

Chapter 7 Reformulating network problems as linear programming problems


negative).
For these values to define a flow, the flow in must equal the flow out at A and B.
The sum of the flow from the source (or into the sink) equals the value of the
flow through the network.
This gives the following linear programming problem.
Maximise SA + SB
subject to SA + BA − AB − AT = 0
SB + AB − BA − BT = 0
SA ⩽ 5, SB ⩽ 2, AB ⩽ 3, AT ⩽ 6, BA ⩽ 3, BT ⩽ 4
and SA, SB, AB, AT, BA, BT all ⩾ 0.

Example 7.5 (i) Explain why changing the objective in the linear programming problem in
Example 7.3 from minimise to maximise does not give a practical solution to
the longest path problem.
(ii) What additional constraints are needed to give a linear programming
problem that will give a solution to the longest path problem that has no
repeated arcs and no cycles?

Solution
(i) AB and BA could be repeated over and over again, to give an infinitely long
path.
(ii) To ensure that the route has no repeats or cycles, it is necessary to make sure
that no vertex is passed through more than once. In the case of the network
in Figure 7.1, this could be done by requiring that
AB + CB ⩽ 1, AC + BC ⩽ 1
in addition to the other constraints.
Finding a critical path is the same problem as finding a longest path through
a directed network with no cycles. In this situation, no vertex can be passed
through more than once. The term ‘longest path’ will always mean the longest
path between two vertices that does not repeat any vertex.

Example 7.6 (i) Write down the longest path from S to T in the directed network in
Figure 7.3.
(ii) Regarding Figure 7.3 as an activity network, find the early and late event
times at the vertices.
(iii) Hence represent the problem of finding the minimum project completion
time as a linear programming problem.

89

9781510403130.indb 89 20/03/18 7:49 AM


Modelling paths and flows

5 3

4 T
S

4
3

Figure 7.3

This formulation finds Solution


the minimum project
completion time but
(i) SBAT = 10
does not find the critical (ii) S = [0, 0]   A = [7, 7]   B = [3, 3]   T = [10, 10] project
activities. To do this, the
latest event times would
(iii) Minimise T duration
be needed as well. early event
subject to B ⩾ 3, A ⩾ 5, A ⩾ 4 + B, T ⩾ 4 + B, T ⩾ 3 + A times

Exercise 7.1 ① Table 7.1 shows, for each of the activities of a project, the immediate
predecessors of the task and the duration, in days, of the task. Formulate a
linear programming problem to find the minimum project completion time.
Activity A B C D E F G H
Immediate
− − A, B A A, B D, E A C, G
predecessors
Duration
15 10 5 2 8 12 3 13
(days)
Table 7.1

② Table 7.2 shows the distances between the six vertices of a network. The
shortest path from E to B is required.
(i) Formulate this as a linear programming problem.
A B C D E F
A 0 15 8 5 21 2
B 15 0 11 23 40 17
C 8 11 0 9 26 12
D 5 23 9 0 17 11
E 21 40 26 17 0 13
F 2 17 12 11 13 0
Table 7.2
(ii) Run your linear programming problem on a solver and interpret the
output.

90

9781510403130.indb 90 20/03/18 7:49 AM


③ Table 7.3 shows the capacities of the arc in a network.
(i) Formulate a linear programming problem to find the maximum flow from
S to T.
7
S B C D E T
S 15 8

Chapter 7 Reformulating network problems as linear programming problems


B 15 11 23 4
C 8 11 9 6
D 23 9 17 11
E 4 6 17 13
T 11 13
Table 7.3
(ii) A linear programming solver produces the following answer report.
OBJECTIVE FUNCTION VALUE ROW SLACK OR SURPLUS
2) 0. 000000
1) 23 . 0 0 0 0 0 3) 0. 000000
4) 0. 000000
VARIABLE VALUE 5) 0. 000000
SB 15. 000000 6) 0. 000000
SC 8. 000000 7) 0. 000000
8) 11 . 0 0 0 0 0 0
CB 0. 000000
2) 11 . 0 0 0 0 0 0
DB 0. 000000 10 ) 8. 000000
EB 0. 000000 11 ) 23. 000000
BC 0. 000000 12 ) 4. 000000
BD 15. 000000 13 ) 4. 000000
BE 0. 000000 14 ) 7. 000000
DC 0. 000000 15 ) 9. 000000
EC 0. 000000 16 ) 0. 000000
CD 2. 000000 17 ) 6. 000000
CE 6. 000000 18 ) 11 . 0 0 0 0 0 0
ED 0. 000000 19 ) 17. 000000
DE 6. 000000 20 ) 0. 000000
DT 11 . 0 0 0 0 0 0 21 ) 1. 000000
ET 12. 000000 NO. ITERATIONS = 8

Figure 7.4
Interpret this report to find the maximum flow.
④ The linear program below is used to solve a longest path problem without
repeating any vertices.
Minimise 5AB + 6AC + 2BC + 2CB + 4BD + CD
subject to AB + AC = 1
AB + CB − BC − BD = 0
AC + BC − CB − CD = 0
BD + CD = 1
BC + CB ⩽ 1
and each variable is an indicator variable.
(i) Explain the purpose of each constraint.
The solution given by a computer software is:
AB AC BC BD CB CD
0 1 0 1 1 0
(ii) Give the path indicated by this solution and its length.

91

9781510403130.indb 91 20/03/18 7:49 AM


Modelling paths and flows

⑤ A type of plastic sheeting is produced in rolls which are 7 m wide. These are
sliced into rolls of narrower width, as shown in Figure 7.5.

cut rolls leftover waste


= ‘trim loss’

Figure 7.5
(i) On a particular day, there is a need for 150 rolls of width 4 m, 200 rolls of
width 3 m and 100 rolls of width 2 m. To provide these, full-sized rolls can
be cut according to the five plans shown in Table 7.5.

Cutting plan 4 m rolls 3 m rolls 2 m rolls Trim loss (m)


1 1 1 0 0
2 1 0 1 1
3 0 2 0 1
4 0 1 2 0
5 0 0 3 1
Table 7.5
The following linear programming problem is formulated to satisfy
(a)
the requirements whilst minimising production.
Minimise x1 + x2 + x3 + x4 + x5
subject to x1 + x2 ⩾ 150
x1+ 2x3 + x4 ⩾ 200
x2 + 2x4 + x5 ⩾ 100
with all variables non-negative integers.
Explain what the variables represent and the meaning of the
constraints.
(b) What does the following linear programming problem achieve?

Minimise x2 + x3 + x4
subject to x1 + x2 ⩾ 150
x1+ 2x3 + x4 ⩾ 200
x2 + 2x4 + x5 ⩾ 100
with all variables non-negative integers.
(ii) On another day, the demand is for 150 rolls of width 4 m, 100 rolls of with
3 m, 250 rolls of width 2 m and 300 rolls of width 1.6 m.
(a) Copy and complete Table 7.6, showing efficient cutting plans (that is,
plans with a trim loss < 1.6 m).

92

9781510403130.indb 92 20/03/18 7:49 AM


Cutting plan 4 m rolls 3 m rolls 2 m rolls 1.6 m rolls Trim loss (m)
1
2
1 1 0 0 0
7
3
4

Chapter 7 Reformulating network problems as linear programming problems


5
6
7
8
9
10
11 0 0 0 4 0.6
Table 7.6
(b) Formulate a linear programming problem to find the minimum
number of full rolls that need to be cut and state how the trim loss is
calculated in this solution.
 [MEI, adapted]

2 Modelling allocation problems


Matching problems
The simplest type of allocation problem is a matching problem. A bipartite graph
shows which elements from one set may be matched with elements from the other
set. A maximal matching maximises the number of matched pairs. A complete
matching is a maximal matching in which every element is involved in a matched pair.

Example 7.7 (i) Find a maximal matching for the bipartite graph described by the following
adjacency matrix in Table 7.7.
E F G H
A 1 0 1 0
B 0 1 1 0
C 1 0 0 1
D 0 1 1 0
Table 7.7

(ii) Explain how the linear programming problem below finds a maximal matching.
Maximise AE + AG + BF + BG + CE + CH + DF + DG
subject to AE + AG ⩽ 1
BF + BG ⩽ 1
CE + CH ⩽ 1
DF + DG ⩽ 1
AE + CE ⩽ 1
BF + DF ⩽ 1
AG + BG + DG ⩽ 1
CH ⩽ 1
with all variables as non-negative integers.
93

9781510403130.indb 93 20/03/18 7:49 AM


Modelling allocation problems

Solution
(i) A−E, B−F, C−H, D−G is a complete matching.
(ii) Each variable appears in the constraints and so is ⩽ 1 and is an indicator
variable.
A variable takes the value 1 if the arc is in the matching and 0 if it is not.
The first four constraints show that at most one arc comes from A, B, C
and D.
The next four constraints show that at most one arc goes to E, F, G and H.
The objective maximises the number of arcs (matchings).

Allocation problems
An allocation problem is the same as a matching problem except that the arcs are
weighted and the complete matching with the maximum total weight is required.
A delivery company needs to find the cheapest way to deliver orders from a
You met this problem in
Chapter 2 (page 29). number of warehouses to a number of shops. There are four warehouses and four
shops and each warehouse can fill the order of any one shop, but the cost of doing
so depends on the distance between the warehouse and the shop.
Table 7.8 shows the cost (in a suitable unit) for each warehouse to supply each
shop. The warehouses need to be paired with the shops to give the least cost
allocation.
Shop
S1 S2 S3 S4
W1 60 62 61 64
Warehouse W2 65 63 60 60
W3 59 61 58 63
W4 60 60 62 60
Table 7.8

Example 7.8 Formulate the delivery company problem as a linear programming problem.

TECHNOLOGY Solution
Use a spreadsheet solver
or other solver to find
An allocation is a weighted complete matching, so instead of having ⩽ 1 in the
the solution to the LP constraints they will each be = 1. The minimum weighted complete matching is
problem in Example 7.8. required.
Minimise 60W1S1 + 62W1S2 + 61W1S3 + 64W1S4 + 65W2S1 + 63W2S2 +
60 W2S3 + 60W2S4 + 59W3S1 + 61W3S2 + 58W3S3 + 63W3S4 +
60W4S1 + 60W4S2 + 62W4S3 + 60W4S4
subject to W1S1 + W1S2 + W1S3 + W1S4 = 1
W2S1 + W2S2 + W2S3 + W2S4 = 1

94

9781510403130.indb 94 20/03/18 7:49 AM


W3S1 + W3S2 + W3S3 + W3S4 = 1
W4S1 + W4S2 + W4S3 + W4S4 = 1 7
W1S1 + W2S1 + W3S1 + W4S1 = 1
W1S2 + W2S2 + W3S2 + W4S2 = 1

Chapter 7 Reformulating network problems as linear programming problems


W1S3 + W2S3 + W3S3 + W4S3 = 1
W1S4 + W2S4 + W3S4 + W4S4 = 1
with all variables as indicator variables.

Transportation problems
A transportation problem is the same as an allocation problem except that
instead of having one delivery between a warehouse and a shop there may be
several, so a warehouse may supply to more than one shop and a shop may be
supplied by more than one warehouse.
In Example 7.8, the table shows unit costs. The availabilities at the warehouses are
W1 = 15 units    W2 = 12 units    W3 = 8 units    W4 = 3 units
and the demands at the shops are
S1 = 10 units    S2 = 10 units    S3 = 12 units    S4 = 6 units
Note that W1 + W2 + W3 + W4 = S1 + S2 + S3 + S4. In this case, there are four
warehouses and four shops, but the number of warehouses (‘out’ vertices) need not
equal the number of shops (‘in’ vertices) provided the total availability equals the
total demand.

Example 7.9 What changes need to be made to the linear programming problem that
represents the allocation problem to convert it into the transportation problem?

TECHNOLOGY Solution
Use a spreadsheet solver Instead of having one delivery from each warehouse and one delivery to
or other solver to find
each shop, the number of deliveries are given by the availabilities and the
the solution to the LP
problem in Example 7.9. requirements.
This gives the following linear programming problem.
Minimise 60W1S1 + 62W1S2 + 61W1S3 + 64W1S4 + 65W2S1 + 63W2S2
+ 60 W2S3 + 60W2S4 + 59W3S1 + 61W3S2 + 58W3S3 +
63W3S4 + 60W4S1 + 60W4S2 + 62W4S3 + 60W4S4
subject to W1S1 + W1S2 + W1S3 + W1S4 = 15
W2S1 + W2S2 + W2S3 + W2S4 = 12
W3S1 + W3S2 + W3S3 + W3S4 = 8
W4S1 + W4S2 + W4S3 + W4S4 = 3
W1S1 + W2S1 + W3S1 + W4S1 = 10
W1S2 + W2S2 + W3S2 + W4S2 = 10
W1S3 + W2S3 + W3S3 + W4S3 = 12
W1S4 + W2S4 + W3S4 + W4S4 = 6

95

9781510403130.indb 95 20/03/18 7:49 AM


Modelling allocation problems

Exercise 7.2 ① Table 7.9 shows the cost of allocating individuals A, B, C to tasks X,Y, Z. Each
individual must do one task and each task must be done by one individual.

X Y Z
A 3 6 4
B 7 4 6
C 6 4 5
Table 7.9
Formulate a linear programming problem to find the minimum cost allocation.
② The annual cost of supplying six warehouses from six depots is £8000 plus
costs given in Table 7.10. Each warehouse is to be supplied from exactly one
depot and each depot is to supply exactly one warehouse.

Warehouses
£ hundreds 1 2 3 4 5 6
A 6 5 3 0 1 2
B 1 2 5 0 3 0
Depots C 10 7 0 2 0 3
D 0 0 0 4 1 5
E 6 3 2 0 5 4
F 3 7 0 3 2 1
Table 7.10
Formulate a linear programming problem to find the minimum cost allocation.
③ A linear programming problem solver is used to find a minimum cost allocation.
It gives the following answer report in Table 7.11. Interpret the report.

AW AX AY AZ BW BX BY BZ
0 0 1 0 0 1 0 0
CW CX CY CZ DW DX DY DZ
0 0 0 1 1 0 0 0
Table 7.11
④ A contractor hires out heavy equipment such as cranes. There are eight jobs
that he has contracted for. Each job should take less than half a day but the sites
are separated and take some time to reach.
Table 7.12 the journey times (in hours) to or from the main depot and the job
durations (also in hours).

Job A B C D W X Y Z
Journey
2 1 1 3 2 2 4 1
time
Job
4 4 4 3 4 2 4 5
duration
Table 7.12
Any of jobs A, B, C, D can be followed by any of W, X,Y, Z but each machine
can only do two jobs, so 4 machines are needed, each of which will do one of
{A, B,C, D} and one of {W, X,Y, Z}.

96

9781510403130.indb 96 20/03/18 7:49 AM


The travel times (in hours) between jobs that can be shared are given in
Table 7.13.
W X Y Z
7
A 1 2 2 3
B 2 1 3 2

Chapter 7 Reformulating network problems as linear programming problems


C 1 4 3 3
D 3 2 1 1
Table 7.13
(i) If a machine was assigned to jobs A and W, for how long would it be away
from the depot?
(ii) Formulate a linear programming problem to pair the jobs to minimise the
sum of the times for which the four machines are away from the depot.
(iii) A student uses a linear programming problem solver. Part of the report
from the solver is given in Figure 7.6.
Variable Cells
Cell Name Original Value Final Value Reduced cost
$A$1 AW 0.000000 0.000000 1.000000
$A$2 AX 0.000000 0.000000 1.000000
$A$3 AY 0.000000 1.000000 0.000000
$A$4 AZ 0.000000 0.000000 1.000000
$B$1 BW 0.000000 0.000000 2.000000
$B$2 BX 0.000000 1.000000 1.000000
$B$3 BY 0.000000 0.000000 0.000000
$B$4 BZ 0.000000 0.000000 1.000000
$C$1 CW 0.000000 1.000000 0.000000
$C$2 CX 0.000000 0.000000 2.000000
$C$3 CY 0.000000 0.000000 0.000000
$C$4 CZ 0.000000 0.000000 0.000000
$D$1 DW 0.000000 0.000000 4.000000
$D$2 DX 0.000000 0.000000 2.000000
$D$3 DY 0.000000 0.000000 0.000000
$D$4 DZ 0.000000 1.000000 0.000000
Figure 7.6
Find the total time taken (journey times, travel times between jobs and job
durations for the eight jobs) using the solution given in the report.
⑤ An electronics company has television manufacturing plants in cities X and Y.
The company is planning to produce some components in cities A, B and C,
where wages are lower.
The total requirements for the components during the next five years are
given in Table 7.14.

Plant Components required


X 30 million
Y 10 million
Table 7.14

97

9781510403130.indb 97 20/03/18 7:49 AM


Modelling allocation problems

The initial costs of building production plants, the cost per component and
plant capacities over five years are given in Table 7.15.

Component plant Initial cost Cost per component Capacity


A £20 million £3.00 15 million
B £40 million £2.00 25 million
C £30 million £2.50 20 million
Table 7.15
The unit costs, in £, of shipping components to X and Y are
A to X = £0.50 B to X = £0.40 C to X = £0.20
A to Y = £1.00 B to Y = £1.20 C to Y = £0.80
The company wants to meet its component needs for the next five years
at the minimum total cost, and must decide where it should produce the
components.
The problem is formulated as a linear programming problem with, for example,
AX representing the number of components supplied from A to X and
indicator variables A, B, C showing whether the component plants are built
or not.
(i) The objective function includes, amongst other expressions, the terms
20 000 000A, 3.5AX and 4AY. Explain each of these terms.
(ii) One of the constraints is of the form AX + AY − kA ⩽ 0. What is the
purpose of this constraint and what values are possible for k?
(iii) Write a constraint that ensures that the requirements at X are met.

LEARNING OUTCOMES
Now you have finished this chapter you should
➤ understand how indicator variables are used
➤ be able to formulate a shortest path problem as a linear programming problem
➤ be able to formulate a network flow problem as a linear programming problem
➤ be able to formulate a longest path problem as a linear programming problem
➤ understand what matching problems are and how to formulate them as linear
programming problems
➤ understand what allocation problems are and how to formulate them as linear
programming problems
➤ understand what transportation problems are and how to formulate them as
linear programming problems.

98

9781510403130.indb 98 20/03/18 7:49 AM


KEY POINTS 7
1 An indicator variable records whether the variable is ‘off’ = 0 or ‘on’ = 1.
2 The shortest path through a network is found by solving the linear programming
problem

Chapter 7 Reformulating network problems as linear programming problems


Minimise Σ(arc weight × indicator) summed over all arcs
subject to Σ(indicators from start vertex) = 1
Σ(indicators to finish vertex) = 1
Σ(indicators to vertex − indicators from vertex) = 0
for other vertices and each indicator takes the value 0 or 1.
3 The maximum flow through a network is found by solving the linear
programming problem
Maximise Σ(flows from source)
subject to Σ(flow to vertex − flow from vertex) = 0
for all vertices apart from source and sink
0 ⩽ flow ⩽ capacity for each arc
4 The longest path through a network is found by solving the linear programming
problem
Maximise Σ(arc weight ×indicator) summed over all arcs
subject to Σ(indicators from start vertex) = 1
Σ(indicators to finish vertex) = 1
Σ(indicators to vertex − indicators from vertex) = 0
and Σ(indicators to vertex) ⩽ 1 for other vertices
and each indicator takes the value 0 or 1.
5 A maximal matching is found by solving the linear programming problem
Maximise Σ indicators summed over all arcs
subject to Σ(indicators from vertex) ⩽ 1 for each vertex
Σ(indicators to vertex) ⩽ 1 for each vertex
and each indicator takes the value 0 or 1.
6 A minimum cost allocation is found by solving the linear programming problem
Minimise Σ(arc weight ×indicator) summed over all arcs
subject to Σ(indicators from vertex) ⩽ 1 for each ‘out’ vertex
Σ(indicators to vertex) ⩽ 1 for each ‘in’ vertex
and each indicator takes the value 0 or 1.
7 A minimum cost transportation problem is modelled as
Minimise Σ(arc weight ×indicator) summed over all arcs
subject to Σ(indicators from vertex) ⩽ availability
for each ‘out’ vertex
Σ(indicators to vertex) ⩽ demand for each ‘in’ vertex
and each indicator takes the value 0 or 1.

99

9781510403130.indb 99 20/03/18 7:49 AM


Answers

Chapter 1 Discussion point (page 5)


INT(2.6M − 5.4) takes the values 2, 5, 7, 10, 12,
Discussion point (page 1) 15, 18, 20, 23, 25, 28, 31 for M = 3, 4, … , 14.
You could work out the perimeter if you knew the The differences between these values are 3, 2, 3, 2, 3,
three edge lengths, or two edge lengths and an angle, 3, 2, 3, 2, 3, 3 and correspond to the number of days
or one edge length and the angles at each end of this in the months in excess of 4 complete weeks.
edge, or the vertices of the triangle, or …
Exercise 1.1 (page 5)
Activity 1.1 (page 2) 1 Input N N a positive integer > 2
Will depend on student’s birth date

Activity 1.2 (page 3) Is N ÷ 2 the same Yes


as INT(N ÷ 2)?

Step N A B Comments Passes No

1 2 Let D = 3

2 1 A= 1
×2
2 No
Is D < N?
1.5 B= First Print
3 1
(1 + (2 ÷ 1)) pass
Yes
2 ‘prime’

(A – B)2 = Is N ÷ D the same Yes


4 as INT(N ÷ D)?`
(1 – 1.5)2 = 0.25
Print
1.5 (new) A = ‘not prime’
5 No
(old) B
Let D = D + 2
1.41667 B = Second
3 1
2
(1.5 + (2 ÷ 1.5)) pass
(1.5 – 1.41667)2 2 (i) sixty-two 8 eight 5 five 4 four 4
4
= 0.00694 (ii) {1, 2, 6, 10} → 3, 5, 4
5 1.41667 {4, 5, 9} → 4
1.41422 (1.41667 – Third {3, 7, 8} → 5, 4
3 1.41422)2 pass {11, 12} → 6, 3, 5, 4
< 0.001 3 (i) The numbers 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
DISPLAY 31, 37, 41, 47, 53, 59, 61, 67, 71, 73, 79, 83,
6
1.41422 89, 97 should all be circled
(ii) Prime numbers. This method is called the
Activity 1.3 (page 4) sieve of Eratosthenes.
Russian algorithm Euclidean algorithm 4 (i) e.g.

13 37 Step 1 Input N, the number of symbols in the


Roman numeral
26 18 x y
Step 2 Let A = 1, R = 1 and T = 0
52 9 6 15
104 4 6  9 Step 3 Read the symbol in position A of the
Roman numeral, call this S
208 2 6  3
416 1 3   3
481 Output value 3
100

9781510403130.indb 100 20/03/18 7:49 AM


Step 4 Read the cell in row R and the column (iv) S econd algorithm is a form of long division.
labelled S. Increase T by the first number in It is more efficient but less transparent.
the cell and change R to the second number 2 (i) 592
in the cell. (iii) A uses 30 592 additions, 0 subtractions and
10 000 comparisons
Step 5 Increase A by 1
B uses 10 592 additions, 1110 subtractions and

Answers
Step 6 If A > N, display T and stop 10 000 comparisons
Step 7 Otherwise go to step 3 B is more efficient than A
3 (i) HCF = 180
(ii) Roman numeral must be less than 5000 (ii) One extra iteration in which A and B are
(iii) e.g. swapped
Step 1 Input N {N a positive integer < 5000} (iii) 12 iterations, formula gives 12.0001…

Step 2 U = N − 10×INT(N ÷ 10) Discussion points (page 11)


Step 3 If U < 5 let I = U Optimal here means using the least number of bins.
If U > 5 let V = 1 and I = U − 5 Depending on the context other criteria may be more
Step 4 N = (N − U) ÷ 10 appropriate, for example it may be better to aim for an
even balance of weights rather than having some full
Step 5 T = N − 10×INT(N ÷ 10) bins and other nearly empty bins, or other factors may
Step 6 If T < 5 let X = T need to be considered, such as the size of the boxes or
If T > 5 let L = 1 and X = T − 5 (for food) their use by dates.

Step 7 N = (N − T) ÷ 10 Using a complete enumeration will be very time


consuming, a good solution that can be found quickly
Step 8 H = N - 10×INT(N ÷ 10) may be more useful than a best solution that cannot be
Step 9 If H < 5 let C = H found quickly.
If H > 5 let D = 1 and C = H − 5
Exercise 1.3 (page 12)
Step 10 N = (N − H) ÷ 10
1 S um of sizes is 1580 kB < 4 × 400 kB, so
Step 11 M = N − 10×INT(N ÷ 10) potentially this is possible.
Step 12 Display M copies of the symbol “M” First-fit decreasing, for example, gives:

Step 13 If C = 4 and D = 0 display “CD” P(200) + J(140) + C(60)


If C = 4 and D = 1 display “CM” L(120) + Q(120) + E(110) + G(50)
Otherwise display D copies “D” followed by
A(100) + N(100) + I(90) + B(80) + F(25)
C copies of “C”
K(75) + M(75) + O(70) + D(65) + H(60) +
Step 14 If X = 4 and L = 0 display “XL”
R(40)
If X = 4 and L = 1 display “XC”
Otherwise display L copies of “L” So it is possible to fit the programs onto four
followed by X copies of “X” 400 kB discs.
Step 15 If I = 4 and V = 0 display “IV” 2 Sum of lengths is 82 m so at least 5 lanes are
If I = 4 and V = 1 display “IX” needed.
Otherwise display V copies of “V” followed by First-fit decreasing, for example, gives
I copies of “I” 14 + 5; 12 + 8; 11 + 4 + 4; 10 + 4 + 4; 3 + 3
Exercise 1.2 (page 8) So five lanes are sufficient.
1 (i) r = 41, q = 0; r = 38, q = 1; … ; r = 2, q = 13 3 3.5 1.5 1, 3.5 1.5 1, 3 1.5 1.5, 2 2 2
(ii) Division by repeated subtraction There are no pipes of length 7, 4 or 6.
(iii) r = 4, q1 = 0; r = 1, q1 = 1; r = 11, q2 = 0; 4 (i) 2 + 1 + 6; 3 + 3; 5 uses 3 bags
r = 8, q2 = 1; r = 5, q2 = 2; r = 2, q2 = 3 (ii) 6 + 3 + 1; 5 + 3+ 2 uses 2 bags (no spare)

101

9781510403130.indb 101 20/03/18 7:49 AM


Discussion point (page 12) 3rd pass (M = 3) 1 5 3 7 9 11 3 2
One way would be to could play a game of patience. 4th pass (M = 4) 1 3 5 7 9 11 2 1
Or you could go through the pack sorting the cards 5th pass (M = 5) 1 3 5 7 9 11 1 0
into four piles, one for each suit, and then sort each Sorted list 1 3 5 7 9 11
pile from ace to king. 15 comparisons and 9 swaps
Answers

(ii) Sublist 7 9 5
Discussion point (page 13) 1st pass 7 5 9 2 1
To adapt quick sort to sort the list into descending 2nd pass 5 7 9 1 1
(decreasing) order, change ‘less than or equal to’ to 3 comparisons and 2 swaps
‘greater than or equal to’ (twice) and ’greater than’ to Sublist 1 11 3
‘less than’ (twice) in step 1, so step 1 reads: 1st pass 1 3 11 2 1
The first value in the list is the pivot. 2 pass
nd
1 3 11 1 0
Excluding the pivot, pass along the list and write down 3 comparisons and 1 swap
each value that is greater than or equal to the pivot (iii) e.g. compare first number in each sublist
value, then write the pivot value and then write down and move the smaller to the end of final list,
the values that are less than the pivot. repeat with reduced sublists until a sublist is
At this stage the pivot is guaranteed to be in its correct empty, then put remaining values in other list
position in the final list and can be marked in some at the end of the final list.
way to indicate this. The pivot splits the list into two 5 7 9 and 1 3 11 → 1 1 comp
sublists: one containing the values that are greater than 5 7 9 and 3 11 → 1 3 1 comp
or equal to the pivot (excluding the pivot itself) and
the other containing the values that are less than the 5 7 9 and 11 → 1 3 5 1 comp
pivot. It is possible that one of these sublists may be And so on. Total = 5 comparisons
empty.
3 (i) Original list 13 56 2 40 10 50 35 comp
Exercise 1.4 (page 14) 1 pass
st
13 56 2 40 10 50 35 1
1 
Original list 6 8 3 2 4 7 7 comparisons 2nd pass 2 13 56 40 10 50 35 2
After 1 pass 3 2 4 6 8 7 7 [6]
st
3rd pass 2 13 40 56 10 50 35 2
After 2 pass 2 3 4 6 7 7 8 [4]
nd
4th pass 2 10 13 40 56 50 35 4
After 3 pass 2 3 4 6 7 7 8 [1]
rd
5 pass
th
2 10 13 40 50 56 35 2
After 4 pass 2 3 4 6 7 7 8 [0]
th
6th pass 2 10 13 35 40 50 56 4
Sorted list 2 3 4 6 7 7 8 Total = 15 comparisons
In the 1st pass each value after pivot is compared (ii) For a list of length n, worst-case uses
with the pivot = 6 comparisons. 1
1 + 2 + 3 + … + (n − 1) = 2 (n − 1)n
In the 2nd pass each ‘non pivot’ is compared with a comparisons, which is a quadratic function of n.
pivot = 2 + 2 = 4 comparisons. (iii) Original list 13 56 2 40 10 50 35 comp
1st pass 2 10 13 56 40 50 35 6
Similarly the 3rd pass uses 1 comparison and the
2nd pass 2 10 13 40 50 35 56 4
4th pass uses 0 comparisons.
3rd pass 2 10 13 35 40 50 56 2
These values are shown in brackets at the end of 4th pass 2 10 13 35 40 50 56 0
each row. Sorted list 2 10 13 35 40 50 56
The total number of comparisons is 11. Total = 12 comparisons
(iv) Both are O(n2), but in this particular case: shuttle
2 (i) Original list 7 9 5 1 11 3 comp swap sort = 15 comp; quick sort = 12 comp; so quick
1 pass (M = 1) 7 5 1 9 3 11 5
st
3 sort was more efficient.
2nd pass (M = 2) 5 1 7 3 9 11 4 3

102

9781510403130.indb 102 20/03/18 7:49 AM


Chapter 2 Exercise 2.2 (page 26)
1 (i) MWCP MW MC MP WC WP CP
Opening activity (page 17)
One way in which this can be done is MWC MWP MCP WCP M W C P

(ii) At the top

Answers
2 (i) A
B
Discussion point (page 22)
F C
The two graphs have the same number of vertices and
the same number of arcs. The vertex orders are the
same and the way in which the vertices are connected E D
are the same. They have the same structure. A B
(ii)
The labelling of the vertices and the orientation and
shape of the arcs are different. C
F

Activity 2.1 (page 22)


There are 2 different (non-isomorphic) trees with four E D

vertices.
(iii) A, B, D together; C, E together; F on its own
3 (i) (3) (1)

B R

Exercise 2.1 (page 23) (1) (2) (2)

1 e.g. (1) (2) (4) (3) (4)


(3)
G (4) Y

2 (i) Graph A has 4 vertices and 3 edges


Graph B has 4 vertices and 3 edges (ii)
(1) (3)
Graph C has 3 vertices and 3 edges B R B
R
B R
(2) (2)
(ii) The
number of vertices is given by the row (4) (1)
(4) (1) (2) (3) (4)
sum and the number of edges is half the sum of (3) G Y
G Y G Y
the vertex orders. For example, with graph A:
1 The subgraphs represent the front/back of the
3 + 0 + 1 = 4 and 2 (3 × 1 + 0 × 2 + 1 × 3) = 3
(iii) e.g. tower, the left/right sides of the tower and the
top/bottom faces of the cubes (most of which are
hidden internally).
A B C

3 Activity 2.2 (page 28)


A B
Mi – Ba – Bu – Bo – Tr – LE

Discussion point (page 28)


C A shorter route is Tr – LE – Tr – Bo – Bu – Ok – Ba
4 (i) (ii)
– Mi – Ta – Ex – To – Pl – Tr = 383 miles. There are
other possibilities.

Discussion point (page 29 upper)


A shorter route is LE – Tr – Bo – Bu – Ba – Mi – Ta –
Ex- To – Pl - Ok – Ex – Pl – Ok – Ba – Ex – Ta - Ba
(iii) 3 connection points and 3 internal points – Bu – Ok – Bo - Pl – Tr = 754 miles. There are other
possibilities.

103

9781510403130.indb 103 20/03/18 7:49 AM


Discussion point (page 29 lower) Prim’s algorithm in network form would be easier
The quickest route may be required and this is not to program, although two lists would be needed, one
necessarily the same as the shortest route because some listing the vertices that are already in the tree and
roads can be travelled at a faster speed than others. Or one listing those that are not yet in the tree, and the
the cheapest route may be required and there could be information about the network would need to be
Answers

a toll to pay on one of the roads. It depends on what is presented as a distance matrix.
meant by best.
Exercise 3.1 (page 37)
Exercise 2.3 (page 30) 1 Do-Ye = 20 SW
1 (i) 12 Sa-Wa = 21
A B Wa Ba
30
40 36 Sa-So = 23 Sa
20 Ye So
E C
30 Bo-Sa = 27
20
12 10 Do Bo
Bo-Do = 28
D
Ba-So = 31
Bo-So = 31
    (ii) mins A B C D E
Ba – Sa= 36
A - 14.4 43.2 24 -
B 14.4 - 30 30 48 Sw-Wa = 37
C 43.2 30 - 12 24 Total weight = 187
D 24 30 12 - 14.4 2 SA-Bi = 24 Total weight
ST Nm
E - 48 24 14.4 - = 286
SA-Wo = 25
Sh Le Or Bi-Le
(iii) A − D − E = 38.4 mins Wo-Gl = 25
Bi = 39 instead
2 (i), (ii) A R1
4 SA-Nn = 39 of SA-Nn,
3 1 2 Nn
B 3 R2 Wo SA Nn-Le = 30 followed by
2 Le-Nm and
2
2 1 Ox Le-Nm = 25 then Le-Nn,
C 4 R3 Gl
1 3 SA-Ox = 40 then as before
2
D 3 R4 Bi-ST = 44
4 5
3 ST-Sh = 34
E 3 R5
33
1 1 (1) (2) (8) (6) (7) (3) (5) (4)
1
F R6
M W H E R T G C
(iii) A= R6, B = R4, C = R3, D = R5, E = R1, M - 8 19 ∞ 19 13 20 ∞
F = R2 W 8 - 25 16 ∞ 15 ∞ ∞
H 19 25 - ∞ 14 ∞ 28 ∞
Chapter 3 E ∞ 16 ∞ - ∞ 13 ∞ 16
R 19 ∞ 14 ∞ - 24 16 ∞
Opening activity (page 32)
T 13 15 ∞ 13 24 - 10 9
31
G 20 ∞ 28 ∞ 16 10 - 9
Discussion point (page 35) C ∞ ∞ ∞ 16 ∞ 9 9 -
For Kruskal’s algorithm, a computer could easily sort 3 M-W, M-T, T-C, C-G, T-E, G-R, R-H
the weights although the arc labels would need to still Total weight = 82
be attached. What is more difficult is checking that an
arc does not form a cycle with those already included.

104

9781510403130.indb 104 20/03/18 7:49 AM


4 Ca
Ca-Pe = 19  r
O
NT
Pe-Ke = 28  o-Mi =50 instead of Pe-SC
Y
Wo Pe
Mi Ke-La = 20
Ke SC
La-Bl = 22 Total weight = 463
BF
La Bl-Pr = 17

Answers
Sk
Bl Yo
Pr-Li = 30
Pr Le
Pr-Ma = 31
Li Ma Sh Ca-Wo = 32
Pr-Sk = 35
Sk-Le = 28
Le-Yo = 24
Le-Sh = 33
Ke-BF = 34
Pe-SC = 50
SC-Mi = 26
Mi-NT = 34

5 D P B W B L W W W S P
D 5 8 5
P 5 12 6 9 14
B 12 7 9 11 16
W 7 8 7 7
B 6 9 8 8 19 11 8 8
L 11 7 8 25 5 6
W 8 19 25 7
W 5 9 11 7 13
W 14 16 8 5 13 10
S 10
P 7 6
Or from Bere Regis to Lytchett Minster or Wareham
Total weight = 66

105

9781510403130.indb 105 20/03/18 7:49 AM


6 BC-Cy = 19 A-D = 34
Ho Cy
Cr Sh-W = 19 BC-L = 34
BC BC-P = 22 BW-MT = 35
P L
Sh F-MH = 22 Cn-MH = 37
D
Answers

W Cf-MT = 22 Cy-Ho = 38
A
Cr-L = 23 BW-He = 39
BW He D-P = 25 Cf-Sw = 40
F Cn-Sw = 27 D-L = 40
Cn L-W = 28 BC-Ho = 43
MT
MH Sw Cw Cf-Cw = 29 He-MT = 43
Cf L-Sh = 31 A-BW = 45
MT-Sw = 31 …
Cw- He = 33 Total = 523

Exercise 3.2 (page 41)


1 (i) P 2 2 Q 6 7 R 7 9 (iii)
2 7 9 4 2 7 4 13 9
A E I
2 4 9
S 1 0 X 4 4 Y 8 10 T 10 15
6 4 10 15
2 1 6 3 10 6
B F J
U 3 3 V 5 6 W 9 10 1 3 6
3 6 10
1 0 14 12
Path: S – U – V – W – T or S – P – Q – R – T = 15 S T
12
(ii) P 2 2 Q 6 7 R 7 9
2 7 9 3 1 8 4 11 6
C G K
1 4 6
S 1 0 X 4 4 Y 8 10 T 10 15
6 4 10 15
5 3 9 5 12 8
D H L
3 5 8
U 3 3 V 5 6 W 9 10
3 6 10
Path: S – B – F – J – T = 12
Path: S – A – B – F – E – D – T = 8

2 (i) Los Angeles – San Francisco – Salt Lake New Orleans – El Paso then by road to Santa
City – Omaha – Chicago = 42 hours Fe and then by road from Santa Fe – Denver
(ii) New Orleans – Chicago – Omaha – = 31 hours
Denver = 34 hours This is 3 hours quicker than the answer from
(iii) Los Angeles – El Paso then by road to Santa
part (ii).
Fe = 23 hours which is greater than Los
Angeles – Santa Fe by train Exercise 3.3 (page 43)
Los Angeles – Santa Fe then by road to 1 2 seconds
Denver and then Denver – Omaha – Chicago 2 125 seconds
= 42 hours 3 4 + 3 + 2 + 1 = 10 comps and 3 + 2 + 1 = 6
This is no quicker than the answer from part (i). additions

106

9781510403130.indb 106 20/03/18 7:49 AM


Chapter 4 5. (i) 44 days, A, B, C, G, I, L, N
(ii) D = 19 days (independent)
Opening activity (page 44) E = 20 days (independent)
F = 20 days (independent)
3 minutes: grill side 1 of slices 1 and 2, then side 2 of
H and K = 1 day (interfering)
slice 2 and side 1 of slice 3, finally side 2 of slices 1 and 3.
J and M = 2 days (interfering)

Answers
Exercise 4.1 (page 50) (iii) M
K
1. B(2)
J
H
A(5) E(6)
F
E
D
A B C G
C(8) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

M
D(12)
K
2. A = 0, B = 1, C = 2, D = 0 J
H
3. (i) A F
F
E
B D
G I
C I 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

M
D K
G
J
H
E H
F
E
D
J I L N
(ii) 45 minutes 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

(iii) C and I (iv) Delay J by 12 days to extend the project


4. (i) C completion time to 54 days.
6. (i) Reduce A by 2 days
A (ii) Reduce A by 2 days, D by 5 days and F by 1
day.
F
E
Exercise 4.2 (page 54)
B
1. (i) Source = B, sink = E
D (ii) 27
2. All other arcs are either from S or to T, apart from
(ii) e.g. CD. Flow in CD must be from C to D since
Day Harry Nisha cannot have flow into S.
1 A1 B1 (i) The maximum that can enter A is 4, from SA,
2 D1 A2 so at most 4 can flow in AD.
3 E1 C1 B2 (ii) SA = 4, SB = 9, SC = 6, AB = 3, AD = 1,

4 F1 D2
CD = 6, BT = 9, DT = 7
(iii) {S, C}{A, B, D, T} (i.e. cut through SA, SB
5 A3 B3 C2
and CD)
6 D3 C3 (iv) No change, e.g. flow 4 along SADT, 9 along
7 E3 E2 SBT and 6 along SDT to give a flow of 19
8 F3 F2 and cut from part (iv) still has value 19.
107

9781510403130.indb 107 20/03/18 7:49 AM


3. (i) (a) {SABCE}{DT} = 15 Minimise 10x + 5y
(b) {SABC}{DET} = 14 subject to x + y ⩽ 14
(ii) (a) SA = 2, SB = 6, SC = 7, AD = 2, AB = 0, x + y ⩾ 10
BD = 5, BE = 1, CB = 0, CE = 7, DT = 7, x⩾y
ET = 8 and x ⩾ 0, y ⩾ 0
Answers

(b) As above, but with SB = 5, EB = 0, ET = 7.


with x and y integers.
4. (i) Add supersource S connected to S1 and S2,
3. Let x = number of spaces for small cars
with capacity of arc SS1 = 20 and capacity of
and y = number of spaces for large cars
arc SS2 = 30.
(ii) Add supersink T connected to T1, T2 and Maximise x + y
T3, with capacity of arc T1T = 25 or more, subject to 5x + 6y ⩽ 150
capacity of arc T2T = 25 or more and capacity 3x − 2y ⩽ 0
of T3T = 20 or more. and x ⩾ 0, y ⩾ 0
(iii) 47, {SS1S2A}{BCDT1T2T3T} with x and y integers.
5. (i) E 1 G
4. (i) 6000, 750
(ii) Maximise 1.5x + 4y
1 2 2
subject to x + 8y ⩽ 6000
B 1 F x + y ⩽ 180
5 D
and x ⩾ 0, y ⩾ 0
2 3
3 C 2 Activity 5.1 (page 68)
3
(ii) ( )
vertices are (0, 0, 0), 0,0, 3 (0, 1, 0),
4
)( )
A
(ii) 8 ( )(
4 ,0,0 , 13 , 0, 1 , 1, 1 ,0
3 10 10 3

( ) ( )
BE = 0, BA = 3, EG = 0, DG = 2, DF = 1,
DC = 2, AC = 1, AF = 2, GF = 2, CF = 3 (iii) 1, 1 ,0 maximises the objective function 37
3 3
{BACDEG}{F}= 8 Exercise 5.2 (page 68)
Flow = cut so, using maximum flow = 1 6 6
minimum cut, this is the maximum flow. 1. x = 3 ,y = 2 ,P = 8
7 7 7
6. (i) SA = 10, SB = 8, SC = 9 2. (i) Let a = metres of cloth A
(ii) PT = 13, QT = 14 b = metres of cloth B
(iii) J = 6, K = 9, L = 3, M = 5 wool: 2a + b ⩽ 100
(iv) 23 litres per second
dye: 3a + 2b ⩽ 168
prep: 4a + 5b ⩽ 360
Chapter 5
loom: 5a + 4b ⩽ 360
Opening activity (page 59) (ii) The loom time constraint does not contribute
Profit will depend on the demand for the product, to the boundaries of the feasible region.
selling price, cost of making the product, position and (Algebraically, adding the dye constraint to
attractiveness of stall, what other stalls are selling, etc. 0.5× the preparation constraint gives
5a + 4.5b ⩽ 348 and since b ⩾ 0 it follows
Exercise 5.1 (page 62) that 5a + 4b ⩽ 348, for example.)
1. Maximise 2x + 5y 1 2
(iii) 17 metres of cloth A and 58 metres of
subject to x + 2y ⩽ 6000 7 7
1
cloth B to give a profit of £197 .
3x + y ⩽ 6000 7
3. x = 1, y = 2, P = 3
and x ⩾ 0, y ⩾ 0 4. (i) Let x = number of rows of club class,
with x and y integers. y = number of rows of economy class.
2. Let x = number of child passengers If an economy class ticket costs 1 unit then a
and y = number of adult passengers club class ticket costs 1.25 units. The tickets
for a row of economy class seats cost 6 units
108

9781510403130.indb 108 20/03/18 7:49 AM


and the tickets for a row of club class seats so x and y should be chosen so that their sum is as
cost 4 × 1.25 = 5 units. small as possible.
The income from the ticket sales is 5x + 6y,
This gives x = 1, y = 2 and z = 17 which gives P = 56.
which is to be maximised.
x + y ⩽ 30 is the constraint on the number Activity 6.1 (page 75)
of rows.

Answers
2x + y + t = 1500 so x = 750 – 0.5y – 0.5t.
4x + 6y ⩽ 150 is the constraint from the
Substituting for x in P = x + 0.8y gives
number of passengers.
P = 0.3y – 0.5t + 750, so P – 0.3y + 0.5t = 750.
x ⩽ 10 is the constraint from the number of
Constraint x + y + s = 1000 becomes 0.5y + s – 0.5t = 250,
club class tickets.
constraint 3x + 2y + u = 2400 becomes
(ii) The optimal solution of the LP problem is
0.5y – 1.5t + u = 150.
x = 10, y = 18.33.
Checking feasible points near this:
Exercise 6.1 (page 77)
(10, 18) gives income 158 units
1. P = 192, x = 3, y = 6 or x = 6, y = 4.
(9, 19) gives income 159 units
1 1
The best integer solution is 9 rows of club 2. P = 12 , x = 1, y = , z = 0.
3 3
class seats and 19 rows of economy seats. 3. P = 350, w = 50, x = 100, y = 0, z = 0.
(iii) x + y = 30 and x = 10 intersect at (10, 20) so 1 2 2
4. P = 333 , w = 66 , x = 66 , y = 0, z = 0.
the capacity becomes 160. 3 3 3
5. (i) 200x + 420y ⩽ 2000 ⇒ 10x + 21y ⩽ 100, Exercise 6.2 (page 81)
1600x + 1800z ⩽ 10000 ⇒ 8x + 9z ⩽ 50 1. P = 192, x = 6, y = 4 or x = 3, y = 6.
1800y + 1200z ⩽ 3000 ⇒ 3y + 2z ⩽ 5 1 1
2. P = 12 , x = 1, y = , z = 0.
(ii) 6.25 3 3
3. P = 100, w = 0, x = 50, y = 50, z = 0.
(iii) z = 1 (5 – 3y)
2 1 2 2
10x + 21y ⩽ 100 4. P = 83 , w = 16 , x = 16 , y = 50, z = 0.
3 3 3
9
8x + (5 – 3y) ⩽ 50 ⇒ 16x – 27y ⩽ 55
2
Exercise 6.3 (page 83)
 1. P = 10.2 when x = 3.4, y = 0
(iv) Maximise 3x + 3.6y + 6  1 (5 – 3y)
2  2. The problem is:
= 15 + 3x – 5.4y maximise P = 25x1 + 30x2
Subject to 10x + 21y ⩽ 100 subject to 20x1 + 30x2 ⩽ 690
16x – 27y ⩽ 55 5x1 + 4x2 ⩽ 120
3y ⩽ 5 and x1 ⩾ 0, x2 ⩾ 0.
x ⩾ 0 and y ⩾ 0 The solution is P = 750
(v) 50 g when x1 = 12, x2 = 15.
3. (i) Row 7: 1 0 0 2.5 1.5 0.25 11.5
Chapter 6 Column F: 0 0 1 0.25 −0.25 0.375
(ii) 2.25 is the value of y (or the second variable)
Opening activity (page 71) at the optimum solution.
4. The problem is to maximise P = 5x + 8y subject
The feasible points could be listed but this would be
to 7x + 3y ⩽ 42, 2x + 5y ⩽ 40,
a long list. For each integer value of x from 1 to 12, y
The maximum value of P is 69.58621 when
can be any integer from 2 to (25 − 2x)/3 and z can be
x = 3.013448 and y = 6.758621 with no slack in
any integer from 3 to (25 − 2x − 3y).
either constraint.
P = x + 2y + 3z has positive coefficients, so for any 5. (i) x = 1.797, y = 4.695
values of x and y the largest possible z value should be (ii) x = 3, y = 3
chosen.
This gives P = x + 2y + (25 − 2x − 3y)
= 25 − x − y

109

9781510403130.indb 109 20/03/18 7:49 AM


Chapter 7 BE + CE + DE − EB − EC −
ED − ET = 0
Opening activity (page 86) SB ⩽ 15, SC ⩽ 8, BC ⩽ 11, CB
ABD, ABCD, ACD, ACBD ⩽ 11,
BD ⩽ 23, DB ⩽ 23, BE ⩽ 4,
Answers

Exercise 7.1 (page 90) EB ⩽ 4, CD ⩽ 9, DC ⩽ 9,


1. Minimise T CE ⩽ 6, EC ⩽ 6, DE ⩽ 17,
subject to T − H ⩾ 13 ED ⩽ 17, DT ⩽ 11, ET ⩽ 13
T − F ⩾ 12 and all variables ⩾ 0.
H− G ⩾ 3 (ii) Maximum flow from S to T = 23
H−C⩾5 SB, SC, CE, DT are full to capacity
Flow in BD = 15, CD = 2, DE = 6, ET = 12
G − A ⩾ 15
4. (i) AB + AC = 1
F−E⩾8 A is the start vertex, the longest path uses
F−D⩾2 either AB or AC
E − B ⩾ 10 AB + CB − BC − BD = 0
If the longest path enters vertex B it must
E − A ⩾ 15
leave it again
D − A ⩾ 15 AC + BC − CB − CD = 0
C − B ⩾ 10 If the longest path enters vertex C it must
C − A ⩾ 15 leave it again
and all variables ⩾ 0 BD + CD = 1
D is the finish vertex, the longest path uses
2. (i) Minimise 15AB + 8AC + 5AD + 2AF +
either BD or CD
8CA + 11CB + 9CD + 12CF +
BC + CB ⩽ 1 so BC and CB are not both
5DA + 23DB + 9DC + 11DF +
used.
21EA + 40EB + 26EC + 17ED
 e.g. flow 11 along SBDT, flow 4 along
+ 13EF + 2FA + 17FB + 12FC +
SBDET, flow 2 along SCDET, flow 6 along
11FD
SCET.
subject to EA + EB + EC + ED + EF = 1
(ii) ACBD = 12.
CA + DA + EA + FA − AB − AC −
5. (i) (a) xi represents the number of full-sized rolls
AD − AF = 0
to be cut according to cutting plan i.
AC + DC + EC + FC − CA − CB The constraints ensure that there are at
− CD − CF = 0 least 150 4 m rolls, 200 3 m rolls and 100
AD + CD + ED + FD − DA − DB 2 m rolls.
− DC − DF = 0 (b) The way to fulfil the order that minimises
AF + CF + DF + EF − FA − FB − the trim loss (waste).
FC − FD = 0 (ii) (a) 1 1 1 0 0 0
AB + CB + DB + EB + FB = 1 2 1 0 1 0 1
and all variables are indicator variables 3 1 0 0 1 1.4
(ii) The shortest path is 30 units, which can be 4 0 2 0 0 1
achieved by travelling e.g. EFB or EFAB. 5 0 1 2 0 0
3. (i) Maximise SB + SC 6 0 1 1 1 0.4
subject to SB + CB + DB + EB − BC − 7 0 1 0 2 0.8
BD − BE = 0 8 0 0 3 0 1
SC + BC + DC + EC − CB − 9 0 0 2 1 1.4
CD − CE = 0
10 0 0 1 3 0.2
BD + CD + ED − DB − DC − 11 0 0 0 4 0.6
DE − DT = 0

110

9781510403130.indb 110 20/03/18 7:49 AM


(b) Minimise x1 + x2 + x3 + x4 + x5 + x6 + A5 + B5 + C5 + D5 + E5 + F5 = 1
x7 + x8 + x9 + x10 + x11 A6 + B6 + C6 + D6 + E6 + F6 = 1
subject to
with all variables as indicator variables.
x1 + x2 + x3 ⩾ 150
3. A is matched with Y, B with X, C with Z
x1 + 2x4 + x5 + x6 + x7 ⩾ 100 and D with W.

Answers
x2 + 2x5 + x6 + 3x8 + 2x9 + x10 ⩾ 250 4. (i) 2 + 4 + 1 + 4 + 2 = 13 hours.
x3 + x6 + 2x7 + x9 + 3x10 + 4x11 ⩾ 300 (ii) The total time from the depot to A, B, C, D,
the job durations and the total time from W,
with all variables non-negative integers.
X,Y, Z to the depot are fixed, so to minimise
Trim loss = x2 + 1.4x3 + x4 + 0.4x6 the total time the total transfer time should be
+ 0.8x7 + x8 + 1.4x9 + 0.2x10 minimised.
+ 0.6x11. Minimise AW + 2AX + 2AY + 3AZ + 2BW
+ BX + 3BY + 2BZ + CW + 4CX + 3CY
TECHNOLOGY (Page 94) + 3CZ + 3DW + 2DX + DY + DZ
Least cost allocation is W1 to S1, W2 to S4, W3 to S3 and subject to AW + AX + AY + AZ = 1
W4 to S2, total cost 238.
BW + BX + BY + BZ = 1
CW + CX + CY + CZ = 1
TECHNOLOGY (Page 95) DW + DX + DY + DZ = 1
Least cost 2280, W1S1 = 10, W1S2 = 5, W2S3 = 6, W2S4 = AX + BX + CX + DX = 1
6, W3S2 = 2, W3S3 = 6, W4S2 = 3
AY+ BY + CY + DY = 1
Exercise 7.2 (page 96) AZ + BZ + CZ + DZ = 1
1. Min 3AX + 6AY + 4AZ + 7BX + 4BY + 6BZ with all variables as indicator variables.
+ 6CX + 4 CY + 5 CZ (iii) A is paired with Y, B with X, C with W
subject to AX + AY + AZ = 1 and D with Z.
BX + BY + BZ = 1 Total transfer time = 2 + 1 + 1 + 1 = 5
hours.
CX + CY + CZ = 1
Total time taken = 51 hours.
AX + BX + CX = 1 5. (i) 20 000 000 A is the cost of building factory A,
AY + BY + CY = 1 or not.
AZ + BZ + CZ = 1 3.5AX is the cost of manufacturing AX
with all variables as indicator variables. components at A and shipping them to X,
similarly 4AY is the cost of manufacturing AY
2. Minimise 6A1 + 5A2 + 3A3 + A5 + 2A6 + B1 +
components at A and shipping them to Y.
2B2 + 5B3 + 3B5 + 10C1 + 7C2 + 2C4 + 3C6 +
(ii) AX + AY − kA ⩽ 0 ensures that if anything
4D4 + D5 + 5D6 + 6E1 + 3E2 + 2E3 + 5E5 + 4E6
is produced at A, then the factory has to
+ 3F1 + 7F2 + 3F4 + 2F5 + F6
be built. k must be (at least) the sum of the
subject to
maximum possible values that AX and AY can
A1 + A2 + A3 + A4 + A5 + A6 = 1 take.
B1 + B2 + B3 + B4 + B5 + B6 = 1 (iii) AX + BX + CX ⩾ 30 000 000.
C1 + C2 + C3 + C4 + C5 + C6 = 1
D1 + D2 + D3 + D4 + D5 + D6 = 1
E1 + E2 + E3 + E4 + E5 + E6 = 1
F1 + F2 + F3 + F4 + F5 + F6 = 1
A1 + B1 + C1 + D1 + E1 + F1 = 1
A2 + B2 + C2 + D2 + E2 + F2 = 1
A3 + B3 + C3 + D3 + E3 + F3 = 1
A4 + B4 + C4 + D4 + E4 + F4 = 1

111

9781510403130.indb 111 20/03/18 7:49 AM

You might also like