Skip to main content
Notes

Note · Optimization & planning

What the planner already knew.

The most important rules of a delivery operation are not in the data. They are with the person who plans, and the work is to write them down.

Alberto - Coral Data Lab

The routing problem in textbooks has trucks, customers and distances. The one faced by a bulk-liquid delivery operator, with its own and subcontracted fleet, also has rules that appear in no table.

We worked with a portfolio of 250 customers across 3 zones, with an average of about 40 orders a day. One person can hold that volume in their head. That is why almost everything was there.

Three of the rules we found:

  • One customer can only be reached one day a week, because of urban planning restrictions.
  • Others can only be served by one specific truck, because of the size of the entrance.
  • Some zones only accept zero-emission vehicles.

None of them came with the order.

The problem as it appears

An order says what to deliver, where and by when. It does not say that the large truck does not fit through the gate, or that nobody can enter that day.

An optimizer that only knows the order proposes routes that look good and cannot be driven. The first test proposals broke rules that the planner spotted in seconds.

With 40 orders a day, one impossible proposal is enough for the team to stop trusting the others.

What the planner already knew

The planner knows the customers one by one. They know which entrance is narrow, which zone is restricted and which customer only receives on one day.

That knowledge is not a flaw in the process. It is the most valuable part. A system that ignores it starts from zero.

We started by listening. Before touching the model, we went through the previous weeks' orders with the planner and asked them to explain each decision. The rules came from there, one by one.

What we did and why

Our first idea was to write each rule into the optimizer's code. It worked with three rules. With 250 customers in 3 zones it stopped working, because every new customer or regulatory change meant touching the code.

We took a different approach: a flexible constraint system that adapts to each use case. The rules become data that the planner can review. The optimizer does not know them in advance. It reads them.

The formulation

A plan is an assignment of orders to vehicles, routes and times. We call it xx. The optimizer looks for the best possible assignment:

min⁡x  c(x)subject togj(x)≤0,j=1,…,m\min_x \; c(x) \quad \text{subject to} \quad g_j(x) \le 0, \quad j = 1,\dots,m

Here c(x)c(x) is the cost of the plan: kilometres, time, fleet. Each gjg_j is a constraint. If a plan breaks one, it is not valid, however good its cost.

This formulation does not change between customers. What changes is the list of gjg_j. That is where the flexibility lies: the model stays the same and the rules are the parameter.

Two kinds of rule

We separate rules by what happens when they are broken.

Hard rules. No exceptions. A truck that does not fit through the entrance does not enter. A zero-emission zone does not receive any other vehicle. These are the gjg_j above.

Soft rules. They are preferred, but can be broken at a cost. A customer who prefers mornings can receive in the afternoon if there is no other option. These move into the cost, with a weight λk\lambda_k:

min⁡x  c(x)+∑kλk pk(x)\min_x \; c(x) + \sum_k \lambda_k \, p_k(x)

pk(x)p_k(x) measures how far the preference kk is broken. It is zero when the preference is met and grows the further the plan moves from it. The higher λk\lambda_k is, the more it costs to break.

The distinction matters more than it seems, and it can fail in both directions. If a soft rule is declared hard, the system may end up with no solution. It happened to us. If a hard rule is treated as soft, the optimizer will break it as soon as that pays off, and the truck ends up at the gate it cannot pass.

Rules as data

Each rule is described with four elements:

  • Scope: who it applies to. A customer, a zone or a vehicle type.
  • Condition: what is required. "Tuesdays only", "zero-emission vehicle only", "this truck only".
  • Type: hard or soft and, for soft rules, its weight.
  • Validity: since when it applies and where it comes from: a bylaw, a contract, an agreement with the customer.

This is how three rules look, with example data:

Scope Condition Type Validity
Zero-emission zone Zero-emission vehicles only Hard Municipal bylaw
Customer A Vehicle of 3.5 t at most Hard Physical access to the dock
Customer B Morning delivery Soft, high weight Commercial agreement, yearly review

With this, adding a new customer does not touch the optimizer. A row is added. A different use case, for example another sector with other access limits, reuses the same model with other rules.

Why this form and not another

  • It can be reviewed. The planner can read the list and say "this one is missing" or "this one no longer applies". Code is not read the same way.
  • It can be explained. When a proposal leaves a customer out, the system can point to the rules that prevent it. That answer is what justifies human approval.
  • It adapts. Rules change with regulation, fleet and customers. The model does not have to change with them, and the validity field flags when each one needs a review.

The cost is the work up front. The rules have to be collected and organised before the system is of any use. In this case they came from the person who planned, and that part was the slowest.

We kept approval on purpose. The system proposes and the team decides. A route nobody has reviewed is not a route anyone can trust.

What did not work

First attempt: letting the optimizer learn the rules from the route history. Rare rules, such as the one-day customer, appeared too few times and the system treated them as noise. A hand-written constraint fails less than an inferred one.

Second attempt: loading all the rules at once. The resulting plan was so constrained that on some days it had no solution. We moved to introducing them zone by zone and to reviewing with the planner which rules were hard and which were preferences.

Results

The case covers 3 zones with 250 customers and an average of about 40 orders a day. The system monitors the SLA at 72 h and raises an alert when ≤ 6 h remain. 100 % of proposals go through approval before they are executed.

Incidents, defined as orders served after 72 h, fell by 23 % Sept'26 - Nov'26.

The figure describes one operator and one period. We do not present it as a promise for other cases.

What we take with us

Constraints are not invented: they are collected. They come from someone who has planned for years, and the optimizer only applies them. With the next customer we would start the same way, with the list of rules before the model.

Alberto - Coral Data Lab