program for Hurwicz criteria

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

//program for Hurwicz criteria
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class hurwicz
{
private :
int A[100][100],i,j,m,n,r,r1;
int small,L[100],large,s[100],h[100];
public :
void getdata(void);
void disp(void);
};
void hurwicz :: getdata(void)
{
cout<<“\n\n\t Enter the size of Matrix… “;
cout<<“\n\n\t Number of row’s : “;
cin>>m;
cout<<“\n\n\t Number of col’s : “;
cin>>n;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<“\n\n\t Enter the value for row “<<i+1<<” : “;
cin>>A[i][j];
}
}
}

void hurwicz :: disp(void)
{
int min=0,max=0;
float alpha=0.5;
large = 0;
small = 9999;
for(i=0;i<m;i++)
{
large = 0;
small = 9999;
for(j=0;j<n;j++)
{
if(large>=A[i][j])
{
large = large;
L[i] = large;
}
else
{
large = A[i][j];
L[i] = large;
}
if(small<=A[i][j])
{
small = small;
s[i] = small;
}
else
{
small = A[i][j];
s[i] = small;
}
}
}

for(i=0;i<m;i++)
{
h[i] = (float(alpha)*L[i])+(float(1-alpha)*s[i]);
}

min = h[0];
max = h[0];
for(i=0;i<m;i++)
{
if(min<=h[i])
min = min;
else
min = h[i];
if(max>=h[i])
max = max;
else
max = h[i];
}

for(i=0;i<m;i++)
{
if(h[i] == min)
r = i+1;
}

for(i=0;i<m;i++)
{
if(h[i] == max)
r1 = i+1;
}

cout<<“\n\n\t Your entered matrix is :\t\t Maximum Minimum”;
cout<<” hurwicz”;
cout<<“\n\n\t\t\t”;
for(i=0;i<m;i++)
{
cout<<” A”<<i+1<<” –>”;
for(j=0;j<n;j++)
{
cout<<” “<<setw(4)<<A[i][j];
}
cout<<” “<<setw(4)<<L[i]<<” “<<setw(4)<<s[i];
cout<<” “<<setw(4)<<h[i];
cout<<“\n\n\t\t\t”;
}

cout<<“\n\n\t Maximum is “<<max;
cout<<“\n\n\t So, for profit the answer is : A”<<r1<<” Alternatives.”;
cout<<“\n\n\n\n\t And Minimum is “<<min;
cout<<“\n\n\t So, for cost the answer is : A”<<r<<” Alternatives.”;
}

void main()
{
clrscr();
hurwicz h;
h.getdata();
clrscr();
h.disp();
getch();
}

output :

Enter the size of Matrix…

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

Enter the value for row 1 : 8000
Enter the value for row 1 : 3500
Enter the value for row 1 : 5000

Enter the value for row 2 : 4500
Enter the value for row 2 : 4500
Enter the value for row 2 : 5000

Enter the value for row 3 : 2000
Enter the value for row 3 : 5000
Enter the value for row 3 : 4000

Your entered matrix is :
Maximum Minimum hurwicz

A1 –> 8000 3500 5000 8000 3500 5750

A2 –> 4500 4500 5000 5000 4500 4750

A3 –> 2000 5000 4000 5000 2000 3500

Maximum is 5750

So, for profit the answer is : A1 Alternatives.

And Minimum is 3500

So, for cost the answer is : A3 Alternatives.

Leave a Reply

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