-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmergencyPatientsQueue.java
More file actions
167 lines (135 loc) · 4.8 KB
/
Copy pathEmergencyPatientsQueue.java
File metadata and controls
167 lines (135 loc) · 4.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
package HealthCareSystem;
import genDevs.modeling.*;
import genDevs.simulation.*;
import GenCol.*;
import simView.*;
public class EmergencyPatientsQueue extends ViewableAtomic{
public static final int MAX_DEPRT = 10;
public static final double SHIFT_TIME = 0; /* time to move a plane in the queue */
protected int count;
protected int max_count_waitingToLand;
protected double sum;
protected int n;
protected entity queue[];
public EmergencyPatientsQueue() {
this("Emergency Patients Queue");
}
public EmergencyPatientsQueue(String nm) {
super(nm);
count = 0;
max_count_waitingToLand = 0;
sum = 0;
n = 0;
queue = new entity [MAX_DEPRT];/*maximum possible size of the queue*/
for(int i = 0;i < MAX_DEPRT;i++)
queue[i] = null;
addInport("in");
addOutport("out");
/*
These 2 ports are added to solve the problem of initial case; when the
aircraft obj is in passive state, and so the queue will not get the input
"RUNWAY_IS_CLEAR" so it'll not forward a new aircraft to the aircraft obj.
This is somehow like handshaking; the queue asks the aircraft obj.
Are you ready? and it simply replys "Yes" if it's in the passive state,
and can accept a new obj. if it's not in the passive state it'll not reply
back, and the queue will not overwhelm the aircraft obj with a new aircraft
*/
addInport("yes_ready");
addOutport("ready");
addTestInput("in", new entity("RUNWAY_IS_CLEAR"), 0);
addTestInput("in", new entity("RUNWAY_IS_CLEAR"), 5);
addTestInput("in", new entity("RUNWAY_IS_CLEAR"), 10);
addTestInput("in", new entity("Patient1"), 0);
addTestInput("in", new entity("Patient1"), 5);
addTestInput("in", new entity("Patient1"), 10);
addTestInput("in", new entity("Patient2"), 0);
addTestInput("in", new entity("Patient3"), 0);
addTestInput("yes_ready", new entity(""), 0);
addTestInput("yes_ready", new entity(""), 10);
}
public void initialize() {
super.initialize();
count = 0;
sum = 0;
max_count_waitingToLand = 0;
n = 0;
for(int i = 0;i < MAX_DEPRT;i++)
queue[i] = null;
holdIn("count = " + count, INFINITY);
}
public void deltext(double e, message x) {
Continue(e);
if(sigma == INFINITY) {
if (somethingOnPort(x,"in")) {
entity ent = getEntityOnPort(x,"in");
if(ent.toString().startsWith("Patient")) { /* new aircraft from the Gen. */
if(queue[count] == null) //empty
queue[count] = new entity (ent.toString());
if(count < MAX_DEPRT) { // MAX Allowed
count += 1; //increase count by 1
if(count > max_count_waitingToLand)
max_count_waitingToLand = count;
sum += count;
n += 1;
}
if(count == 1) /* Go to handshaking */
holdIn("warming", 0);
else
holdIn("count = " + count, INFINITY);//update phase
}
if (ent.eq("RUNWAY_IS_CLEAR")){
if (count > 0) {
if (count == 1){
queue[0] = null;
count = 0;
holdIn("count = " + count, INFINITY);
}
else {
/* shift the queue */
for (int i = 0; i < count - 1; i++)
queue[i] = queue[i + 1];
queue[count - 1] = null;
count -= 1; // decrease count by 1
holdIn("count = " + count, SHIFT_TIME);
}
}
}
}
if (somethingOnPort(x,"yes_ready")) {
/*
here we don't need to update count; just move to the state
"start" to indicate the startup (warming) and to send an aircraft
to the aircraft obj since it's ready. <Handshaking>
*/
holdIn("start", 0);
}
}
}
public void deltint() {
if(phaseIs("warming") || phaseIs("start") || sigma == SHIFT_TIME)
holdIn("count = " + count, INFINITY);
}
public void deltcon(double e, message x) {
deltint();
deltext(0, x);
}
public message out() {
message m = new message();
if (phaseIs("warming"))
m.add(makeContent("ready", new entity("READY")));
else
m.add(makeContent("out", new entity(queue[0].toString())));
return m;
}
public String getTooltipText(){
return super.getTooltipText()+"\nTotal # of Departing AC = " + n +
"\nMAX # AC waiting to takeoff = "+ max_count_waitingToLand+
"\nMean # AC waiting to takeoff = " + ((n>0)? (sum / n): 0);
}
public void showState(){
super.showState();
System.out.println("\nTotal # of Departing AC = " + n);
System.out.println("\nMAX # AC waiting to takeoff = " + max_count_waitingToLand);
System.out.println("\nMean # AC waiting to takeoff = "+((n>0)? (sum / n): 0));
}
}// end of class departureQueue