This implementation is based on the 1968 Murty algorithm for finding a ranked list of the best assignments for an arbitrary cost matrix.
This algorithm uses a user-supplied assignment algorithm, such as the Munkres (Hungarian) algorithm or the JV algorithm to obtain an arbitrary number of best assignment solutions.
Implementations of Munkres and JV algorithms by Yi Cao can be found here:
Eric Trautmann (2020). K-Best Assignment Algorithm (https://www.mathworks.com/matlabcentral/fileexchange/30837-k-best-assignment-algorithm), MATLAB Central File Exchange. Retrieved .
It does not work properly. Even if you set k=1 and the optimal assignment function provided is correct, the function k_best_assign does not return the correct optimal assignment.
In my program I choose the JV algorithm as the opt_fun in your function.I think the "k_best_assign" main function has not any problems.But the subfunction "partition_node" is wrong.In the subfunction "partition_node",you classify the node_in matrix as three parts,"the fixed_assignments","the excluded_assignments","the tmp".Then input these three parts to the subfunction "calc_node_cost" to calculate the cost and the new [row col] matrix as the next cycle input.But If we take a good look at the code of the subfunction "partition_node",we will find some logic problems.In the progress of calculate cost,firstly you use the "fixed_assignments" to make summation of some previous fixed data.Then you use the "inf" to replace these data,and calculate the cost again.At last,you add up the summation of some previous fixed data and cost,and think the result is the cost.But you are wrong,because except some special situations,the cost you calculated is "inf" for in your function the fixed_assignments has changed some entire rows and entire columns into "inf" .So,most of the costs you calculate is "inf".Therefore,your comparing all the cost to find the minimum cost is meaningless.
Does this code work correctly? I am running
cost_mat = magic(5);
k = 5;
optfun = @munkres;
assignment_list = k_best_assign(cost_mat,k,opt_fun);
The resulting assignment_list has 5 assignments that are all exactly the same, namely [1 1; 1 2; 1 3; 1 4; 1 5] with a cost of 15.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!