How to implement Kuhn-Munkres Algorithm ( Hungarian Method ) ?

publicclass Hungarian{

Hungarian (int[][] matrix ){

//input a n by n matrix

}

privatevoid initial(){

//some initial process

}

publicint getMin(){

//main idea

initial();

rowSubtract();

columnSubtract();

while( minCover() < this.size ){

modify();

}

return findSolution();

}

publicint getMax(){

//main idea

initial();

for (int i = 0; i < line; i++ )

for (int j = 0; j < line; j++ )

this.c[i][j] *= -1;

rowSubtract();

columnSubtract();

while( minCover() < this.size )

modify();

return findSolution()();

}

privatevoid rowSubtract(){

int[] minRow =newint[line];

for (int i = 0; i < line; i++ )

minRow[i] = Integer.MAX_VALUE;

for (int i = 0; i < line; i++ )

for (int j = 0; j < line; j++ )

if ( minRow[i] > c[i][j] )

minRow[i] = c[i][j];

for (int i = 0; i < line; i++ )

for (int j = 0; j < line; j++ )

c[i][j] -= minRow[i];

}

privatevoid columnSubtract(){

int[] minColumn =newint[line];

for (int i = 0; i < line; i++ )

minColumn[i] = Integer.MAX_VALUE;

for (int i = 0; i < line; i++ )

for (int j = 0; j < line; j++ )

if ( minColumn[i] > c[j][i] )

minColumn[i] = c[j][i];

for (int i = 0; i < line; i++ )

for (int j = 0; j < line; j++ )

c[j][i] -= minColumn[i];

}

privateint minCover(){

//return the number of minimum cover lines

}

privatevoid modify(){

//some modify process

}

privateint findSolution(){

//according the c[][] matrix find a complete bipartite matching

}

}

I don't know how to find a minimum cover lines and a solution!

Could some nice guy give me a hint?

*^^*

[4544 byte] By [S.Y.Leea] at [2007-9-29 5:35:28]
# 1

> I don't know how to find a minimum cover lines and a

> solution!

>

> Could some nice guy give me a hint?

Yes I can but please don't let me scare you away. My hint is: don't implement this algorithm at all. Especially the matrix, or 'tableaux' version is a mess. Try to get the book:

Linear Network Optimization, Algorithms and Code

Dmitri Bertsekas

MIT Press, ISBN 0-262-02334-2

Section 2.1 carefully eplain how to find an initial basic solution and what steps have to be taken in order to find a better basic solution. Finally it defines the criteria for an optimal solution.

good luck and kind regards,

Jos

JosHorsmeiera at 2007-7-14 18:39:35 > top of Java-index,Other Topics,Algorithms...
# 2
anyway ... thx ... *^^*I find that I can use MaxFlow to solve the problem.
S.Y.Leea at 2007-7-14 18:39:35 > top of Java-index,Other Topics,Algorithms...
# 3

> I find that I can use MaxFlow to solve the problem.

If I may ask so, what is the problem you have to solve? If it is a maxflow problem, your problem is a proper subset of MCNF (Minimal Cost Network Flow) problems. If you can solve the latter, you can also solve the Job Assignment problem, Transshipment problem, Transportation problem, Max Flow problem etc. They all avoid that nasty Hungarian tableau algorithm.

kind regards,

Jos

JosHorsmeiera at 2007-7-14 18:39:35 > top of Java-index,Other Topics,Algorithms...
# 4
I just programmed this one.Here you can find the code to do it. http://www.spatial.maine.edu/~kostas/dev/soft/munkres.htmCheers,Konstantine
Konstantinea at 2007-7-14 18:39:35 > top of Java-index,Other Topics,Algorithms...
# 5
Finally, after all these years...
Ragnvald_id2a at 2007-7-14 18:39:35 > top of Java-index,Other Topics,Algorithms...
# 6
Hehe... you 're right.I answered very hastily and neglected to check the posting date.But you never know :-)K
Konstantinea at 2007-7-14 18:39:35 > top of Java-index,Other Topics,Algorithms...
# 7
That's nice, I was looking for an implementation ;-)
alberthendriksa at 2007-7-14 18:39:35 > top of Java-index,Other Topics,Algorithms...