OR


         PRACTICAL LIST OF OR-2



1)WRITE A PROGRAM   TO IMPLEMENT MINIMIN CREATION.

#include<iostream.h>
#include<conio.h>
#include<math.h>
class pract7
{
int i,j,arr[20][20],r,c,rmin,rmin1[10];
int minimin;
public:
void getdata();
void calculate();
void display();
};
void pract7::getdata()
{
cout<<"enter the number of rows:";
cin>>r;
cout<<"\nenter the number of columns:" ;
cin>>c;
cout<<"\nenter the element of matrix:";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cin>>arr[i][j];
}}
}
void pract7::calculate()
{
for(i=1;i<=r;i++)
{
rmin=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmin>=arr[i][j])
{
rmin=arr[i][j];}
}
rmin1[i]=rmin;
}
cout<<"minimun values form row:";
for(i=1;i<=r;i++)
{
cout<<"\n"<<rmin1[i];
}
for(i=1;i<=r;i++)
{
if(minimin>=rmin1[i])
{
minimin=rmin1[i];}
}
cout<<"\n*** value of minimin is;"<<minimin<<"***";
}
void pract7::display()
{
cout<<"the given matrix is:\n";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}
}
void main()
{
clrscr();
pract7 obj;
obj.getdata();
obj.display();
obj.calculate();
getch();

OUTPUT:

2)  WRITE A  PROGRAM TO FIND IMPLEMENT MAXIMUX CREATION

#include<iostream.h>
#include<conio.h>
#include<math.h>
class pract6
{
int i,j,arr[20][20],r,c,rmax,rmax1[10],max,max1[10];
int maximax;
public:
void getdata();
void calculate();
void display();
};
void pract6::getdata()
{
cout<<"enter the number of row:";
cin>>r;
cout<<"\nenter the number of column:";
cin>>c;
cout<<"\nenter the element of matrix:";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{cin>>arr[i][j] ;
}}
}
void pract6::calculate()
{
for(i=1;i<=r;i++)

{
rmax=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmax<=arr[i][j])
{
rmax=arr[i][j] ;
}
}
rmax1[i]=rmax;
}
cout<<"maximum values from row:";
for(i=1;i<=r;i++)
{
cout<<"\n" <<rmax1[i];
}
maximax=rmax1[i];
for(i=1;i<=r;i++)
{
if(maximax<=rmax1[i])
{
maximax=rmax1[i];
}
}
cout<<"\n* * * value of maximax is:"<<maximax<<"* * *";
}
void pract6::display()
{
cout<<"\n the given matris is:\n";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}
}
void main()
{
clrscr();
pract6  obj;
obj.getdata();
obj.display();
obj.calculate();
getch();
}
OUTPUT:

 

3)WRITE A  PROGRAM TO FIND VALUE OF GAME HAVING NP SADDLE POINT.

#include<iostream.h>
#include<conio.h>
#include<math.h>
class game
{       
int i,j,arr[20][20],rmin,rmin1[10],cmax,cmax1[10],maxmin,minmax;
float a,b,c,d;
float p1,p2,q1,q2,val;
public:
void getdata();
void calculate();
void display();
};
void game::getdata()
{
cout<<"Enter The only 2*2 a Matrix  Element:";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>arr[i][j];
}
}
}
void game::calculate()
{
for(i=0;i<2;i++)
{
rmin=arr[i][j];
for(j=0;j<2;j++)
{
if(rmin>=arr[i][j])
{
rmin=arr[i][j];
}
}
rmin1[i]=rmin;
}
cout<<"Minimum values from row:";
for(i=0;i<2;i++)
{
cout<<"\n"<<rmin1[i];
}
for(i=0;i<2;i++)
{
cmax=arr[1][i];
for(j=0;j<2;j++)
{
if(cmax<=arr[i][j])
{ cmax=arr[j][i];}
}
cmax1[i]=cmax;
}
cout<<"\n Maximum value from coloum:";
for(i=0;i<2;i++)
{
cout<<"\n"<<cmax1[i];}
for(i=0;i<2;i++)
{
maxmin=rmin1[1];
if(maxmin<=rmin1[i])
{ maxmin=rmin1[i];}
}
cout<<"\n value of maxmin is:"<<maxmin;
for(j=0;j<2;j++)
{
minmax=cmax1[1];
if(minmax>=cmax1[j])
{  minmax=cmax1[j];}
}
cout<<"\n value of minmax is:"<<minmax;
if(maxmin==minmax)
cout<<"\n The given problem satisfy saddle point";
else
cout<<"\n The given problem does not satisfy saddle point ";
cout<<"\n\n * * * now we solve game theory problem * * * \n" ;
a=arr[0][0];
b=arr[0][1];
c=arr[1][0];
d=arr[1][1];
cout<<"now here value of A11="<<a;
cout<<"\n \t value ofA12="<<b;
cout<<"\n \t value  ofA21="<<c;
cout<<"\n \t value ofA22="<<d;
p1=((d-c)/((a+d)-(b+c)));
cout<<"\n now \n value of p(1):"<<p1;
p2=(1-p1);
cout<<"\n value of p2:"<<p2;
q1=((d+b)/((a+b)-(b+c)));
cout<<"\v value of q(1):"<<q1;
q2=(1-q1);
cout<<"\v value of q(2):"<<q2;
val=(((a+d)*(b+c))/((a+d)-(b+c)));
cout<<"\n * * * value of game theory problem is:"<<val<<" * * *";
}
void game::display()
{
cout<<"\n The give matrix is:\n";
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{  cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}
}
void main()
{
clrscr();
game obj;
obj.getdata();
obj.display();
obj.calculate();
getch();
}
OUTPUT:
       



4)Write a program to implement  Hurwicz  Creation


#include<iostream.h>
#include<conio.h>
#include<math.h>
class pract8
{
int i,j,arr[20][20],r,c,rmin,rmin1[10],rmax,rmax1[10],small;
float d[10],opt;
public:
void getdata();
void calculate();
void display();
};
void pract8::getdata()
{
cout<<"Enter the no. of rows:";
cin>>r;
cout<<"Enter the no. of columns:";
cin>>c;
cout<<"Enter the element of matrix:";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cin>>arr[i][j];
}}
}
void pract8::calculate()
{
for(i=1;i<=r;i++)
{
rmax=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmax<=arr[i][j])
{
rmax=arr[i][j];
}
}
rmax1[i]=rmax;
}
cout<<"Maximum values from row:";
for(i=1;i<=r;i++)
{
cout<<"\n"<<rmax1[i];
}
for(i=1;i<=r;i++)
{
rmin=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmin>=arr[i][j])
{
rmin=arr[i][j];
}
}
rmin1[i]=rmin;
}
cout<<"\nMinimum values from row:";
for(i=1;i<=r;i++)
{
cout<<"\n"<<rmin1[i];
}
cout<<"\nEnter value for optimistic:";
cin>>opt;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
d[i]=(opt*rmax1[i])+((1-opt)*rmin1[i]);
}
cout<<"\nstrategy="<<d[i];
}
small=0;
small=d[1];
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(small>d[i])
{
small=d[i];
}}
}
cout<<"\n\nValue of Hurwicz="<<small;
}
void pract8::display()
{
cout<<"The given matrix is:\n";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}
}
void main()
{
clrscr();
pract8   obj;
obj.getdata();
obj.display();
obj.calculate();
getch();
}

OUTPUT:


5)Write a program  to implement Expected  Monetory  Value

#include<iostream.h>
#include<conio.h>
#include<math.h>
class pract10
{
int i,j,arr[20][20],r,c,rmin,rmin1[10],rmax,rmax1[10],maximum;
float d[10],opt;
public:
void getdata();
void calculate();
void display();
};
void pract10::getdata()
{
cout<<"Enter the no. of rows:";
cin>>r;
cout<<"Enter the no. of columns:";
cin>>c;
cout<<"Enter the element of matrix:";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cin>>arr[i][j];
}}
}
void pract10::calculate()
{
for(i=1;i<=r;i++)
{
rmax=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmax<=arr[i][j])
{
rmax=arr[i][j];
}
}
rmax1[i]=rmax;
}
cout<<"Maximum values from row:";
for(i=1;i<=r;i++)
{
cout<<"\n"<<rmax1[i];
}
for(i=1;i<=r;i++)
{
rmin=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmin>=arr[i][j])
{
rmin=arr[i][j];
}
}
rmin1[i]=rmin;
}
cout<<"\nMinimum values from row:";
for(i=1;i<=r;i++)
{
cout<<"\n"<<rmin1[i];
}
cout<<"\nEnter value for optimistic:";
cin>>opt;
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
d[i]=(opt*rmax1[i])+((1-opt)*rmin1[i]);
}
cout<<"\nstrategy="<<d[i];
}
maximum=0;
maximum=d[1];
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(maximum<d[i])
{
maximum=d[i];
}}
}
cout<<"\n\nValue of EMV="<<maximum;
cout<<"\nProfit is more in second strategy";
}
void pract10::display()
{
cout<<"\nThe given matrix is:\n";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}
}
void main()
{
clrscr();
pract10   obj;
obj.getdata();
obj.display();
obj.calculate();
getch();
}

OUTPUT:


6)Write a program to find value by Laplace Method

#include<iostream.h>
#include<conio.h>
#include<math.h>
class Laplace
{
int i,j,m,n,max,min,c[10][10],sum[3];
float p[3];
char ch,ch1;
public:
void getdata();
void cal();
};
void Laplace:: getdata()
{
cout<<"Enter the no. of rows:";
cin>>m;
cout<<"Enter the no,of columns:";
cin>>n;
cout<<"Enter value of cost matrix:\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{cin>>c[i][j];
}}
}
void Laplace::cal()
{
for(i=0;i<m;i++)
{
sum[i]=0;
for(j=0;j<n;j++)
{
sum[i]=sum[i]+c[i][j];
}
cout<<"\nSum of row "<<i+1<<"is:"<<sum[i];
p[i]=sum[i]/m;
cout<<"\nProbability of row"<<i+1<<"is:"<<p[i];
}
cout<<"\n----------------------------\n";
cout<<"\nCost Matrix \t\tl\t sum \tl\t prob";
cout<<"\n----------------------------\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<c[i][j]<<"\t";
}
cout<<"l\t"<<sum[i];
cout<<"\tl\t"<<p[i];
cout<<"\n";
}
cout<<"\n-----------------------------\n";
cout<<"Enter 'p' for profit or 'l' for loss:";
cin>>ch;
if(ch=='p')
{
max=p[0];
for(i=0;i<m;i++)
{
if(max<p[i])
{
max=p[i];
}
}
cout<<"Maximum value for profit is:"<<max;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(max==c[i][j])
{
cout<<"\n Alternative A"<<i+1<<" to be chosen";
}}}
}
else if(ch=='l')
{
min=p[0];
for(i=0;i<m;i++)
{
if(min>p[i])
{
min=p[i];
}
}
cout<<"\nMinimum value for Cost is:"<<min;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(min==c[i][j])
{
cout<<"\n Altrenative A"<<i+1<<" to be chosen";
}}}}
}
void main()
{
clrscr();
Laplace  l;
l.getdata();
l.cal();
getch();
}

OUTPUT:


7)Write a program to implement minimax and maximin creation

#include<iostream.h>
#include<conio.h>
#include<math.h>
class pract5
{
int i,j,arr[20][20],r,c,rmax,rmin1[10],rmin,rmax1[10];
int minimax,maximin;
public:
void getdata();
void calculate();
void display();
};
void pract5::getdata()
{
cout<<"\n Enter the no. of rows:";
cin>>r;
cout<<"Enter the no. of columns:";
cin>>c;
cout<<"Enter the elements for matrix:";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{cin>>arr[i][j];
}
}
}
void pract5::calculate()
{
for(i=1;i<=r;i++)
{
rmax=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmax<=arr[i][j])
{rmax=arr[i][j];}
}
rmax1[i]=rmax;
}
cout<<"Maximum values from row:";
for(i=1;i<=r;i++)
{ cout<<"\n"<<rmax1[i];}
for(i=1;i<=r;i++)
{
minimax=rmax1[1];
if(minimax>=rmax1[i])
{
minimax=rmax1[i];
}
}
cout<<"\nValue of Minimax is:"<<minimax;
cout<<"\n----****----****----";
for(i=1;i<=r;i++)
{
rmin=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmin >= arr[i][j])
{
rmin=arr[i][j];
}
}
rmin1[i]=rmin;
}
cout<<"\nMinimum values form row:";
for(i=1;i<=r;i++)
{cout<<"\n"<<rmin1[i];}
for(i=1;i<=r;i++)
{
maximin=rmin1[1];
if(maximin<=rmin1[i])
{
maximin=rmin1[i];
}
}
cout<<"\nValue of Maximin is:"<<maximin;
}
void pract5::display()
{
cout<<"\nThe given matrix is:\n";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}}
void main()
{
clrscr();
pract5  obj;
obj.getdata();
obj.display();
obj.calculate();
getch();
}


OUTPUT:


8)Write a program to implement savage criteria

#include<iostream.h>
#include<conio.h>
#include<math.h>
class pract9
{
int i,j,arr[20][20],r,c,rmax,rmax1[10],sav[20][20];
int maxsav[10],savmin,smax;
public:
void getdata();
void calculate();
void display();
};
void pract9::getdata()
{
cout<<"Enter the no. of rows:";
cin>>r;
cout<<"Enter the no. of columns:";
cin>>c;
cout<<"Enter the elements of matrix:";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cin>>arr[i][j];
}}
}
void pract9::calculate()
{
for(i=1;i<=r;i++)
{
rmax=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmax<=arr[i][j])
{  rmax=arr[i][j];
}}
rmax1[i]=rmax;
}
cout<<"\nMaximum values form each row:";
for(i=1;i<=r;i++)
{
cout<<"\n"<<rmax1[i];
}
cout<<"\nValue of reduce matrix:\n";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
sav[i][j]=((rmax1[i])-arr[i][j]);
cout<<sav[i][j];
cout<<"\t";
}
cout<<"\n";
}
for(i=1;i<=r;i++)
{
smax=sav[i][1];
for(j=1;j<=c;j++)
{
if(smax<=sav[i][j])
{
smax=sav[i][j];
}}
maxsav[i]=smax;
}
cout<<"Maximum values form each row:";
for(i=1;i<=r;i++)
{
cout<<"\n"<<maxsav[i];
}
for(j=1;j<=r;j++)
{
savmin=maxsav[1];
if(savmin>=maxsav[j])
{ savmin=maxsav[j];
}}
cout<<"\nValue of Savage is:"<<savmin;
}
void pract9::display()
{
cout<<"The given matrix is:\n";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}
}
void main()
{
clrscr();
pract9  obj;
obj.getdata();
obj.display();
obj.calculate();
getch();
}
OUTPUT:



9)Write a program to find game without Saddle Point

#include<iostream.h>
#include<conio.h>
class sad
{
int i,j,arr[20][20],r,c,rmin,rmin1[10],cmax,cmax1[10],maxmin,minmax;
public:
void getdata();
void calculate();
void display();
};
void sad:: getdata()
{
cout<<"Enter the no. of rows:";
cin>>r;
cout<<"Enter the no. of columns:";
cin>>c;
cout<<"Enter the element foe matrix:";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cin>>arr[i][j];
}
}}
void sad::calculate()
{
for(i=1;i<=r;i++)
{
rmin=arr[i][1];
for(j=1;j<=c;j++)
{
if(rmin>=arr[i][j])
{
rmin=arr[i][j];
}
}
rmin1[i]=rmin;
}
cout<<"\nMinimum values from row:";
for(i=1;i<=r;i++)
{ cout<<"\n"<<rmin1[i];
}
for(i=1;i<=c;i++)
{
cmax=arr[1][i];
for(j=1;j<=r;j++)
{
if(cmax<=arr[i][j])
{ cmax=arr[j][i];
}
}
cmax1[i]=cmax;
}
cout<<"\nMaximum values from column:";
for(i=1;i<=c;i++)
{ cout<<"\n"<<cmax1[i];
}
for(i=1;i<=r;i++)
{
maxmin=rmin1[1];
if(maxmin<=rmin1[i])
{
maxmin=rmin1[i];
}
}
cout<<"\nValue of Maxmin is:"<<maxmin;
for(j=1;j<=c;j++)
{
minmax=cmax1[1];
if(minmax>=cmax1[j])
{
minmax=cmax1[j];
}}
cout<<"\nValue of Minmax is:"<<minmax;
if(maxmin==minmax)
cout<<"\nThe given problem satisfy Saddle Point";
else
cout<<"\nThe given problem does not satisfy Saddle Point";
}
void sad::display()
{
cout<<"The given matrix is:\n";
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
cout<<"\t"<<arr[i][j];
}
cout<<"\n";
}}
void main()
{
clrscr();
sad    obj;
obj.getdata();
obj.display();
obj.calculate();
getch();
}
OUTPUT:


10)Write a program 1to solve game theory for 2 by 2 pay off  matrix

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<string.h>
class game
{
public:
int max(int a,int b);
int min(int a,int b);
void calculate();
};
int game::max(int a,int b)
{
if(a>=b)
return a;
else
return b;
}
int game::min(int a,int b)
{
if(a<=b)
return a;
else
return b;
}
void game::calculate()
{
int i,j,rows=2,cols=2,p[2][2],c1,c2,r1,r2,sp=0,flag=0;
int a,b,c,d;
float tv,p1,p2,q1,q2;
cout<<"\n***Program to Solve Game Theroy for 2 by 2 Payoff Matrix***";
cout<<"\n\nEnter Values for Rows and Columns of Payoff Matrix:\n";
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
cout<<"\nRow -"<<(i+1)<<"Column -"<<(j+1)<<":";
cin>>p[i][j];
}
}
a=p[0][0];
b=p[0][1];
c=p[1][0];
d=p[1][1];
c1=max(a,c);
c2=max(b,d);
r1=min(a,b);
r2=min(c,d);
if(c1==r1)
{ sp=a;
flag=1;
}
if(c1==r2)
{
sp=c;
flag=1;
}
if(c2==r1)
{
sp=b;
flag=1;
}
if(c2==r2)
{
sp=d;
flag=1;
}
if(flag==1)
{
cout<<"\nProblem is of Pure Strategy!\nValue="<<sp;
}
else
{
cout<<"\n\nProblem is of Mixed Strategy!";
p1=((abs(c-d))*1.0/(abs(a-b)+abs(c-d)));
p2=((abs(a-b))*1.0/(abs(a-b)+abs(c-d)));
q1=((abs(b-d))*1.0/(abs(b-d)+abs(a-c)));
q2=((abs(a-c))*1.0/(abs(b-d)+abs(a-c)));
if(p1>=p2)
cout<<"\n\nPlayer A will use Strategy P1";
else
cout<<"\n\nPlayer A will use Strategy P2";
if(q1<=q2)
cout<<"\n\nPlayer B will use Strategy Q1";
else
cout<<"\n\nPlayer B will use Strategy Q2";
tv=float((a*1.0*(abs(c-d))+c*(abs(a-b)))/(abs(a-b)+abs(c-d)));
cout<<"\n\nValue="<<tv;
}
cout<<"\n\nPress Any Key to Exit...";
}
void main()
{
clrscr();
game   ga;
ga.calculate();
getch();
}


OUTPUT:

























Comments