Introduction to Assignment Problem

26
Slide 1 of 27 Assignment Problem: Assignment Problem: Hungarian Algorithm and Linear Hungarian Algorithm and Linear Programming Programming collected from the Internet and collected from the Internet and edited by edited by Longin Jan Latecki Longin Jan Latecki

description

Assignment Problem: Hungarian Algorithm and Linear Programming collected from the Internet and edited by Longin Jan Latecki. Introduction to Assignment Problem. - PowerPoint PPT Presentation

Transcript of Introduction to Assignment Problem

Page 1: Introduction to Assignment Problem

Slide 1 of 27 Slide 1 of 27

Assignment Problem:Assignment Problem:Hungarian Algorithm and Linear Hungarian Algorithm and Linear

ProgrammingProgramming

collected from the Internet and edited bycollected from the Internet and edited byLongin Jan LateckiLongin Jan Latecki

Page 2: Introduction to Assignment Problem

Slide 2 of 27 Slide 2 of 27

Introduction to Assignment ProblemIntroduction to Assignment Problem

Let Let CC be an be an nxn nxn matrix representing the costs of each of matrix representing the costs of each of n n workers to perform any of workers to perform any of nn jobs.  The assignment problem is to assign jobs to workers so as to minimize the total jobs.  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 cost. Since each worker can perform only one job and each job can be assigned to only one worker the assignments constitute an one worker the assignments constitute an independent set independent set of the matrix of the matrix CC. .

An arbitrary assignment is shown above in which worker An arbitrary assignment is shown above in which worker aa is assigned job is assigned job qq, worker , worker bb is assigned job is assigned job ss and so on.  The total cost of this assignment is and so on.  The total cost of this assignment is 2323.  .  Can you find a lower cost assignment? Can you find a lower cost assignment? Can you find the minimal cost assignment? Can you find the minimal cost assignment? Remember that each assignment must be unique in its row and column. Remember that each assignment must be unique in its row and column.

Page 3: Introduction to Assignment Problem

Slide 3 of 27 Slide 3 of 27

Assignment ProblemAssignment Problem

An An assignment problemassignment problem seeks to minimize the seeks to minimize the total cost assignment of total cost assignment of mm workers to workers to mm jobs, jobs, given that the cost of worker given that the cost of worker ii performing job performing job jj is is ccijij. .

It assumes all workers are assigned and each job It assumes all workers are assigned and each job is performed. is performed.

An assignment problem is a special case of a An assignment problem is a special case of a transportation problem in which all supplies and transportation problem in which all supplies and all demands are equal to 1; hence assignment all demands are equal to 1; hence assignment problems may be solved as linear programs.problems may be solved as linear programs.

The network representation of an assignment The network representation of an assignment problem with three workers and three jobs is problem with three workers and three jobs is shown on the next slide.shown on the next slide.

Page 4: Introduction to Assignment Problem

Slide 4 of 27 Slide 4 of 27

Assignment ProblemAssignment Problem

Network RepresentationNetwork Representation

2222

3333

1111

2222

3333

1111cc1111

cc1212

cc1313

cc2121 cc2222

cc2323

cc3131cc3232

cc3333

WORKERSWORKERS JOBSJOBS

Page 5: Introduction to Assignment Problem

Slide 5 of 27 Slide 5 of 27

Assignment ProblemAssignment Problem

Linear Programming FormulationLinear Programming Formulation

Min Min ccijijxxijij

i ji j

s.t. s.t. xxijij = 1 for each resource (row) = 1 for each resource (row) ii

jj

xxijij = 1 for each job (column) = 1 for each job (column) jj ii xxijij = 0 or 1 for all = 0 or 1 for all ii and and jj..

• Note: Note: A modification to the right-hand side of the first A modification to the right-hand side of the first constraint set can be made if a worker is permitted to constraint set can be made if a worker is permitted to work more than 1 job.work more than 1 job.

Page 6: Introduction to Assignment Problem

Slide 6 of 27 Slide 6 of 27

Linear Programming (LP) problems can be solved Linear Programming (LP) problems can be solved on the computer using Matlab, and many others.on the computer using Matlab, and many others.

There are special classes of LP problems such as There are special classes of LP problems such as the assignment problem (AP).the assignment problem (AP).

Efficient solutions methods exist to solve AP.Efficient solutions methods exist to solve AP. AP can be formulated as an LP and solved by AP can be formulated as an LP and solved by

general purpose LP codes. general purpose LP codes. However, there are many computer packages, However, there are many computer packages,

which contain separate computer codes for which contain separate computer codes for these models which take advantage of the these models which take advantage of the problem network structure.problem network structure.

Page 7: Introduction to Assignment Problem

Slide 7 of 27 Slide 7 of 27

A brute-force algorithm for solving the assignment problem involves generating all A brute-force algorithm for solving the assignment problem involves generating all independent sets of the matrix independent sets of the matrix CC, computing the total costs of each assignment and a , computing the total costs of each assignment and a search of all assignment to find a minimal-sum independent set. The complexity of this 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 method is driven by the number of independent assignments possible in an nxn nxn matrix. matrix. There are There are n n choices for the first assignment, choices for the first assignment, n-1 n-1 choices for the second assignment and choices for the second assignment and so on, giving n! possible assignment sets. Therefore, this approach has, at least, an so on, giving n! possible assignment sets. Therefore, this approach has, at least, an exponential runtime complexity.exponential runtime complexity.

As each assignment is chosen that row and column are eliminated from 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 consideration.  The question is raised as to whether there is a better algorithm.  In fact there exists a polynomial runtime complexity algorithm. there exists a polynomial runtime complexity algorithm.

Page 8: Introduction to Assignment Problem

Slide 8 of 27 Slide 8 of 27

From en.wikipedia.org/wiki/Hungarian_algorithmFrom en.wikipedia.org/wiki/Hungarian_algorithmThe Hungarian method is a combinatorial optimization The Hungarian method is a combinatorial optimization algorithm which solves the assignment problem in algorithm which solves the assignment problem in polynomial time. It was developed and published by polynomial time. It was developed and published by Harold Kuhn in 1955, who gave the name "Hungarian Harold Kuhn in 1955, who gave the name "Hungarian method" because the algorithm was largely based on method" because the algorithm was largely based on the earlier works of two Hungarian mathematicians: the earlier works of two Hungarian mathematicians: Dénes Kőnig and Jenő Egerváry.Dénes Kőnig and Jenő Egerváry.James Munkres reviewed the algorithm in 1957 and James Munkres reviewed the algorithm in 1957 and observed that it is (strongly) polynomial. Since then the observed that it is (strongly) polynomial. Since then the algorithm has been known also as Kuhn-Munkres or algorithm has been known also as Kuhn-Munkres or Munkres assignment algorithm. The time complexity of Munkres assignment algorithm. The time complexity of the original algorithm was the original algorithm was O(nO(n44)), however later it was , however later it was noticed that it can be modified to achieve an noticed that it can be modified to achieve an O(nO(n33)) running time. running time. In 2006, it was discovered that Carl Gustav Jacobi had In 2006, it was discovered that Carl Gustav Jacobi had solved the assignment problem in the 19th century, solved the assignment problem in the 19th century, and published posthumously in 1890 in Latin.and published posthumously in 1890 in Latin.

Page 9: Introduction to Assignment Problem

Slide 9 of 27 Slide 9 of 27

Hungarian MethodHungarian Method

The The Hungarian methodHungarian method solves minimization solves minimization assignment problems with assignment problems with mm workers and workers and mm jobs. jobs.

Special considerations can include:Special considerations can include:• number of workers does not equal the number number of workers does not equal the number

of jobs — add dummy workers/jobs with 0 of jobs — add dummy workers/jobs with 0 assignment costs as neededassignment costs as needed

• worker worker ii cannot do job cannot do job jj — assign — assign ccijij = + = +MM

• maximization objective — create an maximization objective — create an opportunity loss matrix subtracting all profits opportunity loss matrix subtracting all profits for each job from the maximum profit for that for each job from the maximum profit for that job before beginning the Hungarian methodjob before beginning the Hungarian method

Page 10: Introduction to Assignment Problem

Slide 10 of 27 Slide 10 of 27

Hungarian MethodHungarian Method

Step 1: Step 1: For each row, subtract the minimum number For each row, subtract the minimum number in that row from all numbers in that row.in that row from all numbers in that row.

Step 2: Step 2: For each column, subtract the minimum For each column, subtract the minimum number in that column from all numbers in that number in that column from all numbers in that column. column.

Step 3: Step 3: Draw the minimum number of lines to cover Draw the minimum number of lines to cover all zeroes. If this number = all zeroes. If this number = mm, STOP — an , STOP — an assignment can be made.assignment can be made.

Step 4: Step 4: Determine the minimum uncovered number Determine the minimum uncovered number (call it (call it dd).).• Subtract Subtract dd from uncovered numbers. from uncovered numbers.• Add Add dd to numbers covered by two lines. to numbers covered by two lines.• Numbers covered by one line remain the same.Numbers covered by one line remain the same.• Then, GO TO STEP 3.Then, GO TO STEP 3.

Page 11: Introduction to Assignment Problem

Slide 11 of 27 Slide 11 of 27

Hungarian MethodHungarian Method

Finding the Minimum Number of Lines and Finding the Minimum Number of Lines and Determining the Optimal SolutionDetermining the Optimal Solution• Step 1: Step 1: Find a row or column with only one Find a row or column with only one

unlined zero and circle it. (If all rows/columns unlined zero and circle it. (If all rows/columns have two or more unlined zeroes choose an have two or more unlined zeroes choose an arbitrary zero.)arbitrary zero.)

• Step 2: Step 2: If the circle is in a row with one zero, If the circle is in a row with one zero, draw a line through its column. If the circle is in a draw a line through its column. If the circle is in a column with one zero, draw a line through its row. column with one zero, draw a line through its row. One approach, when all rows and columns have One approach, when all rows and columns have two or more zeroes, is to draw a line through one two or more zeroes, is to draw a line through one with the most zeroes, breaking ties arbitrarily.with the most zeroes, breaking ties arbitrarily.

• Step 3: Step 3: Repeat step 2 until all circles are lined. If Repeat step 2 until all circles are lined. If this minimum number of lines equals this minimum number of lines equals mm, the , the circles provide the optimal assignment.circles provide the optimal assignment.

Page 12: Introduction to Assignment Problem

Slide 12 of 27 Slide 12 of 27

Example 1: APExample 1: APA contractor pays his subcontractors a fixed fee plus mileage A contractor pays his subcontractors a fixed fee plus mileage for work performed. On a given day the contractor is faced for work performed. On a given day the contractor is faced with three electrical jobs associated with various projects. with three electrical jobs associated with various projects. Given below are the distances between the subcontractors Given below are the distances between the subcontractors and the projects.and the projects.

ProjectProject AA BB CC Westside Westside 50 36 1650 36 16

Subcontractors Subcontractors Federated Federated 28 30 18 28 30 18 Goliath Goliath 35 32 2035 32 20

Universal Universal 25 25 1425 25 14

How should the contractors be assigned to minimize total How should the contractors be assigned to minimize total costs?costs?NoteNote: There are four subcontractors and three projects. We : There are four subcontractors and three projects. We create a dummy project Dum, which will be assigned to one create a dummy project Dum, which will be assigned to one subcontractor (i.e. that subcontractor will remain idle)subcontractor (i.e. that subcontractor will remain idle)

Page 13: Introduction to Assignment Problem

Slide 13 of 27 Slide 13 of 27

Example 1: APExample 1: AP

Network Representation (note the dummy Network Representation (note the dummy project)project)

5050

3636

161600

28283030

181800

3535 3232

2020

00

2525 2525

1414

00

West.West.West.West.

Dum.Dum.Dum.Dum.

CCCC

BBBB

AAAA

Univ.Univ.Univ.Univ.

Gol.Gol.Gol.Gol.

Fed.Fed.Fed.Fed.

Page 14: Introduction to Assignment Problem

Slide 14 of 27 Slide 14 of 27

Example 1: APExample 1: AP

Initial Tableau SetupInitial Tableau Setup

Since the Hungarian algorithm requires Since the Hungarian algorithm requires that there be the same number of rows as that there be the same number of rows as columns, add a Dummy column so that the first columns, add a Dummy column so that the first tableau is (the smallest elements in each row are tableau is (the smallest elements in each row are marked red):marked red):

AA BB CC DummyDummy

WestsideWestside 50 50 3636 16 16 00

FederatedFederated 28 28 3030 18 18 00

GoliathGoliath 35 35 3232 20 20 00

UniversalUniversal 2525 2525 1414 00

Page 15: Introduction to Assignment Problem

Slide 15 of 27 Slide 15 of 27

Example 1: APExample 1: AP

Step 1: Step 1: Subtract minimum number in each row Subtract minimum number in each row from all numbers in that row. Since each row from all numbers in that row. Since each row has a zero, we simply generate the original has a zero, we simply generate the original matrix (the smallest elements in each column matrix (the smallest elements in each column are marked red). This yields:are marked red). This yields:

AA B B CC DummyDummy

Westside 50 36 16 0Westside 50 36 16 0

Federated 28 30 18 0Federated 28 30 18 0

Goliath 35 32 20 0Goliath 35 32 20 0

Universal Universal 2525 2525 1414 00

Page 16: Introduction to Assignment Problem

Slide 16 of 27 Slide 16 of 27

Example 1: APExample 1: AP

Step 2: Step 2: Subtract the minimum number in each Subtract the minimum number in each column from all numbers in the column. For A it column from all numbers in the column. For A it is 25, for B it is 25, for C it is 14, for Dummy it is is 25, for B it is 25, for C it is 14, for Dummy it is 0. This yields:0. This yields:

AA BB CC DummyDummy

Westside 25 11 2 0Westside 25 11 2 0

Federated 3 5 4 0Federated 3 5 4 0

Goliath 10 7 6 Goliath 10 7 6 00

Universal 0 0 0 0 Universal 0 0 0 0

Page 17: Introduction to Assignment Problem

Slide 17 of 27 Slide 17 of 27

Example 1: APExample 1: AP

Step 3: Step 3: Draw the minimum number of lines to cover all Draw the minimum number of lines to cover all zeroes (called minimum cover). Although one can zeroes (called minimum cover). Although one can "eyeball" this minimum, use the following algorithm. If a "eyeball" this minimum, use the following algorithm. If a "remaining" row has only one zero, draw a line through the "remaining" row has only one zero, draw a line through the column. If a remaining column has only one zero in it, column. If a remaining column has only one zero in it, draw a line through the row. Since the number of lines that draw a line through the row. Since the number of lines that cover all zeros is 2 < 4 (# of rows), the current solution is cover all zeros is 2 < 4 (# of rows), the current solution is not optimal. not optimal.

AA BB CC DummyDummy

Westside 25 11 2 0 Westside 25 11 2 0 Federated 3 5 4 0 Federated 3 5 4 0 Goliath 10 7 6 0 Goliath 10 7 6 0 Universal 0 0 0 0Universal 0 0 0 0

Step 4: Step 4: The minimum uncovered number is 2 (circled). The minimum uncovered number is 2 (circled).

Page 18: Introduction to Assignment Problem

Slide 18 of 27 Slide 18 of 27

Example 1: APExample 1: AP

Step 5: Step 5: Subtract 2 from uncovered numbers; Subtract 2 from uncovered numbers; add 2 to all numbers at line intersections; leave add 2 to all numbers at line intersections; leave all other numbers intact. This gives:all other numbers intact. This gives:

AA BB CC DummyDummy

Westside 23 9 0 0 Westside 23 9 0 0

Federated 1 3 2 0 Federated 1 3 2 0

Goliath 8 5 4 0 Goliath 8 5 4 0

Universal 0 0 0 Universal 0 0 0 22

Page 19: Introduction to Assignment Problem

Slide 19 of 27 Slide 19 of 27

Example 1: APExample 1: AP

Step 3: Step 3: Draw the minimum number of lines to Draw the minimum number of lines to cover all zeroes. Since 3 (# of lines) < 4 (# of cover all zeroes. Since 3 (# of lines) < 4 (# of rows), the current solution is not optimal. rows), the current solution is not optimal.

AA BB CC DummyDummy

Westside 23 9 0 0 Westside 23 9 0 0

Federated 1 3 2 0 Federated 1 3 2 0

Goliath 8 5 4 0 Goliath 8 5 4 0

Universal 0 0 0 2Universal 0 0 0 2

Step 4: Step 4: The minimum uncovered number is 1 The minimum uncovered number is 1 (circled).(circled).

Page 20: Introduction to Assignment Problem

Slide 20 of 27 Slide 20 of 27

Example 1: APExample 1: AP

Step 5: Step 5: Subtract 1 from uncovered numbers. Subtract 1 from uncovered numbers. Add 1 to numbers at intersections. Leave other Add 1 to numbers at intersections. Leave other numbers intact. This gives:numbers intact. This gives:

AA BB CC DummyDummy

Westside 23 9 0 Westside 23 9 0 11

Federated 0 2 1 0 Federated 0 2 1 0

Goliath 7 4 3 0 Goliath 7 4 3 0

Universal 0 0 0 Universal 0 0 0 33

Page 21: Introduction to Assignment Problem

Slide 21 of 27 Slide 21 of 27

Example 1: APExample 1: AP

Find the minimum cover:Find the minimum cover:

AA BB CC DummyDummy

Westside 23 9 0 Westside 23 9 0 1 1

Federated 0 2 1 0 Federated 0 2 1 0

Goliath 7 4 3 0 Goliath 7 4 3 0

Universal 0 0 0 Universal 0 0 0 3 3

Step 4: Step 4: The minimum number of lines to cover The minimum number of lines to cover all 0's is four. Thus, the current solution is all 0's is four. Thus, the current solution is optimal (minimum cost) assignment.optimal (minimum cost) assignment.

Page 22: Introduction to Assignment Problem

Slide 22 of 27 Slide 22 of 27

Example 1: APExample 1: AP

The optimal assignment occurs at locations of The optimal assignment occurs at locations of zeros such that there is exactly one zero in each zeros such that there is exactly one zero in each row and each column:row and each column:

AA BB CC DummyDummy

Westside 23 9 Westside 23 9 00 1 1

Federated Federated 00 2 1 0 2 1 0

Goliath 7 4 3 Goliath 7 4 3 00

Universal 0 Universal 0 00 0 0 3 3

Page 23: Introduction to Assignment Problem

Slide 23 of 27 Slide 23 of 27

Example 1: APExample 1: AP

The optimal assignment is (go back to the original The optimal assignment is (go back to the original table for the distances):table for the distances):

SubcontractorSubcontractor ProjectProject DistanceDistance

Westside C 16Westside C 16

Federated A 28Federated A 28

Universal B 25Universal B 25

Goliath (unassigned) Goliath (unassigned)

Total Distance = 69 miles Total Distance = 69 miles

Page 24: Introduction to Assignment Problem

Slide 24 of 27 Slide 24 of 27

Example 1: AP via LPExample 1: AP via LP In our example the LP formulation is:In our example the LP formulation is:

Min z = 50xMin z = 50x1111 + 36x + 36x1212 + 16x + 16x13 13 + 0x+ 0x1414 + 28x + 28x2121 + 30x + 30x2222 + + 18x18x2323 + 0x + 0x2424 + 35x + 35x3131 + 32x + 32x3232 + 20x + 20x3333 + 0x + 0x3434 + + 25x + + 25x4141 + + 25x25x4242 + 14x + 14x4343 + 0x + 0x4444

s.t.s.t.

xx1111 + x + x1212 + x + x13 13 + x+ x14 14 = 1= 1 (row 1)(row 1)

xx2121 + x + x2222 + x + x23 23 + x+ x24 24 = 1= 1 (row 2)(row 2)

xx3131 + x + x3232 + x + x33 33 + x+ x34 34 = 1= 1 (row 3)(row 3)

xx4141 + x + x4242 + x + x43 43 + x+ x44 44 = 1= 1 (row 4)(row 4)

xx1111 + x + x2121 + x + x31 31 + x+ x41 41 = 1= 1 (column 1)(column 1)

xx1212 + x + x2222 + x + x32 32 + x+ x42 42 = 1= 1 (column 2)(column 2)

xx1313 + x + x2323 + x + x33 33 + x+ x43 43 = 1= 1 (column 3)(column 3)

xx1414 + x + x2424 + x + x34 34 + x+ x44 44 = 1= 1 (column 4)(column 4)

xxij ij >= 0 for i = 1, 2, 3, 4 and j = 1, 2, 3, 4 (nonnegativity)>= 0 for i = 1, 2, 3, 4 and j = 1, 2, 3, 4 (nonnegativity)

Page 25: Introduction to Assignment Problem

Slide 25 of 27 Slide 25 of 27

Example 1: AP via LPExample 1: AP via LP

The solver formulation is:The solver formulation is:

Distances FromContractors to Projects at:

Contractor A B C DummyWest Side 50 36 16 0Federated 28 30 18 0Goliath 35 32 20 0Universal 25 25 14 0

Assignment of Contractorsto Projects at:

Contractor A B C Dummy Assigned AvailableWest Side 0 0 0 0 0 1Federated 0 0 0 0 0 1Goliath 0 0 0 0 0 1Universal 0 0 0 0 0 1Assigned 0 0 0 0Capacity 1 1 1 1

Total Distance: 0

The Assignment Problem

Page 26: Introduction to Assignment Problem

Slide 26 of 27 Slide 26 of 27

Example 1: AP via LPExample 1: AP via LP

The solver solution is:The solver solution is:

Distances FromContractors to Projects at:

Contractor A B C DummyWest Side 50 36 16 0Federated 28 30 18 0Goliath 35 32 20 0Universal 25 25 14 0

Assignment of Contractorsto Projects at:

Contractor A B C Dummy Assigned AvailableWest Side 0 0 1 0 1 1Federated 1 0 0 0 1 1Goliath 0 0 0 1 1 1Universal 0 1 0 0 1 1Assigned 1 1 1 1Capacity 1 1 1 1

Total Distance: 69

The Assignment Problem