FIND THE MIN TRANSPORTATION COST BY NWC METHOD

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

//PROGRAM TO FIND THE MIN TRANSPORTATION COST BY NWC METHOD

#include<iostream.h>
#include<conio.h>
class north
{
public:
int c[10][10],s1[10],d1[10],s[10],d[10];
int m,n,i,j;
int ssum,dsum;
void getdata();
void cal();
};
void north::getdata(void)
{
lab:
ssum=0;dsum=0;
//input for dimensions
cout<<“enter number of row (m) : – “;
cin>>m;
cout<<“enter number of column (n) : – “;
cin>>n;
//input for cost matrix
cout<<endl<<“ENTER THE COST MATRIX”<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<endl<<“enter element of row “;
cout<<i+1<<” and column “<<j+1<<” : – “;
cin>>c[i][j];
}
}
//input for supply
cout<<endl<<“ENTER THE SUPPLY ARRAY”<<endl;
for(j=0;j<m;j++)
{
cin>>s[j];
s1[j]=s[j];
ssum=ssum+s[j];
}
//input for demand
cout<<endl<<“ENTER THE DEMAND ARRAY”<<endl;
for(j=0;j<n;j++)
{
cin>>d[j];
d1[j]=d[j];
dsum=dsum+d[j];
}
cout<<endl<<“ssum:-“<<ssum<<“\tdsum:-“<<dsum;
if(ssum!=dsum)
{
cout<<“enter only balanced problem”;
goto lab;
}
}
void north::cal(void)
{
i=0;j=0;
int sum=0;
start: if(i==m&&j==n)
goto end;
else
{
if (s[i]==d[j])
{
sum=sum+(c[i][j]*s[i]);
i++;j++;
}
else if(s[i]<d[j])
{
d[j]=d[j]-s[i];
sum=sum+(c[i][j]*s[i]);
i++;
}
else if(s[i]>d[j])
{
s[i]=s[i]-d[j];
sum=sum+(c[i][j]*d[j]);
j++;
}
}
goto start;
end:
clrscr();
cout<<endl<<” ——————————-“<<endl;
cout<<“|\t\t\t\t|”<<endl;
for(i=0;i<m;i++)
{
cout<<“|\t”;
for(j=0;j<n;j++)
{
cout<<c[i][j]<<“\t”;
}
cout<<“|\t”<<s1[i]<<endl<<“|\t\t\t\t|”;
cout<<endl<<“|\t\t\t\t|”<<endl;
}
cout<<” ——————————–“<<endl<<endl;
for(i=0;i<n;i++)
{
cout<<“\t”<<d1[i];
// cout<<endl<<“|\t\t\t\t|”<<endl;
}
//cout<<“|”<<endl;
cout<<“\n\n\t\tTHE MINIMUM TRANSPORTATION COST = “<<sum<<” units”;
}
void main()
{
clrscr();
north n;
n.getdata();
n.cal();
getch();
}

/*****************output********************

——————————-
| |
| 2 4 3 | 7
| |
| |
| 1 3 4 | 8
| |
| |
| 3 2 1 | 9
| |
| |
——————————–

8 8 8

THE MINIMUM TRANSPORTATION COST = 46 units

****************************************

Leave a Reply

Your email address will not be published. Required fields are marked *