-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
567 lines (503 loc) · 25.8 KB
/
main.cpp
File metadata and controls
567 lines (503 loc) · 25.8 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
#include <iostream>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <iterator>
#include <vector>
#include <queue>
#include <ctime>
#include "Order.h"
#include "Cashier.h"
#include "Barista.h"
using namespace std;
struct sortByOrderDoneTime
{
inline bool operator() (const Order* struct1, const Order* struct2)
{
return ((*(struct1)).orderDoneTime < (*(struct2)).orderDoneTime);
}
};
template <class Container>
void split1(const string& str, Container& cont)
{
istringstream iss(str);
copy(istream_iterator<string>(iss),
istream_iterator<string>(),
back_inserter(cont));
}
int main(int argc, char* argv[]) {
std::clock_t start;
double duration;
start = std::clock();
// below reads the input file
// in your next projects, you will implement that part as well
if (argc != 3) {
cout << "Run the code with the following command: ./project1 [input_file] [output_file]" << endl;
return 1;
}
ifstream infile(argv[1]);
string line;
vector<string> input;
// process first line
getline(infile, line);
int cashierNum = stoi(line);
cout << "number of cashiers: " << cashierNum << endl;
vector<Cashier> cashierVec;
for(int i=0;i<cashierNum;i++){
Cashier newCashier(i+1,0);
cashierVec.push_back(newCashier);
}
vector<Barista> baristaVec;
int baristaNum = cashierNum/3;
for(int i=0;i<cashierNum/3;i++){
Barista newBarista(i+1,0);
baristaVec.push_back(newBarista);
}
getline(infile,line);
int orderNum = stoi(line);
cout << "number of orders: " << orderNum << endl;
vector<Order*> orderVec; // a vector which holds the orders
//The following code generates the orderVec dynamicaly using the input file
Order* p;
for (int i=0; i<orderNum; i++) {
getline(infile, line);
vector<string> words;
split1(line,words);
p = new Order(stod(words[0]),stod(words[1]),stod(words[2]),stod(words[3]));
orderVec.push_back(p);
}
//creates queues for baristas and stores them in a vector for 2nd model
vector<queue<Order*>*> secondModelVec;
for(int i=0;i<baristaNum;i++){
queue<Order*>* q = new queue<Order*>;
secondModelVec.push_back(q);
}
long maxLengthOfCashierQueue = 0; //for both 1st model and 2nd model
long maxLengthOfBaristaQueue = 0; //for 1st model
//These 2 queues are used to simulate the queues for cashier and barista queues
queue<Order *> tempQueueForCashiers;
queue<Order *> tempQueueForBaristas;
//fills the cashier queue
for (int i = 0; i < orderNum; i++) {
tempQueueForCashiers.push(orderVec[i]);
}
/**************************CASHIER QUEUE BEGINS FOR 1ST AND 2ND MODEL*************************/
std::clock_t start2;
double duration2;
start2 = std::clock();
bool orderTaken = 0;
while (!tempQueueForCashiers.empty())
{
bool orderProcessed = false; //becomes true if the current order is put to an empty cashier
bool thereIsAnEmptyCashier = false;
int indexOfTheEmptySpot=0;
//this loop detects the empty cashier with the earliest index
for (int j = 0; j < cashierNum; j++) {
if (cashierVec[j].isEmpty) {
indexOfTheEmptySpot = j;
thereIsAnEmptyCashier = true;
break;
}
}
//the following if block puts the current order to the empty spot if there is one
if(thereIsAnEmptyCashier){
cashierVec[indexOfTheEmptySpot].isEmpty = 0;
(*(tempQueueForCashiers.front())).orderDoneTime = (*(tempQueueForCashiers.front())).arrivalTime + (*(tempQueueForCashiers.front())).orderTime;
cashierVec[indexOfTheEmptySpot].busyTime += (*(tempQueueForCashiers.front())).orderTime;
cashierVec[indexOfTheEmptySpot].currentOrderptr = tempQueueForCashiers.front();
//Every order has a cashIndex field which specifies in which cashier it is processed
//This index is used to determine in which barista queue for 2nd Model we will put it
//if you divide cashIndex by 3 , you'll get the index of the queue where the order will be put
(*(tempQueueForCashiers.front())).cashIndex = indexOfTheEmptySpot; // 2ndModel index
tempQueueForCashiers.pop();
orderProcessed = true;
}
//if an order is put to an empty spot do not enter this loop, instead go back to while and process the next order
if (!orderProcessed) {
//Following code finds the cashier that becomes available earliest
int indexOfEarliestEmptyCashier = 0; //this field is used if the arrival time of the order in front of the queue is smaller than the orderDoneTimes of all cashiers
double minOrderDoneTime = (*(cashierVec[0].currentOrderptr)).orderDoneTime;
for (int i = 1; i < cashierNum; i++) {
if ((*(cashierVec[i].currentOrderptr)).orderDoneTime < minOrderDoneTime) {
minOrderDoneTime = (*(cashierVec[i].currentOrderptr)).orderDoneTime;
indexOfEarliestEmptyCashier = i;
}
}
vector<Order*> tempVectorForSorting; //this vector is created to sort the orders that are being processed
//refresh the cashiers according to the arrival time of the current order
for(int j = 0; j < cashierNum;j++){
if((*(tempQueueForCashiers.front())).arrivalTime > (*(cashierVec[j].currentOrderptr)).orderDoneTime){
cashierVec[j].isEmpty = true;
tempVectorForSorting.push_back(cashierVec[j].currentOrderptr); //this for the Barista queue
}
}
//This 5 lines of code sorts the orders that are freed after the refreshment and pushs them to the barista queue
sort(tempVectorForSorting.begin(),tempVectorForSorting.end(),sortByOrderDoneTime());
for(int i=0;i<tempVectorForSorting.size();i++){
tempQueueForBaristas.push(tempVectorForSorting[i]);
}
tempVectorForSorting.clear();
//places the order in front of the queue to the cashier with the earliest index after refreshment
for(int j = 0; j < cashierNum;j++){
if(cashierVec[j].isEmpty){
cashierVec[j].isEmpty = 0;
(*(tempQueueForCashiers.front())).orderDoneTime = (*(tempQueueForCashiers.front())).arrivalTime + (*(tempQueueForCashiers.front())).orderTime;
cashierVec[j].currentOrderptr = tempQueueForCashiers.front();
cashierVec[j].busyTime += (*(tempQueueForCashiers.front())).orderTime;
(*(tempQueueForCashiers.front())).cashIndex = j; // 2ndModel index
orderTaken = 1;
break;
}
}
//means that arrival time of the order in front of the queue is larger orderDoneTimes of some of the cashiers
//in this case we placed it to the empty cashier with the smallest index according to its arrival time
if(orderTaken){
orderTaken=0;
tempQueueForCashiers.pop();
}
//if the order waits in the queue means that it enters a queue
else {
//The following 2 for loop and 1 if statement is there to find the maximum length of the cashier queue
long currentQueueSize = 0; // this is for max length
vector<Order *> tempVectorForTraversingTheQueue;
long sizeOfTheQueue = tempQueueForCashiers.size(); // this is for loop count
for (int i = 0; i < sizeOfTheQueue; i++) {
Order *front = tempQueueForCashiers.front();
tempVectorForTraversingTheQueue.push_back(front);
tempQueueForCashiers.pop();
}
for (int i = 0; i < tempVectorForTraversingTheQueue.size(); i++) {
if ((*(tempVectorForTraversingTheQueue[i])).arrivalTime <
(*(cashierVec[indexOfEarliestEmptyCashier].currentOrderptr)).orderDoneTime) {
currentQueueSize++;
} else {
break;
}
}
if (currentQueueSize > maxLengthOfCashierQueue) {
maxLengthOfCashierQueue = currentQueueSize;
}
//copy the vector back to the queue
for (int i = 0; i < tempVectorForTraversingTheQueue.size(); i++) {
tempQueueForCashiers.push(tempVectorForTraversingTheQueue[i]);
}
tempVectorForTraversingTheQueue.clear();
//this block handles the replacement part
(*(tempQueueForCashiers.front())).orderDoneTime = (*(tempQueueForCashiers.front())).orderTime +
(*(cashierVec[indexOfEarliestEmptyCashier].currentOrderptr)).orderDoneTime; //The difference
tempQueueForBaristas.push(cashierVec[indexOfEarliestEmptyCashier].currentOrderptr); // for BaristaQueue
(*(tempQueueForCashiers.front())).cashIndex = indexOfEarliestEmptyCashier; // 2ndModel index
//(*(secondModelVec[((*(tempQueueForCashiers.front())).cashIndex)/3])).push(tempQueueForCashiers.front()); // 2ndModel push
cashierVec[indexOfEarliestEmptyCashier].busyTime += (*(tempQueueForCashiers.front())).orderTime;
cashierVec[indexOfEarliestEmptyCashier].currentOrderptr = tempQueueForCashiers.front();
tempQueueForCashiers.pop();
}
}
}
//This additional part pushes the orders to the barista queue that are left in the cashiers according to their
//orderDoneTimes
vector<Order*> tempVectorForSorting;
for(int j = 0; j < cashierNum;j++){
tempVectorForSorting.push_back(cashierVec[j].currentOrderptr); //this for the Barista queue
}
//This 5 lines of code sorts the order that are freed after the refreshment and pushs them to the barista queue
sort(tempVectorForSorting.begin(),tempVectorForSorting.end(),sortByOrderDoneTime());
for(int i=0;i<tempVectorForSorting.size();i++){
tempQueueForBaristas.push(tempVectorForSorting[i]);
//(*(secondModelVec[((*(tempVectorForSorting[i])).cashIndex)/3])).push(tempVectorForSorting[i]); // 2ndModel push
}
tempVectorForSorting.clear();
//copying the queue to a vector to copy it to another vector for 2nd model later
vector<Order*> tempVect;
int length = tempQueueForBaristas.size();
for(int i=0;i<length;i++){
Order* ptr =tempQueueForBaristas.front();
tempVect.push_back(ptr);
tempQueueForBaristas.pop();
}
for(int i=0;i<tempVect.size();i++){
tempQueueForBaristas.push(tempVect[i]);
}
duration2 = ( std::clock() - start2 ) / (double) CLOCKS_PER_SEC;
std::cout<<"1st loop takes : "<< duration2 << " seconds" << endl;
/*****************************CASHIER QUEUE IS PROCESSED*****************************************/
/**************************BARISTA QUEUE BEGINS FOR 1ST MODEL************************************/
std::clock_t start3;
double duration3;
start3 = std::clock();
bool orderTaken2 = 0;
while (!tempQueueForBaristas.empty())
{
bool orderProcessed = false;
bool thereIsAnEmptyBarista = false;
int indexOfTheEmptySpot=0;
//if there is an available barista, fill it with the element in front of the queue
for (int j = 0; j < baristaNum; j++) {
if (baristaVec[j].isEmpty) {
indexOfTheEmptySpot = j;
thereIsAnEmptyBarista = true;
break;
}
}
if(thereIsAnEmptyBarista){
baristaVec[indexOfTheEmptySpot].isEmpty = 0;
(*(tempQueueForBaristas.front())).brewDoneTime = (*(tempQueueForBaristas.front())).orderDoneTime + (*(tempQueueForBaristas.front())).brewTime;
baristaVec[indexOfTheEmptySpot].busyTime += (*(tempQueueForBaristas.front())).brewTime;
baristaVec[indexOfTheEmptySpot].currentOrderptr = tempQueueForBaristas.front();
tempQueueForBaristas.pop();
orderProcessed = true;
}
//if an order is put to an empty spot do not enter this loop, instead go back to while
if (!orderProcessed) {
//Following code finds the barista that becomes available earliest
int indexOfEarliestEmptyBarista = 0; //this field is used if the arrival time of the order in front of the queue is smaller than the brewDoneTimes of all baristas
double minBrewDoneTime = (*(baristaVec[0].currentOrderptr)).brewDoneTime;
for (int i = 1; i < baristaNum; i++) {
if ((*(baristaVec[i].currentOrderptr)).brewDoneTime < minBrewDoneTime) {
minBrewDoneTime = (*(baristaVec[i].currentOrderptr)).brewDoneTime;
indexOfEarliestEmptyBarista = i;
}
}
//refresh the baristas according to the arrival time of the current order
for(int j = 0; j < baristaNum;j++){
if((*(tempQueueForBaristas.front())).orderDoneTime > (*(baristaVec[j].currentOrderptr)).brewDoneTime){
baristaVec[j].isEmpty = true;
}
}
//places the order in front of the queue to the barista with the earliest index after refreshment
for(int j = 0; j < baristaNum;j++){
if(baristaVec[j].isEmpty){
baristaVec[j].isEmpty = 0;
(*(tempQueueForBaristas.front())).brewDoneTime = (*(tempQueueForBaristas.front())).orderDoneTime + (*(tempQueueForBaristas.front())).brewTime;
baristaVec[j].currentOrderptr = tempQueueForBaristas.front();
baristaVec[j].busyTime += (*(tempQueueForBaristas.front())).brewTime;
orderTaken2 = 1;
break;
}
}
//means that arrival time of the order in front of the queue is larger brewDoneTimes of some of the baristas
//in this case we placed it to the empty barista with the smallest index according to its arrival time
if(orderTaken2){
orderTaken2=0;
tempQueueForBaristas.pop();
}
//if the order waits in the queue means that it enters a queue
else {
//The following 2 for loop and 1 if statement is there to find the maximum length of the barista queue
long currentQueueSize = 0; // this is for max length
vector<Order *> tempVectorForTraversingTheQueue;
long sizeOfTheQueue = tempQueueForBaristas.size(); // this is for loop count
for (int i = 0; i < sizeOfTheQueue; i++) {
Order *front = tempQueueForBaristas.front();
tempVectorForTraversingTheQueue.push_back(front);
tempQueueForBaristas.pop();
}
for (int i = 0; i < tempVectorForTraversingTheQueue.size(); i++) {
if ((*(tempVectorForTraversingTheQueue[i])).orderDoneTime <
(*(baristaVec[indexOfEarliestEmptyBarista].currentOrderptr)).brewDoneTime) {
currentQueueSize++;
} else {
break;
}
}
if (currentQueueSize > maxLengthOfBaristaQueue) {
maxLengthOfBaristaQueue = currentQueueSize;
}
//The following for loop finds the index of the order which has the maximum price
double maxPrice = 0;
int maxPriceIndex = 0; //index of the order which has the maximum price in the current queue
for(int i=0;i<currentQueueSize;i++){
if((*(tempVectorForTraversingTheQueue[i])).price > maxPrice){
maxPrice = (*(tempVectorForTraversingTheQueue[i])).price;
maxPriceIndex = i;
}
}
//copy the vector back to the queue
for (int i = 0; i < tempVectorForTraversingTheQueue.size(); i++) {
//copy all the elements to the queue except the one with the max price
if(i != maxPriceIndex){
tempQueueForBaristas.push(tempVectorForTraversingTheQueue[i]);
}
}
//this block handles the replacement part
(*(tempVectorForTraversingTheQueue[maxPriceIndex])).brewDoneTime = (*(tempVectorForTraversingTheQueue[maxPriceIndex])).brewTime +
(*(baristaVec[indexOfEarliestEmptyBarista].currentOrderptr)).brewDoneTime; //The difference
baristaVec[indexOfEarliestEmptyBarista].busyTime += (*(tempVectorForTraversingTheQueue[maxPriceIndex])).brewTime;
baristaVec[indexOfEarliestEmptyBarista].currentOrderptr = tempVectorForTraversingTheQueue[maxPriceIndex];
tempVectorForTraversingTheQueue.clear();
}
}
}
duration3 = ( std::clock() - start3 ) / (double) CLOCKS_PER_SEC;
std::cout<<"2nd loop takes: "<< duration3 << " seconds" << endl;
/********************BARISTA QUEUE FOR 1ST MODEL IS PROCESSED**************************************/
double totalRunningTime1stModel = 0;
for(int i =0;i<orderNum;i++){
if((*(orderVec[i])).brewDoneTime > totalRunningTime1stModel){
totalRunningTime1stModel = (*(orderVec[i])).brewDoneTime;
}
}
//File writings for the 1st model
FILE *myfile;
myfile = fopen(argv[2],"w");
fprintf(myfile,"%.2lf\n",totalRunningTime1stModel);
fprintf(myfile,"%lu\n",maxLengthOfCashierQueue);
fprintf(myfile,"%lu\n",maxLengthOfBaristaQueue);
//utilizations of cashiers
for(int i=0;i<cashierNum;i++){
double util=cashierVec[i].busyTime/totalRunningTime1stModel;
fprintf(myfile,"%.2lf\n",util);
}
//utilizations of baristas
for(int i=0;i<baristaNum;i++){
double util=baristaVec[i].busyTime/totalRunningTime1stModel;
fprintf(myfile,"%.2lf\n",util);
}
//Turnaround times of order
for(int i=0;i<orderNum;i++){
fprintf(myfile,"%.2lf\n",orderVec[i]->brewDoneTime - orderVec[i]->arrivalTime);
}
/************PREPARATION FOR 2ND MODEL**********************/
//The necessary vector is constituted from tempVect
for(int i=0;i<orderNum;i++){
(*(secondModelVec[((*(tempVect[i])).cashIndex)/3])).push(tempVect[i]);
}
//the loop for 1st model is above, therefore we need to update the baristas to their default values
for(int i=0;i<baristaNum;i++){
baristaVec[i].isEmpty=1;
baristaVec[i].busyTime = 0;
Order o(0,0,0,0);
Order* p=&o;
baristaVec[i].currentOrderptr = p;
}
//update the brewDoneTimes of the orders
for(int i=0;i<orderNum;i++){
orderVec[i]->brewDoneTime=0;
}
/******************PREPARATION FOR 2ND MODEL IS DONE***********/
/******************BARISTA QUEUE FOR 2ND MODEL BEGINS*********************************/
std::clock_t start4;
double duration4;
start4 = std::clock();
for(int t=0;t<baristaNum;t++){
bool orderTaken2 = 0;
while (!(*(secondModelVec[t])).empty())
{
bool orderProcessed = false;
//if the current barista is empty, place the order to it
if(baristaVec[t].isEmpty){
baristaVec[t].isEmpty = 0;
(*((*(secondModelVec[t])).front())).brewDoneTime = (*((*(secondModelVec[t])).front())).orderDoneTime + (*((*(secondModelVec[t])).front())).brewTime;
baristaVec[t].busyTime += (*((*(secondModelVec[t])).front())).brewTime;
baristaVec[t].currentOrderptr = (*(secondModelVec[t])).front();
(*(secondModelVec[t])).pop();
orderProcessed = true;
}
//if an order is put to an empty spot do not enter this loop, instead go back to while
if (!orderProcessed) {
//refresh the barista
if( (*((*(secondModelVec[t])).front())).orderDoneTime > (*(baristaVec[t].currentOrderptr)).brewDoneTime){
baristaVec[t].isEmpty = true;
}
//places the order after refreshment
if(baristaVec[t].isEmpty){
baristaVec[t].isEmpty = 0;
(*((*(secondModelVec[t])).front())).brewDoneTime = (*((*(secondModelVec[t])).front())).orderDoneTime + (*((*(secondModelVec[t])).front())).brewTime;
baristaVec[t].currentOrderptr = (*(secondModelVec[t])).front();
baristaVec[t].busyTime += (*((*(secondModelVec[t])).front())).brewTime;
orderTaken2 = 1;
}
//means that arrival time of the order in front of the queue is larger orderDoneTimes of some of the cashiers
//in this case we placed it to the the empty cashier with the smallest index according to its arrival time
if(orderTaken2){
orderTaken2=0;
(*(secondModelVec[t])).pop();
}
//if the order waits in the queue means that it enters a queue
else {
//The following 2 for loop and 1 if statement is there to find the maximum length of the cashier queue
long currentQueueSize = 0; // this is for max length
vector<Order *> tempVectorForTraversingTheQueue;
long sizeOfTheQueue = (*(secondModelVec[t])).size(); // this is for loop count
for (int i = 0; i < sizeOfTheQueue; i++) {
Order *front = (*(secondModelVec[t])).front();
tempVectorForTraversingTheQueue.push_back(front);
(*(secondModelVec[t])).pop();
}
for (int i = 0; i < tempVectorForTraversingTheQueue.size(); i++) {
if ((*(tempVectorForTraversingTheQueue[i])).orderDoneTime <
(*(baristaVec[t].currentOrderptr)).brewDoneTime) {
currentQueueSize++;
} else {
break;
}
}
if (currentQueueSize > baristaVec[t].maxLength2ndModel) {
baristaVec[t].maxLength2ndModel = currentQueueSize;
}
//The following for loop finds the index of the order which has the maximum price
double maxPrice = 0;
int maxPriceIndex = 0; //index of the order which has the maximum price in the current queue
for(int i=0;i<currentQueueSize;i++){
if((*(tempVectorForTraversingTheQueue[i])).price > maxPrice){
maxPrice = (*(tempVectorForTraversingTheQueue[i])).price;
maxPriceIndex = i;
}
}
//copy the vector back to the queue
for (int i = 0; i < tempVectorForTraversingTheQueue.size(); i++) {
//copy all the elements to the queue except the one with the max price
if(i != maxPriceIndex){
(*(secondModelVec[t])).push(tempVectorForTraversingTheQueue[i]);
}
}
//this block handles the replacement part
(*(tempVectorForTraversingTheQueue[maxPriceIndex])).brewDoneTime = (*(tempVectorForTraversingTheQueue[maxPriceIndex])).brewTime +
(*(baristaVec[t].currentOrderptr)).brewDoneTime; //The difference
baristaVec[t].busyTime += (*(tempVectorForTraversingTheQueue[maxPriceIndex])).brewTime;
baristaVec[t].currentOrderptr = tempVectorForTraversingTheQueue[maxPriceIndex];
tempVectorForTraversingTheQueue.clear();
}
}
}
}
duration4 = ( std::clock() - start4 ) / (double) CLOCKS_PER_SEC;
std::cout<<"3rd loop takes: "<< duration4 << " seconds" << endl;
/****************BARISTA QUEUE FOR 2ND MODEL IS PROCESSED*****************************/
double totalRunningTime2ndModel =0;
for(int i =0;i<orderNum;i++){
if((*(orderVec[i])).brewDoneTime > totalRunningTime2ndModel){
totalRunningTime2ndModel = (*(orderVec[i])).brewDoneTime;
}
}
fprintf(myfile,"\n");
fprintf(myfile,"%.2lf\n",totalRunningTime2ndModel);
fprintf(myfile,"%lu\n",maxLengthOfCashierQueue);
for(int i=0;i<baristaNum;i++){
fprintf(myfile,"%lu\n",baristaVec[i].maxLength2ndModel);
}
//utilizations of cashiers
for(int i=0;i<cashierNum;i++){
double util=cashierVec[i].busyTime/totalRunningTime2ndModel;
fprintf(myfile,"%.2lf\n",util);
}
//utilizations of baristas
for(int i=0;i<baristaNum;i++){
double util=baristaVec[i].busyTime/totalRunningTime2ndModel;
fprintf(myfile,"%.2lf\n",util);
}
//Turnaround times of order
for(int i=0;i<orderNum;i++){
fprintf(myfile,"%.2lf\n",orderVec[i]->brewDoneTime - orderVec[i]->arrivalTime);
}
fclose(myfile);
for(int i=0;i<orderNum;i++){
delete orderVec[i];
}
for(int i=0;i<baristaNum;i++){
delete secondModelVec[i];
}
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
std::cout<<"Main process takes: "<< duration << " seconds" << endl;
return 0;
}