Professional Documents
Culture Documents
TRANSPORTATION PROBLEM
CODING EXPERIMENT
Group 4
Group members:
Submitted by Christopher Basumatary
OBJECTIVE
To develop a code using to calculation transportation problem using North West Corner
method.
SOLUTION
The code is developed in such a way that it is able to read the input as shown in the format
mentioned below
Mumba
Delhi i Supply
Kochi 80 215 1000
Coimbator
e 100 108 1500
Vizag 102 68 1200
Demand 2300 1400 3700
coltotal = {}
rowtotal = {}
#total of each column is stored in a dictionary
for i in df_1.columns:
coltotal[i]=df_1[i].loc[totrows-1]
#a while loop with the condition to stop when rowtotal anc column total
becomes zero is defined
while (max(rowtotal.values())!=0) and (max(coltotal.values())!=0):
#below loop identifies minimum value from the dataset
#takes the column name and checks the corresponding total in the dictionary
#if column total is not zero, it checks row total of different rows of same
column
#if column total of any column or row total of any row is zero, it is
skipped
#minimum values are identified where row total and column total is not zero
for i in coltotal.keys():
if coltotal[i]==0:
continue
else:
for j in rowtotal.keys():
if rowtotal[j]==0:
continue
else:
if df_1[i].loc[j] <= a:
a = df_1[i].loc[j]
col = i
row = j
#once minimum value is identified, the corresponding row total or column
total is checked if high
#reduces the higher total value with lower total value and replaces it in
the dictionary in the place of the higher total value
#lower total values is updated as zero
#minimum cost is computed by multiplying variable “a” value with minimum
total value
#this value is then appended to minimum cost variable and continues the
process till all row total and column total are zero
INFERENCE
The same code can be used to solve different transportation problems with different
conditions such when the number of sources or destinations are different using the minimum
cost method.
For example, consider the situation,
1 2 3 4 Supply
1 10 2 20 11 15
2 12 7 9 20 25
3 4 14 16 18 10
Deman
d 5 15 15 15 50
Comparing with our initial problem, the number of destinations is more in the above case.
However, this can be solved using the same code by giving this data as input to the code and
running it. The output of this case is as shown below:
As long as the last row is the demand row and the last column is supply column, the same
code would be sufficient to solve transportation problem using Minimum Cost Method.
input.csv