FM Modelling With Algorithms
FM Modelling With Algorithms
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
AS and
A LEVEL
FURTHER
MATHEMATICS
Modelling with Algorithms
iii
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.
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.
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.
Chapter 1 Algorithms
Step 2 If M < 3 then M = M + 12 and Y = Y – 1
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?
−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
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?
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
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.
3x2 + 2x + 9: 3 multiplications 1
and 2 additions
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.
● 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.
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
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
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.
10
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.
11
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.
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
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
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
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
➤ 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
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
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
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
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.
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
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)
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
(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.
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.
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.
Figure 2.10
20
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
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.
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
① 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
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
23
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
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
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
26
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
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
29
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
➤ understand the terms simple, connected, complete, bipartite, tree and digraph in
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
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.
Historical note
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
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
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
52 31 41 30 31
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
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
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
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
④ 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
Holyhead 3
38 47
Conwy Chester
43 19
50 Betws-y-Coed 23
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
39
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
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
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
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
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–)
44
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)
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
Example 4.1 Figure 4.2 shows an activity network in which three dummy activities have been
used.
Table 4.2
C E
2 5 7
F H
A
6
1 8
B
G
D
3 4
Figure 4.2
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.
46
0 22 42
shower (3) dry hair (8) dress (10) drive to interview (20)
1 2 3 4 5
3 12
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.
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
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
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
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
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
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
52
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
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
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
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
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
58
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
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
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
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
2 Graphical solutions
When a problem has just two variables it can be illustrated graphically.
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
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.
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
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
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
(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.
67
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.
(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
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.
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?
69
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
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)
71
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
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
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
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
75
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
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
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
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
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
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
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
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
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
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
Figure 6.2
(i) Complete the missing row 7 and column F.
(ii) Interpret the entry 2.25 in cell G9.
83
④ Table 6.19 shows the answer report from a linear programming solver.
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
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
85
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
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.
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
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
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
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
5 3
4 T
S
4
3
Figure 7.3
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
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
⑤ 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.
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.
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
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
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
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
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
97
The initial costs of building production plants, the cost per component and
plant capacities over five years are given in Table 7.15.
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
99
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’
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…
101
(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
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
vertices.
(iii) A, B, D together; C, E together; F on its own
3 (i) (3) (1)
B R
103
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
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
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
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
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
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
( ) ( )
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
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
110
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