HungarianMethod runs in endless loop in following snip code:
while(coveredNodes.size() != partA.size()){
updateGraph(graph, coveredNodes); printBipartiteGraph(partA, partB); GraphUtils.clearGraph(graph); coveredNodes = getMin(graph, partA, partB); debug("Min Number of covered rows/column=" + coveredNodes.size());
}
Please consider if it is bug.
This is the test code I tried:
public void test_debug(){
MatrixEntry matrix[][] = new MatrixEntry[3][17]; List<INodeExt> vnodes = new ArrayList<INodeExt>(); List<INodeExt> wnodes = new ArrayList<INodeExt>(); for(int i =1; i<4; i++){ INodeExt newnode = GraphExtentionFactory.createNodeExtention("v" + i); vnodes.add(newnode); } for(int i =1; i<18; i++){ INodeExt newnode = GraphExtentionFactory.createNodeExtention("w"+i); wnodes.add(newnode); } List<Integer> pnoderes = new ArrayList<Integer>(); int[][] resultvalue = new int[][]{ {6,14,4,1,1,16,4,5,1,1,3,1,7,6,4,1,1}, {6,12,4,1,1,15,4,5,1,1,3,1,7,6,4,1,1}, {6,13,4,1,1,7,4,5,1,1,3,1,7,8,4,1,1}}; for(int i = 0; i < 3; i++){ for(int j = 0; j < 17; j++){ INodeExt child1 =vnodes.get(i); INodeExt child2 =wnodes.get(j); MatrixEntry me = new MatrixEntry(); me.v = child1; me.w = child2; matrix[i][j] = me; me.result = resultvalue[i][j]; } } int size[] = {3, 17}; /* DEBUG */ printMatrix(matrix, size); /* create a bipartite graph from the matrix */ List<INodeExt> part1 = new ArrayList<INodeExt>(); List<INodeExt> part2 = new ArrayList<INodeExt>(); IDirectedGraphExt graph = createBibartitGraph(matrix, size, part1, part2); /* an optimization to avoid the creation of an empty matrix */ if(graph.getEdgeList().size() == 0){ return; } /* find max bipartite matching in weighted bipartite graph */ MaxWeightedBipartiteMatching mwbm = new MaxWeightedBipartiteMatching(); List<IEdgeExt> MatchedEdges = mwbm.execute(graph, part1, part2); /*increase edges weight of matched nodes in bipartite graph*/ return; }
I re-implement the 'HungarianMethod ' module with python munkres, which can finish the calculating in a short duration:
def execute_with_munkres(self, graph, partA, partB):
Last edit: seven 2014-10-23
I've solved the problem with my HungarianMethod java implementation. It is indeed a bug. please fix!