-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
124 lines (104 loc) · 3.76 KB
/
main.cpp
File metadata and controls
124 lines (104 loc) · 3.76 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
//Matthew Puentes Andrew Levy
#include<iostream>
#include<queue>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include"tellerLine.h"
#include"Event.h"
float avgVector(std::vector<float> s){
float av = 0;
for (unsigned int i = 0; i < s.size(); i++) {
av += s.at(i);
}
return av/s.size();
}
int main(int argc, char* argv[]) {
if (argc == 6) {
unsigned int i = atoi(argv[5]);
srand(i);
} else if (argc == 5)
srand(time(0));
else {
std::cout << "Please input 4 or 5 arguments" << std::endl;
}
int custNum = atoi(argv[1]);
int tellNum = atoi(argv[2]);
float simTime = atoi(argv[3])*60;
Event::maxSimTime = simTime;
float avgServiceTime = atoi(argv[4])*60;
std::cout <<std::endl << "first trial with one line per teller" <<std::endl;
Event::commonLine = false;
std::priority_queue<Event> timeLine;
Event::timeLine = &timeLine;
Event::averageServiceTime = avgServiceTime;
Event::timeInBank = *(new std::vector<float>());
Event::timeWaitBank = 0;
//create Customers
for (int i = 0; i < custNum; i++) {
float randTime = (rand() / float(RAND_MAX)) * (simTime);
const Event newC = *(new Event(randTime, 'c', true));
timeLine.push(newC);
}
//create tellers, tellerLines.
std::vector<tellerLine> *tellerLineList = new std::vector<tellerLine>();
for (int i = 0; i < tellNum; i++) {
tellerLineList->push_back(*(new const tellerLine()));
timeLine.push(*(new Event(0, 't', false)));
}
float totalTime = 0;
float time = 0;
while (!timeLine.empty()) {
Event e = timeLine.top();
time = e.time;
timeLine.pop();
e.action(tellerLineList);
}
float avServeTime = avgVector(Event::timeInBank);
float avTellerServe = avgVector(Event::tellerServ);
float avTellerIdle = avgVector(Event::tellerIdle);
totalTime = time;
std::cout << "there were " << custNum << " customers helped in " << float(totalTime/60) << " minutes" <<std::endl;
std::cout << "on average, customers spend " << float(avServeTime/60) << " min in the bank" << std::endl;
std::cout << "The longest wait time a customer had was " << float(Event::timeWaitBank/60) << std::endl;
std::cout << "On average the tellers idled for " << float(avTellerIdle) << " minutes and served coustomers for "
<< float(avTellerServe) << " minutes " << std::endl;
std::cout <<std::endl << "second trial with one common line" <<std::endl;
//time with one common line.
Event::commonLine = true;
timeLine = *(new std::priority_queue<Event>());
Event::timeLine = &timeLine;
Event::averageServiceTime = avgServiceTime;
Event::timeInBank = *(new std::vector<float>());
Event::timeWaitBank = 0;
//create Customers
for (int i = 0; i < custNum; i++) {
float randTime = (rand() / float(RAND_MAX)) * (simTime);
const Event newC = *(new Event(randTime, 'c', true));
timeLine.push(newC);
}
//create tellers, tellerLines.
tellerLineList = new std::vector<tellerLine>();
for (int i = 0; i < tellNum; i++) {
tellerLineList->push_back(*(new const tellerLine()));
timeLine.push(*(new Event(0, 't', false)));
}
totalTime = 0;
time = 0;
while (!timeLine.empty()) {
Event e = timeLine.top();
time = e.time;
timeLine.pop();
e.action(tellerLineList);
}
avServeTime = avgVector(Event::timeInBank);
avTellerServe = avgVector(Event::tellerServ);
avTellerIdle = avgVector(Event::tellerIdle);
totalTime = time;
std::cout << "there were " << custNum << " customers helped in " << float(totalTime/60) << " minutes" <<std::endl;
std::cout << "on average, customers spend " << float(avServeTime/60) << " min in the bank" << std::endl;
std::cout << "The longest wait time a customer had was " << float(Event::timeWaitBank/60) << std::endl;
std::cout << "On average the tellers idled for " << float(avTellerIdle) << " minutes and served coustomers for "
<< float(avTellerServe) << " minutes " << std::endl;
return 1;
}