Skip to content

Concepts

The problem

Given source points \(x_1, \dots, x_n\) of \(\mathbb{R}^d\) with masses \(a_i \ge 0\), and target points \(y_1, \dots, y_m\) with masses \(b_j \ge 0\) of the same total, deblais solves the discrete Monge-Kantorovich problem for the cost \(|x - y|^p\), the squared Euclidean cost \(p = 2\) by default:

\[ \min_{P \ge 0} \; \sum_{i,j} P_{ij} \, |x_i - y_j|^p \quad \text{subject to} \quad \sum_j P_{ij} = a_i, \qquad \sum_i P_{ij} = b_j . \]

With probability masses the optimal value is \(W_2^2\), the squared Wasserstein-2 distance between the two measures, and \(W_p^p\) for another exponent. Any \(p > 0\) is accepted (option p); the automatic mode is tuned for \(p = 2\), see Other costs.

This is a linear program, and deblais returns one of its optimal vertices: there is no regularization, no blur and no stopping tolerance. The price is the running time, which grows faster than linearly with the number of points; see deblais and remblais for the trade-off with entropic transport.

The plan

An optimal vertex has at most \(n + m - 1\) non-zero entries, so the plan is returned as a list of arcs (source, target, mass), sorted by source then by target. When \(n = m\) with uniform masses the plan is a permutation: the optimal assignment.

The potentials

The dual problem maximizes \(\sum_i a_i f_i + \sum_j b_j g_j\) over the potentials that satisfy

\[ f_i + g_j \le |x_i - y_j|^p \quad \text{for all } i, j . \]

deblais returns an optimal pair \((f, g)\): the inequality holds for every pair, with equality on the arcs of the plan, and the dual value equals the cost. The potentials are defined up to a constant (\(f + t\), \(g - t\)), and they are the gradient of the cost with respect to the masses.

Points of zero mass take no part in the solve. Their potentials are completed afterwards by a \(c\)-transform, \(f_i = \min_j \bigl(|x_i - y_j|^p - g_j\bigr)\) (and symmetrically for \(g\)), so that the pair stays feasible on all the points.

Certificates

A plan with the right marginals and a feasible pair of potentials with the same value prove each other optimal: this is linear programming duality, and it does not depend on how they were computed. deblais::certify (C++) measures the three quantities:

Field Meaning
marginal_error largest error on a row or column sum, relative to the total mass
gap \(\lvert \text{primal} - \text{dual} \rvert / \text{primal}\)
dual_violation largest \(f_i + g_j - \lvert x_i - y_j \rvert^p\), relative to the largest cost

The last one looks at all the \(n\,m\) pairs: it is meant for tests and for problems of moderate size. The solver itself ends with a pass over all the pairs (with pruning) that finds no arc of negative reduced cost; that is what status == optimal reports.

Integer and real flows

When the masses are uniform on each side, or are integers, the simplex works with integer flows: additions and subtractions of integers are exact, so no tolerance decides whether an arc is saturated. The masses of the plan are then exact multiples of a common unit. Otherwise the flows are doubles. This is automatic; flows forces one or the other.

The reduced costs are always doubles. The final status is stalled instead of optimal in the rare case where the last pass still sees violations that are below what double precision can resolve; max_violation gives their size.

The methods

All the methods return an optimal plan. They differ in speed.

line: closed form in dimension 1

On the line the optimal plan is the monotone rearrangement: sort both clouds and merge. \(O((n + m) \log (n + m))\), a hundred million points in seconds.

simplex: network simplex with column generation

The transport problem is a minimum cost flow on the complete bipartite graph, which has \(n\,m\) arcs. A classical network simplex stores all of them. Here the cost is geometric, so the arcs are never stored:

  • a pricing pass looks at all the pairs for the current potentials and keeps, for each source, the few arcs with the most negative reduced cost. It runs in parallel, filters in single precision before confirming in double, and prunes whole blocks of targets with bounding boxes;
  • the simplex then pivots on this small pool of arcs only, with a strongly feasible spanning tree;
  • when the pool is optimal, a new pass is made. The solve ends when a pass finds nothing.

Memory is linear in \(n + m\). On large problems, helper threads keep pricing ahead of the simplex while it pivots.

multiscale: a warm start from coarse problems

The points are sorted along a Hilbert curve and clustered. The coarse problem between clusters is solved first; its plan and potentials are refined into a start for the next level, down to the full problem. The final simplex then starts close to the optimum.

decomposition: parallel sweeps of a domain decomposition

At each level of the multiscale start, the sources are split into cells. The cells of a partition are independent sub-problems, each between its sources and the targets they currently ship to: they are solved in parallel, and staggered partitions let mass cross the cell boundaries. A few sweeps bring the plan close to the optimum; the global simplex only has to finish the job, with a number of pivots that is a small fraction of the number of points.

For assignment problems (as many targets as sources, uniform masses) the levels are solved by an auction algorithm rather than by the simplex, which is much faster on them; the final simplex starts from the plan of the auction and proves optimality.

The auction lowers its step \(\varepsilon\) in stages, and on uniform clouds a stage costs at most about a hundred bids per point. On clouds with empty regions, such as letters or the tails of a Gaussian, a stage can start a price war: the prices climb by steps of \(\varepsilon\) until a point decides to cross the gap, thousands of bids per point. deblais caps every stage at 128 bids per point. When a stage runs out, the auction gives up and the simplex solves that problem; after three such failures, the auction is turned off for the rest of the solve.

This is the method that benefits the most from several threads (see Performance for the measured scaling), and the default above a few thousand points.