Fork me on GitHub

Fun with Petrol Cost and Car mileage

Petrol has gotten more expensive, so we all drive less than before. Which raises the question: "When is the best time/place to fill petrol?"

Imagine that you are going on a car journey (go to some destination and then return home), but you need to add petrol to complete the journey. Along the route there are various petrol stations with various prices. Where should you fill up?

It will not necessarily be the cheapest station, as that may introduce a longer journey. And it may not be the nearest station, as that may be more expensive. What to do? How do we choose?

Possible Routes

Well - maths (and a plethora of assumptions) come to the rescue! Because: Of course it does.

This turned out to be a far more interesting problem than I initially thought.

Choice of Metric

We need a metric to … well… measure things. A number that can unambigously tell us whether one option is better than another one.

The real world makes this complicated: The vehicle will already have some petrol in it - which may have been bought at a different price. And we don't want to have an empty tank at the end of a journey - we'd be stuck at home! (It is fair assume we do not have a petrol station at home)

When the choices made for one journey will affect the next journey, we cannot consider each journey in complete isolation. We end up having to track how much petrol is left and the price that was bought for. And that complicates things.

There are some options here:

  • Total distance travelled? Unfortunately this will ignore the cost completely. But at least we won't have one journey affecting the next (they all start from "home") unless we cannot make it to the petrol station.

  • The total cost of fuel purchased? That fails to take account for the petrol left in the tank afterwards, which would be important for the next journey…

  • The amount petrol left in the tank after the complete journey? (This would be equivalent to "range in miles after arriving home") Sounds clever, right? Although this would bias the results towards shorter total journeys, it would also bias the results towards filling up "as late as possible". And it would ignore the money aspect completely, which does not sound right…

  • The cost of petrol left in the tank after the complete journey? Similar to above, but at least that takes the price somewhat into account - but it would favour more expensive petrol and filling up "late"!

  • Total cost of petrol consumed? This is complicated by the petrol already present before the journey starts; it may not have been bought at the same price. And it ignores the cost of the petrol remaining in the tank at the end…

  • Measuring the cost per mile somehow? for the journey and ignore the remaining petrol? Sounds closer to "right", but not quite there…

In the end I decided on "total cost of petrol consumed" (lower is better), and I assume that the price per liter of the initial volume of petrol is the same as the petrol purchased. This has the downside of biasing the choices strongly towards "shorter journeys" - even if it means buying expensive petrol (as the petrol left in the tank simply is ignored. And that may have been expensive!)

I'm sure that other metrics are available. Somewhere. Let me know if you have any ideas!

Assumptions

We also need to make some assumptions - which turned out to be quite a few:

  • Fuel efficiency (miles/gallon) is constant - i.e. not affected by how much petrol is in the tank and not affected by the route (hills?) or weather (e.g. winds, rain etc)

  • The cost for driving on the road is the same for all routes are the same - e.g. road tolls, ferry costs, coffee stops etc.

  • Routes are "symmetrical" - the distance from A to B is the same as the distance from B to A. So we ignore things like one-way roads and motorways which only allow you to join in one direction. They were really annoying oddities anyway.

  • The distances for petrol stations are known beforehand. If a new petrol station "pops up" out of nowhere, we can blatantly ignore it. And we assume that they do not suddenly dissapear off the face of the planet.

  • Petrol prices are known beforehand. And they do not change during our journey.

  • We only add petrol once for the journey. Adding petrol at multiple stations with different distances and different prices will surely complicate things! This also implies that our destination is near enough to not require multiple petrol station visits.

  • We cannot sell back any unused petrol. Nobody does that anyway.

  • When adding petrol we fill the tank to the brim. We are not the sort of people prone to half measures.

  • No vehicle breakdowns or accidents. Ever.

  • The wear and tear on the vehicle can be ignored completely.

  • Our time is free. Yes: I know, it really isn't, but I doubt it will make much of a difference here. It's complicated enough already.

Variables

We love variables in maths. So let's define some useful ones:

  • $m_g$ : Petrol efficiency expressed in miles/gallon

  • $m_l$ : Petrol efficiency expressed in miles/litre. This is simply $m_g \times 4.54609$. This also allow us to express the per-mile consumption as ${1 \over m_l} = {4.54609 \over m_g}$

(It would have been great if the UK had gone fully metric and measured fuel efficiency in the same units as they sell petrol in, but the English are English, so we need to deal with the weird gallons here… But we don't have to worry too much about such idiosyncracies if we treat it as a pure maths problem)

  • $a_x$ : Distance from home to petrol station #x in miles

  • $b_x$ : Distance from petrol station #x to the destination in miles

  • $p_x$ : Cost of petrol at petrol station #x in £/ltr

  • $h$ : Distance from the destination to home - in miles. If we want to threat it as a one-way journey, then we can set $h = 0$

The "detour" incurred by going via a petrol station can then be expressed as $a_x + b_x - h$

Doing the Maths

We can express our chosen metric ("total cost of petrol consumed") as:

$p_x \times \frac{ a_x + b_x + h}{ m_l }$

for petrol station #x

Comparing 2 petrol stations

Imagine we have a choice of petrol station #1 and #2. They will have different prices, different distance from home and different distance to the destination.

For petrol station #1 to be the best, this must be true according to our chosen metric:

$p_1 \times {{ a_1 + b_1 + h} \over m_l} < p_2 \times {{ a_2 + b_2 + h} \over m_l}$

Multiply by $m_l$ on both sides (we know this cannot be zero):

$\Leftrightarrow p_1 \times ( a_1 + b_1 + h) < p_2 \times ( a_2 + b_2 + h)$

Divide by $p_2$ on both sides (it won't be zero as petrol is not free):

$\Leftrightarrow \frac{p_1}{p_2} \times ( a_1 + b_1 + h) < a_2 + b_2 + h$

Divide by $a_1 + b_1 + h$ on both sides (it represents the roundtrip length and thus cannot be zero either):

$\Leftrightarrow \frac{p_1}{p_2} < \frac{a_2 + b_2 + h} {a_1 + b_1 + h}$

In other words, it is the ratios of petrol prices and roundtrip lengths that matter:

A petrol stations which sells petrol X% cheaper is a better choice if the increase in roundtrip length is less than X%

Note that the fuel efficiency of the vehicle plays no part in the choice of petrol station; there is no $m_l$ or $m_g$ in the result.

Unfortunately there are a few things the formula does not take into account:

  • Have you got enough petrol to reach the petrol station?

  • How much petrol is left in the tank at the end? Hopefully enough for the next journey - or at least reach a petrol station!

  • Wear and tear on the vehicle is not accounted for

  • Time is not accounted for - and time is money

So we have a formula which appears to be useful, based on our chosen metric

But as we disucssed - the metri has some flaws.

Can we do better? Probably!