Monday, September 23, 2013

SIMULATION OF SINGLE SERVER QUEUE -( WITH NUMBER OF LOOPS OPTIMIZED )

Note:  All the computations (i.e. computation of Cumulative Arrival Time,Cumulative Departure Time, Queue Length, Idle Time and Waiting Time) have been carried out using a single loop

Abbreviations used:

at: Arrival Time,  st: Service Time, cat: Cumulative Arrival Time, cdt: Cumulative Departure Time, ql: Queue Length, idt: Idle Time, wt: Waiting Time.

Assumptions:  Time gap  between he arrival of any two consecutive customers (at) is  between 5 to 30   minutes

Service Time is from 5 to 35 minutes

Simulation has been done for 20 customers
------------------------------------------------------------------------------------------------------------

#include < stdio.h >
#include < conio.h >
#include < math.h >
#include < stdlib.h >
void main()
 {
     clrscr();
     int at[20],st[20],cat[20],cdt[20],ql[20],idt[20],wt[20];
     int i,j,k;
     cat[0]=0,wt[0]=0,idt[0]=0;
     randomize();
     for(k=0;k<=19;k++)
       {
         at[k]=(5+rand()%25);
         st[k]=(5+rand()%30);
         ql[k]=0;
       }
      at[0]=0;
      cdt[0]=st[0];
      for(j=1;j<=19;j++)
      {
         cat[j]=cat[j-1]+at[j];
         if(cat[j]<=cdt[j-1])
            cdt[j]=cdt[j-1]+st[j];
        else
           cdt[j]=cat[j]+st[j];
        k=j-1;
         while(cdt[k] > cat[j] && k>=0)
          {
            ql[j]=ql[j]+1;
             k=k-1;
           }
         if(cat[j]<=cdt[j-1])
          {
            wt[j]=cdt[j-1]-cat[j];
            idt[j]=0;
          }
        else
          {
             idt[j]=cat[j]-cdt[j-1];
             wt[j]=0;
           }
          }

     printf(" AT    ST    CAT    CDT     QL    IDT    WT \n\n\n");
     for(k=0;k<=19;k++)

       {
        printf("%3d   %3d    %3d    %3d    %3d    %3d   %3d",at[k],st[k],cat[k],cdt[k],ql[k],idt[k],wt[k]);
         printf("\n\n");
        }
     getch();
      }

No comments: