Zenpanik
Scheduling the money: job shops, Hungarian matching and AI agents in paymentsBy Pavel Nikolov, November 8, 2026

Part 3: Who pays what

Part 3 of 5 in a deep dive on money movement as an optimization problem, and how AI agents can use scheduling and matching algorithms. Start with Part 1 if you are new to the series.

The assignment problem

The assignment problem has n workers, n tasks and a cost for every pairing. You want the one-to-one assignment with the lowest total cost. Harold Kuhn published the Hungarian method in 1955, naming it after Dénes Kőnig and Jenő Egerváry, whose work it built on, and James Munkres showed in 1957 that it runs in polynomial time (Wikipedia).

Edmonds and Karp, and independently Tomizawa, later brought it down to O(n³). In 2006 historians found that Carl Gustav Jacobi had already solved the problem in the 19th century, in a paper published after his death, in Latin, in 1890.

The mechanics fit in a paragraph. Subtract each row's minimum from that row, then each column's minimum from that column. Look for a full set of zeros with no two in the same row or column; if there isn't one, shift the prices on the uncovered cells and look again.

Under the hood, the algorithm keeps a price for every row and every column. When it stops, those prices prove that no cheaper assignment exists (cp-algorithms). An agent that uses it can show an auditor the assignment and the certificate that it is optimal, which a language model's “I think this is best” cannot.

Friday, 16:30 CET: who pays what

This example is illustrative; the costs are made up to show the mechanics. A fintech's treasury agent has three obligations and three liquidity pools, and each pool can cover exactly one obligation today.

The obligations are €4.0 million to German suppliers due today, $6.0 million to US marketplace sellers due Monday at 09:00 ET, and about $1.5 million to a partner in Mexico due Saturday. The pools are EUR at a German bank (T2 and SEPA Instant), USDC in the treasury wallet (24/7, through an off-ramp partner) and USD at a US bank (Fedwire and FedNow).

The agent prices every pairing, adding fees, FX spread and a lateness penalty. The Mexico payment costs a lot from either bank, because neither can deliver it by Saturday.

Figure 4. The Hungarian method on the Friday example, one step every few seconds. Teal numbers are zeros; the shaded cells in step 4 are the assignment. Costs are illustrative.

A greedy agent that handles the largest payment first and gives it the cheapest pool puts the US sellers on USDC (1), the suppliers on the EUR bank (2), and leaves Mexico with the USD bank (20). That costs $23,000, and the Mexico payment arrives late. The Hungarian method gets to $9,000 in one pass, with every payment on time. Of the six possible assignments, the next best costs $19,000.

Total cost of the Friday assignment, $ thousandsLargest first, cheapest poolMexico, late: 2023Hungarian method9Each segment is one obligation. Amber marks the payment that misses its due date.
Figure 5. Greedy against optimal on the same three payments. The greedy rule saves $2,000 on the biggest payment and loses $16,000 on the smallest. Costs are illustrative.

Three jobs with this shape

Funding
Which account or liquidity pool covers which obligation, as in the Friday example.
Reconciliation
Which bank statement line belongs to which ledger entry or invoice. The cost of a pairing is a mismatch score built from amount difference, date gap, reference text and counterparty name. A dummy column with a threshold cost catches lines that match nothing, and those go to the exception queue.
Work routing
Which exception goes to which reviewer or which agent, with cost set to expected handling time or error rate.

Reconciliation is where greedy matching fails most often. A rule that matches each line to its closest entry, in statement order, lets an early line take the entry a later line needed, and both end up wrong. Multi-PSP stacks make it worse, because each provider labels fees, declines and settlements in its own format (Fintech Wrap Up's deep dive on data intelligence in a multi-PSP stack).

The method has two hard limits. It is strictly one-to-one, so one wire that pays three invoices, or one payout split across two rails, needs its more general cousins, min-cost flow or an integer program. And it needs costs as numbers. Turning a statement line, an FX quote and a cut-off into a number is the part an agent is good at, which is where Part 4 starts.

Continue to Part 4: Agents frame, solvers decide