← All work

Contract allocation for a commodity exporter

Canvia (IT consulting) · Data Scientist · Dec 2023 – Dec 2024 · 2 min read

est. gross margin +55%costs −40%2 weeks → <20 min

Python · scikit-learn · optimization

Problem
A fishmeal exporter planned blends and contract allocation by hand: around five analysts in Excel, two weeks per cycle.
My role
I built the branch-and-bound allocation, deployed it on the client's Azure Power Apps, and presented the results to about 15 stakeholders, including VPs.
Result
Planning went from two weeks to under 20 minutes; the client's month of testing estimated gross margin +55% and operating costs −40%.

The problem, from zero

Fishmeal sells by quality band (super prime, prime, and lower grades), and a pile's band is determined by its measured composition: protein, fat, histamine, and other metrics. The interesting part is that piles can be blended, and blending produces a new pile with a new composition. The goal is not to maximize premium volume; it is to maximize revenue across all contracts. And blending has hard constraints: some piles can be blended up into a higher band, while others can never reach it no matter what you mix them with.

Allocation adds a second layer. Clients contract tonnage per quality band, and partial fulfillment is not free: if a contract takes most of a quality's stock, the leftover tons must still meet that band's composition to be sellable later. Piles come in fractional weights and live in physical bags, and splitting a bag is expensive and slow, so the plan has to hit contract tonnage as closely as possible while splitting as few bags as possible and keeping every composition constraint intact.

What existed before

Around five analysts working across Excel sheets, hand-picking piles by trial and error. Two weeks of planning, even for small contracts.

What I built

A branch-and-bound search over blend and allocation combinations: I enumerated the combinations as a tree and pruned aggressively, cutting a whole branch as soon as partial results proved it could not contain a better solution. Planning went from two weeks to under 20 minutes. The client asked for delivery through Azure Power Apps, so that is how it was deployed, and I presented results to about 15 client stakeholders, including VPs. Delivering on the client's own stack, then standing in their room to defend the numbers, is forward deployed work, and it is the part I want more of.

Piles + contracts blend A blend B Allocate Allocate cut cut best plan cut cut = its best possible revenue cannot beat the best complete plan found so far, so the whole branch is skipped Every plan must keep each band's composition hit contract tonnage closely leave sellable leftovers split few bags ~5 analysts, Excel, 2 weeks branch-and-bound, under 20 minutes
The search behind the plan, and the rules every plan has to respect.

How the client measured it

The client ran a month of testing on their own data: the algorithm's plans against the plans their team produced, with the client setting the baseline. Their estimate: gross margin up 55% and operating costs down 40%.