Skip to content
I.STEM Lab

Concept · Applied Maths

The story of the delivery rider: optimisation, constraints and finding the best answer

How to pick the best route, the best mix or the best setting when there are too many choices to try, and why computers search instead of checking everything.

Intermediate8 min read

Key takeaways

  • Optimisation means finding the best choice under limits: maximise a good thing or minimise a bad thing, while obeying constraints.
  • The number of possible solutions can explode, so smart methods search instead of trying everything.
  • Simple heuristics give good answers quickly. Exact methods give the best answer when the problem is small or structured.
  • Machine learning is optimisation: training a model searches for the settings with the lowest error.

Bikram rides a motorbike for a small delivery business in a hill town. Each morning, he loads parcels for several customers scattered along winding roads. The company pays him by the day, and his bosses care about two things: fuel and time. “Just take the shortest way,” they say. Bikram smiles. “Which one is that?”

That question, simple to ask and surprisingly hard to answer, is the beginning of optimisation. It is the mathematics of making the best choice when there are many possibilities and some rules you cannot break.

The three ingredients

Every optimisation problem has the same three parts.

  • The decision: what can you choose? Here, the order in which to visit the stops.
  • The objective: what do you want as large or as small as possible? Here, the total distance, or the time.
  • The constraints: what rules must be respected? Here, each parcel must be delivered, the bike carries only so much, and one customer is only at home after noon.

Writing the problem down in this way often solves half of it. Many disagreements in organisations come from people having different objectives without realising it, such as one wanting speed while another wants low cost.

Too many routes to try

On Monday, Bikram has four stops. He can try them all: four stops can be visited in 24 different orders, which is a small enough list to check by hand. On Friday, he has ten stops. Ten stops can be ordered in 3,628,800 ways, and no one can check that many on paper.

A delivery company with twenty stops faces about 2.4 quintillion possible orders, which is 24 followed by 17 zeros. Even a computer checking a billion routes every second would take decades. The number of choices explodes, and this is the central difficulty of optimisation. It is called a combinatorial explosion.

Simple rules that work well enough

Bikram invents a rule of thumb. Start at the depot, go to the nearest unvisited stop, and repeat. This greedy method, called nearest neighbour, is quick, needs no computer and gives a route that is often 20 to 25 percent longer than the best, but is perfectly sensible.

  • Greedy methods pick the best-looking move at each step. They are fast and simple, but can paint themselves into a corner.
  • Heuristics are practical rules that give good answers without proof that they are the best.
  • Improvement methods start with a route and keep making small changes, such as swapping two stops, as long as they help.

When Bikram looks at his greedy route on a map, he spots two roads that cross, which means he is doubling back. He swaps two stops, and the route uncrosses and gets shorter. This simple improvement step is the basis of many professional routing tools.

Exact methods when the problem has structure

Some problems can be solved exactly, even when they are large, because they have a helpful structure. A farmer, Lhamo, is deciding how to split 10 hectares between rice, which earns 5 units of profit per hectare, and vegetables, which earn 8. Rice needs 2 workers per hectare, vegetables need 3, and she has 24 workers. She wants to maximise profit.

  • Decision: hectares of rice and of vegetables.
  • Objective: 5 times rice plus 8 times vegetables, as large as possible.
  • Constraints: rice plus vegetables is at most 10, and 2 times rice plus 3 times vegetables is at most 24.

Try a few sensible plans. All rice: 10 hectares needs 20 workers and earns 50. All vegetables is limited by labour: 24 divided by 3 is 8 hectares, earning 64. A mix of 6 rice and 4 vegetables uses all land and 24 workers, and earns 30 plus 32, which is 62. The best of these is 8 hectares of vegetables, with 2 hectares left fallow, earning 64.

This kind of problem, with a straight-line objective and straight-line constraints, is called linear programming. Standard methods solve it exactly, even with thousands of variables. Many real planning problems, such as scheduling shifts, blending feeds or allocating budgets, are of this type.

Walking downhill: how models are trained

There is a third family of methods, for smooth problems with many settings. Imagine standing on a foggy hillside, trying to reach the lowest valley. You feel the slope under your feet and step downhill, again and again. This is gradient descent, and it is how machine learning models are trained: the hillside is the error of the model, the position is its settings and the slope tells you which way to adjust.

  • The model has millions of settings, and there are no ways to check them all.
  • Each step reduces the error a little.
  • The method can get stuck in a small dip that is not the lowest, which is why training involves tricks and restarts.

Trade-offs and multiple goals

Real problems rarely have a single objective. Bikram’s bosses want the shortest distance, but customers want early deliveries, and Bikram wants a route that does not take him down the dangerous road after dark. The answers often form a trade-off: a faster route is longer, or a cheaper plan is less reliable.

  • Combine the goals into one score with weights, such as cost plus a penalty for late delivery.
  • Or set a limit on one and optimise the other: the cheapest route that arrives before 5 pm.
  • Or show the set of best compromises, and let people choose.

Where this shows up in AI, maps and 3D

  • Routing: mapping services find the shortest or fastest path through a road network, using algorithms built for the purpose.
  • Site selection: GIS analysts choose where to put a school or a clinic to minimise travel time for the most people.
  • Machine learning: training, tuning settings and choosing which features to use are all optimisation.
  • Photogrammetry: the step that adjusts camera positions and 3D points until errors are smallest, called bundle adjustment, is a huge optimisation.
  • 3D and VR: engines choose how much detail to draw to keep the frame rate high, trading quality against speed.
  • Drone planning: choosing flight lines that cover an area with the least battery.

The formulas behind the story

Bikram and Lhamo faced the same structure: a number to make best, and rules to obey.

n! = n × (n − 1) × … × 2 × 1

Where
  • n: the number of stops
  • n!: the number of different orders in which to visit them

In the story: 4! = 24 orders on Monday, 10! = 3,628,800 on Friday and 20! ≈ 2.4 × 10¹⁸ for twenty stops. This explosion is why searching cleverly beats checking everything.

maximise 5x + 8y subject to x + y ≤ 10 and 2x + 3y ≤ 24, x, y ≥ 0

Where
  • x: hectares of rice, y: hectares of vegetables
  • 5x + 8y: the objective, the profit to make as large as possible
  • the two inequalities: the constraints on land and on workers

In the story: the best corner is x = 0, y = 8, which gives 5 × 0 + 8 × 8 = 64. Check the constraints: 0 + 8 = 8 ≤ 10 and 2 × 0 + 3 × 8 = 24 ≤ 24. Linear programming proves that the best answer sits at a corner of the allowed region.

θ_new = θ − η × ∇L(θ)

Where
  • θ: the model’s settings
  • L(θ): the error (loss) to make small
  • ∇L(θ): the gradient, the slope pointing uphill, so we subtract it to go downhill
  • η (eta): the learning rate, the size of each step

In the story, as a tiny example: let L(θ) = (θ − 3)², so the gradient is 2(θ − 3). Start at θ = 0 with η = 0.1. The gradient is −6, so θ_new = 0 − 0.1 × (−6) = 0.6. Repeat, and θ creeps toward 3, the lowest point.

Try it yourself

  1. 01List six places you visit on errands. Sketch them as dots on a page.
  2. 02Plan a route by always going to the nearest unvisited place. Measure its length.
  3. 03Look for crossing lines, swap two stops to remove them and measure again.
  4. 04Write down your objective and constraints. Did they change what you thought best?

Frequently asked questions

Is the best answer always necessary?
Often a good answer found quickly beats a perfect one found too late. Decide how much better the best could be, and what the search will cost.
What is a local optimum?
A solution that is better than all its close neighbours, but not the best overall, like a small dip on a hillside that is not the lowest valley.
Why do navigation apps sometimes suggest strange routes?
They optimise a combined score, such as predicted time with live traffic, and may weigh things you did not expect, such as turns, tolls or road class.
How is optimisation different from prediction?
Prediction estimates what will happen. Optimisation chooses what to do about it. Many systems predict first and then optimise.

Bikram’s route today is not the mathematically perfect one. It is a good, safe, sensible one, found by a simple rule and a small improvement. That is how most optimisation works in the real world. State the goal and the limits clearly, search intelligently, and be satisfied with a very good answer found in good time.

Share

Join the conversation

Reactions & comments

Comments are opening soon.

In the meantime, tell us what you think by email at info.istem.lab@gmail.com.

Start a project

Need this built for your organization?

If you would rather have a working system than a tutorial, tell us your goal and we will scope it with you.