#include<iostream.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
#define seed 12345
void main()
{
clrscr();
int i,j,k,kk,run,counter;
int n=6,m= 5,s=4;
float se[10];
float r,iat,st,nat,wt,cwt;
float p[]={0.0,0.05,0.4,0.65,0.8,0.9,0.97,1.0};
float at[]={0,0.5,1,1.5,2,2.5,3};
float f[]={0,0.05,0.3,0.65,0.85,1.0};
float t[]={1,2,3,4,5};
cout<<"Enter the value of run:";
cin>>run;
for(j=0;j<=s;++j)
{
srand(seed);
counter=0;
nat=0;
cwt=0;
for(i=1;i<=j;++i)
{
se[i]=0;
}
cwt=0;
counter=0;
for(counter=1;counter<=run;++counter)
{
r=rand()/32768.0;
for(i=0;i<=n;++i)
{
if(r>p[i] && r<=p[i+1])
iat=at[i];
}
r=rand()/32768.0;
for(i=0;i<=m;++i)
{
if(r>f[i] && r<=f[i+1])
st=t[i];
}
nat=nat+iat;
float min=99.9;
for(i=1;i<=j;++i)
{
if(se[i]<=min)
{
min=se[i];
k=i;
}
}
if(nat<=min )
{
se[k]=min+st;
wt=min-nat;
}
else
se[k]=nat+st;
cwt=cwt+wt;
}
cout<<"server\t Total arrival\t Average waiting time "<<"\n";
cout<
if((cwt/run)<=2)
break;
}
getch();
}
/* OUTPUT
Enter the value of run:30
server Total arrival Average waiting time
0 31 80.583336
server Total arrival Average waiting time
1 31 30.213335
server Total arrival Average waiting time
2 31 8.183333
server Total arrival Average waiting time
3 31 1.866667
*/
No comments:
Post a Comment