## Maths in a minute: Some basic linear programming

How many of these should you plant?

Imagine you have an allotment and you want to make some money by planting and selling two crops, cocoa and pineapples (you're lucky to live in a warm country). You obviously want to maximise your return, but you're constrained by how much money you can spend up front and by the size of your plot. How much of each crop should you plant?

This sounds like one of those headachey word problems we all know from school, but it turns out that it has a neat graphical solution. Let’s write for the amount of cocoa you’ll plant and for the amount of pineapples. Suppose that when you harvest the crops you’ll get a unit return of on the cocoa, and of on the pineapples. Your total return will therefore be

(1) |

That’s the amount you’d like to maximise. However, planting also comes with a cost. The unit cost of cocoa seed is , and of pineapple seed is , and there’s an upfront cost just to use the field in the first place. The total cost of growing the two crops is given by

(2) |

You only have in the bank, so you need the total cost to be less than that:

(3) |

The size of the field also provides a constraint. If the amount of space taken up by a unit cocoa is and by a unit pineapple is then the total amount of space taken up in the field by our two crops is given by

(4) |

The size of your plot is , so cannot exceed this value:

(5) |

It’s also clear that and both need to be greater than or equal to (you can’t plant a negative amount of crops).

Here’s how to solve the problem. First, consider a Cartesian coordinate system with the -axis representing cocoa and the -axis representing pineapples. Rewriting inequality 3 and turning it into an equation gives the equation of a line. The points satisfying inequality 3 are those points that lie underneath that line. Similarly, the points that lie underneath the line satisfy inequality 5.

Remembering that both and need to be greater than or equal to , we see that the shaded line in the graph below gives us the points in the -plane satisfying all constraints.

The red line represents *y = -2x + 46* and the blue line represents *y = -x + 30*. The values of *x* and *y* are both positive in the top right quadrant of the coordinate system. Hence, the shaded region contains all the values of *x* and *y* that satisfy all the constraints.

Now what about maximising ? Rewriting equation 1 we see that Whatever the value of , this equation gives a line of slope . By increasing the value of from upwards (use the slider in the Geogebra applet below), we see that the last contact point between the line and the shaded region occurs at the corner point of the shaded region. That's the point for which is maximised but the constraints are still satisfied. Hence you should plant units of cocoa and units of pineapples. Your return will be

Even if the green line, representing the relationship of and and , had a different slope, you can convince yourself that is always maximised at one of the corner points of the shaded region. This is true whatever the numbers in equations 1, 2 and 4. As long as these equations are *linear* (ie don’t involve any powers of and or their products), you can solve the problem by finding a shaded region using the constraints, and then working out for which of its corner points is largest.

Our method is an example of a *linear programming problem*, which involves optimising a quantity subject to restraints, when all the relationships are linear. The method can be extended to work with more constraints (this simply gives you a shaded region possibly bounded by more lines) and also to work when more than two variables (crops) are involved. The extended method is called the *simplex algorithm*. It was invented in 1947 by George Dantzig and has a huge range of applications.