Hungarian Algorithm Vida Movahedi Elderlab, York University June 2007.

Slides:



Advertisements
Similar presentations
The Assignment Problem
Advertisements

Min-Max Relations, Hall’s Theorem, and Matching-Algorithms Graphs & Algorithms Lecture 5 TexPoint fonts used in EMF. Read the TexPoint manual before you.
Assignment Problem: Hungarian Algorithm and Linear Programming collected from the Internet and edited by Longin Jan Latecki.
Operations Research Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD4207 University of Palestine.
Transportation Problem (TP) and Assignment Problem (AP)
Introduction to Algorithms
Assignment Meeting 15 Course: D Deterministic Optimization Year: 2009.
R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 8 Network models.
Augmenting path algorithm Two theorems to recall: Theorem (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting.
Quantitative Techniques for Decision Making M.P. Gupta & R.B. Khanna © Prentice Hall India.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
(Algorithms in Bipartite Graphs). Introduction Algorithms in unweighted bipartite graph (Yehong & Gordon) Maximum matching A simple algorithm Hopcroft-Karp.
Allocation problems - The Hungarian Algorithm The Hungarian algorithm Step 1Reduce the array by both row and column subtractions Step 2Cover the zero elements.
The Out of Kilter Algorithm in Introduction The out of kilter algorithm is an example of a primal-dual algorithm. It works on both the primal.
Yangjun Chen 1 Bipartite Graphs What is a bipartite graph? Properties of bipartite graphs Matching and maximum matching - alternative paths - augmenting.
The Hungarian algorithm for non-square arrays
Assignment Problem Step by Step illustration automatically generated by a C# application:)
Matchings Matching: A matching in a graph G is a set of non-loop edges with no shared endpoints.
Maximum Bipartite Matching
Matchings Matching: A matching in a graph G is a set of non-loop edges with no shared endpoints Maximal Matching: A maximal matching in a graph is a matching.
Yangjun Chen 1 Bipartite Graph 1.A graph G is bipartite if the node set V can be partitioned into two sets V 1 and V 2 in such a way that no nodes from.
1 Bipartite Matching Lecture 3: Jan Bipartite Matching A graph is bipartite if its vertex set can be partitioned into two subsets A and B so that.
Linear Programming Applications
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Maximum Bipartite Matching In a graph G, if no M-augmenting path exists, then M is a maximum matching in G. Idea: Iteratively seek augmenting paths to.
CSE, IIT KGP Matchings and Factors. CSE, IIT KGP Matchings A matching of size k in a graph G is a set of k pairwise disjoint edges.A matching of size.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Slide 1 of 27 Assignment Problem: Hungarian Algorithm and Linear Programming collected from the Internet and edited by Longin Jan Latecki.
Chapter 7 Transportation, Assignment & Transshipment Problems
1 Optimal Cycle Vida Movahedi Elder Lab, January 2008.
Assignment Problem. Definition Assignment Problem is a balanced transportation problem in which all supplies and demand are equal to 1.
Notes 5IE 3121 Knapsack Model Intuitive idea: what is the most valuable collection of items that can be fit into a backpack?
5.8 Graph Matching  Example: Set of worker assign to a set of task  Four tasks are to be assigned to four workers.  – Worker 1 is qualified to do tasks.
3.2 Matchings and Factors: Algorithms and Applications This copyrighted material is taken from Introduction to Graph Theory, 2 nd Ed., by Doug West; and.
1/24 Introduction to Graphs. 2/24 Graph Definition Graph : consists of vertices and edges. Each edge must start and end at a vertex. Graph G = (V, E)
Two Discrete Optimization Problems Problem: The Transportation Problem.
1 Network Models Transportation Problem (TP) Distributing any commodity from any group of supply centers, called sources, to any group of receiving.
5.8 Graph Matching  Example: Set of worker assign to a set of task  Four tasks are to be assigned to four workers.  – Worker 1 is qualified to do tasks.
Matching Algorithms and Networks. Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 25.
Network Flow Problems – The Assignment Problem
TM 631 Optimization Assignment Problems. Prototype Problem K-Corp has 3 parts, each of which can be assigned to 1 of 3 machines. The problem is to assign.
Introduction to Graph Theory
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Matchings and Factors Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering,
The Hungarian Algorithm – Maximisation problems The Hungarian algorithm for maximisation problems To solve a maximisation problem using the Hungarian algorithm,
Example Program Development
Assignment Problem: Hungarian Algorithm and Linear Programming collected from the Internet and extended by Longin Jan Latecki.
The Hungarian algorithm for non-square arrays
Chapter 10 Iterative Improvement
ENGM 535 Optimization Assignment Problems.
BIPARTITE GRAPHS AND ITS APPLICATIONS
Assignment Problem: Hungarian Algorithm and Linear Programming collected from the Internet and extended by Longin Jan Latecki.
Bipartite Graphs What is a bipartite graph?
Algorithms and Networks
The Taxi Scheduling Problem
1.3 Modeling with exponentially many constr.
Assignment Problem A balanced transportation problem in which
Assignment Problem: Hungarian Algorithm and Linear Programming collected from the Internet and extended by Longin Jan Latecki.
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Analysis of Algorithms
Chapter 7 Transportation, Assignment & Transshipment Problems
R. Johnsonbaugh Discrete Mathematics 5th edition, 2001
Problem Solving 4.
Systems of distinct representations
Bipartite Graph 1. A graph G is bipartite if the node set V can be partitioned into two sets V1 and V2 in such a way that no nodes from the same set are.
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
The Hungarian algorithm for non-square arrays
Richard Anderson Lecture 22 Network Flow
Assignment Problem: Hungarian Algorithm and Linear Programming collected from the Internet and extended by Longin Jan Latecki.
Presentation transcript:

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

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, J. Munkres, "Algorithms for the Assignment and Transportation Problems", Journal of the Society of Industrial and Applied Mathematics, 5(1):32-38, 1957.

The Assignment Problem

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

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?

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

Bipartite Graphs & The Matching Problem

Bipartite Graph IndividualsJobs Alternatin g Path

*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.

*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)?

*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.

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?

*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-augmenting path M-augmenting paths can be used to enlarge matchings. M !M M An M-alternating path whose endpoints are unsaturated by M.

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

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

Network Flow

Matching as Network Flow t s Bipartite Graph Network Flow Augmentation Graph

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?

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

*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

Network Flow Red 1Red 2Red 3Red 4 Blue Blue Blue Blue Knowing the following capacities, what is the maximum flow from source to sink?

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

The Hungarian Algorithm

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 )

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 Machine Machine Machine

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.

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.

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.

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 Machine Machine Machine

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.

Example: Step 1(a) Job 1Job 2Job 3Job 4 Machine Machine Machine Machine Job 1Job 2Job 3Job 4 Machine Machine Machine Machine Row Reduction

Example: Step 1(b) Job 1Job 2Job 3Job 4 Machine Machine Machine Machine Job 1Job 2Job 3Job 4 Machine Machine Machine Machine Column Reduction

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?!

Example: Step 2 Job 1Job 2Job 3Job 4 Machine Machine Machine Machine We need 3<4 lines, so continue to Step 3

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.

Example: Step 3 Job 1Job 2Job 3Job 4 Machine Machine Machine Machine Job 1Job 2Job 3Job 4 Machine Machine Machine Machine 40135

Example: Step 2 (again) Job 1Job 2Job 3Job 4 Machine Machine Machine Machine Need 4 lines, so we have the optimal assignment and we stop Zero Assignment

Example: Final Solution Job 1Job 2Job 3Job 4 Machine Machine Machine Machine Optimal assignment How did we know which 0’s to choose?!

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’

Resources (Thanks to Patrick Denis) Mathworks central exchange (download code): adFile.do?objectIde43&objectType=file adFile.do?objectIde43&objectType=file Helpful websites ex.html ex.html

References 9/Slides/MC ppt es/ graph-theory/Ch3 Matching and Factors.ppt /syllabus/03.5-NetworkFlow.ppt