How much of each should the bakery make?
Operations research is the use of mathematics to make the best choice when resources are limited. A bakery with one oven and a sack of flour is a typical case.
Before anybody can find the best plan, the choice must be written down as a model. You will learn to write one from a short story.
By the end of this lesson
Note
I can write a decision as variables, an objective and constraints.
Key words
| Word | What it means | Example |
|---|---|---|
| Decision variable | a number you are free to choose | x = 4 |
| Objective | the quantity you want as large or as small as possible | |
| Constraint | a limit that every plan must respect | |
| Feasible plan | a plan that breaks no constraint | |
| Linear program | a model whose objective and constraints are all straight-line sums |
The cells students fill in are left blank in this preview.
A model has variables, an objective and constraints
The bakery makes batches of loaves and batches of cakes. Let x be the loaf batches and y the cake batches. These are the decision variables: the numbers the baker chooses.
The objective is the profit to make as large as possible. The constraints are the limits: oven hours and kilograms of flour. Nobody can bake a negative batch, so x and y are never below 0.
Worked example: the bakery in one table
| Item | One loaf batch | One cake batch | Available |
|---|---|---|---|
| Oven hours | 1 | 2 | 8 |
| Flour in kg | 3 | 2 | 18 |
| Profit in pounds | 20 | 30 | make it large |
The cells students fill in are left blank in this preview.
The table becomes three lines of algebra
Read the table row by row. The oven row says a loaf batch uses 1 hour and a cake batch uses 2. So the hours used are x + 2y, and this must not pass 8.
The flour row gives 3x + 2y <= 18. The profit row gives the objective: maximise 20x + 30y.
Check a plan against the model
loaves = 4
cakes = 2
oven_used = loaves + 2 * cakes
flour_used = 3 * loaves + 2 * cakes
profit = 20 * loaves + 30 * cakes
print(oven_used, "of 8 oven hours")
print(flour_used, "of 18 kg of flour")
print(profit, "pounds")
# Change loaves to 5 and cakes to 2. Which limit does the plan now break?
A feasible plan breaks no constraint
A feasible plan meets every constraint at once. The plan of 4 loaf batches and 2 cake batches uses 8 oven hours and 16 kg of flour, so it is feasible.
The plan of 5 and 2 needs 9 oven hours, which is too many. It is infeasible, even though its profit looks good.
Test the plan of 4 and 2
docker exec jupyter python3 -c "x = 4; y = 2; print(x + 2 * y <= 8, 3 * x + 2 * y <= 18, 20 * x + 30 * y)"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Test the plan of 5 and 2
docker exec jupyter python3 -c "x = 5; y = 2; print(x + 2 * y <= 8, 3 * x + 2 * y <= 18, 20 * x + 30 * y)"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A common mistake
Warning
Many people think every limit must be used up exactly, so they write an equals sign. A limit is a ceiling. A plan may leave oven time unused and still be feasible. Write <= for a ceiling and use = only when a quantity must be hit exactly.
A diet or timetable has the same parts
A diet problem chooses grams of two foods. The objective is the cost to make as small as possible, and the constraints are minimums of protein and energy, written with >=.
A timetable problem chooses how many hours each person works. The constraints say every shift is covered and nobody works too long. The method is the same: variables, objective, constraints.
Worked example: a cheap meal as a model
| Part | In words | In symbols |
|---|---|---|
| Variables | Portions of rice and of beans | r and b |
| Objective | Spend as little as possible: 40p and 60p a portion | minimise 0.4r + 0.6b |
| Constraint | At least 20 g of protein: 4 g and 10 g a portion | 4r + 10b >= 20 |
| Constraint | No negative portions | r >= 0 and b >= 0 |
The cells students fill in are left blank in this preview.
Going further
In the code block, try three plans of your own. Find one that is feasible and earns more than 140 pounds, if you can.
Then write the model of your own week. Choose two things to spend time on and name a limit on your hours. Say what you want as large as possible.