Tuesday, October 25, 2011

Coding for M/M/1 server




#include
#include
void main()
{
int i,a,d,arrival[11],clock=0,inter[]={2,3,1,4,1,6,1,1,5,2,1},service[]= {2,5,4,3,3,5,6,6,6,3,2};
int wait[11],q=0,sum=0,avg,server;
arrival[0]=clock+inter[0];
d=clock+service[0];
server=1;
a=arrival[0];
wait[0]=0;
for(i=0;i<11;i++){arrival[i]=arrival[i-1]+inter[i];}printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[0]) ;i=1;while(clock<30){if(ad)
{wait[i]=0;
printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[1]) ;
i++;
}
else
if(da)
{
wait[i]=d-a;
}
printf("\nclock = %d (A,%d) (D,%d) (w,%d)",clock,a,d,wait[i]);
}
else
{
wait[i]=0;
printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[i]) ;
server=0;
}
}
else
{
clock=0;
a=arrival[i];
d=clock+service[i-q];
if(a{
wait[i]=d-a;
}
else
{
wait[i]=0;
i++;
printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[i]) ;
}
}
else
{
clock=0;
a=arrival[i];
d=clock+service[i];
wait[i]=d-a;
i++;
printf("clock=%d (A=%d)(D=%d)(W=%d)",clock,a,d,wait[i]) ;
for(i=0;i<11;i++)
{
sum+=wait[i];
}
avg=sum/11;
if (avg<1)
printf("efficient system");
else
printf("inefficient system");
getch();
}



neha bahadur
mca455309

No comments:

Post a Comment