-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReceptionist.java
More file actions
232 lines (198 loc) · 7.14 KB
/
Receptionist.java
File metadata and controls
232 lines (198 loc) · 7.14 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
import java.lang.Math;
public class Receptionist extends Server {
private static final int JDOC_SERVICE_TIME_C1 = (int) Math.round(395/3);
private static final int JDOC_SERVICE_TIME_C2 = (int) Math.round(403/3);
private static final int JDOC_SERVICE_TIME_C3 = (int) Math.round(200/3);
private static final int JDOC_SERVICE_TIME_C4 = (int) Math.round(66/3);
private static final int JDOC_SERVICE_TIME_C5 = (int) Math.round(37/3);
private PatientQueue seniorDoc_queue;
private PatientQueue juniorDoc_queue;
private boolean queues_both_full;
private int ctas3_junior_doc = 1;
public Receptionist(String name, long hourly_wage, int max_number_of_users, PatientQueue seniorDoc_queue, PatientQueue juniorDoc_queue) {
super(name, hourly_wage, max_number_of_users);
this.seniorDoc_queue = seniorDoc_queue;
this.juniorDoc_queue = juniorDoc_queue;
this.queues_both_full = false;
}
public PatientQueue getSeniorDoc_queue() {
return seniorDoc_queue;
}
public void setSeniorDoc_queue(PatientQueue seniorDoc_queue) {
this.seniorDoc_queue = seniorDoc_queue;
}
public PatientQueue getJuniorDoc_queue() {
return juniorDoc_queue;
}
public void setJuniorDoc_queue(PatientQueue juniorDoc_queue) {
this.juniorDoc_queue = juniorDoc_queue;
}
@Override
public boolean serve_user() {
/**
* New patient arrives at receptionist desk. Receptionist determines which queue to send them to from here
*
* @return whether a user has been served
*/
if (isUnderMaintenance()) {
return false;
}
// queues_both_full = !juniorDoc_queue.room_for_more_patients() && !seniorDoc_queue.room_for_more_patients();
// if () {
// System.out.println("Both Queue full!");
// }
// else if (!seniorDoc_queue.room_for_more_patients()) {
// System.out.println("Senior Queue full!");
//
// }
// else if (!juniorDoc_queue.room_for_more_patients()) {
// System.out.println("Junior queue full!");
//
// }
if(!seniorDoc_queue.room_for_more_patients() && !juniorDoc_queue.room_for_more_patients()) {
queues_both_full = true;
System.out.println("Both queues full!");
remaining_service_time = 1;
return false;
}
User next_usr = my_queue.get_next_user();
if (next_usr == null) {
return false;
}
next_usr.start_service(this.curr_time);
number_served += 1;
current_user_being_served = next_usr;
remaining_service_time = 2 * (next_usr.getSeverity()) + 1;
next_usr.start_waiting(this.curr_time + remaining_service_time);
if (assignJuniorDoctor(next_usr) && juniorDoc_queue.room_for_more_patients() || !seniorDoc_queue.room_for_more_patients()) {
next_usr.setService_time(calculateServiceTime(next_usr, false));
next_usr.setPriority(calculatePriority(next_usr));
juniorDoc_queue.add_user(next_usr);
}
else if (seniorDoc_queue.room_for_more_patients()) {
next_usr.setService_time(calculateServiceTime(next_usr, true));
next_usr.setPriority(calculatePriority(next_usr));
seniorDoc_queue.add_user(next_usr);
} else {
queues_both_full = true;
System.out.println("SOMETHING FAILED");
return false;
}
return true;
}
private boolean assignJuniorDoctor(User usr) {
/**
* Discriminating function, where the receptionist determines if the junior doctor should be chosen.
* Either there are too many people waiting for the senior queue,
* or the total wait time for one line is significantly greater than another
*
* @param usr: Current user being served by the receptionist.
*/
if (usr.getSeverity() <= 2) {
return false;
}
else if (usr.getSeverity() == 3) {
switch(ctas3_junior_doc) {
case 1:
ctas3_junior_doc++;
return false;
case 2:
ctas3_junior_doc++;
return true;
case 3:
ctas3_junior_doc = 1;
return true;
default:
return false;
}
}
else {
return true;
}
}
private int calculateServiceTime(User usr, boolean isSeniorDoctor) {
/**
* This function calculates how long it will take to service the patient, based off
* the expertise of their doctor chosen. Senior doctor works faster, but takes on more
* severe cases
*
* @param usr: Current user being calculated:
* @param isSeniorDoctor: used to determine how long it will take to service
* @returns int: service time calculated
*/
int serviceTime;
if (usr.getSeverity() == 1) {
serviceTime = JDOC_SERVICE_TIME_C1;
}
else if (usr.getSeverity() == 2) {
serviceTime = JDOC_SERVICE_TIME_C2;
}
else if (usr.getSeverity() == 3) {
serviceTime = JDOC_SERVICE_TIME_C3;
}
else if (usr.getSeverity() == 4) {
serviceTime = JDOC_SERVICE_TIME_C4;
}
else if (usr.getSeverity() == 5) {
serviceTime = JDOC_SERVICE_TIME_C5;
}
else {
serviceTime = -1;
}
if (isSeniorDoctor) {
serviceTime /= 2;
}
return serviceTime;
}
private int calculatePriority(User usr) {
int priority;
if (usr.getSeverity() == 1) {
priority = 1;
}
else if (usr.getSeverity() == 2) {
priority = 81+curr_time;
}
else if (usr.getSeverity() == 3) {
priority = 151+curr_time;
}
else if (usr.getSeverity() == 4) {
priority = 158+curr_time;
}
else if (usr.getSeverity() == 5) {
priority = 146+curr_time;
}
else {
priority = -1;
}
return priority;
// if (usr.getSeverity() == 1) {
// priority_adjust = 24;
// }
// else if (usr.getSeverity() == 2) {
// priority_adjust = 81;
// }
// else if (usr.getSeverity() == 3) {
// priority_adjust = 151;
// }
// else if (usr.getSeverity() == 4) {
// priority_adjust = 158;
// }
// else if (usr.getSeverity() == 5) {
// priority_adjust = 146;
// }
// else {
// priority_adjust = -1;
// }
// return Math.min(usr.getSeverity()-1, 1)*(priority_adjust+curr_time);
}
public boolean isUnderMaintenance() {
/**
* Called between patients to check if maintenance is required
* In our simulation the receptionist does not go on break.
*
* @return: whether the server is under maintenance
*/
isMaintenance = false;
return false;
}
}