File Exchange

image thumbnail

Fast Linear Assignment Problem using Auction Algorithm (mex)

version 2.6 (5.7 KB) by

Mex Implementation of Bertsekas' auction algorithm for solving the linear assignment problem

9 Ratings



View License

Mex implementation of Bertsekas' auction algorithm [1] for a very fast solution of the linear assignment problem.
The implementation is optimised for sparse matrices where an element A(i,j) = 0 indicates that the pair (i,j) is not possible as assignment. Solving a sparse problem of size 950,000 by 950,000 with around 40,000,000 non-zero elements takes less than 8 mins. The method is also efficient for dense matrices, e.g. it can solve a 20,000 by 20,000 problem in less than 3.5 mins.
Both, the auction algorithm and the Kuhn-Munkres algorithm have worst-case time complexity of (roughly) O(N^3). However, the average-case time complexity of the auction algorithm is much better. Thus, in practice, with respect to running time, the auction algorithm outperforms the Kuhn-Munkres (or Hungarian) algorithm significantly.
When using this implementation in your work, in addition to [1], please cite our paper [2].

[1] Bertsekas, D.P. 1998. Network Optimization: Continuous and Discrete Models. Athena Scientific.
[2] Bernard, F., Vlassis, N., Gemmar, P., Husch, A., Thunberg, J., Goncalves, J. and Hertel, F. 2016. Fast correspondences for statistical shape models of brain structures. SPIE Medical Imaging, San Diego, CA, 2016.

The author would like to thank Guangning Tan for helpful feedback. If you want to use the Auction algorithm without Matlab, please check out Guangning Tan's C++ interface, available here: .

Comments and Ratings (13)

Florian Bernard

Florian Bernard (view profile)

@fudong: could you please provide an example problem along with the optimal solution that is obtained by the other methods, so that I can look into this?


fudong (view profile)

The solution obtained by this code is different from those by Hungarian/LAPJV/linear program. Moreover, its optimal value is a little bigger than optimal values of Hungarian/LAPJV/linear program.

Thank you.
Tested it on a 3000x3000 array.

Windows SDK C++ does not have reserve as a member of std::unordered_map, so if using such a compiler then the line
should be replaced by the equivalent
objectToAssignmentIndex.rehash(ceil(n / objectToAssignmentIndex.max_load_factor()));

Zorah Lähner

ary die

Florian Bernard

Florian Bernard (view profile)

@Murat Uney: yes, the current code is tailored towards symmetric problems.


Dmitry (view profile)

Murat Uney

I suppose this version is particularly for NxN problems with the MxN variant being the forward-reverse auction* not covered by this function, is that right?
(*) Bertsekas, Castanon, "A forward/reverse auction algorithm for asymmetric assignment problems," Computational Optimization and Applications
December 1992, Volume 1, Issue 3, pp 277–297.


bugfix related to the epsilon heuristic

Guangning Tan

I appreciate the author's constant and timely support. Very nice code. Thank you!

Evan Oman

Fantastic! There are far too few Auction Algorithm implementations available online(besides Bertsekas' Fortran version). Your code is readable, efficient, and exactly what I was looking for.




- use of dmperm() to perform fast feasibility check
- added reference to C++ interface


- improved performance for very large sparse matrices
- added feasibility check


bugfix (concerned benefit matrices where for some of the rows exactly one assignment is allowed, thanks to Gary Guangning Tan for pointing out this problem)


bugfix related to the epsilon heuristic (2)


bugfix related to the epsilon heuristic


updated description


- mex implementation, which leads to a significant performance improvement
- support for sparse matrices





MATLAB Release
MATLAB 9.0 (R2016a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video