Detailed explanation of Hungarian algorithm principle

Detailed explanation of Hungarian algorithm principle

The main reference is the detailed example link here Detailed example
:
insert image description here
insert image description here
insert image description here
Presumably through the above example, you can basically understand a little bit.
The Hungarian algorithm is used to solve the allocation problem of seeking the maximum allocation. This is an algorithm that is actually used to solve problems at work. Solve the corresponding The cost matrix makes the cost matrix the smallest, and the matching result is the best, which is the original intention of the Hungarian algorithm.

The final best matching problem is completed under the condition that all zeros are covered with the least rows and equal to the size of the matrix (n=4). In some cases, for example, if the matrix is ​​not equal to row and col, the algorithm operation can be completed by padding zeros .

I was also very confused about the optimal result at the time, and I didn’t know how it came about. In the end, after reading a few more examples, I will understand. When there are multiple 0s in each row, which number in the original matrix should be used?

First of all, if the best match is satisfied, you should first independently search for rows with only one zero in each row, find the corresponding number in the original matrix, and then need to satisfy that each column has only one 0 placeholder, and then it is easy to find other rows Count it, it's that simple! Ha ha!

I want to understand the principle of the code, hand masturbation should not be a problem ^ - ^ !

Guess you like

Origin blog.csdn.net/ganbelieve/article/details/114021150