/**********************************************************************/ /* */ /* mm1_bmeans.c */ /* */ /* M/M/1 queue simulation model calling bmeans.c functions */ /* to get the average delay per customer measure to within 10% */ /* accuracy with 95% confidence level */ /* */ /**********************************************************************/ #include "smpl.h" #define TOKENS 1000 #define TRUE 1 #define FALSE 0 int main() { real Ta=200.0,Ts=100.0,mean,hw; int tk_id=0,customer=0,event,server,nb; real ts[TOKENS]; /* start time stamp */ int cont=TRUE; smpl(0,"M/M/1 Queue"); init_bm(200,2000); /* let m0 be 200 and mb be 2000 observations */ server=facility("server",1); schedule(1,0.0,tk_id); while (cont) { cause(&event,&customer); switch(event) { case 1: /* arrival */ ts[customer] = time(); schedule(2,0.0,customer); if (++tk_id >= TOKENS) tk_id=0; schedule(1,expntl(Ta),tk_id); break; case 2: /* request server */ if (request(server,customer,0)==0) then schedule(3,expntl(Ts),customer); break; case 3: /* release server */ release(server,customer); if (obs(time()-ts[customer]) == 1) cont = FALSE; break; } } civals(&mean, &hw, &nb); printf("Mean is %f and half width is %f after %d batches\n", mean, hw, nb); return 0; }