least cost /matrix minima method

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

//program for least cost or matrix minima method

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class LeastCost
{
private:
int B[100],C[100],i,j,m,n,sum1,sum2,S,p,q,s,t,min,min1;
long int A[100][100];
public:
void getdata(void);
void display(void);
void calculate(void);
};
void LeastCost::getdata(void)
{
cout<<“\n\n Enter the size of cost matrix… “;
cout<<“\n\n Number of row’s : “;
cin>>m;
cout<<“\n\n Number of col’s : ” ;
cin>>n;
cout<<“\n\n Enter the element of the matrix…”;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<“\n\n Enter the element of row “<<i+1<<” : “;
cin>>A[i][j];
}
}
for(i=0;i<n;i++)
{
cout<<“\n\n Enter the supply cost of row “<<i+1<<” : “;
cin>>B[i];
}
for(j=0;j<n;j++)
{
cout<<“\n\n Enter the demand of colomn “<<j+1<<” : “;
cin>>C[j];
}
}

void LeastCost :: display(void)
{
cout<<“\n\n The entered matrix is…\n\t\t\t\t\t SUPPLY\n”;
cout<<“\t\t\t———————\n”;
for(i=0;i<m;i++)
{
cout<<“\t\t”;
for(j=0;j<n;j++)
{
cout<<“\t”;
cout<<setw(2)<<A[i][j];
cout<<” |”;
if(j==2)
{
cout<<” “<<B[i];
}
}
cout<<“\n\t\t\t———————\n”;
}
cout<<“\n\t\t DEMAND”;
for(j=0;j<n;j++)
{
cout<<“\t”<<C[j];
}
}
void LeastCost::calculate(void)
{
sum1=0;
sum2=0;
S=0;
char ch;

for(i=0;i<m;i++)
{
sum1 = sum1+B[i];
}

for(j=0;j<n;j++)
{
sum2 = sum2+C[j];
}

cout<<“\n\n SUPPLY = “<<sum1;
cout<<“\n\n DEMAND = “<<sum2;

if(sum1 != sum2)
{
cout<<“\n\n The SUPPLY != DEMAND \n\n So, Problem is Unbalence. “;
}
else
{
int count=0,min1=0;
while(count<m*n)
{
min = 100;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(A[i][j]<=min && A[i][j]>min1)
min = A[i][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(A[i][j] == min && B[i] != 0 && C[j] != 0)
{
if(C[j] >= B[i])
{
S = S + (A[i][j] * B[i]);
C[j] = C[j] – B[i];
B[i] = 0;
}
else if(C[j] <= B[i])
{
S = S + (A[i][j] * C[j]);
B[i] = B[i] – C[j];
C[j] = 0;
}
}
}
}
min1 = min;
count++;
}
}
cout<<“\n\n\t Total Transportation Cost is : “<<S<<” Unit.”;
}
}
void main()
{
clrscr();
LeastCost ls;
ls.getdata();
clrscr();
ls.display();
ls.calculate();
getch();
}

output :

Enter the size of cost matrix…

Number of row’s : 3
Number of col’s : 3

Enter the element of the matrix…

Enter the element of row 1 : 10
Enter the element of row 1 : 7
Enter the element of row 1 : 15
Enter the element of row 2 : 3
Enter the element of row 2 : 6
Enter the element of row 2 : 12
Enter the element of row 3 : 9
Enter the element of row 3 : 0
Enter the element of row 3 : 10

Enter the supply cost of row 1 : 50
Enter the supply cost of row 2 : 80
Enter the supply cost of row 3 : 80
Enter the demand of colomn 1 : 60
Enter the demand of colomn 2 : 70
Enter the demand of colomn 3 : 80

The entered matrix is…
SUPPLY
——————-
10 | 7 | 15 | 50
——————-
3 | 6 | 12 | 80
——————-
9 | 0 | 10 | 80
——————-

DEMAND 60 70 80

SUPPLY = 210
DEMAND = 210

Total Transportation Cost is : 1150 Unit.

5 thoughts on “least cost /matrix minima method

  1. i am a maths student .i am studied in m.sc. maths .the last sem. project. T.P. problem pls help me in row minima method in c++ program. pls return the row minima method in c++ in my mail.(barathiriya@yahoo.in)give me a two days.thank U.

  2. I am a II B.Sc(Computer Science) Student at RKM Vivekananda College in Chennai, Tamilnadu, India
    Your C++ Program very helpful for me
    To create a C program to solve Transportation problem using Least cost Entry Method
    Thank and Like

Leave a Reply

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