Download presentation
Presentation is loading. Please wait.
Published byShon Greene Modified over 9 years ago
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
The Simple Assignment Problem (Cont.) Start from an assignment Impossible to improve “Complete” “Incomplete” Transfer 1 Transfer 2 New Assignment
8
Bipartite Graphs & The Matching Problem
9
Bipartite Graph IndividualsJobs Alternatin g 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 X 1, …, X m and jobs Y 1, …, Y n. 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 (X i, Y j ) is given a weighting w ij indicated the ‘effectiveness’ (e.g. profit to company) of assigning worker X i to job Y j. 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 {V 1, V 2 }. 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
15
*M-augmenting path M-augmenting paths can be used to enlarge matchings. M !M M An M-alternating path whose endpoints are unsaturated by 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
Matching as Network Flow t s Bipartite Graph Network Flow Augmentation Graph
20
The General Assignment Problem n individuals (i=1, 2, …, n) n jobs (j=1, 2, …, n) cost c ij, cost of individual i to do job j How can we assign the jobs to individuals to minimize the total cost? Rating r ij 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 c ij be the cost of assigning i to j.
22
*Optimization Problem St. X 11 +X 12 +X 13 +X 14 =1 X 21 +X 22 +X 24 +X 24 =1 X 31 +X 32 +X 33 +X 34 =1 X 41 +X 42 +X 43 +X 44 =1 X 11 +X 21 +X 31 +X 41 =1 X 12 +X 22 +X 32 +X 42 =1 X 13 +X 23 +X 33 +X 43 =1 X 14 +X 24 +X 34 +X 44 =1 Min. 4X 11 +6X 12 +5X 13 +5X 14 +7X 21 +4X 22 +5X 23 +6X 24 +4X 31 +7X 32 +6X 33 +4X 34 +5X 41 +3X 42 +4X 43 +7X 44
23
Network Flow Red 1Red 2Red 3Red 4 Blue 12534 Blue 213245 Blue 34383 Blue 413643 Knowing the following capacities, what is the maximum flow from source to sink?
24
Augmentation Graphs -General case u v 0/75 0/10 Flow Graph u v 75 10 Augmentation Graph 75-21=54 21+10=31 u v 21/75 0/10 Flow Graph u v Augmentation Graph
25
The Hungarian Algorithm
26
Why Hungarian? Bipartite graph G with V nodes and E edges The Hungarian algorithm: O(V 3 ) The Network Flow algorithm: O(V.E 2 )
27
Example We must determine how jobs should be assigned to machines to minimize setup times, which are given below: Job 1Job 2Job 3Job 4 Machine 114587 Machine 221265 Machine 37839 Machine 424610
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 c ij x ij = 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 1. From each line (row or column) subtract its minimum element. 2. Find a maximum set of N’ mutually independent zeroes. 3. if N’ = N such zeroes have been found: output their indices and stop otherwise: 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: Job 1Job 2Job 3Job 4 Machine 114587 Machine 221265 Machine 37839 Machine 424610
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) Job 1Job 2Job 3Job 4 Machine 114587 Machine 221265 Machine 37839 Machine 424610 Job 1Job 2Job 3Job 4 Machine 19032 Machine 201043 Machine 34506 Machine 40248 Row Reduction
34
Example: Step 1(b) Job 1Job 2Job 3Job 4 Machine 19030 Machine 201041 Machine 34504 Machine 40246 Job 1Job 2Job 3Job 4 Machine 19032 Machine 201043 Machine 34506 Machine 40248 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 Job 1Job 2Job 3Job 4 Machine 19030 Machine 201041 Machine 34504 Machine 40246 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 Job 1Job 2Job 3Job 4 Machine 19030 Machine 201041 Machine 34504 Machine 40246 Job 1Job 2Job 3Job 4 Machine 110030 Machine 20930 Machine 35504 Machine 40135
39
Example: Step 2 (again) Job 1Job 2Job 3Job 4 Machine 110030 Machine 20930 Machine 35504 Machine 40135 Need 4 lines, so we have the optimal assignment and we stop Zero Assignment
40
Example: Final Solution Job 1Job 2Job 3Job 4 Machine 110030 Machine 20930 Machine 35504 Machine 40135 Optimal assignment How did we know which 0’s to choose?!
41
Munkres Contribution Providing a constructive procedure for finding 1)A minimal set of lines which contain all zeros, 2)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/lo adFile.do?objectIde43&objectType=file http://www.mathworks.com/matlabcentral/fileexchange/lo adFile.do?objectIde43&objectType=file Helpful websites http://en.wikipedia.org/wiki/Hungarian_algorithm http://www.public.iastate.edu/~ddoty/HungarianAlgorithm.html http://www.public.iastate.edu/~ddoty/HungarianAlgorithm.html http://www.ifors.ms.unimelb.edu.au/tutorial/hungarian/ind ex.html http://www.ifors.ms.unimelb.edu.au/tutorial/hungarian/ind ex.html
43
References http://www.skidmore.edu/~adean/MC302040 9/Slides/MC302041019.ppt http://www.math.ntu.edu.tw/~gjchang/cours es/2002-09-graph-theory/Ch3 Matching and Factors.ppt https://www.cse.yorku.ca/~jeff/courses/6111 /syllabus/03.5-NetworkFlow.ppt
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.