Pages

Source Code Untuk Menghitung Waktu Antrian Dengan Turbo C++

Sourcode di bawah ini menjelaskan tentang antrian dari waktu datang hingga selesai.
  • Arrival Time
  • Inter Arriveal Time
  • Service Begin / Start
  • Service End
  • Service Time
  • Waiting Time In Queue
  • Time Spent In System
  • Server Idle
jika ingin dikembangkan, saya persilahkan... :)


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include<conio.h>
#include<stdio.h>

void main()
{
 int arrivalTime[20];
 int serviceStart[20];
 int serviceEnd[20];
 int interArrivalTime[20];
 int serviceTime[20];
 int waitingTimeInQueue[20];
 int timeSpentInSystem[20];
 int serverIdle[20];
 char tambah;
 int costumer=1;

 do
 {
  clrscr();
  printf("No Costumer   : %d",costumer);
  arrivalTime[0]=0;

  do
  {
     printf("\nArrival Time  : ");
     scanf("%d",&arrivalTime[costumer]);
  }while(arrivalTime[costumer]<arrivalTime[costumer-1]);

  serviceEnd[0]=0;

  do
  {
     printf("service start : ");
     scanf("%d",&serviceStart[costumer]);
  }while(arrivalTime[costumer] >= serviceStart[costumer] || serviceStart[costumer] <[costumer-1]);
   
  do
  {
     printf("service End   : ");
     scanf("%d",&serviceEnd[costumer]);
  }while(serviceStart[costumer] >= serviceEnd[costumer]);
   
  arrivalTime[0]=0;
  interArrivalTime[costumer]= arrivalTime[costumer]-arrivalTime[costumer-1];
  serviceTime[costumer]=serviceEnd[costumer] - serviceStart[costumer];
  waitingTimeInQueue[costumer]= serviceStart[costumer] - interArrivalTime[costumer];
  timeSpentInSystem[costumer]= waitingTimeInQueue[costumer] + serviceTime[costumer];
   
  if(costumer==1)
   serviceEnd[0]=0;

  serverIdle[costumer]=serviceStart[costumer]-serviceEnd[costumer-1];
  
  printf("Masukkan Costumer ? Y/T");

  tambah=getch();
  costumer++;
 
 }while(tambah=='Y'||tambah=='y');
  
  clrscr();

 int i=0;
 int y=6;

 printf(" _____________________________________________________________________________\n");
 printf("|    |  time   |Interarrival|   Service   |Service |Waiting |  Time  | server |\n");
 printf("| No | Arrival |    Time    |-------------|  Time  |  Time  |Spent In|  idle  |\n");
 printf("|    |         |            | Start | End |        |In Queue| System |        |\n");
 printf("|----|---------|------------|-------|-----|--------|--------|--------|--------|\n");

 for(i=1;i<costumer;i++)
 {
  gotoxy(1,y); printf("| %d",i);
  gotoxy(6,y); printf("|%8d",arrivalTime[i]);
  gotoxy(16,y);printf("|%11d",interArrivalTime[i]);
  gotoxy(29,y);printf("|%6d",serviceStart[i]);
  gotoxy(37,y);printf("|%4d",serviceEnd[i]);
  gotoxy(43,y);printf("|%7d",serviceTime[i]);
  gotoxy(52,y);printf("|%7d",waitingTimeInQueue[i]);
  gotoxy(61,y);printf("|%7d",timeSpentInSystem[i]);
  gotoxy(70,y);printf("|%7d |",serverIdle[i]);
  y++;
 }

 printf(" |----------------------------------------------------------------------------\n");        

 //***********************************************************

  int n=costumer-1; //total jumlah pelanggan
  
  gotoxy(1,y+1);printf("|%2d",n);
  
  int total_si=0;//total service time
  
  for(int si=1;si<=n;si++)
  {
  total_si=total_si+serviceTime[si];
  }
  
  gotoxy(43,y+1);printf("|%7d",total_si);
  
  printf("\n|-----------------------------------------------------------------------------\n");
  
  int total_wi=0;  //total waiting time in queue

  for(int wi=1;wi<=n;wi++)
  {
  total_wi=total_wi+waitingTimeInQueue[wi];
  }

  gotoxy(52,y+1);printf("|%7d",total_wi);   //waiting time spent in system
   
  int total_siwi=0;
  
  for(int siwi=1;siwi<=n;siwi++)
  {
  total_siwi=total_siwi+timeSpentInSystem[siwi];
  }

  gotoxy(61,y+1);printf("|%7d",total_siwi);

 //*****************************************************
  
  int taksen=interArrivalTime[costumer-1];
  float averageRate= n/float(taksen);
 //    printf("\n\n\nAverage Rate(lambda)");
  printf("\n\n\nN/T' = %d/%d = %.2f",n,taksen,averageRate);
  
  float averageInterArrivalTime=1/float(averageRate);
 //    printf("\nAverage Inter Arrival Time = ");
  printf("\n1/lambda = 1/%.2f",averageInterArrivalTime);
  
  float averageServiceRate=n/float(total_si);
 //    printf("\nAverage Servic3e Rate(miu) =");
  printf("\nN/total si = %d/%d = %.2f", n, total_si,averageServiceRate);
  
  float averageServiceTime=n/float(total_si);
 //    printf("\nAverage Service Time=");
  printf("\nN/Total si = %d/%d = %.2f",n,total_si,averageServiceTime);
  
  float utilazationOfServer=averageRate/float(averageServiceRate);
 //printf("\nUtilization Of Server(rho)= ");
  printf("\nlambda/miu = %.2f/%.2f = %.2f",averageRate,averageServiceRate,utilazationOfServer);
  
  float averageWaitingTimeInQueue=total_wi/float(n);
 //    printf("\nAverage Waiting Time In Queue = ");
  printf("\nN/Total si = %d/%d = %.2f",total_wi,n,averageWaitingTimeInQueue);
  
  float averageTimeSpentInSystem = total_siwi/float(n);
 //    printf("\nAverage Time Spent In System = ");
  printf("\nN/Total si = %d/%d = %.2f",total_siwi,n,averageTimeSpentInSystem);
  
  float averageNumberCostumerInQueue = utilazationOfServer/float(1-utilazationOfServer);
 //    printf("\nAverage Number Costumer In Queue =");
  printf("\nrho/(1-rho) = %.2f/(1-%.2f) = %.2f",utilazationOfServer,utilazationOfServer,averageNumberCostumerInQueue);

  getch();
}


Jhohannes H Purba Coding Sederhana April 13, 2010

No comments:

Post a Comment