-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tables.m
492 lines (391 loc) · 16.9 KB
/
Tables.m
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
clear;
InitBreach;
init_log();
prompt1 = "Which specification would you like to check? Choose one from (1-4): \n1. AFC-1 \n2. AFC-2\n3. AFC-3\n4. AT-1\n";
spec = input(prompt1);
prompt2 = "How many times would you like to repeat executing for each trace? Input a number (we use 10 in paper):\n";
repeat = input(prompt2);
disp('=======Please wait ...')
%=============write your specification here
spec_str = {'alw_[10, 50](abs(AF[t]-AFref[t]) < 0.1 )', ...
'alw_[10, 48.5](ev_[0,1.5](abs(AF[t] - AFref[t]) < 0.08))', ...
'alw_[10, 50] ( (not (abs(AF[t]-AFref[t]) > 0.08)) or (ev_[0, 2](abs(AF[t]-AFref[t]) < 0.08)))', ...
'alw_[0,30](not(speed[t] > 50) or ev_[1,3](RPM[t] < 3000))'};
spec_mdl = {'AFC', 'AFC', 'AFC', 'AT'};
% spec_str = {'alw_[10, 50](abs(AF[t]-AFref[t]) < 0.05 )'};
% spec_mdl = {'AFC'};
% spec = 1;
%=============write your input signals here
FC_input = [ 14.7059 67.4300 791.2254 980.1683 585.1318; ...
7.3993 72.1628 905.7348 997.9803 933.5854; ...
10.3834 74.9034 915.6351 988.5357 921.3306; ...
14.6189808085505 50.1158556033517 1054.98209294230 1063.46064413069 1073.73894107270; ...
13.1814855385962 70.4386773019822 1044.48791847337 929.973088495593 1031.92105058166; ...
13.6929220764009 64.4926146841393 1009.97204036727 928.990959644745 1070.60622354438; ...
7.3992 53.0830 936.7816 947.9905 983.4534; ...
8.90937802323736 70.7844935709767 1060.67287832049 912.094235833979 979.851554122715; ...
8.37719409821377 72.5013461604416 973.849356224043 922.240551058757 1056.05041366423; ...
10.6119979270966 72.0466625112953 1033.83506090688 938.086653435991 973.783309212779];
%FC_input = [15 60 1000 1000 1000];
AT_input = [58.2986 25.1806 29.0441 61.7091 86.2163 267.9223 319.3656 237.3309; ...
37.6272 19.0924 42.8253 48.2022 39.1988 191.5899 73.5110 125.0012; ...
61.0959 77.8802 42.3453 9.0823 86.6032 49.9384 91.3267 143.0277; ...
67.6122 28.9065 67.1808 69.5140 22.0976 82.8068 72.8130 217.0456; ...
84.4392 34.4462 78.0520 67.5332 2.1825 195.7054 125.7006 297.6972; ...
98.9872 51.4423 88.4281 58.8026 50.2945 64.9554 132.2603 243.3294; ...
94.5174 20.8935 70.9282 23.6231 38.8038 197.3738 146.2948 149.0858; ...
66.1945 77.0286 35.0218 66.2010 135.2515 273.6270 270.6980 83.3433; ...
99.3705 21.8677 10.5798 10.9697 20.6672 131.4885 145.7212 118.8903; ...
94.9304 32.7565 67.1264 43.8645 270.8877 249.8776 54.3574 280.1437];
[FC_input_num, ~] = size(FC_input);
[AT_input_num, ~] = size(AT_input);
if strcmp(spec_mdl{spec}, 'AT')
AT_init_warm;
%======d=0
claM_comp = [];
claM_sim = [];
for i = 1:AT_input_num
disp(['===============ClaM Trace #', int2str(i)]);
phi_autotrans = spec_str{spec};
input = AT_input(i, :);
d = 0;
diagnoser = d;
times = repeat;
AT.SetParam({'Throttle_u0', 'Throttle_u1', 'Throttle_u2', 'Throttle_u3', 'Brake_u0', 'Brake_u1', 'Brake_u2', 'Brake_u3'}, input);
AT.SetParam({'max_rob', 'diagnoser'}, [max_rob, d]);
init_log();
claM_start = tic;
for j = 1:times
AT.ResetSimulations();
AT.Sim(0:.01:30);
disp(['ClaM Repeatation: ', int2str(j)]);
end
simTime = toc(claM_start);
claM_sim_cost = simTime/times;
arr = read_log();
claM_comp_cost = mean(arr);
claM_comp = [claM_comp; claM_comp_cost];
claM_sim = [claM_sim; claM_sim_cost];
end
disp('====ClaM finished')
%======d=2
resM_comp = [];
resM_sim = [];
for i = 1:AT_input_num
disp(['===============ResM Trace #', int2str(i)]);
phi_autotrans = spec_str{spec};
input = AT_input(i, :);
d = 2;
diagnoser = d;
times = repeat;
AT.SetParam({'Throttle_u0', 'Throttle_u1', 'Throttle_u2', 'Throttle_u3', 'Brake_u0', 'Brake_u1', 'Brake_u2', 'Brake_u3'}, input);
AT.SetParam({'max_rob', 'diagnoser'}, [max_rob, d]);
init_log();
resM_start = tic;
for j = 1:times
AT.ResetSimulations();
AT.Sim(0:.01:30);
disp(['ResM Repeatation: ', int2str(j)]);
end
simTime = toc(resM_start);
resM_sim_cost = simTime/times;
arr = read_log();
resM_comp_cost = mean(arr);
resM_comp = [resM_comp; resM_comp_cost];
resM_sim = [resM_sim; resM_sim_cost];
end
disp('====ResM finished')
%======d=3
bCauM_comp = [];
bCauM_sim = [];
for i = 1:AT_input_num
disp(['===============BCauM Trace #', int2str(i)]);
phi_autotrans = spec_str{spec};
input = AT_input(i, :);
d = 3;
diagnoser = d;
times = repeat;
AT.SetParam({'Throttle_u0', 'Throttle_u1', 'Throttle_u2', 'Throttle_u3', 'Brake_u0', 'Brake_u1', 'Brake_u2', 'Brake_u3'}, input);
AT.SetParam({'max_rob', 'diagnoser'}, [max_rob, d]);
init_log();
bCauM_start = tic;
for j = 1:times
AT.ResetSimulations();
AT.Sim(0:.01:30);
disp(['BCauM Repeatation: ', int2str(j)]);
end
simTime = toc(bCauM_start);
bCauM_sim_cost = simTime/times;
arr = read_log();
bCauM_comp_cost = mean(arr);
bCauM_comp = [bCauM_comp; bCauM_comp_cost];
bCauM_sim = [bCauM_sim; bCauM_sim_cost];
end
disp('====BCauM finished')
%======d=4
qCauM_comp = [];
qCauM_sim = [];
for i = 1:AT_input_num
disp(['===============QCauM Trace #', int2str(i)]);
phi_autotrans = spec_str{spec};
input = AT_input(i, :);
d = 4;
diagnoser = d;
times = repeat;
AT.SetParam({'Throttle_u0', 'Throttle_u1', 'Throttle_u2', 'Throttle_u3', 'Brake_u0', 'Brake_u1', 'Brake_u2', 'Brake_u3'}, input);
AT.SetParam({'max_rob', 'diagnoser'}, [max_rob, d]);
init_log();
qCauM_start = tic;
for j = 1:times
AT.ResetSimulations();
AT.Sim(0:.01:30);
disp(['QCauM Repeatation: ', int2str(j)]);
end
simTime = toc(qCauM_start);
qCauM_sim_cost = simTime/times;
arr = read_log();
qCauM_comp_cost = mean(arr);
qCauM_comp = [qCauM_comp; qCauM_comp_cost];
qCauM_sim = [qCauM_sim; qCauM_sim_cost];
end
disp('====QCauM finished')
%======Table 2
delta_claM = (qCauM_comp - claM_comp)*100.0./claM_comp;
delta_resM = (qCauM_comp - resM_comp)*100.0./resM_comp;
delta_bCauM = (qCauM_comp - bCauM_comp)*100.0./bCauM_comp;
traces = 1:AT_input_num;
traces = traces';
table2 = table(traces, claM_comp, resM_comp, bCauM_comp, qCauM_comp, delta_claM, delta_resM, delta_bCauM);
table2.Properties.VariableNames("claM_comp") = "ClaM";
table2.Properties.VariableNames("resM_comp") = "ResM";
table2.Properties.VariableNames("bCauM_comp") = "BCauM";
table2.Properties.VariableNames("qCauM_comp") = "QCauM";
%======Table 1
claM_sim = claM_sim*1000;
resM_sim = resM_sim*1000;
bCauM_sim = bCauM_sim*1000;
qCauM_sim = qCauM_sim*1000;
claM_comp_mean = mean(claM_comp);
claM_comp_std = std(claM_comp);
claM_sim_mean = mean(claM_sim);
claM_sim_std = std(claM_sim);
resM_comp_mean = mean(resM_comp);
resM_comp_std = std(resM_comp);
resM_sim_mean = mean(resM_sim);
resM_sim_std = std(resM_sim);
bCauM_comp_mean = mean(bCauM_comp);
bCauM_comp_std = std(bCauM_comp);
bCauM_sim_mean = mean(bCauM_sim);
bCauM_sim_std = std(bCauM_sim);
qCauM_comp_mean = mean(qCauM_comp);
qCauM_comp_std = std(qCauM_comp);
qCauM_sim_mean = mean(qCauM_sim);
qCauM_sim_std = std(qCauM_sim);
table1 = table(claM_comp_mean, claM_comp_std, claM_sim_mean, claM_sim_std,...
resM_comp_mean, resM_comp_std, resM_sim_mean, resM_sim_std,...
bCauM_comp_mean, bCauM_comp_std, bCauM_sim_mean, bCauM_sim_std,...
qCauM_comp_mean, qCauM_comp_std, qCauM_sim_mean, qCauM_sim_std);
table1.Properties.VariableNames("claM_comp_mean") = "ClaM_monitor_avg";
table1.Properties.VariableNames("claM_comp_std") = "ClaM_monitor_stdv";
table1.Properties.VariableNames("claM_sim_mean") = "ClaM_total_avg";
table1.Properties.VariableNames("claM_sim_std") = "ClaM_total_stdv";
table1.Properties.VariableNames("resM_comp_mean") = "ResM_monitor_avg";
table1.Properties.VariableNames("resM_comp_std") = "ResM_monitor_stdv";
table1.Properties.VariableNames("resM_sim_mean") = "ResM_total_avg";
table1.Properties.VariableNames("resM_sim_std") = "ResM_total_stdv";
table1.Properties.VariableNames("bCauM_comp_mean") = "BCauM_monitor_avg";
table1.Properties.VariableNames("bCauM_comp_std") = "BCauM_monitor_stdv";
table1.Properties.VariableNames("bCauM_sim_mean") = "BCauM_total_avg";
table1.Properties.VariableNames("bCauM_sim_std") = "BCauM_total_stdv";
table1.Properties.VariableNames("qCauM_comp_mean") = "QCauM_monitor_avg";
table1.Properties.VariableNames("qCauM_comp_std") = "QCauM_monitor_stdv";
table1.Properties.VariableNames("qCauM_sim_mean") = "QCauM_total_avg";
table1.Properties.VariableNames("qCauM_sim_std") = "QCauM_total_stdv";
%======display
disp('==========Table1:');
disp(table1);
disp('==========Table2:');
disp(table2);
elseif strcmp(spec_mdl{spec}, 'AFC')
FC_init_warm;
%======d=0
claM_comp = [];
claM_sim = [];
for i = 1:FC_input_num
%spec = 'alw_[10, 50](abs(AF[t]-AFref[t]) < 0.1 )';
disp(['===============ClaM Trace #', int2str(i)]);
phi_AFC = spec_str{spec};
input = FC_input(i, :);
d = 0;
BrAFC.ResetSimulations();
BrAFC.SetParam({'Pedal_Angle_pulse_period', 'Pedal_Angle_pulse_amp', 'Engine_Speed_u0','Engine_Speed_u1','Engine_Speed_u2'}, input);
BrAFC.SetParam({'max_rob', 'diagnoser'}, [0.5, d]);
init_log();
times = repeat;
claM_start= tic;
for j = 1:times
BrAFC.ResetSimulations();
BrAFC.Sim(0:.1:50);
disp(['ClaM Repeatation: ', int2str(j)]);
end
simTime = toc(claM_start);
claM_sim_cost = simTime/times;
arr = read_log();
claM_comp_cost = mean(arr);
claM_comp = [claM_comp; claM_comp_cost];
claM_sim = [claM_sim; claM_sim_cost];
end
disp('====ClaM finished')
%======d=2
resM_comp = [];
resM_sim = [];
for i = 1:FC_input_num
%spec = 'alw_[10, 50](abs(AF[t]-AFref[t]) < 0.1 )';
disp(['===============ResM Trace #', int2str(i)]);
phi_AFC = spec_str{spec};
input = FC_input(i, :);
d = 2;
BrAFC.ResetSimulations();
BrAFC.SetParam({'Pedal_Angle_pulse_period', 'Pedal_Angle_pulse_amp', 'Engine_Speed_u0','Engine_Speed_u1','Engine_Speed_u2'}, input);
BrAFC.SetParam({'max_rob', 'diagnoser'}, [0.5, d]);
init_log();
times = repeat;
resM_start= tic;
for j = 1:times
BrAFC.ResetSimulations();
BrAFC.Sim(0:.1:50);
disp(['ResM Repeatation: ', int2str(j)]);
end
simTime = toc(resM_start);
resM_sim_cost = simTime/times;
arr = read_log();
resM_comp_cost = mean(arr);
resM_comp = [resM_comp; resM_comp_cost];
resM_sim = [resM_sim; resM_sim_cost];
end
disp('====ResM finished')
%======d=3
bCauM_comp = [];
bCauM_sim = [];
for i = 1:FC_input_num
disp(['===============BCauM Trace #', int2str(i)]);
%spec = 'alw_[10, 50](abs(AF[t]-AFref[t]) < 0.1 )';
phi_AFC = spec_str{spec};
input = FC_input(i, :);
d = 3;
BrAFC.ResetSimulations();
BrAFC.SetParam({'Pedal_Angle_pulse_period', 'Pedal_Angle_pulse_amp', 'Engine_Speed_u0','Engine_Speed_u1','Engine_Speed_u2'}, input);
BrAFC.SetParam({'max_rob', 'diagnoser'}, [0.5, d]);
init_log();
times = repeat;
bCauM_start= tic;
for j = 1:times
BrAFC.ResetSimulations();
BrAFC.Sim(0:.1:50);
disp(['BCauM Repeatation: ', int2str(j)]);
end
simTime = toc(bCauM_start);
bCauM_sim_cost = simTime/times;
arr = read_log();
bCauM_comp_cost = mean(arr);
bCauM_comp = [bCauM_comp; bCauM_comp_cost];
bCauM_sim = [bCauM_sim; bCauM_sim_cost];
end
disp('====BCauM finished')
%======d=4
qCauM_comp = [];
qCauM_sim = [];
for i = 1:FC_input_num
%spec = 'alw_[10, 50](abs(AF[t]-AFref[t]) < 0.1 )';
disp(['===============QCauM Trace #', int2str(i)]);
phi_AFC = spec_str{spec};
input = FC_input(i, :);
d = 4;
BrAFC.ResetSimulations();
BrAFC.SetParam({'Pedal_Angle_pulse_period', 'Pedal_Angle_pulse_amp', 'Engine_Speed_u0','Engine_Speed_u1','Engine_Speed_u2'}, input);
BrAFC.SetParam({'max_rob', 'diagnoser'}, [0.5, d]);
init_log();
times = repeat;
qCauM_start= tic;
for j = 1:times
BrAFC.ResetSimulations();
BrAFC.Sim(0:.1:50);
disp(['QCauM Repeatation: ', int2str(j)]);
end
simTime = toc(qCauM_start);
qCauM_sim_cost = simTime/times;
arr = read_log();
qCauM_comp_cost = mean(arr);
qCauM_comp = [qCauM_comp; qCauM_comp_cost];
qCauM_sim = [qCauM_sim; qCauM_sim_cost];
end
disp('====QCauM finished')
%======Table 2
delta_claM = (qCauM_comp - claM_comp)*100.0./claM_comp;
delta_resM = (qCauM_comp - resM_comp)*100.0./resM_comp;
delta_bCauM = (qCauM_comp - bCauM_comp)*100.0./bCauM_comp;
traces = 1:FC_input_num;
traces = traces';
table2 = table(traces, claM_comp, resM_comp, bCauM_comp, qCauM_comp, delta_claM, delta_resM, delta_bCauM);
table2.Properties.VariableNames("claM_comp") = "ClaM";
table2.Properties.VariableNames("resM_comp") = "ResM";
table2.Properties.VariableNames("bCauM_comp") = "BCauM";
table2.Properties.VariableNames("qCauM_comp") = "QCauM";
%======Table 1
claM_sim = claM_sim*1000;
resM_sim = resM_sim*1000;
bCauM_sim = bCauM_sim*1000;
qCauM_sim = qCauM_sim*1000;
claM_comp_mean = mean(claM_comp);
claM_comp_std = std(claM_comp);
claM_sim_mean = mean(claM_sim);
claM_sim_std = std(claM_sim);
resM_comp_mean = mean(resM_comp);
resM_comp_std = std(resM_comp);
resM_sim_mean = mean(resM_sim);
resM_sim_std = std(resM_sim);
bCauM_comp_mean = mean(bCauM_comp);
bCauM_comp_std = std(bCauM_comp);
bCauM_sim_mean = mean(bCauM_sim);
bCauM_sim_std = std(bCauM_sim);
qCauM_comp_mean = mean(qCauM_comp);
qCauM_comp_std = std(qCauM_comp);
qCauM_sim_mean = mean(qCauM_sim);
qCauM_sim_std = std(qCauM_sim);
table1 = table(claM_comp_mean, claM_comp_std, claM_sim_mean, claM_sim_std,...
resM_comp_mean, resM_comp_std, resM_sim_mean, resM_sim_std,...
bCauM_comp_mean, bCauM_comp_std, bCauM_sim_mean, bCauM_sim_std,...
qCauM_comp_mean, qCauM_comp_std, qCauM_sim_mean, qCauM_sim_std);
table1.Properties.VariableNames("claM_comp_mean") = "ClaM_monitor_avg";
table1.Properties.VariableNames("claM_comp_std") = "ClaM_monitor_stdv";
table1.Properties.VariableNames("claM_sim_mean") = "ClaM_total_avg";
table1.Properties.VariableNames("claM_sim_std") = "ClaM_total_stdv";
table1.Properties.VariableNames("resM_comp_mean") = "ResM_monitor_avg";
table1.Properties.VariableNames("resM_comp_std") = "ResM_monitor_stdv";
table1.Properties.VariableNames("resM_sim_mean") = "ResM_total_avg";
table1.Properties.VariableNames("resM_sim_std") = "ResM_total_stdv";
table1.Properties.VariableNames("bCauM_comp_mean") = "BCauM_monitor_avg";
table1.Properties.VariableNames("bCauM_comp_std") = "BCauM_monitor_stdv";
table1.Properties.VariableNames("bCauM_sim_mean") = "BCauM_total_avg";
table1.Properties.VariableNames("bCauM_sim_std") = "BCauM_total_stdv";
table1.Properties.VariableNames("qCauM_comp_mean") = "QCauM_monitor_avg";
table1.Properties.VariableNames("qCauM_comp_std") = "QCauM_monitor_stdv";
table1.Properties.VariableNames("qCauM_sim_mean") = "QCauM_total_avg";
table1.Properties.VariableNames("qCauM_sim_std") = "QCauM_total_stdv";
%======display
disp('==========Table1:');
disp(table1);
disp('==========Table2:');
disp(table2);
else
disp('Please check the specification (spec_str and spec_mdl) again ...')
end
function init_log()
fileID = fopen("log.txt", "w");
fclose(fileID);
end
function arr = read_log()
fileID = fopen('log.txt','r');
formats = '%f';
arr = fscanf(fileID,formats);
end