#include #include #include #include #define NUM 1000 #define MAXIDOL 3600; #define MAXSERVT 1800; /* MAXIDOL/2 = expectation of interarrival time MAXSERVT/2 = expectation of serving time t=time of arrival of the ith customer(t0=0) A=interarrival time S=time that server actually spends serving ith customer D=delay in queue of ith customer c=t+D+S=time that ith customer completes service and departs e=time of occurrence of ith event of any type */ int main() { int S[NUM],t[NUM]; t[0]=rand()%MAXSERVT; int A[NUM],D[NUM],c[NUM],e[NUM],i,j,stop,stoptime; float tsum,dtave; /*make random variable*/ srand((unsigned) time(NULL)); S[0]=rand()%MAXSERVT; for(i=1;i=60*60*9){ stop=i-1; stoptime=t[i-1]; i=NUM; } } for(i=0;i<=stop;i++){ printf("t[%2d] %2d:%2d:%2d \n",i,t[i]/(60*60), (t[i]%(60*60))/60,t[i]%60); } A[0]=0; D[0]=0; c[0]=0; e[0]=0; for(i=1;i<=stop;i++){ c[i-1]=t[i-1]+S[i-1]+D[i-1]; if(c[i-1]>t[i]) D[i]=c[i-1]-t[i]; else D[i]=0; } for(i=0;i<=stop;i++){ printf("D[%2d] %2d:%2d:%2d \n",i,D[i]/(60*60), (D[i]%(60*60))/60,D[i]%60); } printf("n=%d stoptime=%2d:%2d:%2d\n",stop+1,stoptime/3600,(stoptime%3600)/60, stoptime%60); for(i=0;i<=stop;i++){ tsum=tsum+D[i]; } dtave=tsum/(stop+1); printf("average=%2d:%2d:%2d\n",(int)dtave/3600,((int)dtave%3600)/60, ((int)dtave%60)); int Dnum[stop]; for(i=0;i=0){ if((c[i-j]-t[i])>0) Dnum[j]=Dnum[j]+1; else Dnum[j]=Dnum[j]+0; } } } for(i=1;Dnum[i]!=0;i++){ printf("queue %d = %d\n",i,Dnum[i]); } }