← Back to the lab

Simulation

Medicine supply digital twin (4/14): when there isn’t enough, who gets what?

Splitting in proportion to orders looks fair and isn't. The alternative is to equalize days of coverage, a water-filling problem solved by bisection.

By ·

The supplier delivered half. Or a third. The warehouse has 744 units of an item and the units are asking for 2,480. Someone has to decide how much each one gets, and that decision is made, often, every week.

The rule that looks fair

The usual approach is to split in proportion to orders: if 30 % of what was ordered is available, each unit gets 30 % of its order.

qiprop=A⋅ri∑jrjq_i^{\text{prop}} = A \cdot \frac{r_i}{\sum_j r_j}

It sounds even-handed, but it allocates by what each unit ordered, not by what it needs. And what was ordered depends on how each unit’s maximum was computed, which often comes from a plan that no longer matches its use. A unit whose demand grew orders little for what it uses; one whose demand fell over-orders.

The rule that looks at the patient

What matters at a unit is how many days its stock will last. If there isn’t enough for everyone, the sensible goal is for all units to end up with the same coverage, so none runs out before the rest.

Call that common coverage TT. Unit ii, with real demand did_i and stock sis_i, needs Tdi−siT d_i - s_i units to reach TT days; if it already has more, it gets nothing. We need the TT that allocates exactly what’s available:

N(T)=∑imax⁡(0,  T wi di−si)=AN(T) = \sum_i \max\big(0,\; T\,w_i\,d_i - s_i\big) = A

wiw_i is a weight: in the twin, hospitals count 1.5 and primary care units 1, because running out at a hospital is more serious. Vital items also weigh more.

This procedure is known as water-filling: picture containers with floors at different heights, one per unit, and pour in the available water; the level rises evenly and containers that were already high get nothing until the water reaches them.

How T is found: bisection

N(T)N(T) never goes down as TT goes up: more days need more units. It is continuous and piecewise linear, so it can be searched with bisection: bracket TT between a value that asks too little and one that asks too much, test the midpoint and discard the half that doesn’t work. Each round halves the interval; after 40 rounds the error is about a trillionth of the initial interval.

With eight units

The aid has eight units, two of them hospitals. Each ordered what it needs to reach its 30-day maximum, but that maximum was computed from an old plan: hospital H1 uses 40 units a day and its plan said 24; unit C5 uses 6 and its plan said 10.

With 30 % of what was ordered (744 units):

  • Proportionally, H1 ends up with 6.8 days and C3 with 6.6. Two units, one of them a hospital, will run out before the next weekly delivery.
  • Equalizing coverage, T=9.25T = 9.25: no unit drops below 9.2 days and H1, as a hospital, gets 13.9.

Same units of medicine; what changes is who they reach.

Inventory and allocation tab (“Inventario y asignación”): how the CEDIS inventory is shared among units when it falls short. (Interface in Spanish.) · Open full screen

What comes next

We now know how much each unit gets. Now it has to be delivered. The next post builds the delivery routes with the Clarke and Wright savings algorithm and improves them with 2-opt.