-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDPs.java
More file actions
147 lines (122 loc) · 4.98 KB
/
UDPs.java
File metadata and controls
147 lines (122 loc) · 4.98 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
package simModel;
class UDPs
{
SMTravel model; // for accessing the clock
// Constructor
protected UDPs(SMTravel model) { this.model = model; }
// User Defined Procedures
// Check the time waited of each type of users if they waited too
protected boolean userWaitedTooLong(int typeOfUser, double timeWaited){
boolean result = true;
if(typeOfUser == Constants.REGULAR) {
if(timeWaited > 15){
result= true;
}
else {
result = false;
}
}
if(typeOfUser == Constants.SILVER) {
if(timeWaited > 3){
result= true;
}
else {
result = false;
}
}
if(typeOfUser == Constants.GOLD) {
if(timeWaited > 1.5){
result = true;
}
else {
result = false;;
}
}
return result;
}
//Get total Cost
protected int computeTotalCost(){
int tn[] = {0,0,0};
for(int id = Constants.REGULAR; id <= Constants.GOLD; id++){
for(int i = 0; i < 5; i++){
tn[id] += model.rgOperators[id].schedule[i];
}
}
return ((tn[Constants.GOLD] * 8 * 23) + (tn[Constants.SILVER] * 8 * 20) +
(tn[Constants.REGULAR] * 8 * 16) + (model.qPhoneSystem.trunklinesNum - 50) * 170);
}
// One of the three calls is ready for processing
protected boolean canServiceCall(Call icCall)
{
boolean first = (model.qPhoneSystem.list.peek() == icCall);
boolean regOpAvail = model.rgOperators[Constants.REGULAR].numOfBusy < model.rgOperators[Constants.REGULAR].uNumOperators;
boolean silvOpAvail = model.rgOperators[Constants.SILVER].numOfBusy < model.rgOperators[Constants.SILVER].uNumOperators;
boolean goldOpAvail = model.rgOperators[Constants.GOLD].numOfBusy < model.rgOperators[Constants.GOLD].uNumOperators;
//System.err.println(regOpAvail + " : " +silvOpAvail + " : " +goldOpAvail );
if(icCall.uType == Constants.REGULAR) {
return first && regOpAvail;
}
else if(icCall.uType == Constants.SILVER) {
return first && (regOpAvail || silvOpAvail);
}
else if(icCall.uType == Constants.GOLD) {
return first && (regOpAvail || silvOpAvail || goldOpAvail);
} else {
return false;
}
}
protected int assignOperator(Call icCall) {
int res = -1; // If there are no operator that can serve return -1
if(icCall.uType == Constants.GOLD &&
model.rgOperators[Constants.GOLD].numOfBusy < model.rgOperators[Constants.GOLD].uNumOperators) {
//model.rgOperators[Constants.GOLD].numOfBusy++;
res = Constants.GOLD;
}
else if(icCall.uType != Constants.REGULAR &&
model.rgOperators[Constants.SILVER].numOfBusy < model.rgOperators[Constants.SILVER].uNumOperators) {
//model.rgOperators[Constants.SILVER].numOfBusy++;
res = Constants.SILVER;
}
else if(model.rgOperators[Constants.REGULAR].numOfBusy < model.rgOperators[Constants.REGULAR].uNumOperators){
//model.rgOperators[Constants.REGULAR].numOfBusy++;
res = Constants.REGULAR;
}
return res;
}
//Increments the number of customers who got a busy signal in each hour
protected void incBusySignal(int customerType)
{
model.output.busyPerHourMatrix[customerType][(int) (model.getClock()/60)] ++;
}
//Increments longwait matrix --Ma
protected void incLongWait(Call icCall){
int t = (int) icCall.uStartWaitTime / 60;
model.output.longWaitPerHourMatrix[icCall.uType][t] ++;
}
//Increments the number of customer that arrived in each hour
protected void incNumberArrival(int customerType)
{
//System.out.println("Arrival Time: " + (model.getClock()/60));
model.output.arrivalPerHourMatrix[customerType][(int) (model.getClock()/60)] ++;
}
// protected void insertArray(Call icCall){
//if(icCall.uType == Constants.REGULAR){
// model.qPhoneSystem.list.add(icCall);
//System.out.println("Insertion attemped at "+ model.getClock());
//System.out.println(model.qPhoneSystem.list);
// } else if(icCall.uType == Constants.SILVER){
// model.qPhoneSystem.list.add(icCall);
// } else {
// model.qPhoneSystem.list.add(icCall);
// }
// }
// protected void removeArray(Call icCall){
// if(icCall.uType == Constants.REGULAR){
// model.qPhoneSystem.list.remove(icCall);
// } else if(icCall.uType == Constants.SILVER){
// model.qPhoneSystem.list.remove(icCall);
// } else {
// model.qPhoneSystem.list.remove(icCall);
// }
// }
}