Code covered by the BSD License  

Highlights from
LAPJV - Jonker-Volgenant Algorithm for Linear Assignment Problem V2.4

5.0

5.0 | 9 ratings Rate this file 25 Downloads (last 30 days) File Size: 4.4 KB File ID: #26836

LAPJV - Jonker-Volgenant Algorithm for Linear Assignment Problem V2.4

by Yi Cao

 

03 Mar 2010 (Updated 16 Jan 2011)

A Matlab implementation of the Jonker-Volgenant algorithm solving LAPs.

| Watch this File

File Information
Description

The Jonker-Volgenant algorithm is much faster than the famous Hungarian algorithm for the Linear Assignment Problem (LAP). This Matlab implementation is modified from the original C++ code made by Roy Jonker, one of the inventors of the algorithm. It is about 10 times faster than the munkres code (v2.2) of the author. It can solve a 1000 x 1000 problem in about 3 seconds in a normal Intel Centrino processor.

V1.1 returns the dual variables and the reduced cost matrix as well.
V1.2 can deal with nonsquare assignment problems.
V2.0 is faster for problems with a large range of costs.
V2.1 includes an option to change the cost resolution to improve performance for some problems.
v2.2 removes a small bug to avoid NAN for 1x1 case.
v2.3 removes a small bug to handle a cost matrix with all inf's.
v2.4 fixes a bug associated with resolution to address the known problem of the algorithm.
Reference:
R. Jonker and A. Volgenant, "A shortest augmenting path algorithm for dense and spare linear assignment problems", Computing, Vol. 38, pp. 325-340, 1987.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Munkres Assignment Algorithm, Hungarian Algorithm for Linear Assignment Problems (V2.3)
This submission has inspired the following:
K-Best Assignment Algorithm, Faster Jonker-Volgenant Assignment Algorithm

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (33)
12 Apr 2010 Turkay YILDIZ

Thank you. Great algorithm and matlab code. I would also very much like to see this algorithm's solution for TSP and other problems, if it's possible.

05 Jul 2010 Amir Hossein  
05 Jul 2010 Amir

it is a great code. how can i get the dual variables?

20 Jul 2010 Yi Cao

Amir,

In the new version (V1.1), dual variables are returned.

Yi

21 Jul 2010 Chaoran Du

Thank you for your code. Its really useful.
Do you know how to solve an asymmetric assignment problem by using the Jonker-Volgenant algorithm? (assign n people to m jobs and n<m)

22 Jul 2010 Yi Cao

Chaoran,

The new version (V1.2) has the ability to deal with nonsquare cases.

Yi

22 Jul 2010 Chaoran Du

Fantastic!
But I can't find V1.2, have you posted it yet?
Thanks again for all your help!

Chaoran

22 Jul 2010 Yi Cao

Chaoran,

Yes, it has been posted and should be online within a day.

Yi

22 Jul 2010 Chaoran Du

Yi, I download the file but the m-file is the same as V1.1, and it shows that the m-file was modified on 19th July while license.txt was modified today. Could you please check the file?

Really appreciate all your help!

Chaoran

22 Jul 2010 Yi Cao

Chaoran,

I reloaded the file now. Wish this time it works.

Yi

23 Jul 2010 Chaoran Du

Hi Yi,

I still can't download the updated version and I don't know if there is something wrong here. Do you mind email me the updated m-file? Thank you very much for all your help!

Email: C.Du@ed.ac.uk

23 Jul 2010 Yi Cao

Chaoran,

The page has not been updated. You can check the 'updates' list for another 22 Jul 2010 item to ensure the file has been updated.

Yi

24 Jul 2010 Chaoran Du

Hi Yi, I've got the m-file, thanks a lot!!!

Chaoran

27 Jul 2010 Amir

 it is a wonderful code. I have some questions which directly or indirectly are related to your code. I would really appreciate if you could find some time and answer my questions:

1. If I want to exclude some assignments such as i-->i assignment, I consider Cii as Big-M. Does the value of Big-M affect the computing time? What is the best value?
2. If I have a matrix whose elements are random integers from the following interval [0 10000] and another one whose elements are from [0 100], does the computing time differ? My experience is that the first one is lengthier.
3. Do you have any experience working with a sparse matrix?
Everybody claims the computing time has to decrease. However, I have a different experience. It remains more or less the same. I think the main reason can be referred to the above item. I think solving a matrix with larger element with LAPJV is lengthier.
4. Can I have negative elements?
5. Is LAPJV v1.1 faster than LAPJV v1.2? Because, in that one you don't calculate dual variables and reduced cost matrix.

12 Aug 2010 Kishore Mosaliganti

Hi,

There is an error in line 85 in the downloaded code. It is not running.
[~,c]=min(v1);

Should the ~ be r ?

13 Aug 2010 Yi Cao

Hi, Kishore,

No, this is not an error. This is a new feature of Matlab since 2009(a?), which indicates that the corresponding output arguments are not needed. If you use an older version, you need to replace ~ with a dummy variable.

Yi

17 Aug 2010 Immanuel Weber

Hi Yi,
as I used your Hungarian-Code before and I want to implement Jonkers&Volgenant's algorithm for rectangular matrices in C, your code was a nice finding. Do you use any of the algorithm modifications presented in Volgenant's papers "Linear and semi-assignment problems, a core oriented approach"[1996] and/or "Solving the Rectangular assignment problem and applications"[2010] to solve rectangular matrices? Or do you use a different, maybe simplier to understand approach?
I'm trying to implement the modifications presented in the last one, but I'm having difficulties with some of the lines in the pseudo code.
In addition I want to point out a little bug, which rarely will occur, but if you use 1x1 matrix as an input for your code, it will compute a NaN cost.

Immanuel

17 Aug 2010 Yi Cao

Immanuel,

Thanks for pointing out the bug. It has been removed in v2.2. In terms of rectangular matriices, I did not know these two references you mentioned. I just used a simple approach to fill the cost matrix with zeros to square it.

Yi

18 Aug 2010 Immanuel Weber

Hi Yi,
that was fast! Okay, that's the solution I want to avoid, as the task in my case is very time critical and resizing an existing 2d array appears to be very unattractive. But nevertheless thanks for your information and your good code.

Immanuel

18 Aug 2010 Amir

anyone has lapjv v1.2?

14 Oct 2010 Jiangmin zhang

i think matlab should take this code into itself as a build-in function

10 Nov 2010 Roberto Olmi

Very usefull code!! Compared to the version 1.1 the version 2.2 seems to be also capable to manage Inf values in the cost matrix. Yi, is it correct?

10 Nov 2010 Roberto Olmi

I've noticed a little bug for scalar input Inf ( lapjv(inf) ). The error occurs at line 85.

10 Nov 2010 Yi Cao

Roberto,

Thanks for pointing this out. Initially, a full Inf cost matrix is not considered. Now, this has been corrected in v2.3.

Yi

12 Nov 2010 KS

What does N stand for in the function parameters? Thanks.

19 Nov 2010 Yi Cao

KS,

The code is updated with more clear explaination. Wish this helps.

Yi

19 Nov 2010 KS  
14 Jan 2011 Andrew McFarland

Great code--I have found some interesting behavior. When I run the "standard" examples like A=rand(1000,1000) for the cost matrix, solves in seconds. However, I have an assignment problem (for PCB assignment) and when I run a 500X500 cost matrix it takes more than a day to solve. I have tried scaling the matrix values and also randomly shuffling the matrix elements and still doesn't reduce the solver time. Is there something inherent in the structure of the cost matrix that can cause the solution to take longer??

14 Jan 2011 Alexander Kosenkov

Andrew McFarland, you should specify second parameter - minimum resoulution for your data. If several values are very close to each other, then it hangs because of a minor bug in programming.

I made a patch to the function - originally EPS function was used incorrectly. I hope, Mr. Cao will fix this in next releases.

Index: lapjv.m
@@ -68,7 +68,7 @@
 if nargin<2
- resolution=eps;
+ resolution=4 * eps(max(max(A)));
 end
@@ -164,7 +164,7 @@
         i0 = colsol(j1);
- if usubmin - umin > eps
+ if usubmin - umin > resolution
             % change the reduction of the minmum column to increase the

14 Jan 2011 Andrew McFarland

Alexander,
Thanks for the help...I tried this out and it did help a lot, but it is still taking much longer with my dataset (for example, 80X80 cost matrix takes ~150 seconds to solve) vs the example ones. Any ideas--maybe normalizing of some sort?

22 Mar 2011 Eric Trautmann

I've been using both of your Munkres and JV LAP algorithm implementations. JV is much faster for a single matrix, as expected, but I also found that when I used the JV algorithm within the Murty k-best assignment algorithm, it was much slower than your implementation of Munkres. When I dug into this, I found that the JV implementation does not cull out rows or columns all marked as inf. When I made this modification (copied the validRow/validCols lines from munkres.m), it sped up the algorithm by a factor of ~7.

25 May 2011 Andy

Sorry here is the costmat code:

costMat = zeros(n,n);

%Populate nxn error matrix
%--------------------------------
for j = 1:n
    for k = 1:n
        costMat(j,k) = ( x_pred(j)-x_meas(k) )^2 + ( y_pred(j)-y_meas(k) )^2;
    end
end

25 May 2011 Andy

My post was deleted somehow

I am having a problem with bad assignments. The data I am using is two sets of 8x2 centroids specified by (row,col). The first set is measured data and tsecond data is predicted via alpha-beta filter. I using the assignemtn algorithm to match up masured data with existing filter pipelines, but even for a simple scenario such as:

meas =
[122.9178,122.9178;122.9178,202.9178;0,0;0,0;0,0;0,0;0,0;0,0];
pred =
[122.4879,121.0182;0,0;0,0;0,0;0,0;0,0;0,0;0,0];

i get
rowsol = [2;3;6;7;8;1;4;5],

wich is obviously not right. Even with Munkres i get
rowsol_munkres = [2;1;3;4;5;6;7;8],

which is still off.

Any suggestions?

Please login to add a comment or rating.
Updates
04 Mar 2010

update descriptions

31 Mar 2010

a bug fixed

19 Jul 2010

Version 1.1 returns dual variables and reduced cost matrix

22 Jul 2010

V1.2 is able to deal with nonsquare cases.

22 Jul 2010

update the file

28 Jul 2010

V2.0 is faster for problems with a large range of cost values.

13 Aug 2010

option to change cost resolution.

17 Aug 2010

v2.2 removes a small bug to avoid NAN for 1x1 case.

10 Nov 2010

Removes a small bug to handle a cost matrix with all inf's.

18 Nov 2010

update description

16 Jan 2011

Big fix

Tag Activity for this File
Tag Applied By Date/Time
linear assignment problemoptimizationhungarian algorithmmunkres Yi Cao 04 Mar 2010 10:43:23
linear assignment problem Yi Cao 04 Mar 2010 12:56:58
optimization Yi Cao 04 Mar 2010 12:56:58
munkres algorithm Yi Cao 04 Mar 2010 12:56:58
hungarian algorithm Yi Cao 04 Mar 2010 12:56:58
hungarian algorithm KS 12 Nov 2010 10:30:52

Contact us at files@mathworks.com