(Example on the picture above, with root in W4)That’s all for the theory, now let’s look at the algorithm: First let’s have a look on the scheme of the Hungarian algorithm: Step 0. (See Picture 1)Picture 1Here are the global variables that will be used in the code:#define N 55 //max number of vertices in one part#define INF 100000000 //just infinityint cost[N][N]; //cost matrixint n, max_match; //n workers and n jobsint lx[N], ly[N]; //labels of X and Y partsint xy[N]; //xy[x] - vertex that is matched with x,int yx[N]; //yx[y] - vertex that is matched with ybool S[N], T[N]; //sets S and T in algorithmint slack[N]; //as in the algorithm descriptionint slackx[N]; //slackx[y] such a vertex, that// l(slackx[y]) l(y) - w(slackx[y],y) = slack[y]int prev[N]; //array for memorizing alternating paths It’s easy to see that next initial labeling will be feasible: And as an initial matching we’ll use an empty one. The code for initializing is quite easy, but I’ll paste it for completeness: The next three steps will be implemented in one function, which will correspond to a single iteration of the algorithm.Find some initial feasible vertex labeling and some initial matching. If M is perfect, then it’s optimal, so problem is solved. (x – is a root of the alternating tree we’re going to build). When the algorithm halts, we will have a perfect matching, that's why we'll have n iterations of the algorithm and therefore (n 1) calls of the function.Tags: Sdan Skriver Du Et Godt Engelsk EssayLiterary Essays Negative TonesDefence Essay Dramatick PoesieService Industry Business PlanChild Obesity EssayLa Writing Service
Discuss this article in the forums Are you familiar with the following situation?
You open the Div I Medium and don’t know how to approach it, while a lot of people in your room submitted it in less than 10 minutes.
We’ll handle the assignment problem with the Hungarian algorithm (or Kuhn-Munkres algorithm).
I’ll illustrate two different implementations of this algorithm, both graph theoretic, one easy and fast to implement with O(n4) complexity, and the other one with O(n3) complexity, but harder to implement.
Wiley Online Library requires cookies for authentication and use of other site features; therefore, cookies must be enabled to browse the site.