matching v 1
TRANSCRIPT
-
7/27/2019 Matching v 1
1/26
Slide 1 of 27
Assignment Problem:Hungarian Algorithm and Linear Programming
collected from the Internet and edited by
Longin Jan Latecki
-
7/27/2019 Matching v 1
2/26
Slide 2 of 27
Introduction to Assignment Problem
Let Cbe an nxn matrix representing the costs of each ofn workers to perform any ofnjobs. The assignment problem is to assign jobs to workers so as to minimize the total
cost. Since each worker can perform only one job and each job can be assigned to only
one worker the assignments constitute an independent setof the matrix C.
An arbitrary assignment is shown above in which workera is assigned job q, workerbis assigned jobs and so on. The total cost of this assignment is 23.
Can you find a lower cost assignment?
Can you find the minimal cost assignment?
Remember that each assignment must be unique in its row and column.
-
7/27/2019 Matching v 1
3/26
Slide 3 of 27
Assignment Problem
An assignment problem seeks to minimize the total cost
assignment of m workers to m jobs, given that the costof worker i performing jobj is cij.
It assumes all workers are assigned and each job isperformed.
An assignment problem is a special case of atransportation problem in which all supplies and alldemands are equal to 1; hence assignment problemsmay be solved as linear programs.
The network representation of an assignment problemwith three workers and three jobs is shown on the nextslide.
-
7/27/2019 Matching v 1
4/26
Slide 4 of 27
Assignment Problem
Network Representation
2
3
1
2
3
1c11
c12
c13
c21c
22
c23
c31c
32
c33
WORKERS JOBS
-
7/27/2019 Matching v 1
5/26
Slide 5 of 27
Assignment Problem
Linear Programming Formulation
Min SScijxiji j
s.t. Sxij = 1 for each resource (row) ij
Sxij = 1 for each job (column)ji
xij = 0 or 1 for all i andj.
Note: A modification to the right-hand side of the firstconstraint set can be made if a worker is permitted to workmore than 1 job.
-
7/27/2019 Matching v 1
6/26
Slide 6 of 27
Linear Programming (LP) problems can be solved on
the computer using Matlab, and many others.
There are special classes of LP problems such as theassignment problem (AP).
Efficient solutions methods exist to solve AP.
AP can be formulated as an LP and solved by generalpurpose LP codes.
However, there are many computer packages, whichcontain separate computer codes for these models
which take advantage of the problem networkstructure.
-
7/27/2019 Matching v 1
7/26Slide 7 of 27
A brute-force algorithm for solving the assignment problem involves generating all
independent sets of the matrix C, computing the total costs of each assignment and a
search of all assignment to find a minimal-sum independent set. The complexity of this
method is driven by the number of independent assignments possible in an nxn matrix.There are n choices for the first assignment, n-1 choices for the second assignment and
so on, giving n! possible assignment sets. Therefore, this approach has, at least, an
exponential runtime complexity.
As each assignment is chosen that row and column are eliminated from
consideration. The question is raised as to whether there is a better algorithm. In fact
there exists a polynomial runtime complexity algorithm.
-
7/27/2019 Matching v 1
8/26Slide 8 of 27
From en.wikipedia.org/wiki/Hungarian_algorithm
The Hungarian method is a combinatorial optimizationalgorithm which solves the assignment problem in polynomial
time. It was developed and published by Harold Kuhn in 1955,who gave the name "Hungarian method" because thealgorithm was largely based on the earlier works of twoHungarian mathematicians: Dnes Knigand Jen Egervry.
James Munkres reviewed the algorithm in 1957 and observedthat it is (strongly) polynomial. Since then the algorithm hasbeen known also as Kuhn-Munkres or Munkres assignmentalgorithm. The time complexity of the original algorithm wasO(n4), however later it was noticed that it can be modified to
achieve an O(n3) running time.In 2006, it was discovered that Carl Gustav Jacobi had solvedthe assignment problem in the 19th century, and publishedposthumously in 1890 in Latin.
-
7/27/2019 Matching v 1
9/26Slide 9 of 27
Hungarian Method
The Hungarian method solves minimization
assignment problems with m workers and m jobs.
Special considerations can include:
number of workers does not equal the number ofjobs add dummy workers/jobs with 0 assignment
costs as needed worker i cannot do jobj assign cij = +M
maximization objective create an opportunity lossmatrix subtracting all profits for each job from the
maximum profit for that job before beginning theHungarian method
-
7/27/2019 Matching v 1
10/26Slide 10 of 27
Hungarian Method
Step 1: For each row, subtract the minimum number in
that row from all numbers in that row. Step 2: For each column, subtract the minimum number
in that column from all numbers in that column.
Step 3: Draw the minimum number of lines to cover all
zeroes. If this number = m, STOP an assignment canbe made.
Step 4: Determine the minimum uncovered number(call it d).
Subtract d from uncovered numbers.
Add d to numbers covered by two lines.
Numbers covered by one line remain the same.
Then, GO TO STEP 3.
-
7/27/2019 Matching v 1
11/26Slide 11 of 27
Hungarian Method
Finding the Minimum Number of Lines and
Determining the Optimal Solution Step 1: Find a row or column with only one unlined
zero and circle it. (If all rows/columns have two ormore unlined zeroes choose an arbitrary zero.)
Step 2: If the circle is in a row with one zero, draw aline through its column. If the circle is in a columnwith one zero, draw a line through its row. Oneapproach, when all rows and columns have two ormore zeroes, is to draw a line through one with the
most zeroes, breaking ties arbitrarily. Step 3: Repeat step 2 until all circles are lined. If this
minimum number of lines equals m, the circlesprovide the optimal assignment.
-
7/27/2019 Matching v 1
12/26Slide 12 of 27
Example 1: AP
A contractor pays his subcontractors a fixed fee plus mileage forwork performed. On a given day the contractor is faced with three
electrical jobs associated with various projects. Given below arethe distances between the subcontractors and the projects.
Project
A B C
Westside 50 36 16
Subcontractors Federated 28 30 18Goliath 35 32 20
Universal 25 25 14
How should the contractors be assigned to minimize total costs?
Note: There are four subcontractors and three projects. We create adummy project Dum, which will be assigned to one subcontractor(i.e. that subcontractor will remain idle)
-
7/27/2019 Matching v 1
13/26Slide 13 of 27
Example 1: AP
Network Representation (note the dummy project)
50
36
160
2830
18
0
3532
20
0
25 25
14
0
West.
Dum.
C
B
A
Univ.
Gol.
Fed.
-
7/27/2019 Matching v 1
14/26Slide 14 of 27
Example 1: AP
Initial Tableau Setup
Since the Hungarian algorithm requires that therebe the same number of rows as columns, add a Dummycolumn so that the first tableau is (the smallest elementsin each row are marked red):
A B C Dummy
Westside 50 36 16 0
Federated 28 30 18 0
Goliath 35 32 20 0
Universal 25 25 14 0
-
7/27/2019 Matching v 1
15/26Slide 15 of 27
Example 1: AP
Step 1: Subtract minimum number in each row from all
numbers in that row. Since each row has a zero, wesimply generate the original matrix (the smallestelements in each column are marked red). This yields:
A B C DummyWestside 50 36 16 0
Federated 28 30 18 0
Goliath 35 32 20 0
Universal 25 25 14 0
-
7/27/2019 Matching v 1
16/26Slide 16 of 27
Example 1: AP
Step 2: Subtract the minimum number in each column
from all numbers in the column. For A it is 25, for B itis 25, for C it is 14, for Dummy it is 0. This yields:
A B C Dummy
Westside 25 11 2 0
Federated 3 5 4 0
Goliath 10 7 6 0
Universal 0 0 0 0
-
7/27/2019 Matching v 1
17/26Slide 17 of 27
Example 1: AP
Step 3: Draw the minimum number of lines to cover all zeroes
(called minimum cover). Although one can "eyeball" thisminimum, use the following algorithm. If a "remaining" row hasonly one zero, draw a line through the column. If a remainingcolumn has only one zero in it, draw a line through the row. Sincethe number of lines that cover all zeros is 2 < 4 (# of rows), thecurrent solution is not optimal.
A B C Dummy
Westside 25 11 2 0
Federated 3 5 4 0
Goliath 10 7 6 0
Universal 0 0 0 0
Step 4: The minimum uncovered number is 2 (circled).
-
7/27/2019 Matching v 1
18/26Slide 18 of 27
Example 1: AP
Step 5: Subtract 2 from uncovered numbers; add 2 to all
numbers at line intersections; leave all other numbersintact. This gives:
A B C Dummy
Westside 23 9 0 0
Federated 1 3 2 0
Goliath 8 5 4 0
Universal 0 0 0 2
-
7/27/2019 Matching v 1
19/26
Slide 19 of 27
Example 1: AP
Step 3: Draw the minimum number of lines to cover all
zeroes. Since 3 (# of lines) < 4 (# of rows), the currentsolution is not optimal.
A B C Dummy
Westside 23 9 0 0
Federated 1 3 2 0
Goliath 8 5 4 0
Universal 0 0 0 2
Step 4: The minimum uncovered number is 1 (circled).
-
7/27/2019 Matching v 1
20/26
Slide 20 of 27
Example 1: AP
Step 5: Subtract 1 from uncovered numbers. Add 1 to
numbers at intersections. Leave other numbers intact.This gives:
A B C Dummy
Westside 23 9 0 1
Federated 0 2 1 0
Goliath 7 4 3 0
Universal 0 0 0 3
-
7/27/2019 Matching v 1
21/26
Slide 21 of 27
Example 1: AP
Find the minimum cover:
A B C Dummy
Westside 23 9 0 1
Federated 0 2 1 0Goliath 7 4 3 0
Universal 0 0 0 3
Step 4: The minimum number of lines to cover all 0's isfour. Thus, the current solution is optimal (minimumcost) assignment.
-
7/27/2019 Matching v 1
22/26
Slide 22 of 27
Example 1: AP
The optimal assignment occurs at locations of zeros
such that there is exactly one zero in each row and eachcolumn:
A B C Dummy
Westside 23 9 0 1
Federated 0 2 1 0
Goliath 7 4 3 0
Universal 0 0 0 3
-
7/27/2019 Matching v 1
23/26
Slide 23 of 27
Example 1: AP
The optimal assignment is (go back to the original table
for the distances):
Subcontractor Project Distance
Westside C 16
Federated A 28
Universal B 25
Goliath (unassigned)
Total Distance = 69 miles
-
7/27/2019 Matching v 1
24/26
Slide 24 of 27
Example 1: AP via LP
In our example the LP formulation is:
Min z = 50x11 + 36x12 + 16x13 + 0x14 + 28x21 + 30x22 + 18x23 + 0x24 +
35x31 + 32x32 + 20x33 + 0x34 + + 25x41 + 25x42 + 14x43 + 0x44s.t.
x11 + x12 + x13 + x14 = 1 (row 1)
x21 + x22 + x23 + x24 = 1 (row 2)
x31 + x32 + x33 + x34 = 1 (row 3)x41 + x42 + x43 + x44 = 1 (row 4)
x11 + x21 + x31 + x41 = 1 (column 1)
x12 + x22 + x32 + x42 = 1 (column 2)
x13 + x23 + x33 + x43 = 1 (column 3)
x14 + x24 + x34 + x44 = 1 (column 4)
xij >= 0 for i = 1, 2, 3, 4 and j = 1, 2, 3, 4 (nonnegativity)
-
7/27/2019 Matching v 1
25/26
Slide 25 of 27
Example 1: AP via LP
The solver formulation is:
Distances From
Contractors to Projects at:
Contractor A B C Dummy
West Side 50 36 16 0
Federated 28 30 18 0
Goliath 35 32 20 0
Universal 25 25 14 0
Assignment of Contractors
to Projects at:
Contractor A B C Dummy Assigned Available
West Side 0 0 0 0 0 1
Federated 0 0 0 0 0 1
Goliath 0 0 0 0 0 1
Universal 0 0 0 0 0 1
Assigned 0 0 0 0Capacity 1 1 1 1
Total Distance: 0
The Assignment Problem
-
7/27/2019 Matching v 1
26/26
Slid 26 f 27
Example 1: AP via LP
The solver solution is:
Distances From
Contractors to Projects at:
Contractor A B C Dummy
West Side 50 36 16 0
Federated 28 30 18 0
Goliath 35 32 20 0
Universal 25 25 14 0
Assignment of Contractors
to Projects at:
Contractor A B C Dummy Assigned Available
West Side 0 0 1 0 1 1
Federated 1 0 0 0 1 1
Goliath 0 0 0 1 1 1
Universal 0 1 0 0 1 1
Assigned 1 1 1 1
Capacity 1 1 1 1
Total Distance: 69
The Assignment Problem