1 / 43

Hungarian Algorithm

Hungarian Algorithm. Vida Movahedi Elderlab, York University June 2007. Outline. The Assignment Problem Bipartite Graphs and Matching Network Flow Hungarian Algorithm Example Note: I am using some slides from reference files without any changes, I have marked them with a * in title.

dalila
Download Presentation

Hungarian Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hungarian Algorithm Vida Movahedi Elderlab, York University June 2007

  2. Outline • The Assignment Problem • Bipartite Graphs and Matching • Network Flow • Hungarian Algorithm • Example • Note: I am using some slides from reference files without any changes, I have marked them with a * in title

  3. History • Two Hungarian mathematicians: Dénes König (1936) and Jenő Egerváry (1931) • Harold W. Kuhn, "The Hungarian Method for the assignment problem", Naval Research Logistic Quarterly, 2:83-97, 1955. • J. Munkres, "Algorithms for the Assignment and Transportation Problems", Journal of the Society of Industrial and Applied Mathematics, 5(1):32-38, 1957.

  4. The Assignment Problem

  5. The Simple Assignment Problem • Four individuals (i=1, 2, 3, 4) • Four jobs (j=1, 2, 3, 4) Qualification Matrix 

  6. The Simple Assignment Problem (Cont.) What is the largest number of jobs that can be assigned to qualified individuals (with not more than one job assigned to each individual)? What is the largest number of 1’s that can be chosen from Q with no two chosen from the same row or column?

  7. Transfer 1 New Assignment Transfer 2 The Simple Assignment Problem (Cont.) • Start from an assignment Impossible to improve  “Complete” “Incomplete”

  8. Bipartite Graphs & The Matching Problem

  9. Individuals Jobs Bipartite Graph Alternating Path

  10. *Characterizing Bipartite Graphs • Theorem. Let G be a graph with at least 2 vertices. The following statements about G are equivalent: • 1. G is bipartite. • 2. G can be properly 2-colored. • 3. G has no odd cycles.

  11. *Applications of Bipartite Graphs • Personnel Assignment Problem • A company has workers X1, …, Xm and jobs Y1, …, Yn. Each worker is qualified to do some jobs, but not others. • Can every worker be assigned a job? • Optimal Assignment Problem • Same basic setup as above, but now each pair (Xi, Yj) is given a weighting wij indicated the ‘effectiveness’ (e.g. profit to company) of assigning worker Xi to job Yj. • How should jobs be assigned to maximize the total effectiveness of the assignments? • Marriage Problem • There are k men and m women, and each male-female pair has expressed whether or not they are willing to marry. • How can we pair them up so that all the men are paired with acceptable mates (or the gender-reversed question)?

  12. *Matchings • All three problems involve forming a matching in a bipartite graph: • Definition: Let G be a graph with {V1, V2}. A matching in G is a set of edges, no two of which share an endpoint. • Note: G does not need to bipartite, but in applications it often is.

  13. Maximum and Perfect Matchings • A matching M is maximum if it has the largest size among all possible matchings. • A matching M is perfect if every vertex in G is incident with an edge in the matching. • Does maximum imply perfect? • Does perfect imply maximum?

  14. *M-alternating path • Given a matching M, a M-alternating path is a path that alternates between edges in M and edges not in M !M !M M M

  15. *M-augmenting path • M-augmenting paths can be used to enlarge matchings. • An M-alternating path whose endpoints are unsaturated by M. !M !M !M M M

  16. Berge’s Theorem • Berge’s Theorem: A matching M is maximum if and only if it has no M-augmenting paths.

  17. Formulating - Simple Assignment • Decision variable • Let A be the set of allowed assignments

  18. Network Flow

  19. t s Matching as Network Flow • Bipartite Graph • Network Flow • Augmentation Graph

  20. The General Assignment Problem • n individuals (i=1, 2, …, n) • n jobs (j=1, 2, …, n) • cost cij, cost of individual i to do job j • How can we assign the jobs to individuals to minimize the total cost? • Rating rij indicating the quality of work • How can we assign the jobs to individuals to maximize the total rating?

  21. Formulating- General Assignment • Decision variable • Let A be the set of allowed assignments and cij be the cost of assigning i to j.

  22. *Optimization Problem St. X11+X12+X13+X14=1 X21+X22+X24+X24=1 X31+X32+X33+X34=1 X41+X42+X43+X44=1 X11+X21+X31+X41=1 X12+X22+X32+X42=1 X13+X23+X33+X43=1 X14+X24+X34+X44=1 Min. 4X11+6X12+5X13+5X14 +7X21+4X22+5X23+6X24 +4X31+7X32+6X33+4X34 +5X41+3X42+4X43+7X44

  23. Network Flow Knowing the following capacities, what is the maximum flow from source to sink?

  24. Flow Graph Flow Graph 0/75 21/75 u u v v 0/10 0/10 Augmentation Graph Augmentation Graph 75 u u v v 10 Augmentation Graphs -General case 75-21=54 21+10=31

  25. The Hungarian Algorithm

  26. Why Hungarian? • Bipartite graph G with V nodes and E edges • The Hungarian algorithm: O(V3) • The Network Flow algorithm: O(V.E2)

  27. Example • We must determine how jobs should be assigned to machines to minimize setup times, which are given below:

  28. Hungarian Algorithm • Two Observations • Adding a constant to any row or column does not change the solution  Changing C • If C is nonnegative and åcijxij = 0 then X is a solution. • Let 2 zeroes in C be called independent if they appear in different rows and columns.

  29. Hungarian Theorem • A set of elements of a matrix are said to be ‘independent’ if no two of them lie in the same row or column. • König Theorem: If C is a matrix and m is the number of independent zero elements of C, then there are m lines which contain all the zero elements of C.

  30. Hungarian Algorithm • From each line (row or column) subtract its minimum element. • Find a maximum set of N’ mutually independent zeroes. • if N’ = N such zeroes have been found: output their indices and stopotherwise: cover all zeroes in W with N’ lines and find the minimum uncovered value; subtract it from all uncovered elements, and add it to all doubly covered elements; go to 2.

  31. Example • We must determine how jobs should be assigned to machines to minimize setup times, which are given below:

  32. Hungarian Algorithm • Step 1: (a) Find the minimum element in each row of the cost matrix. Form a new matrix by subtracting this cost from each row. (b) Find the minimum cost in each column of the new matrix, and subtract this from each column. This is the reduced cost matrix.

  33. Example: Step 1(a) Row Reduction

  34. Example: Step 1(b) Column Reduction

  35. Hungarian Algorithm • Step 2: Draw the minimum number of lines that are needed to cover all the zeros in the reduced cost matrix. If m lines are required, then an optimal solution is available among the covered zeros in the matrix. Otherwise, continue to Step 3. How do we find the minimum number of lines?!

  36. Example: Step 2 We need 3<4 lines, so continue to Step 3

  37. Hungarian Algorithm • Step 3: Find the smallest nonzero element (say, k) in the reduced cost matrix that is uncovered by the lines. Subtract k from each uncovered element, and add k to each element that is covered by two lines. Return to Step 2.

  38. Example: Step 3

  39. Example: Step 2 (again) Zero Assignment Need 4 lines, so we have the optimal assignment and we stop

  40. Example: Final Solution Optimal assignment How did we know which 0’s to choose?!

  41. Munkres Contribution • Providing a constructive procedure for finding • A minimal set of lines which contain all zeros, • A maximal set of independent zeros • “Starred zeros” and “Primed zeros” • Alternating sequence between 0* and 0’

  42. Resources (Thanks to Patrick Denis) • Mathworks central exchange (download code): • http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectIde43&objectType=file • Helpful websites • http://en.wikipedia.org/wiki/Hungarian_algorithm • http://www.public.iastate.edu/~ddoty/HungarianAlgorithm.html • http://www.ifors.ms.unimelb.edu.au/tutorial/hungarian/index.html

  43. References • http://www.skidmore.edu/~adean/MC3020409/Slides/MC302041019.ppt • http://www.math.ntu.edu.tw/~gjchang/courses/2002-09-graph-theory/Ch3 Matching and Factors.ppt • https://www.cse.yorku.ca/~jeff/courses/6111/syllabus/03.5-NetworkFlow.ppt

More Related