SlideShare a Scribd company logo
BY:
Preeti Baliyan
Ankita Deka
AtulAnand Pathak
Davishmaan Baranwal
Poornima Shrivastwa
WHAT IS AN
ASSIGNMENT
PROBLEM?
A case of transportation
problem and a
fundamental
combinatorial
optimization problem.
WHAT ISTHE
OBJECTIVE?
To assign a number of
resources to an equal
number of activities so
as to minimise total cost
or maximize total profit
of allocation.
WHY DOES IT
ARISE?
It arises because
available resources have
varying degrees of
efficiency for different
activities,Thus the
problem is, “How should
the assignments be
made so as to optimize
the given objective?”
 Example: 1) assignment of workers to machines
2) Salesman to different sales area
 Suppose there are n jobs to be performed and n persons are available for doing these jobs.
Assume that each person can do each job at a term, though with varying degree of efficiency,
let cij be the cost if the i-th person is assigned to the j-th job.The problem is to find an
assignment (which job should be assigned to which person one on-one basis) So that the total
cost of performing all jobs is minimum, problem of this kind are known as assignment
problem.
TYPESOF ASSIGNMENT PROBLEM
BALANCED UNBALANCED
 The assignment problem can be stated that in the form of mxn matrix cij called a Cost Matrix (or) Effectiveness Matrix where
cij is the cost of assigning i th machine to j th job.
 Consider an assignment problem of assigning n jobs to n machines (one job to one machine). Let cij be the unit cost of
assigning ith machine to the jth job and,i th machine to j th job.
 Let xij = 1 , if j th job is assigned to i th machine. xij = 0 , if j th job is not assigned to i th machine.
 Minimize :-
 subject to the constraints :-
Hungarian Assignment Problem
Step 1: Whether the matrix/problem is balanced or unbalanced. If matrix is
unbalanced we have to convert it into a balanced matrix.
Problem: A company has five jobsV, W, X,Y and Z and five machines A, B, C, D and E.
The matrix entries are processing time of each machine in hours. Solve the following
assignment problem shown inTable using Hungarian method.
Step 2: Row Reduction- Subtract the smallest cost element of each row from all the
elements of that particular row of the given cost matrix.
Step3: Column Reduction- Subtract the smallest cost element of each column from all the
elements of that particular column of the resulting cost matrix obtained by step 2.
Step 4: Assigning/Covering Zeros:
i) Row Scanning- Starting from the first row, ask
the following questions. If there is only one zero
in that row, mark a square around that zero and
draw a vertical line. If there is more than one zero
in that row, skip that row and go the next row.
ii) Column scanning- Starting from the first
column, ask the following questions. If there is
only one zero in that column, mark a square
around that zero and draw a horizontal line. If
there is more than one zero in that column, skip
that column and go the next column.
Step 5: If the number of squares drawn are equal to
number of rows or columns.Then it is an optimal
solution.We can have assignments. If number of
squares are not equal to number of rows/columns go to
step 6.
Step 6: Identify the minimum value among the uncovered cells. Add that value to the
crossed cells and subtract it from the uncovered cells. Covered cells value remain same.
Covered Cells: Cells through which a line passes.
Uncovered Cells: Cells through which no lines passes.
Crossed Cells: Cells which are at the interaction of horizontal and vertical line.
Step 7: Repeat step 4 and 5 of assigning/covering zeroes to get an optimal solution.
Step 8: Assignment- Optimal Solution.
Unbalanced Assignment Problem:
 It is an assignment problem where,
 Convert to a balanced assignment problem by adding a
dummy row or dummy column with zero values.
No. of rows ≠ No. of
columns
Question:
Solve the assignment problem.
7 5 8 4
5 6 7 4
8 7 9 8
A B C D
1
2
3
JOBS
MEN
Solution:
Add a dummy row.
7 5 8 4
5 6 7 4
8 7 9 8
A B C D
1
2
3
Phase 1: Row and Column Reduction
 Step 1: Subtract minimum value of each row from entries that row.
Phase 2: Optimation of problem
 Step 1: Starting from first row, check if there is only one zero in that row. If yes, mark a square
around that zero entry and draw a vertical line through that zero.
• After scanning the last row, check whether all the zeroes are covered with lines.
 Step 2: Starting from first column, check if there is only one zero in that column. If yes, mark a
square around that zero entry and draw a horizontal line through that zero.
• After scanning the last column, check whether all the zeroes are covered with lines.
• Step 3: Check whether the no. of squares marked is equal to no. of rows of the matrix.
 Step 4: Identify the minimum value of the undeleted cell values.
i. Add the minimum undeleted cell value at the intersection points of the present matrix.
ii. Subtract the minimum undeleted cell value from all the other undeleted cell values.
iii. The other entries remail the same.
 Step 5: Do row scanning and column scanning again.
MEN JOB TIME
1 D 4
2 A 5
3 B 7
4 C 0
Total ProcessingTime 16
Question:
Solve the assignment problem At the head office of a company there are five registration counters.
Five persons are available for service. How should the counters be assigned to persons so as to
maximize the profit?
30 37 40 28 40
40 24 27 21 36
40 32 33 30 35
25 38 40 36 36
29 62 41 34 39
A B C D E
1
2
3
4
5
PERSO
N
COMPAN
Y
Convert the maximization problem to a minimization problem.
30 37 40 28 40
40 24 27 21 36
40 32 33 30 35
25 38 40 36 36
29 62 41 34 39
A B C D E
1
2
3
4
5
Phase 1: Row and Column Reduction
 Step 1: Subtract minimum value of each row from entries that row.
 Step 2: Subtract minimum value of each column from entries that column.
Step 3: Assigning the zeros, we have the following
 Step 4: Marking the unassigning the zeros row and crossed zero column of marked row, we
have the following.
 Step 5: Crossing the marked column and unmarked row.
 Step 6: Determine the smallest cost element not covered by the straight lines. Sub- tract this
smallest cost element from all the uncovered elements and add this to all those elements
which are lying in the intersection of these straight lines and do not change the remaining
elements which lie on the straight lines.
 Step 7: Assigning the zeros, we have the following
30 37 40 28 40
40 24 27 21 36
40 32 33 30 35
25 38 40 36 36
29 62 41 34 39
A B C D E
1
2
3
4
5
Company Person Time
1 C 40
2 E 36
3 A 40
4 D 36
5 B 62
Total ProcessingTime 214
Hungarian Assignment Problem
Travelling salesman route will be plan in such a way that in a given N
number of cities cost of travelling from one city to any other city what is
the minimum round trip route that visit each city once and then return to
the starting place. The goal is to find the shortest tour that visit each city
in a given cities exactly ones and then return to the starting city. The only
solution to the travelling salesman problem is to calculate and compare
the length of all possible ordered combinations.
Find the route that
takes the shortest
time for a person
through every city
and back to the
starting point from A.
A → D → B → C → A
A
D
C
B
3
5
2
4
Following are the
cost (in INR ‘00)
of travelling in
various cities.
Akshay, a sales
agent, wants to
cover all cities in
lowest cost. In
which order/path
he should go to
be economical?
A B C D
A 0 25 75 45
B 35 0 150 25
C 35 40 0 15
D 65 75 130 0
 Step 1 ROW REDUCTION
Subtract minimum element of each row from all the elements in its row
A B C D
A x 25 75 45
B 35 x 150 25
C 35 40 x 15
D 65 75 130 x
→ 25
→ 25
→ 15
→ 65
A B C D
A x 0 50 20
B 10 x 125 0
C 20 25 x 0
D 0 10 65 x
Subtract minimum element of each column from all the elements in its column
A B C D
A x 0 0 20
B 10 x 75 0
C 20 25 x 0
D 0 10 15 x
A B C D
A x 0 50 20
B 10 x 125 0
C 20 25 x 0
D 0 10 65 x
↓ ↓ ↓ ↓
0 0 50 0
 Identify the row with single O only and subsequently eliminate its address column.
Eventually, identify the column with single O only and subsequently eliminate its
address row.
A B C D
A x 0 0 20
B 10 x 75 0
C 20 25 x 0
D 0 10 15 x
For optimal solution, No. of assigned Os = No. of order of matrix
But here, No. of assigned Os < No. of order of matrix
A B C D
A x 0 0 20
B 10 x 75 0
C 20 25 x 0
D 0 10 15 x
Contd.
 Of the remaining undeleted items, identify the minimum and subtract it from rest
of the undeleted items and add to the intersection of lines.
 The remaining deleted items should be brought down as it is
A B C D
A x 0 0 20
B 10 x 75 0
C 20 25 x 0
D 0 10 15 x
A B C D
A x 0 0 30
B 10 x 65 0
C 20 15 x 0
D 0 0 5 x
x
A B C D
A x 0 0 30
B 10 x 65 0
C 20 15 x 0
D 0 0 5 x
x
A B C D
A x 0 0 30
B 10 x 65 0
C 20 15 x 0
D 0 0 5 x
A B C D
A x 0 0 40
B 0 x 55 0
C 10 5 x 0
D 0 0 5 x
Here, No. of assigned Os = No. of order of matrix
Hence, it satisfies the optimal solution for minimum cost
A B C D
A x 0 0 40
B 0 x 55 0
C 10 5 x 0
D 0 0 5 x
A → C → D → B → A 1,3,4,2
i.e. Total Cost = 7,500 + 1,500 + 7,500 + 3,500 = INR 20,000
A B C D
A x 0 0 40
B 0 x 55 0
C 10 5 x 0
D 0 0 5 x
A B C D
A 0 25 75 45
B 35 0 150 25
C 35 40 0 15
D 65 75 130 0
The 'Travelling salesman problem' is very similar to the
assignment problem except that in the former, there are
additional restrictions that a salesman starts from his city,
visits each city once and returns to his home city, so that the
total distance (cost or time) is minimum
 Given N men and N women, where each person has ranked all members of the opposite sex in
order of preference, marry the men and women together such that there are no two people of
opposite sex who would both rather have each other than their current partners. If there are no
such people, all the marriages are “stable”.
 It uses Gale-Shapely algorithm to solve the problem.
 EXAMPLES :-
1.Student choosing their future universities
2. Man and women seeking each other to create families
3. Internet services that need to be connected with users with the smallest amount of time.
In all these cases we need to create stable pairs that need to satisfied certain criteria.
 Example:-
Males 1 2 3 4 5
A O M L N P
B P N M L O
C M P L O N
D P M O N L
E O L M N P
Females 1 2 3 4 5
L D B E C A
M B A D C E
N A C E D B
O D A C B E
P B E A C D
Males 1 2 3 4 5
A O M L N P
B P N M L O
C M P L O N
D P M O N L
E O L M N P
Females 1 2 3 4 5
L D B E C A
M B A D C E
N A C E D B
O D A C B E
P B E A C D
Males 1 2 3 4 5
A O M L N P
B P N M L O
C M P L O N
D P M O N L
E O L M N P
Females 1 2 3 4 5
L D B E C A
M B A D C E
N A C E D B
O D A C B E
P B E A C D
Males 1 2 3 4 5
A O M L N P
B P N M L O
C M P L O N
D P M O N L
E O L M N P
Females 1 2 3 4 5
L D B E C A
M B A D C E
N A C E D B
O D A C B E
P B E A C D
Males 1 2 3 4 5
A O M L N P
B P N M L O
C M P L O N
D P M O N L
E O L M N P
Females 1 2 3 4 5
L D B E C A
M B A D C E
N A C E D B
O D A C B E
P B E A C D
Males 1 2 3 4 5
A O M L N P
B P N M L O
C M P L O N
D P M O N L
E O L M N P
Females 1 2 3 4 5
L D B E C A
M B A D C E
N A C E D B
O D A C B E
P B E A C D
Males 1 2 3 4 5
A O M L N P
B P N M L O
C M P L O N
D P M O N L
E O L M N P
Females 1 2 3 4 5
L D B E C A
M B A D C E
N A C E D B
O D A C B E
P B E A C D
Males 1 2 3 4 5
A O M L N P
B P N M L O
C M P L O N
D P M O N L
E O L M N P
Females 1 2 3 4 5
L D B E C A
M B A D C E
N A C E D B
O D A C B E
P B E A C D
Males 1 2 3 4 5
A O M L N P
B P N M L O
C M P L O N
D P M O N L
E O L M N P
Females 1 2 3 4 5
L D B E C A
M B A D C E
N A C E D B
O D A C B E
P B E A C D
The main difference between stable marriage problem and assignment
problem is that of optimality. In assignment problem we are concerned
with overall minimized cost/timing/distance without focusing on
individual allocation whether it is good or bad but in case of stable
marriage problem we are concerned with the individual stability of the
assigned pair.
Functions used in the program :-
1. as.integer() :- Converts a character type object into integer type object .
2. readline() :- reads text lines from an input file.
3. matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) :- creates a matrix from the given set of
values.
4. for(), if() :- these are control flow constructs in R language.
5. lp.assign (cost.mat, direction = "min", presolve = 0, compute.sens = 0) :- Interface to lp_solve linear/integer
programming system specifically for solving assignment problems
6. lp.assign()$solution : - gives solution matrix.
library(lpSolve)
#entering number of rows and columns
r <- as.integer(readline ( "Enter number of assignees(will be treated as rows):"))
c <- as.integer(readline("Enter number of jobs to be assigned(will be treated as column) :"))
#printing number of rows and columns for matrix
print(r)
print(c)
#creating matrix with given number of rows and columns
mat <- matrix(nrow = r, ncol = c)
#printing matrix with no values entered
print(mat)
#using for loop to enter the values in matrix from the user
for ( i in 1:r){
for (j in 1:c){
print(paste("Enter element with row no.", i, "and column no.", j))
mat[i,j] <- as.integer(readline())
}
}
if(r>c)
mat = cbind(mat, c(rep.int(0, r)))
if(r<c)
mat = rbind(mat, c(rep.int(0, c)))
#printing the matrix with value
print(mat)
#Using lp.assign() method to find the solution of the assignment problem
lp.assign(mat)
#displaying the allocation matrix
lp.assign(mat)$solution
Hungarian Assignment Problem

More Related Content

PPTX
Transportation problem
PPT
Simplex Method
PDF
simplex method for operation research .pdf
PPTX
Hungarian Method
PPT
simplex method
PPTX
Transportation Problem
PPTX
Integer Linear Programming
PPTX
Assignment model
Transportation problem
Simplex Method
simplex method for operation research .pdf
Hungarian Method
simplex method
Transportation Problem
Integer Linear Programming
Assignment model

What's hot (20)

DOCX
Transportation model
PPTX
Simplex method concept,
PPTX
Assignment problem
PPTX
Transportation Problem- Stepping Stone Method
PPTX
LP special cases and Duality.pptx
PDF
Optimal Solution by MODI Method
PDF
Simplex method
PPTX
FIRMS - ENGINEERING ECONOMICS AND FINANCIAL ACCOUNTING
PPTX
Transportation problem
 
PPTX
transporation problem - stepping stone method
PPT
Assignment Problem
PPSX
Linear programing
PDF
Unit.2. linear programming
PDF
Chapter 3.Simplex Method hand out last.pdf
DOC
Procedure Of Simplex Method
PPT
North West Corner Method
PDF
Duality in Linear Programming Problem
PPTX
Transportation Problem In Linear Programming
PDF
Assignment problems
PPTX
MODI Method (Operations Research)
Transportation model
Simplex method concept,
Assignment problem
Transportation Problem- Stepping Stone Method
LP special cases and Duality.pptx
Optimal Solution by MODI Method
Simplex method
FIRMS - ENGINEERING ECONOMICS AND FINANCIAL ACCOUNTING
Transportation problem
 
transporation problem - stepping stone method
Assignment Problem
Linear programing
Unit.2. linear programming
Chapter 3.Simplex Method hand out last.pdf
Procedure Of Simplex Method
North West Corner Method
Duality in Linear Programming Problem
Transportation Problem In Linear Programming
Assignment problems
MODI Method (Operations Research)
Ad

Similar to Hungarian Assignment Problem (20)

PDF
Asssignment problem
PPTX
Assignment problem
PPT
Lesson 33: The Assignment Problem
PDF
A Comparative Analysis Of Assignment Problem
PDF
Operations Research Project
PDF
Assignment Chapter - Q & A Compilation by Niraj Thapa
PDF
A0280115(1)
PPTX
Chapter 1 Assignment Problems (DS) (1).pptx
PDF
qadm-ppt-150918102124-lva1-app6892.pdf
PPT
Transportation and Assiggnment problem ppt
PDF
Decision Science.pdf
PDF
AMA_Assignment Theory notes
PPTX
QABD Transportation problems-UNIT-3.pptx
PPTX
OPERATIONAL RESEARCH BUSINESS APPLICATIONS
PDF
Chapter 03
PPTX
Assignment method
PDF
Assignment problem notes
PPTX
Hungarian algorithm
PDF
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...
PPTX
Linear Programing.pptx
Asssignment problem
Assignment problem
Lesson 33: The Assignment Problem
A Comparative Analysis Of Assignment Problem
Operations Research Project
Assignment Chapter - Q & A Compilation by Niraj Thapa
A0280115(1)
Chapter 1 Assignment Problems (DS) (1).pptx
qadm-ppt-150918102124-lva1-app6892.pdf
Transportation and Assiggnment problem ppt
Decision Science.pdf
AMA_Assignment Theory notes
QABD Transportation problems-UNIT-3.pptx
OPERATIONAL RESEARCH BUSINESS APPLICATIONS
Chapter 03
Assignment method
Assignment problem notes
Hungarian algorithm
Quantitativeanalysisfordecisionmaking 13427543542352-phpapp02-120719222252-ph...
Linear Programing.pptx
Ad

More from VivekSaurabh7 (9)

PPTX
Transportation Problem
PPTX
PPTX
Operations REsearch
PPTX
MODI_SteppingStone.pptx
PPTX
OR PPT 280322 maximin final - nikhil tiwari.pptx
PPTX
EM GROUP 1.pptx
PPTX
STRATERGIES TO IMPROVE BUSINESS COMMUNICATION.pptx
PPTX
Job offer.pptx
PPTX
EM-10.pptx
Transportation Problem
Operations REsearch
MODI_SteppingStone.pptx
OR PPT 280322 maximin final - nikhil tiwari.pptx
EM GROUP 1.pptx
STRATERGIES TO IMPROVE BUSINESS COMMUNICATION.pptx
Job offer.pptx
EM-10.pptx

Recently uploaded (20)

PDF
MARG’s Door & Window Hardware Catalogue | Trending Branding Digital Solutions
PPTX
"Best Healthcare Digital Marketing Ideas
PPTX
UNIT 3 - 5 INDUSTRIAL PRICING.ppt x
PPTX
Ranking a Webpage with SEO (And Tracking It with the Right Attribution Type a...
PDF
Unit 1 -2 THE 4 As of RURAL MARKETING MIX.pdf
PDF
How a Travel Company Can Implement Content Marketing
PDF
EVOLUTION OF RURAL MARKETING IN INDIAN CIVILIZATION
PDF
Prove and Prioritize Profitability in Every Marketing Campaign - Zach Sherrod...
PPTX
Presentation - MindfulHeal Digital Ayurveda GTM & Marketing Plan.pptx
PDF
Coleção Nature .
DOCX
marketing plan starville............docx
PDF
Mastering Content Strategy in 2025 ss.pdf
PDF
RC 14001 Certification: Enhancing ISO 14001 with EHS & Security Standards
PDF
UNIT 1 -4 Profile of Rural Consumers (1).pdf
PPTX
Fixing-AI-Hallucinations-The-NeuroRanktm-Approach.pptx
DOCX
Parkville marketing plan .......MR.docx
PDF
Digital Marketing Agency in Thrissur with Proven Strategies for Local Growth
PPTX
Kimberly Crossland Storytelling Marketing Class 5stars.pptx
PDF
E_Book_Customer_Relation_Management_0.pdf
PDF
20K Btc Enabled Cash App Accounts – Safe, Fast, Verified.pdf
MARG’s Door & Window Hardware Catalogue | Trending Branding Digital Solutions
"Best Healthcare Digital Marketing Ideas
UNIT 3 - 5 INDUSTRIAL PRICING.ppt x
Ranking a Webpage with SEO (And Tracking It with the Right Attribution Type a...
Unit 1 -2 THE 4 As of RURAL MARKETING MIX.pdf
How a Travel Company Can Implement Content Marketing
EVOLUTION OF RURAL MARKETING IN INDIAN CIVILIZATION
Prove and Prioritize Profitability in Every Marketing Campaign - Zach Sherrod...
Presentation - MindfulHeal Digital Ayurveda GTM & Marketing Plan.pptx
Coleção Nature .
marketing plan starville............docx
Mastering Content Strategy in 2025 ss.pdf
RC 14001 Certification: Enhancing ISO 14001 with EHS & Security Standards
UNIT 1 -4 Profile of Rural Consumers (1).pdf
Fixing-AI-Hallucinations-The-NeuroRanktm-Approach.pptx
Parkville marketing plan .......MR.docx
Digital Marketing Agency in Thrissur with Proven Strategies for Local Growth
Kimberly Crossland Storytelling Marketing Class 5stars.pptx
E_Book_Customer_Relation_Management_0.pdf
20K Btc Enabled Cash App Accounts – Safe, Fast, Verified.pdf

Hungarian Assignment Problem

  • 1. BY: Preeti Baliyan Ankita Deka AtulAnand Pathak Davishmaan Baranwal Poornima Shrivastwa
  • 2. WHAT IS AN ASSIGNMENT PROBLEM? A case of transportation problem and a fundamental combinatorial optimization problem. WHAT ISTHE OBJECTIVE? To assign a number of resources to an equal number of activities so as to minimise total cost or maximize total profit of allocation. WHY DOES IT ARISE? It arises because available resources have varying degrees of efficiency for different activities,Thus the problem is, “How should the assignments be made so as to optimize the given objective?”
  • 3.  Example: 1) assignment of workers to machines 2) Salesman to different sales area  Suppose there are n jobs to be performed and n persons are available for doing these jobs. Assume that each person can do each job at a term, though with varying degree of efficiency, let cij be the cost if the i-th person is assigned to the j-th job.The problem is to find an assignment (which job should be assigned to which person one on-one basis) So that the total cost of performing all jobs is minimum, problem of this kind are known as assignment problem. TYPESOF ASSIGNMENT PROBLEM BALANCED UNBALANCED
  • 4.  The assignment problem can be stated that in the form of mxn matrix cij called a Cost Matrix (or) Effectiveness Matrix where cij is the cost of assigning i th machine to j th job.
  • 5.  Consider an assignment problem of assigning n jobs to n machines (one job to one machine). Let cij be the unit cost of assigning ith machine to the jth job and,i th machine to j th job.  Let xij = 1 , if j th job is assigned to i th machine. xij = 0 , if j th job is not assigned to i th machine.  Minimize :-  subject to the constraints :-
  • 7. Step 1: Whether the matrix/problem is balanced or unbalanced. If matrix is unbalanced we have to convert it into a balanced matrix. Problem: A company has five jobsV, W, X,Y and Z and five machines A, B, C, D and E. The matrix entries are processing time of each machine in hours. Solve the following assignment problem shown inTable using Hungarian method.
  • 8. Step 2: Row Reduction- Subtract the smallest cost element of each row from all the elements of that particular row of the given cost matrix.
  • 9. Step3: Column Reduction- Subtract the smallest cost element of each column from all the elements of that particular column of the resulting cost matrix obtained by step 2.
  • 10. Step 4: Assigning/Covering Zeros: i) Row Scanning- Starting from the first row, ask the following questions. If there is only one zero in that row, mark a square around that zero and draw a vertical line. If there is more than one zero in that row, skip that row and go the next row. ii) Column scanning- Starting from the first column, ask the following questions. If there is only one zero in that column, mark a square around that zero and draw a horizontal line. If there is more than one zero in that column, skip that column and go the next column. Step 5: If the number of squares drawn are equal to number of rows or columns.Then it is an optimal solution.We can have assignments. If number of squares are not equal to number of rows/columns go to step 6.
  • 11. Step 6: Identify the minimum value among the uncovered cells. Add that value to the crossed cells and subtract it from the uncovered cells. Covered cells value remain same. Covered Cells: Cells through which a line passes. Uncovered Cells: Cells through which no lines passes. Crossed Cells: Cells which are at the interaction of horizontal and vertical line. Step 7: Repeat step 4 and 5 of assigning/covering zeroes to get an optimal solution.
  • 12. Step 8: Assignment- Optimal Solution.
  • 13. Unbalanced Assignment Problem:  It is an assignment problem where,  Convert to a balanced assignment problem by adding a dummy row or dummy column with zero values. No. of rows ≠ No. of columns
  • 14. Question: Solve the assignment problem. 7 5 8 4 5 6 7 4 8 7 9 8 A B C D 1 2 3 JOBS MEN
  • 15. Solution: Add a dummy row. 7 5 8 4 5 6 7 4 8 7 9 8 A B C D 1 2 3
  • 16. Phase 1: Row and Column Reduction  Step 1: Subtract minimum value of each row from entries that row.
  • 17. Phase 2: Optimation of problem  Step 1: Starting from first row, check if there is only one zero in that row. If yes, mark a square around that zero entry and draw a vertical line through that zero. • After scanning the last row, check whether all the zeroes are covered with lines.
  • 18.  Step 2: Starting from first column, check if there is only one zero in that column. If yes, mark a square around that zero entry and draw a horizontal line through that zero. • After scanning the last column, check whether all the zeroes are covered with lines. • Step 3: Check whether the no. of squares marked is equal to no. of rows of the matrix.
  • 19.  Step 4: Identify the minimum value of the undeleted cell values. i. Add the minimum undeleted cell value at the intersection points of the present matrix. ii. Subtract the minimum undeleted cell value from all the other undeleted cell values. iii. The other entries remail the same.
  • 20.  Step 5: Do row scanning and column scanning again.
  • 21. MEN JOB TIME 1 D 4 2 A 5 3 B 7 4 C 0 Total ProcessingTime 16
  • 22. Question: Solve the assignment problem At the head office of a company there are five registration counters. Five persons are available for service. How should the counters be assigned to persons so as to maximize the profit? 30 37 40 28 40 40 24 27 21 36 40 32 33 30 35 25 38 40 36 36 29 62 41 34 39 A B C D E 1 2 3 4 5 PERSO N COMPAN Y
  • 23. Convert the maximization problem to a minimization problem. 30 37 40 28 40 40 24 27 21 36 40 32 33 30 35 25 38 40 36 36 29 62 41 34 39 A B C D E 1 2 3 4 5
  • 24. Phase 1: Row and Column Reduction  Step 1: Subtract minimum value of each row from entries that row.
  • 25.  Step 2: Subtract minimum value of each column from entries that column.
  • 26. Step 3: Assigning the zeros, we have the following
  • 27.  Step 4: Marking the unassigning the zeros row and crossed zero column of marked row, we have the following.
  • 28.  Step 5: Crossing the marked column and unmarked row.
  • 29.  Step 6: Determine the smallest cost element not covered by the straight lines. Sub- tract this smallest cost element from all the uncovered elements and add this to all those elements which are lying in the intersection of these straight lines and do not change the remaining elements which lie on the straight lines.
  • 30.  Step 7: Assigning the zeros, we have the following
  • 31. 30 37 40 28 40 40 24 27 21 36 40 32 33 30 35 25 38 40 36 36 29 62 41 34 39 A B C D E 1 2 3 4 5 Company Person Time 1 C 40 2 E 36 3 A 40 4 D 36 5 B 62 Total ProcessingTime 214
  • 33. Travelling salesman route will be plan in such a way that in a given N number of cities cost of travelling from one city to any other city what is the minimum round trip route that visit each city once and then return to the starting place. The goal is to find the shortest tour that visit each city in a given cities exactly ones and then return to the starting city. The only solution to the travelling salesman problem is to calculate and compare the length of all possible ordered combinations.
  • 34. Find the route that takes the shortest time for a person through every city and back to the starting point from A. A → D → B → C → A A D C B 3 5 2 4
  • 35. Following are the cost (in INR ‘00) of travelling in various cities. Akshay, a sales agent, wants to cover all cities in lowest cost. In which order/path he should go to be economical? A B C D A 0 25 75 45 B 35 0 150 25 C 35 40 0 15 D 65 75 130 0
  • 36.  Step 1 ROW REDUCTION Subtract minimum element of each row from all the elements in its row A B C D A x 25 75 45 B 35 x 150 25 C 35 40 x 15 D 65 75 130 x → 25 → 25 → 15 → 65 A B C D A x 0 50 20 B 10 x 125 0 C 20 25 x 0 D 0 10 65 x
  • 37. Subtract minimum element of each column from all the elements in its column A B C D A x 0 0 20 B 10 x 75 0 C 20 25 x 0 D 0 10 15 x A B C D A x 0 50 20 B 10 x 125 0 C 20 25 x 0 D 0 10 65 x ↓ ↓ ↓ ↓ 0 0 50 0
  • 38.  Identify the row with single O only and subsequently eliminate its address column. Eventually, identify the column with single O only and subsequently eliminate its address row. A B C D A x 0 0 20 B 10 x 75 0 C 20 25 x 0 D 0 10 15 x
  • 39. For optimal solution, No. of assigned Os = No. of order of matrix But here, No. of assigned Os < No. of order of matrix A B C D A x 0 0 20 B 10 x 75 0 C 20 25 x 0 D 0 10 15 x Contd.
  • 40.  Of the remaining undeleted items, identify the minimum and subtract it from rest of the undeleted items and add to the intersection of lines.  The remaining deleted items should be brought down as it is A B C D A x 0 0 20 B 10 x 75 0 C 20 25 x 0 D 0 10 15 x A B C D A x 0 0 30 B 10 x 65 0 C 20 15 x 0 D 0 0 5 x
  • 41. x A B C D A x 0 0 30 B 10 x 65 0 C 20 15 x 0 D 0 0 5 x
  • 42. x A B C D A x 0 0 30 B 10 x 65 0 C 20 15 x 0 D 0 0 5 x A B C D A x 0 0 40 B 0 x 55 0 C 10 5 x 0 D 0 0 5 x
  • 43. Here, No. of assigned Os = No. of order of matrix Hence, it satisfies the optimal solution for minimum cost A B C D A x 0 0 40 B 0 x 55 0 C 10 5 x 0 D 0 0 5 x
  • 44. A → C → D → B → A 1,3,4,2 i.e. Total Cost = 7,500 + 1,500 + 7,500 + 3,500 = INR 20,000 A B C D A x 0 0 40 B 0 x 55 0 C 10 5 x 0 D 0 0 5 x A B C D A 0 25 75 45 B 35 0 150 25 C 35 40 0 15 D 65 75 130 0
  • 45. The 'Travelling salesman problem' is very similar to the assignment problem except that in the former, there are additional restrictions that a salesman starts from his city, visits each city once and returns to his home city, so that the total distance (cost or time) is minimum
  • 46.  Given N men and N women, where each person has ranked all members of the opposite sex in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. If there are no such people, all the marriages are “stable”.  It uses Gale-Shapely algorithm to solve the problem.  EXAMPLES :- 1.Student choosing their future universities 2. Man and women seeking each other to create families 3. Internet services that need to be connected with users with the smallest amount of time. In all these cases we need to create stable pairs that need to satisfied certain criteria.
  • 47.  Example:- Males 1 2 3 4 5 A O M L N P B P N M L O C M P L O N D P M O N L E O L M N P Females 1 2 3 4 5 L D B E C A M B A D C E N A C E D B O D A C B E P B E A C D
  • 48. Males 1 2 3 4 5 A O M L N P B P N M L O C M P L O N D P M O N L E O L M N P Females 1 2 3 4 5 L D B E C A M B A D C E N A C E D B O D A C B E P B E A C D
  • 49. Males 1 2 3 4 5 A O M L N P B P N M L O C M P L O N D P M O N L E O L M N P Females 1 2 3 4 5 L D B E C A M B A D C E N A C E D B O D A C B E P B E A C D
  • 50. Males 1 2 3 4 5 A O M L N P B P N M L O C M P L O N D P M O N L E O L M N P Females 1 2 3 4 5 L D B E C A M B A D C E N A C E D B O D A C B E P B E A C D
  • 51. Males 1 2 3 4 5 A O M L N P B P N M L O C M P L O N D P M O N L E O L M N P Females 1 2 3 4 5 L D B E C A M B A D C E N A C E D B O D A C B E P B E A C D
  • 52. Males 1 2 3 4 5 A O M L N P B P N M L O C M P L O N D P M O N L E O L M N P Females 1 2 3 4 5 L D B E C A M B A D C E N A C E D B O D A C B E P B E A C D
  • 53. Males 1 2 3 4 5 A O M L N P B P N M L O C M P L O N D P M O N L E O L M N P Females 1 2 3 4 5 L D B E C A M B A D C E N A C E D B O D A C B E P B E A C D
  • 54. Males 1 2 3 4 5 A O M L N P B P N M L O C M P L O N D P M O N L E O L M N P Females 1 2 3 4 5 L D B E C A M B A D C E N A C E D B O D A C B E P B E A C D
  • 55. Males 1 2 3 4 5 A O M L N P B P N M L O C M P L O N D P M O N L E O L M N P Females 1 2 3 4 5 L D B E C A M B A D C E N A C E D B O D A C B E P B E A C D
  • 56. The main difference between stable marriage problem and assignment problem is that of optimality. In assignment problem we are concerned with overall minimized cost/timing/distance without focusing on individual allocation whether it is good or bad but in case of stable marriage problem we are concerned with the individual stability of the assigned pair.
  • 57. Functions used in the program :- 1. as.integer() :- Converts a character type object into integer type object . 2. readline() :- reads text lines from an input file. 3. matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) :- creates a matrix from the given set of values. 4. for(), if() :- these are control flow constructs in R language. 5. lp.assign (cost.mat, direction = "min", presolve = 0, compute.sens = 0) :- Interface to lp_solve linear/integer programming system specifically for solving assignment problems 6. lp.assign()$solution : - gives solution matrix.
  • 58. library(lpSolve) #entering number of rows and columns r <- as.integer(readline ( "Enter number of assignees(will be treated as rows):")) c <- as.integer(readline("Enter number of jobs to be assigned(will be treated as column) :")) #printing number of rows and columns for matrix print(r) print(c)
  • 59. #creating matrix with given number of rows and columns mat <- matrix(nrow = r, ncol = c) #printing matrix with no values entered print(mat) #using for loop to enter the values in matrix from the user for ( i in 1:r){ for (j in 1:c){ print(paste("Enter element with row no.", i, "and column no.", j)) mat[i,j] <- as.integer(readline()) } }
  • 60. if(r>c) mat = cbind(mat, c(rep.int(0, r))) if(r<c) mat = rbind(mat, c(rep.int(0, c))) #printing the matrix with value print(mat) #Using lp.assign() method to find the solution of the assignment problem lp.assign(mat) #displaying the allocation matrix lp.assign(mat)$solution