-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomework.xml
More file actions
435 lines (406 loc) · 14.5 KB
/
Homework.xml
File metadata and controls
435 lines (406 loc) · 14.5 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_2.dtd'>
<nta>
<declaration>/* PAMRAMETERS TO CHANGE */
/**
* 1: Just the time necessary to arrive without exceeding the maximum delay
* 2: filling all the battery every time
*/
const int chargingStrategy = 1;
/** resubmission time [min] */
const int R = 1;
/** Minimum time to pass in a station [min] */
const int minTimeInStation = 1;
/* OTHER PAMRAMETERS */
const int N_STATIONS = 7; // Number of stations
// channels
chan entry[N_STATIONS], accepted[N_STATIONS], departed[N_STATIONS];
broadcast chan rejected[N_STATIONS];
/// Railway
typedef struct {
int distance; // in km
int maxDelay; // in min
} Link;
const Link railway_small[N_STATIONS-1] = {
{8, 5}, // Milano Centrale - Milano Lambrate
{17, 5}, // Milano Lambrate - Treviglio
{13, 5}, // Treviglio - Romano
{13, 5}, // Romano - Chiari
{10, 5}, // Chiari - Rovato
{15, 5} // Rovato - Brescia
};
const Link railway[N_STATIONS-1] = railway_small;
int maxTimeForStations(){
int maxDistance = 0;
int i=0;
for(i=0; i<N_STATIONS-1; i++){
maxDistance = maxDistance >? railway[i].distance;
}
return maxDistance;
}
const int maxDistance = maxTimeForStations();
</declaration>
<template>
<name>Train</name>
<parameter>const int C0, const int Cmax, const int pV, const int pCdis, const int pCrec, const int station, const bool forward</parameter>
<declaration>const int SOCmax = Cmax; // State Of Charge [min]
const int V = pV; // Speed [Km/h]
int SOC = C0; // State Of Charge [min]
const int Cdis = pCdis; // Rate of discharge [min/min_discharge]
const int Crec = pCrec; // Rate of recharge [min/min_recharge]
int nTimesRetried = 0; // Times the train had to request the entering to the station
int[0,N_STATIONS-1] lastStation = station; // index of the last station where the train has been (or is)
bool goingForward = forward; // direction of the train
clock timeInStation; // time spent charging the battery
clock timeTravelling; // time spent discharging the battery
clock timeForResubmission; // time spent waiting for the next resubmission
int maxTimeForNextStation; // Debug info
/* HELPER FUNCTIONS */
bool isGoingForward(bool actualState){
return (lastStation == 0 ?
true :
(lastStation == (N_STATIONS-1) ?
false :
actualState)
);
}
int nextStation(){
return goingForward ? lastStation+1 : lastStation-1;
}
int nextMaxDelay(){
return (goingForward ? railway[lastStation].maxDelay : railway[lastStation-1].maxDelay);
}
int nextDistance(){
return (goingForward ? railway[lastStation].distance : railway[lastStation-1].distance);
}
int estimatedTimeTravelling(){
return nextDistance() * 60 / V;
}
int maximumTimeAvailable(){
return (estimatedTimeTravelling() + nextMaxDelay());
}
int maximumTimeRequired(){
// selecting policy of recharging [min]
int timeToRecharge = 0;
if(chargingStrategy == 1){
// Just the time necessary to arrive without exceeding the maximum delay
timeToRecharge = maximumTimeAvailable();
} else if (chargingStrategy == 2) {
// filling all the battery every time
timeToRecharge = SOCmax;
}
return timeToRecharge;
}
int calculateDischargedSOC(){
return SOC - (Cdis*(estimatedTimeTravelling() + nTimesRetried*R));
}
/**
* convert maxTimeRequired in charge required for the battery,
* take the amount of charge needed
*/
int rechargeTimeRequired(){
return ((((maximumTimeRequired()*Cdis - SOC)/Crec)+1) >? 0);
}
/* STATE FUNCTIONS */
/**
- updating lastStation
- calculate the new discharged SOC
- resetting clock
*/
void arrivedToNextStation(){
SOC = calculateDischargedSOC();
lastStation = nextStation();
goingForward = isGoingForward(goingForward);
timeInStation = 0;
}
/**
- calculate the new recharged SOC
- resetting clock
*/
void departing(){
SOC = ((SOC + Crec*rechargeTimeRequired()) <? SOCmax);
timeTravelling = 0;
maxTimeForNextStation = maximumTimeRequired(); // debug
}
// TODO: check link railways indexes</declaration>
<location id="id0" x="-44115" y="-44302">
<name x="-44183" y="-44293">charging</name>
<label kind="invariant" x="-44353" y="-44276">timeInStation <= (rechargeTimeRequired() >? minTimeInStation)</label>
</location>
<location id="id1" x="-43691" y="-44302">
<name x="-43673" y="-44327">travelling</name>
<label kind="invariant" x="-43673" y="-44310">timeTravelling <= estimatedTimeTravelling()</label>
</location>
<location id="id2" x="-44115" y="-44480">
<name x="-44208" y="-44488">waitToEnter</name>
<urgent/>
</location>
<location id="id3" x="-43690" y="-44480">
<name x="-43673" y="-44488">ArrivedOutsideOfStation</name>
<urgent/>
</location>
<location id="id4" x="-43690" y="-44149">
<name x="-43724" y="-44157">Init</name>
<urgent/>
</location>
<location id="id5" x="-44115" y="-44667">
<name x="-44148" y="-44718">askToEnter</name>
<label kind="invariant" x="-44191" y="-44701">timeForResubmission <= R</label>
</location>
<init ref="id4"/>
<transition>
<source ref="id4"/>
<target ref="id1"/>
<label kind="assignment" x="-43681" y="-44259">timeInStation = 0,
timeTravelling = 0,
goingForward = isGoingForward(goingForward),
nTimesRetried = 0</label>
</transition>
<transition>
<source ref="id2"/>
<target ref="id5"/>
<label kind="synchronisation" x="-44055" y="-44608">rejected[nextStation()]?</label>
<label kind="assignment" x="-44055" y="-44591">timeForResubmission = 0,
nTimesRetried++</label>
<nail x="-44063" y="-44583"/>
</transition>
<transition>
<source ref="id3"/>
<target ref="id2"/>
<label kind="synchronisation" x="-44055" y="-44480">entry[nextStation()]!</label>
<label kind="assignment" x="-44055" y="-44463">nTimesRetried = 0</label>
<nail x="-43979" y="-44480"/>
</transition>
<transition>
<source ref="id0"/>
<target ref="id1"/>
<label kind="guard" x="-44098" y="-44302">timeInStation >= (rechargeTimeRequired() >? minTimeInStation)</label>
<label kind="synchronisation" x="-43961" y="-44319">departed[lastStation]!</label>
<label kind="assignment" x="-43936" y="-44336">departing()</label>
</transition>
<transition>
<source ref="id2"/>
<target ref="id0"/>
<label kind="synchronisation" x="-44268" y="-44404">accepted[nextStation()]?</label>
<label kind="assignment" x="-44260" y="-44387">arrivedToNextStation()</label>
</transition>
<transition>
<source ref="id1"/>
<target ref="id3"/>
<label kind="guard" x="-43682" y="-44403">timeTravelling >= estimatedTimeTravelling()</label>
</transition>
<transition>
<source ref="id5"/>
<target ref="id2"/>
<label kind="guard" x="-44336" y="-44599">timeForResubmission >= R</label>
<label kind="synchronisation" x="-44293" y="-44582">entry[nextStation()]!</label>
<nail x="-44166" y="-44574"/>
</transition>
</template>
<template>
<name>Station</name>
<parameter>const int pIndex, const int pCapacity</parameter>
<declaration>int index = pIndex; // index that corresponds to this station in the channels array
const int capacity = pCapacity; // Max number of trains that the station can contain
int[0,capacity] N = 0; // number of trains present in a station
void trainDeparted() {
N--;
}
void trainArrived() {
N++;
}
bool canEnter() {
return N<capacity;
}</declaration>
<location id="id6" x="-204" y="-51">
<name x="-187" y="-59">TrainsWaiting</name>
<urgent/>
</location>
<location id="id7" x="-416" y="-51">
<name x="-459" y="-59">Idle</name>
</location>
<init ref="id7"/>
<transition>
<source ref="id7"/>
<target ref="id7"/>
<label kind="synchronisation" x="-578" y="-68">departed[index]?</label>
<label kind="assignment" x="-578" y="-51">trainDeparted()</label>
<nail x="-467" y="-17"/>
<nail x="-467" y="-76"/>
</transition>
<transition>
<source ref="id7"/>
<target ref="id6"/>
<label kind="synchronisation" x="-348" y="-68">entry[index]?</label>
</transition>
<transition>
<source ref="id6"/>
<target ref="id7"/>
<label kind="guard" x="-357" y="-178">canEnter()</label>
<label kind="synchronisation" x="-357" y="-161">accepted[index]!</label>
<label kind="assignment" x="-357" y="-144">trainArrived()</label>
<nail x="-204" y="-127"/>
<nail x="-416" y="-127"/>
</transition>
<transition>
<source ref="id6"/>
<target ref="id7"/>
<label kind="guard" x="-357" y="8">!canEnter()</label>
<label kind="synchronisation" x="-357" y="25">rejected[index]!</label>
<nail x="-204" y="8"/>
<nail x="-416" y="9"/>
</transition>
</template>
<system>// Train instantiations
/**
* With this model we will pass or fail the safety tests deciding the "chargingPolicy"
* in Declarations. With policy 1 we will pass, with policy 2 we will fail.
*
* Other than this, we can change everything here and the systems will adapt
* to the variation of parameters
*/
// Trains
// (int SOC0, int SOCmax, int V, int pCdis, int pCrec, int station, bool forward)
t0 = Train(60, 100, 120, 3, 6, 0, true);
t1 = Train(60, 100, 120, 3, 6, 0, true);
t2 = Train(60, 100, 120, 3, 6, 0, true);
t3 = Train(60, 100, 120, 3, 6, 4, true);
t4 = Train(60, 100, 120, 3, 6, 4, true);
// Stations
// (index, capacity)
MC = Station(0, 5); // Milano Centrale
ML = Station(1, 4); // Milano Lambrate
Tr = Station(2, 3); // Treviglio
RL = Station(3, 2); // Romano di Lombardia
Ch = Station(4, 2); // Chiari
Ro = Station(5, 3); // Rovato
Bs = Station(6, 5); // Brescia
// List one or more processes to be composed into a system.
system t0, t1, t2, t3, t4, MC, ML, Tr, RL, Ch, Ro, Bs;</system>
<queries>
<query>
<formula>A[] (t0.SOC <= t0.SOCmax and
t1.SOC <= t1.SOCmax and
t2.SOC <= t2.SOCmax and
t3.SOC <= t3.SOCmax and
t4.SOC <= t4.SOCmax)</formula>
<comment>CORRECTNESS: Check that the trains won't ever exceed SOCmax</comment>
</query>
<query>
<formula>A[] (t0.lastStation==0 imply t0.goingForward==1) and (t0.lastStation==(N_STATIONS-1) imply t0.goingForward==0) and
(t1.lastStation==0 imply t1.goingForward==1) and (t1.lastStation==(N_STATIONS-1) imply t1.goingForward==0) and
(t2.lastStation==0 imply t2.goingForward==1) and (t2.lastStation==(N_STATIONS-1) imply t2.goingForward==0) and
(t3.lastStation==0 imply t3.goingForward==1) and (t3.lastStation==(N_STATIONS-1) imply t3.goingForward==0) and
(t4.lastStation==0 imply t4.goingForward==1) and (t4.lastStation==(N_STATIONS-1) imply t4.goingForward==0)</formula>
<comment>CORRECTNESS: Check that every time a train reaches one of the two final stations, the train will continue in the right direction</comment>
</query>
<query>
<formula>A[] MC.N <= MC.capacity and
ML.N <= ML.capacity and
Tr.N <= Tr.capacity and
RL.N <= RL.capacity and
Ch.N <= Ch.capacity and
Ro.N <= Ro.capacity and
Bs.N <= Bs.capacity</formula>
<comment>CORRECTNESS: Check that every station will always have less or equal trains than the station capacity</comment>
</query>
<query>
<formula>A[] MC.N >= 0 and
ML.N >= 0 and
Tr.N >= 0 and
RL.N >= 0 and
Ch.N >= 0 and
Ro.N >= 0 and
Bs.N >= 0</formula>
<comment>CORRECTNESS: Check that every station won't ever have a negative number of trains</comment>
</query>
<query>
<formula>A[] (t0.Init imply (t0.SOC >= t0.Cdis*t0.estimatedTimeTravelling())) and
(t1.Init imply (t1.SOC >= t1.Cdis*t1.estimatedTimeTravelling())) and
(t2.Init imply (t2.SOC >= t2.Cdis*t2.estimatedTimeTravelling())) and
(t3.Init imply (t3.SOC >= t3.Cdis*t3.estimatedTimeTravelling())) and
(t4.Init imply (t4.SOC >= t4.Cdis*t4.estimatedTimeTravelling()))</formula>
<comment>CORRECTNESS: check that every train have enough initial power to reach the next station</comment>
</query>
<query>
<formula>A[] (t0.SOCmax >= (maxDistance*t0.Cdis*60/t0.V)) and
(t1.SOCmax >= (maxDistance*t1.Cdis*60/t1.V)) and
(t2.SOCmax >= (maxDistance*t2.Cdis*60/t2.V)) and
(t3.SOCmax >= (maxDistance*t3.Cdis*60/t3.V)) and
(t4.SOCmax >= (maxDistance*t4.Cdis*60/t4.V))</formula>
<comment>CORRECTNESS: Check that the train, with his maximum charge, can travel for the maximum distance when the station has tracks available (best case)</comment>
</query>
<query>
<formula></formula>
<comment></comment>
</query>
<query>
<formula>A[] t0.SOC >= 0 and
t1.SOC >= 0 and
t2.SOC >= 0 and
t3.SOC >= 0 and
t4.SOC >= 0</formula>
<comment>SAFETY: Check that the trains will always have enough charge to reach the next station </comment>
</query>
<query>
<formula>A[] (t0.waitToEnter imply (t0.timeTravelling <= t0.maximumTimeAvailable())) and
(t1.waitToEnter imply (t1.timeTravelling <= t1.maximumTimeAvailable())) and
(t2.waitToEnter imply (t2.timeTravelling <= t2.maximumTimeAvailable())) and
(t3.waitToEnter imply (t3.timeTravelling <= t3.maximumTimeAvailable())) and
(t4.waitToEnter imply (t4.timeTravelling <= t4.maximumTimeAvailable()))</formula>
<comment>SAFETY: Check that the trains will always reach the stations in time, not exceeding the maximum time available</comment>
</query>
<query>
<formula>A[] not deadlock </formula>
<comment>SAFETY: Check that the system won't deadlock</comment>
</query>
<query>
<formula></formula>
<comment></comment>
</query>
<query>
<formula>t0.charging --> t0.travelling</formula>
<comment></comment>
</query>
<query>
<formula>t0.travelling --> t0.charging</formula>
<comment></comment>
</query>
<query>
<formula>t1.charging --> t1.travelling</formula>
<comment></comment>
</query>
<query>
<formula>t1.travelling --> t1.charging</formula>
<comment></comment>
</query>
<query>
<formula>t2.charging --> t2.travelling</formula>
<comment></comment>
</query>
<query>
<formula>t2.travelling --> t2.charging</formula>
<comment></comment>
</query>
<query>
<formula>t3.charging --> t3.travelling</formula>
<comment></comment>
</query>
<query>
<formula>t3.travelling --> t3.charging</formula>
<comment></comment>
</query>
<query>
<formula>t4.charging --> t4.travelling</formula>
<comment></comment>
</query>
<query>
<formula>t4.travelling --> t4.charging</formula>
<comment></comment>
</query>
<query>
<formula></formula>
<comment></comment>
</query>
</queries>
</nta>