-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
69 lines (54 loc) · 1.69 KB
/
Event.java
File metadata and controls
69 lines (54 loc) · 1.69 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
public class Event {
public double timestamp;
public Event next;
public Type type;
public int index;
public enum Type {
BIRTH, DEATH, LOG
}
public Event(double timestamp, Type t, int index){
this.type = t;
this.timestamp = timestamp;
this.next = null;
this.index = index;
}
public Event myFunction(MM1System system, double time, double Ts, double anExpRV) {
switch (type) {
case BIRTH:
double Tq = 0;
for(int i = 0; i < system.getQueueSize() + 1; i++){ // 1 for its own service time + the service time of all those in line
Tq += Controller.getExponential(1/Ts);
}
system.enqueue(this, time);
double timeOfDeath = time + Tq;
Event death = new Event(timeOfDeath, Event.Type.DEATH, index);
return death;
case DEATH:
system.dequeue();
return null;
case LOG:
system.tallyQueue();
Event log = new Event(time + anExpRV, Event.Type.LOG, -1);
return log;
}
return null;
}
public double getTimestamp(){
return this.timestamp;
}
public Type getType(){
return this.type;
}
public Event getNext(){
return this.next;
}
public int getIndex(){
return this.index;
}
public void setNext(Event e){
this.next = e;
}
public String toString(){
return "a " + type + " scheduled for " + this.timestamp;
}
}