Home > Operation Research calculators > Travelling salesman problem using hungarian method example

2. Travelling salesman problem using Hungarian method example ( Enter your problem )
  1. Rules & Example-1
  2. Example-2
Other related methods
  1. Assignment problem using Hungarian method
  2. Travelling salesman problem using Hungarian method
  3. Travelling salesman branch and bound (penalty) method
  4. Travelling salesman branch and bound method
  5. Travelling salesman nearest neighbor method
  6. Travelling salesman diagonal completion method
  7. Crew assignment problem

1. Rules & Example-1
(Previous example)
3. Travelling salesman branch and bound (penalty) method
(Next method)

2. Example-2





Find Solution of Travelling salesman problem (MIN case)
Work\JobABCDE
Ax5845
B5x745
C87x86
D448x8
E5568x


Solution:
The number of rows = 5 and columns = 5
   `A`  `B`  `C`  `D`  `E`    
 `A` M5845
 `B` 5M745
 `C` 87M86
 `D` 448M8
 `E` 5568M
   



Step-1: Find out the each row minimum element and subtract it from that row
   `A`  `B`  `C`  `D`  `E`    
 `A`  M M 1 `1=5-4` 4 `4=8-4` 0 `0=4-4` 1 `1=5-4` (-4) Minimum element of `1^(st)` row
 `B`  1 `1=5-4` M M 3 `3=7-4` 0 `0=4-4` 1 `1=5-4` (-4) Minimum element of `2^(nd)` row
 `C`  2 `2=8-6` 1 `1=7-6` M M 2 `2=8-6` 0 `0=6-6` (-6) Minimum element of `3^(rd)` row
 `D`  0 `0=4-4` 0 `0=4-4` 4 `4=8-4` M M 4 `4=8-4` (-4) Minimum element of `4^(th)` row
 `E`  0 `0=5-5` 0 `0=5-5` 1 `1=6-5` 3 `3=8-5` M M (-5) Minimum element of `5^(th)` row
   


Step-2: Find out the each column minimum element and subtract it from that column.
   `A`  `B`  `C`  `D`  `E`    
 `A`  M M 1 `1=1-0` 3 `3=4-1` 0 `0=0-0` 1 `1=1-0`
 `B`  1 `1=1-0` M M 2 `2=3-1` 0 `0=0-0` 1 `1=1-0`
 `C`  2 `2=2-0` 1 `1=1-0` M M 2 `2=2-0` 0 `0=0-0`
 `D`  0 `0=0-0` 0 `0=0-0` 3 `3=4-1` M M 4 `4=4-0`
 `E`  0 `0=0-0` 0 `0=0-0` 0 `0=1-1` 3 `3=3-0` M M
    (-0) Minimum element of `1^(st)` column (-0) Minimum element of `2^(nd)` column (-1) Minimum element of `3^(rd)` column (-0) Minimum element of `4^(th)` column (-0) Minimum element of `5^(th)` column


Iteration-1 of steps 3 to 6
Step-3: Make assignment in the opporunity cost table

a. Identify rows with exactly one unmarked 0. Make an assignmment to this single 0 by make a square ( [0] ) around it and cross off all other 0 in the same column.

b. Identify columns with exactly one unmarked 0. Make an assignmment to this single 0 by make a square ( [0] ) around it and cross off all other 0 in the same rows.

c. If a row and/or column has two or more unmarked 0 and one cannot be chosen by inspection, then choose the cell arbitarily.

d. Continue this process until all 0 in rows/columns are either assigned or cross off( ).

Step-3: Make assignment in the opporunity cost table
(1) Rowwise cell `(A,D)` is assigned, so columnwise cell `(B,D)` crossed off.

(2) Rowwise cell `(C,E)` is assigned

(3) Columnwise cell `(E,C)` is assigned, so rowwise cell `(E,A)`,`(E,B)` crossed off.

(4) Rowwise cell `(D,B)` is assigned

(5) Columnwise cell `(D,A)` is assigned, so rowwise cell `(D,B)` crossed off.


Rowwise & columnwise assignment shown in table
   `A`  `B`  `C`  `D`  `E`    
 `A` M13 [0] (1) Rowwise cell `(A,D)` is assigned
so columnwise cell `(B,D)` crossed off.
1
 `B` 1M2 0 Columnwise `(B,D)` crossed off because
(1) Rowwise cell `(A,D)` is assigned
1
 `C` 21M2 [0] (2) Rowwise cell `(C,E)` is assigned
 `D`  [0] (5) Columnwise cell `(D,A)` is assigned
so rowwise cell `(D,B)` crossed off.
 0 Rowwise `(D,B)` crossed off because
(5) Columnwise cell `(D,A)` is assigned
3M4
 `E`  0 Rowwise `(E,A)` crossed off because
(3) Columnwise cell `(E,C)` is assigned
 0 Rowwise `(E,B)` crossed off because
(3) Columnwise cell `(E,C)` is assigned
 [0] (3) Columnwise cell `(E,C)` is assigned
so rowwise cell `(E,A)`,`(E,B)` crossed off.
3M
   


Step-4: Number of assignments = 4, number of rows = 5
Which is not equal, so solution is not optimal.

Step-5: Draw a set of horizontal and vertical lines to cover all the 0

a. Tick(✓) mark all the rows in which no assigned 0.

b. Examine Tick(✓) marked rows, If any 0 cell occurs in that row, then tick(✓) mark that column.

c. Examine Tick(✓) marked columns, If any assigned 0 exists in that columns, then tick(✓) mark that row.

d. Repeat this process until no more rows or columns can be marked.

e. Draw a straight line for each unmarked rows and marked columns.

f. If the number of lines is equal to the number of rows then the current solution is the optimal, otherwise goto step-6

Step-5: Cover the 0 with minimum number of lines
(1) Mark(✓) row `B` since it has no assignment

(2) Mark(✓) column `D` since row `B` has 0 in this column

(3) Mark(✓) row `A` since column `D` has an assignment in this row `A`.

(4) Since no other rows or columns can be marked, therefore draw straight lines through the unmarked rows `C,D,E` and marked columns `D`


Tick mark not allocated rows and allocated columns
   `A`  `B`  `C`  `D`  `E`    
 `A` M13[0]1 ✓(3) (3) Mark(✓) row `A` since column `D` has an assignment in this row `A`.
 `B` 1M201 ✓(1) (1) Mark(✓) row `B` since it has no assignment
 `C` 21M2[0]
 `D` [0]03M4
 `E` 00[0]3M
    
(2)
 (2) Mark(✓) column `D` since row `B` has 0 in this column


Step-6: Develop the new revised opportunity cost table

a. Select the minimum element, say k, from the cells not covered by any line,

b. Subtract k from each element not covered by a line.

c. Add k to each intersection element of two lines.

Step-6: Develop the new revised table by selecting the smallest element, among the cells not covered by any line (say k = 1)
Subtract k = 1 from every element in the cell not covered by a line.
Add k = 1 to every elment in the intersection cell of two lines.

   `A`  `B`  `C`  `D`  `E`    
 `A`  M `M=M-1`
cell not covered by a line
 0 `0=1-1`
cell not covered by a line
 2 `2=3-1`
cell not covered by a line
 0 cell covered by a line 0 `0=1-1`
cell not covered by a line
 `B`  0 `0=1-1`
cell not covered by a line
 M `M=M-1`
cell not covered by a line
 1 `1=2-1`
cell not covered by a line
 0 cell covered by a line 0 `0=1-1`
cell not covered by a line
 `C`  2 cell covered by a line 1 cell covered by a line M cell covered by a line 3 `3=2+1`
intersection cell of two lines
 0 cell covered by a line
 `D`  0 cell covered by a line 0 cell covered by a line 3 cell covered by a line M `M=M+1`
intersection cell of two lines
 4 cell covered by a line
 `E`  0 cell covered by a line 0 cell covered by a line 0 cell covered by a line 4 `4=3+1`
intersection cell of two lines
 M cell covered by a line
   


Repeat steps 3 to 6 until an optimal solution is arrived.


Iteration-2 of steps 3 to 6
Step-3: Make assignment in the opporunity cost table
(1) Rowwise cell `(C,E)` is assigned, so columnwise cell `(A,E)`,`(B,E)` crossed off.

(2) Columnwise cell `(E,C)` is assigned, so rowwise cell `(E,A)`,`(E,B)` crossed off.

(3) Rowwise cell `(A,D)` is assigned, so columnwise cell `(B,D)` crossed off.

(4) Rowwise cell `(B,A)` is assigned, so columnwise cell `(D,A)` crossed off.

(5) Rowwise cell `(D,B)` is assigned, so columnwise cell `(A,B)` crossed off.


Rowwise & columnwise assignment shown in table
   `A`  `B`  `C`  `D`  `E`    
 `A` M 0 Columnwise `(A,B)` crossed off because
(5) Rowwise cell `(D,B)` is assigned
2 [0] (3) Rowwise cell `(A,D)` is assigned
so columnwise cell `(B,D)` crossed off.
 0 Columnwise `(A,E)` crossed off because
(1) Rowwise cell `(C,E)` is assigned
 `B`  [0] (4) Rowwise cell `(B,A)` is assigned
so columnwise cell `(D,A)` crossed off.
M1 0 Columnwise `(B,D)` crossed off because
(3) Rowwise cell `(A,D)` is assigned
 0 Columnwise `(B,E)` crossed off because
(1) Rowwise cell `(C,E)` is assigned
 `C` 21M3 [0] (1) Rowwise cell `(C,E)` is assigned
so columnwise cell `(A,E)`,`(B,E)` crossed off.
 `D`  0 Columnwise `(D,A)` crossed off because
(4) Rowwise cell `(B,A)` is assigned
 [0] (5) Rowwise cell `(D,B)` is assigned
so columnwise cell `(A,B)` crossed off.
3M4
 `E`  0 Rowwise `(E,A)` crossed off because
(2) Columnwise cell `(E,C)` is assigned
 0 Rowwise `(E,B)` crossed off because
(2) Columnwise cell `(E,C)` is assigned
 [0] (2) Columnwise cell `(E,C)` is assigned
so rowwise cell `(E,A)`,`(E,B)` crossed off.
4M
   


Step-4: Number of assignments = 5, number of rows = 5
The solution gives the sequence : `A->D,D->B,B->A`

The above solution is not a solution to the travelling salesman problem as he visits each city only once.


Iteration-3 of steps 3 to 6

The next best solution can be obtained by bringing the minimum non-zero element, i.e., 1 into the solution.
The cost 1 occurs at 2 places. We will consider all the cases separately until the acceptable solution is obtained.

Case: 1 of 2 for minimum non-zero element 1
Make the assignment in the cell `(B,C)` and repeat Step-3.

Step-3: Make assignment in the opporunity cost table
(1) Rowwise cell `(B,C)` is assigned, so columnwise cell `(E,C)`,`(B,A)`,`(B,D)`,`(B,E)` crossed off.

(2) Columnwise cell `(A,D)` is assigned, so rowwise cell `(A,B)`,`(A,E)` crossed off.

(3) Columnwise cell `(C,E)` is assigned, so rowwise cell `(C,B)` crossed off.

(4) Rowwise cell `(D,B)` is assigned, so columnwise cell `(E,B)` crossed off.

(5) Rowwise cell `(E,A)` is assigned, so columnwise cell `(D,A)` crossed off.


Rowwise & columnwise assignment shown in table
   `A`  `B`  `C`  `D`  `E`    
 `A` M 0 Rowwise `(A,B)` crossed off because
(2) Columnwise cell `(A,D)` is assigned
2 [0] (2) Columnwise cell `(A,D)` is assigned
so rowwise cell `(A,B)`,`(A,E)` crossed off.
 0 Rowwise `(A,E)` crossed off because
(2) Columnwise cell `(A,D)` is assigned
 `B`  0 Columnwise `(B,A)` crossed off because
(1) Rowwise cell `(B,C)` is assigned
M [1] (1) Rowwise cell `(B,C)` is assigned
so columnwise cell `(E,C)`,`(B,A)`,`(B,D)`,`(B,E)` crossed off.
 0 Columnwise `(B,D)` crossed off because
(1) Rowwise cell `(B,C)` is assigned
 0 Columnwise `(B,E)` crossed off because
(1) Rowwise cell `(B,C)` is assigned
 `C` 2 1 Rowwise `(C,B)` crossed off because
(3) Columnwise cell `(C,E)` is assigned
M3 [0] (3) Columnwise cell `(C,E)` is assigned
so rowwise cell `(C,B)` crossed off.
 `D`  0 Columnwise `(D,A)` crossed off because
(5) Rowwise cell `(E,A)` is assigned
 [0] (4) Rowwise cell `(D,B)` is assigned
so columnwise cell `(E,B)` crossed off.
3M4
 `E`  [0] (5) Rowwise cell `(E,A)` is assigned
so columnwise cell `(D,A)` crossed off.
 0 Columnwise `(E,B)` crossed off because
(4) Rowwise cell `(D,B)` is assigned
 0 Columnwise `(E,C)` crossed off because
(1) Rowwise cell `(B,C)` is assigned
4M
   


Step-4: Number of assignments = 5, number of rows = 5
The solution gives the sequence : `A->D,D->B,B->C,C->E,E->A`

So solution is optimal

Optimal assignments are
   `A`  `B`  `C`  `D`  `E`    
 `A`  M Original cost M 0 Original cost 5 2 Original cost 8 [0] Original cost 4 0 Original cost 5
 `B`  0 Original cost 5 M Original cost M [1] Original cost 7 0 Original cost 4 0 Original cost 5
 `C`  2 Original cost 8 1 Original cost 7 M Original cost M 3 Original cost 8 [0] Original cost 6
 `D`  0 Original cost 4 [0] Original cost 4 3 Original cost 8 M Original cost M 4 Original cost 8
 `E`  [0] Original cost 5 0 Original cost 5 0 Original cost 6 4 Original cost 8 M Original cost M
   


Optimal solution is
WorkJobCost
`A``D`4
`B``C`7
`C``E`6
`D``B`4
`E``A`5
Total26



This material is intended as a summary. Use your textbook for detail explanation.
Any bug, improvement, feedback then Submit Here



1. Rules & Example-1
(Previous example)
3. Travelling salesman branch and bound (penalty) method
(Next method)





Share this solution or page with your friends.


 
Copyright © 2024. All rights reserved. Terms, Privacy
 
 

.