Image

Programs - C++ - Operation Research

Program:


#include<iostream.h>
#include<conio.h>
#include<string.h>
class savag
{

private:
int sava;
public:
void calculate();
long savage(long d[10][10],int rows,int cols);
};

void savag::calculate()
{
  // rows - No. of Events of Decision Matrix
// cols - No. of Alternatives of Decision Matrix

int i,j,k,rows,cols;
long d[10][10],smimx=0;

cout<<"\n* * * Program to Take Decision on the Basis of * * *";
cout<<"\n* * *       Savage Criterion       * * *";
cout<<"\nEnter the Number of Rows (Events) of Decision Matrix( <10 ): ";
cin>>rows;
cout<<"\nEnter the Number of Columns (Alternatives) of Decision Matrix( <10 ): ";
cin>>cols;

// Input Values for Rows and Columns of Decision Matrix

cout<<"Enter Values for Rows and Columns of Decision Matrix: \n";
for(i=0;i<rows;i++)
 {
  for(j=0;j<cols;j++)
  {
   cout<<"Row- "<<(i+1)<<" Column- "<<(j+1)<<" : ";
   cin>>d[i][j];
  }
 }

cout<<"\nThe Original Decision Matrix is:";
cout<<endl;
for(i=0;i<rows;i++)
 {
  for(j=0;j<cols;j++)
  {
   cout<<"\t";
    if(d[i][j]<0)
     cout<<"\b";
   cout<<d[i][j];
  }
  cout<<endl;
 }

cout<<"\nPress Any Key To Continue...";
 getch();

 smimx=savage(d,rows,cols);

cout<<"\n\nMinimax Value By Savage Criterion= "<<smimx;
cout<<"\nMinimax Value Corresponds to Alternative: "<<sava;
cout<<"\n\nPress Any Key to Exit...";
}

long savag::savage(long d[10][10],int rows,int cols)
{
int i,j;
long *mxpo,*ma,m=0;

// mxpo -- Array containing max pay-off of each event

 mxpo=new long[rows];
 ma=new long[cols];

// Find Max Pay-off for each event

for(i=0;i<rows;i++)
 {
  m=d[i][0];
  for(j=0;j<cols;j++)
  {
   if(d[i][j]>m)
   {
    m=d[i][j];
   }
  }
  mxpo[i]=m;
 }

// Form New Matrix by substracting each element
// from Max Pay-off of corresponding event

for(i=0;i<rows;i++)
 {
  for(j=0;j<cols;j++)
  {
   d[i][j]=mxpo[i]-d[i][j];
  }
 }


// Find Maximum Pay-off for each Alternative

for(i=0;i<cols;i++)
 {
  m=d[0][i];
  for(j=0;j<rows;j++)
  {
   if(d[j][i]>m)
   {
    m=d[j][i];
   }
  }
  ma[i]=m;
 }

 m=ma[0];
for(i=0;i<cols;i++)
 {
  if(ma[i]<=m)
  {
   m=ma[i];
   sava=i+1;
  }
 }
 return(m);
}

void main()
{
 clrscr();
savag sa;
sa.calculate();
 getch();
}
/*Output:

* * * Program to Take Decision on the Basis of * * *
* * *           Savage Criterion          * * *
Enter the Number of Rows (Events) of Decision Matrix( <10 ): 4

Enter the Number of Columns (Alternatives) of Decision Matrix( <10 ): 3
Enter Values for Rows and Columns of Decision Matrix:
Row- 1 Column- 1 : 50000
Row- 1 Column- 2 : 70000
Row- 1 Column- 3 : 80000
Row- 2 Column- 1 : 25000
Row- 2 Column- 2 : 30000
Row- 2 Column- 3 : 15000
Row- 3 Column- 1 : -25000
Row- 3 Column- 2 : -40000
Row- 3 Column- 3 : -1000
Row- 4 Column- 1 : -45000
Row- 4 Column- 2 : -80000
Row- 4 Column- 3 : -10000

The Original Decision Matrix is:
    50000  70000  30000
    25000  30000  15000
    -25000 -40000 -1000
    -45000 -80000 -10000

Press Any Key To Continue...

Minimax Value By Savage Criterion= 35000
Minimax Value Corresponds to Alternative: 1

Press Any Key to Exit...
*/