hrldcpr / hungarian

Hungarian / Munkres' algorithm for the linear assignment problem, in Python
MIT License
71 stars 22 forks source link

for rectangular matrix matching question #15

Open HenryBao91 opened 3 years ago

HenryBao91 commented 3 years ago

Thanks for your code.It's amazing, I ran this code with a big data which size is 35003500. It cost lease than 1 second. But I have an question about the input data. The code only supports square matrix, such as 33 , 66 or 5050. But It doesn't support rectangular matrix, such as 34 , 58 , or 50*80. I wonder my way to solve it is right or not. When I have an rectangular matrix, for example:

    b = np.array(
            [[3,4,6,4,9,5],
            [6,4,5,3,8,3],
            [6,3,2,2,5,3],
            [8,4,5,4,7,2]]
    )

This is an rectangular matrix :4 * 6, so I fill it with an big number,:

    f = 100
    b2 = np.array(
            [[3,4,6,4,9,5],
            [6,4,5,3,8,3],
            [6,3,2,2,5,3],
            [8,4,5,4,7,2],
            [f,f,f,f,f,f], 
            [f,f,f,f,f,f]]
    )

And then, I can run the code ,is it right ? And given a matrix of positive weights, the code finds the minimum weight bipartite matching between to arrays. If I want to find the max, I only need to use the max element of the matrix minus every element. So, if someone element unmatched rows in the case of unbalanced entries,what index will return ? -1 ? or ?