-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutPatientCenter.java
More file actions
138 lines (109 loc) · 3.53 KB
/
Copy pathOutPatientCenter.java
File metadata and controls
138 lines (109 loc) · 3.53 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
package HealthCareSystem;
import java.lang.*;
import genDevs.modeling.*;
import genDevs.simulation.*;
import GenCol.*;
import util.*;
import simView.*;
import statistics.*;
public class OutPatientCenter extends ViewableAtomic{
public static final double ARRIVING_RANDOM_CONST = 6;
protected double assessing_time;
protected double clock;
protected int n;
protected rand r = null;
public OutPatientCenter() {
this("Out Patient Center");
}
public OutPatientCenter(String nm) {
super(nm);
this.assessing_time = 0;//will be set later randomelys
clock = 0;
n = 0;
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("ready");
addOutport("yes_ready");
addTestInput("in", new entity("DOCTOR_AVAILABLE"), 0);
addTestInput("in", new entity("DOCTOR_AVAILABLE"), 5);
addTestInput("in", new entity("DOCTOR_AVAILABLE"), 10);
addTestInput("in", new entity("Patient"), 0);
addTestInput("in", new entity("Patient"), 5);
addTestInput("in", new entity("Patient"), 10);
addTestInput("ready", new entity(""), 0);
addTestInput("ready", new entity(""), 10);
r = new rand(1);
}
public void initialize() {
super.initialize();
passivate();
}
public void deltext(double e, message x) {
Continue(e);
if (somethingOnPort(x,"in"))
{
entity ent = getEntityOnPort(x, "in");
if(phaseIs("passive")) {
if(ent.toString().startsWith("Patient"))
holdIn("active",0);
}
if(phaseIs("WAITING CLEARANCE")) {
if (ent.eq("DOCTOR_AVAILABLE")) {
assessing_time = r.uniform(ARRIVING_RANDOM_CONST);
double overhead_time = r.expon(ARRIVING_RANDOM_CONST);
/*
This overhead time is because of taxi onto runway for TO
or roll out after landing
*/
clock += (assessing_time+overhead_time);
n += 1;
holdIn("Assessing", assessing_time + overhead_time);
}
}
}
if (somethingOnPort(x,"ready")) {
if (phaseIs("passive")) {
holdIn("YES", 0); //for handshaking
}
}
}
public void deltint() {
if(phaseIs("active"))
holdIn("WAITING CLEARANCE",INFINITY);
else if(phaseIs("Assessing"))
passivate();
else if(phaseIs("YES"))
passivate();
}
public void deltcon(double e,message x) {
deltint();
deltext(0,x);
}
public message out() {
message m = new message();
if ( phaseIs("active"))
m.add(makeContent("out",new entity("Walkin_REQ")));
else if ( phaseIs("Assessing"))
m.add(makeContent("out",new entity("DOCTOR_AVAILABLE")));
else if(phaseIs("YES"))
m.add(makeContent("yes_ready",new entity("YES")));
return m;
}
public String getTooltipText(){
return super.getTooltipText() + "\nMean time spent landing = " +
((n>0)? (clock / n): 0);
}
public void showState(){
super.showState();
System.out.println("\nMean time spent landing = " + ((n>0)? (clock / n): 0));
}
}// end of class arrivingAircraft