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:
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.