-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine_dev.js
More file actions
123 lines (99 loc) · 4 KB
/
engine_dev.js
File metadata and controls
123 lines (99 loc) · 4 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
function trafficSimulation (FLIGHT_TIME, TURN_TIME, SIMTIME,SEED,LAMBDA) {
var sim = new Sim();
var stats = new Sim.Population();
// Struture to a possible event based sistem instead of messages to book keep vessels locations
var Location = ["Corvo",
"Faial"
];
// Buffers array to Gares, until we change the logic of passenger dispatcher
var gBuffers = [];
//Needed to the current logic of schedules
var gGare = [];
//Gateway Buffers, aat the end there should be n*(n-1)....
var Gare1 = new Sim.Buffer("Gare do Corvo",1000);
var Gare2 = new Sim.Buffer("Gare do Faial",1500);
//Gateway Buffers array, until we change the logic of passenger dispatcher
gBuffers[0]=Gare1;
gBuffers[1]=Gare2;
// Vessel Buffers -- at the end each vessel shoud have at least 8 buffers...or maybe and proprety array with 8 length
var Plane1 = new Sim.Buffer("Q200_1",30);
// Random variable
var random = new Random(SEED);
//Function to control the logic of passenger travel it should model the passenger decision process based on known stats
function passDispatcher (plane_BUFFER,gare_BUFFER) {
var nPassTravel = 0;
nPassTravel = Math.min(plane_BUFFER.size()-plane_BUFFER.current(),gare_BUFFER.current());
return nPassTravel;
}
//Gateways entities
var Gare = {
start: function () {
//document.write("Gare do " +this.name+" está aberta <br>");
},
onMessage: function (sender,message) {
//Receive message and schedule reply
document.write(this.time()+" - Avião está no " + this.name + "<br>");
//Empty th plane
this.getBuffer(sender.buff,sender.buff.current());
//schedule new message for take off
var newMessage = "Runway clear <br>";
this.send(newMessage,TURN_TIME,sender);
}
};
var Q200 = {
currentLocation: 0, //the location of the vessel
start: function () {
//send start message - - this logic shoud change to support diferent starting points
var aMessage = "Aterrei" + Location[this.currentLocation].name;
this.send(aMessage,0,gCorvo);
document.write(this.time()+" - Primeira aterragem no "+ Location[this.currentLocation].name + " <br>");
},
onMessage: function (sender, message) {
//receive message and procede with the take off and landing cycle
//take off
document.write(this.time()+" - "+ sender.name + "'s Runway clear <br>");
document.write(this.time()+" - Mensagem recebida, over <br>");
//boarding passengers
var passEmbarca = passDispatcher(this.buff, sender.buff);
this.putBuffer(this.buff,passEmbarca);
//Logging
document.write(this.time()+" - Avião tem " + Plane1.current()+" passageiros <br>");
document.write(this.time()+" - Avião está no ar <br>");
//Tirar passageiros da Gare
this.getBuffer(sender.buff,passEmbarca);
//landing procedure
this.currentLocation = 1 - this.currentLocation;
var aMessage = "Aterrei" + Location[this.currentLocation].name;
this.send(aMessage,FLIGHT_TIME,gGare[this.currentLocation]);
}
};
//Ii poupulates the system
var centralReservas = {
start: function () {
var nextReserv = random.exponential(LAMBDA);
this.putBuffer(gBuffers[0],1);
this.putBuffer(gBuffers[1],1);
document.write(this.time()+" - "+gBuffers[0].name+" tem "+gBuffers[0].current()+" passageiros;<br> "+gBuffers[1].name+" tem " +gBuffers[1].current()+" passageiros;<br>");
this.setTimer(nextReserv).done(this.start);
}
};
// Initiate entities, centralReservas() and entiites - important to keep the order
var Reservas = sim.addEntity(centralReservas);
var gCorvo = sim.addEntity(Gare);
var gFaial = sim.addEntity(Gare);
//Extend entities properties
gCorvo.name = "Corvo";
gFaial.name = "Faial";
gCorvo.buff = Gare1;
gFaial.buff = Gare2;
gGare[0]=gCorvo;
gGare[1]=gFaial;
// Initiate vessels and extend it's properties
var Q200_1 = sim.addEntity(Q200);
Q200_1.name ="Q200";
Q200_1.buff = Plane1;
sim.setLogger(function (str) {
document.write(str);
});
sim.simulate(SIMTIME);
}