Sie sind auf Seite 1von 3

Roll No.

: 101
Practical 12 : Program to implement Regret or Savage criterion.
#include<iostream.h>
#include<conio.h>
class Regret
{
private :
int r,c;
long int ns[20][20],maxn[20],maxs[20],payoff;
public :
void showdata();
private :
void getdata();
void calculate();
void showmat();
};
void Regret :: getdata()
{
cout<<"\nEnter the no. of states of nature : ";
cin>>r;
cout<<"\nEnter the no. of alternatives : ";
cin>>c;
cout<<"\nEnter "<<r*c<<" values :";
for (int i=1;i<=r;i++)
{
for (int j=1;j<=c;j++)
{
cin>>ns[i][j];
}
}
}
void Regret :: showmat()
{
for (int i=1;i<=r;i++)
{
for (int j=1;j<=c;j++)
{
cout<<ns[i][j]<<"\t";
}
cout<<"\n";
}
}

void Regret :: calculate()


{
getdata();
cout<<"\nThe Payoff Matrix : \n";
showmat();
int i,j;
long int max;
for (i=1;i<=r;i++)
{
max = ns[i][1];
for (j=1;j<=c;j++)
{
if (max < ns[i][j])
{
max = ns[i][j];
}
maxn[i] = max;
}
}
for (i=1;i<=r;i++)
{
for (j=1;j<=c;j++)
{
ns[i][j] = maxn[i] - ns[i][j];
}
}
cout<<"\nOpportunity Loss Matrix : \n";
showmat();
for (i=1;i<=c;i++)
{
max = ns[1][i];
for (j=1;j<=r;j++)
{
if (max < ns[j][i])
{
max = ns[j][i];
}
maxs[i] = max;
}
}
long int min = maxs[1];
for (i=1;i<=c;i++)
{
if (min > maxs[i])
{

min = maxs[i];
}
}
payoff = min;
}
void Regret :: showdata()
{
calculate();
cout<<"\nPayoff = "<<payoff;
}
void main()
{
clrscr();
Regret R;
R.showdata();
getch();
}
Output :
Enter the no. of states of nature : 3
Enter the no. of alternatives : 3
Enter 9 values :700000 500000 300000 300000 450000 300000 150000 0 300000
The Payoff Matrix :
700000 500000 300000
300000 450000 300000
150000 0
300000
Opportunity Loss Matrix :
0
200000 400000
150000 0
150000
150000 300000 0
Payoff = 150000

Das könnte Ihnen auch gefallen