Bipartite Matching
I need to find an algorithm (preferably in Java) to solve the following problem (hoping it will be clearly expressed):
Given a matrix (not necessarily square) of 1 and 0 values, like the following:
I must be able to determine the maximum number of cells, so that there are no pairs of cells among those selected having a row or a column in common.
For example, if the cell (Row_A, Col_Y)
was selected, then the cells (Row_A, Col_V)
, (Row_A, Col_S)
, (Row_C, Col_Y)
, (Row_G, Col_Y)
must be excluded.
The problem must be tackled as a bipartite graph, where a partition of the nodes is repres开发者_如何学Cented by rows, and columns from the other. There is a link only between nodes that have 1 in their respective cells.
So we will have the partition Part_Row, that will contain the following nodes: A, B, C, D, E, F, G. While the partition Part_Col will contain the nodes: Z, Y, X, W, V, T, S, R, Q. The arches will be:
A->Y, A->S
B->Z, B->D
C->Y, C->X, C->S,
etc., etc.
How can I determine the maximum number of cells? Does it make sense to solve the maximum matching problem as a problem of maximum flow?
精彩评论