-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVechIntersection4cars.m
470 lines (407 loc) · 14.6 KB
/
VechIntersection4cars.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
clear all
load('cache\L.mat')
steps = 5;
VPl{1}{1} = logical(1);
VPl{1}{2} = logicalZonotope.enclosePoints(logical([0,1]));
VPl{1}{3} = logical(0);
VPl{1}{4} = logicalZonotope.enclosePoints(logical([0,1]));
VplOrig = VPl;
CFl{1}{1} = logical(1);
CFl{1}{2} = logicalZonotope.enclosePoints(logical([0,1]));
CFl{1}{3} = logical(0);
CFl{1}{4} = logicalZonotope.enclosePoints(logical([0,1]));
CFlOrig = CFl;
Ul{1} = logicalZonotope.enclosePoints(logical([0,1]));
Ul{2} = logical(0);
Ul{3} = logicalZonotope.enclosePoints(logical([0,1]));
Ul{4} = logicalZonotope.enclosePoints(logical([0,1]));
Ul{5} = logicalZonotope.enclosePoints(logical([0,1]));
Ul{6} = logical(0);
Ul{7} = logicalZonotope.enclosePoints(logical([0,1]));
Ul{8} = logicalZonotope.enclosePoints(logical([0,1]));
UlOrig = Ul;
tic
for i=1:steps
[VPl{i+1},CFl{i+1}] = vehLogicZono4(Ul,VPl{i},CFl{i});
end
execlogicZono = toc
VP1data=evaluate(VPl{steps+1}{1});
VP2data=evaluate(VPl{steps+1}{2});
VP3data=evaluate(VPl{steps+1}{3});
VP4data=evaluate(VPl{steps+1}{4});
CF1data=evaluate(CFl{steps+1}{1});
CF2data=evaluate(CFl{steps+1}{2});
CF3data=evaluate(CFl{steps+1}{3});
CF4data=evaluate(CFl{steps+1}{4});
VP1NPoints=length(VP1data);
VP2NPoints=length(VP2data);
VP3NPoints=length(VP3data);
VP4NPoints=length(VP4data);
CF1NPoints=length(CF1data);
CF2NPoints=length(CF2data);
CF3NPoints=length(CF3data);
CF4NPoints=length(CF4data);
totalPointsZono = VP1NPoints + VP2NPoints +VP3NPoints + VP4NPoints ...
+ CF1NPoints + CF2NPoints + CF3NPoints + CF4NPoints
%%----------- Poly Zonotope ---------%%
%VPl ={};
%CFl ={};
% for i =1:4
% if isa(VplOrig{1}{i},'logicalZonotope')
% VPl{1}{i}= logicalPolyZonotope(VPl{1}{i}.c,VPl{1}{i}.G,eye(length(VPl{1}{i}.G)),i);
% elseif VplOrig{1}{i}== logical(0)
% VPl{1}{i}= logical(0);
% else
% VPl{1}{i}= logical(1);
% end
% end
%
% for i =1:4
% if isa(CFlOrig{1}{i},'logicalZonotope')
% CFl{1}{i}= logicalPolyZonotope(CFl{1}{i}.c,CFl{1}{i}.G,eye(length(CFl{1}{i}.G)),i+4);
% elseif CFlOrig{1}{i}== logical(0)
% CFl{1}{i}= logical(0);
% else
% CFl{1}{i}= logical(1);
% end
% end
%
% for i =1:8
% if isa(UlOrig{i},'logicalZonotope')
% Ul{i}= logicalPolyZonotope(Ul{i}.c,Ul{i}.G,eye(length(Ul{i}.G)),i+8);
% elseif UlOrig{i}== logical(0)
% Ul{i}= logical(0);
% else
% Ul{i}= logical(1);
% end
% end
%
%
% tic
% for i=1:steps
% [VPl{i+1},CFl{i+1}] = vehLogicPolyZono4(Ul,VPl{i},CFl{i});
%
% % CFl{i+1}{1}=rmZeroGens(CFl{i+1}{1});
% % CFl{i+1}{2}=rmZeroGens(CFl{i+1}{2});
% % VPl{i+1}{1}=rmZeroGens(VPl{i+1}{1});
% % VPl{i+1}{2}=rmZeroGens(VPl{i+1}{2});
% end
% execlogicPolyZono = toc
%
%
% VP1PZdata=evaluate(VPl{steps+1}{1});
% VP2PZdata=evaluate(VPl{steps+1}{2});
% VP3PZdata=evaluate(VPl{steps+1}{3});
% VP4PZdata=evaluate(VPl{steps+1}{4});
% CF1PZdata=evaluate(CFl{steps+1}{1});
% CF2PZdata=evaluate(CFl{steps+1}{2});
% CF3PZdata=evaluate(CFl{steps+1}{3});
% CF4PZdata=evaluate(CFl{steps+1}{4});
%
% VP1PZNPoints=length(VP1PZdata);
% VP2PZNPoints=length(VP2PZdata);
% VP3PZNPoints=length(VP3PZdata);
% VP4PZNPoints=length(VP4PZdata);
% CF1PZNPoints=length(CF1PZdata);
% CF2PZNPoints=length(CF2PZdata);
% CF3PZNPoints=length(CF3PZdata);
% CF4PZNPoints=length(CF4PZdata);
%
% totalPointsPZ = VP1PZNPoints + VP2PZNPoints + CF1PZNPoints + CF2PZNPoints ...
% +VP3PZNPoints + VP4PZNPoints + CF3PZNPoints + CF4PZNPoints
%%-----------Exact Poly Zonotope ---------%%
%VPl ={};
%CFl ={};
for i =1:4
if isa(VplOrig{1}{i},'logicalZonotope')
VPl{1}{i}= logicalPolyZonotope(VPl{1}{i}.c,VPl{1}{i}.G,eye(length(VPl{1}{i}.G)),i);
elseif VplOrig{1}{i}== logical(0)
VPl{1}{i}= logical(0);
else
VPl{1}{i}= logical(1);
end
end
for i =1:4
if isa(CFlOrig{1}{i},'logicalZonotope')
CFl{1}{i}= logicalPolyZonotope(CFl{1}{i}.c,CFl{1}{i}.G,eye(length(CFl{1}{i}.G)),i+4);
elseif CFlOrig{1}{i}== logical(0)
CFl{1}{i}= logical(0);
else
CFl{1}{i}= logical(1);
end
end
for i =1:8
if isa(UlOrig{i},'logicalZonotope')
Ul{i}= logicalPolyZonotope(Ul{i}.c,Ul{i}.G,eye(length(Ul{i}.G)),i+8);
elseif UlOrig{i}== logical(0)
Ul{i}= logical(0);
else
Ul{i}= logical(1);
end
end
tic
for i=1:steps
[VPl{i+1},CFl{i+1}] = vehLogicExactPolyZono4(Ul,VPl{i},CFl{i});
% CFl{i+1}{1}=rmZeroGens(CFl{i+1}{1});
% CFl{i+1}{2}=rmZeroGens(CFl{i+1}{2});
% VPl{i+1}{1}=rmZeroGens(VPl{i+1}{1});
% VPl{i+1}{2}=rmZeroGens(VPl{i+1}{2});
end
execlogicExactPolyZono = toc
VP1PZdata=evaluate(VPl{steps+1}{1});
VP2PZdata=evaluate(VPl{steps+1}{2});
VP3PZdata=evaluate(VPl{steps+1}{3});
VP4PZdata=evaluate(VPl{steps+1}{4});
CF1PZdata=evaluate(CFl{steps+1}{1});
CF2PZdata=evaluate(CFl{steps+1}{2});
CF3PZdata=evaluate(CFl{steps+1}{3});
CF4PZdata=evaluate(CFl{steps+1}{4});
VP1PZNPoints=length(VP1PZdata);
VP2PZNPoints=length(VP2PZdata);
VP3PZNPoints=length(VP3PZdata);
VP4PZNPoints=length(VP4PZdata);
CF1PZNPoints=length(CF1PZdata);
CF2PZNPoints=length(CF2PZdata);
CF3PZNPoints=length(CF3PZdata);
CF4PZNPoints=length(CF4PZdata);
totalExactPointsPZ = VP1PZNPoints + VP2PZNPoints + CF1PZNPoints + CF2PZNPoints ...
+VP3PZNPoints + VP4PZNPoints + CF3PZNPoints + CF4PZNPoints
%%----------- BCN ---------%%
for i =1:4
if isa(VplOrig{1}{i},'logicalZonotope')
VPl{1}{i}= [[0;1],[1;0]];
elseif VplOrig{1}{i}== logical(0)
VPl{1}{i}= [0;1];
else
VPl{1}{i}= [1;0];
end
end
for i =1:4
if isa(CFlOrig{1}{i},'logicalZonotope')
CFl{1}{i}= [[0;1],[1;0]];
elseif CFlOrig{1}{i}== logical(0)
CFl{1}{i}= [0;1];
else
CFl{1}{i}= [1;0];
end
end
for i =1:8
if isa(UlOrig{i},'logicalZonotope')
Ul{i}= [[0;1],[1;0]];
elseif UlOrig{i}== logical(0)
Ul{i}= [0;1];
else
Ul{i}= [1;0];
end
end
tic
xpoints{1}= [];
for i1=1:length(VPl{1}{1}(1,:))
for i2=1:length(VPl{1}{2}(1,:))
for i3=1:length(VPl{1}{3}(1,:))
for i4=1:length(VPl{1}{4}(1,:))
for j1 = 1:length(CFl{1}{1}(1,:))
for j2 = 1:length(CFl{1}{2}(1,:))
for j3 = 1:length(CFl{1}{3}(1,:))
for j4 = 1:length(CFl{1}{4}(1,:))
xVP =semiKron(VPl{1}{1}(:,i1),semiKron(VPl{1}{2}(:,i2), semiKron(VPl{1}{3}(:,i3),VPl{1}{4}(:,i4))));
xCF =semiKron(CFl{1}{1}(:,j1),semiKron(CFl{1}{2}(:,j2), semiKron(CFl{1}{3}(:,j3),CFl{1}{4}(:,j4))));
xpoints{1} = [ xpoints{1} semiKron(xVP,xCF)];
end
end
end
end
end
end
end
end
for s = 1:steps
xpoints{s+1} = [];
for i=1:length(xpoints{s}(1,:))
for j=1:length(Ul{1}(1,:))
for j2 = 1:length(Ul{2}(1,:))
for j3=1:length(Ul{3}(1,:))
for j4 = 1:length(Ul{4}(1,:))
for j5=1:length(Ul{5}(1,:))
for j6 = 1:length(Ul{6}(1,:))
for j7=1:length(Ul{7}(1,:))
for j8 = 1:length(Ul{8}(1,:))
usemi = semiKron(Ul{1}(:,j),semiKron(Ul{2}(:,j2),semiKron(Ul{3}(:,j3),Ul{4}(:,j4))));
newx = semiKron(semiKron(Lcomp,usemi),xpoints{s}(:,i));
xpoints{s+1} = [ xpoints{s+1} newx];
end
end
end
end
end
end
end
end
end
xpoints{s+1} = unique(xpoints{s+1}','rows')';
end
execBCN = toc
%%----------- BDD ---------%%
for i =1:4
if isa(VplOrig{1}{i},'logicalZonotope')
VPl{1}{i}= [[0],[1]];
elseif VplOrig{1}{i}== logical(0)
VPl{1}{i}= [0];
else
VPl{1}{i}= [1];
end
end
for i =1:4
if isa(CFlOrig{1}{i},'logicalZonotope')
CFl{1}{i}= [[0],[1]];
elseif CFlOrig{1}{i}== logical(0)
CFl{1}{i}= [0];
else
CFl{1}{i}= [1];
end
end
for i =1:8
if isa(UlOrig{i},'logicalZonotope')
Ul{i}= [[0],[1]];
elseif UlOrig{i}== logical(0)
Ul{i}= [0];
else
Ul{i}= [1];
end
end
VP1points{1}=VPl{1}{1};
VP2points{1}=VPl{1}{2};
VP3points{1}=VPl{1}{3};
VP4points{1}=VPl{1}{4};
CF1points{1}=CFl{1}{1};
CF2points{1}=CFl{1}{2};
CF3points{1}=CFl{1}{3};
CF4points{1}=CFl{1}{4};
tic
for s = 1:steps
VP1points{s+1} = [];
VP2points{s+1} = [];
VP3points{s+1} = [];
VP4points{s+1} = [];
CF1points{s+1} = [];
CF2points{s+1} = [];
CF3points{s+1} = [];
CF4points{s+1} = [];
for iVP1=1:length(VP1points{s}(1,:))
for iVP2=1:length(VP2points{s}(1,:))
for iVP3=1:length(VP3points{s}(1,:))
for iVP4=1:length(VP4points{s}(1,:))
for iCF1=1:length(CF1points{s}(1,:))
for iCF2=1:length(CF2points{s}(1,:))
for iCF3=1:length(CF3points{s}(1,:))
for iCF4=1:length(CF4points{s}(1,:))
for j=1:length(Ul{1}(1,:))
for j2 = 1:length(Ul{2}(1,:))
for j3=1:length(Ul{3}(1,:))
for j4 = 1:length(Ul{4}(1,:))
for j5=1:length(Ul{5}(1,:))
for j6 = 1:length(Ul{6}(1,:))
for j7=1:length(Ul{7}(1,:))
for j8 = 1:length(Ul{8}(1,:))
Uin{1}=Ul{1}(j);
Uin{2}=Ul{2}(j2);
Uin{3}=Ul{3}(j3);
Uin{4}= Ul{4}(j4);
Uin{5}=Ul{5}(j5);
Uin{6}=Ul{6}(j6);
Uin{7}=Ul{7}(j7);
Uin{8}= Ul{8}(j8);
VPin{1}=VP1points{s}(iVP1);
VPin{2}=VP2points{s}(iVP2);
VPin{3}=VP3points{s}(iVP3);
VPin{4}=VP4points{s}(iVP4);
CFin{1}=CF1points{s}(iCF1);
CFin{2}=CF2points{s}(iCF2);
CFin{3}=CF3points{s}(iCF3);
CFin{4}=CF4points{s}(iCF4);
[VPin,CFin] = vehLogicZono4(Uin,VPin,CFin);
%[VPin,CFin] = vehLogicBDD4(Uin,VPin,CFin);
VP1points{s+1} = [ VP1points{s+1} VPin{1}];
VP2points{s+1} = [ VP2points{s+1} VPin{2}];
VP3points{s+1} = [ VP3points{s+1} VPin{3}];
VP4points{s+1} = [ VP4points{s+1} VPin{4}];
CF1points{s+1} = [ CF1points{s+1} CFin{1}];
CF2points{s+1} = [ CF2points{s+1} CFin{2}];
CF3points{s+1} = [ CF3points{s+1} CFin{3}];
CF4points{s+1} = [ CF4points{s+1} CFin{4}];
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
VP1points{s+1} = unique(VP1points{s+1}','rows')';
VP2points{s+1} = unique(VP2points{s+1}','rows')';
VP3points{s+1} = unique(VP3points{s+1}','rows')';
VP4points{s+1} = unique(VP4points{s+1}','rows')';
CF1points{s+1} = unique(CF1points{s+1}','rows')';
CF2points{s+1} = unique(CF2points{s+1}','rows')';
CF3points{s+1} = unique(CF3points{s+1}','rows')';
CF4points{s+1} = unique(CF4points{s+1}','rows')';
end
execBDD = toc
VP1BDDNPoints=length(VP1points{steps+1});
VP2BDDNPoints=length(VP2points{steps+1});
VP3BDDNPoints=length(VP3points{steps+1});
VP4BDDNPoints=length(VP4points{steps+1});
CF1BDDNPoints=length(CF1points{steps+1});
CF2BDDNPoints=length(CF2points{steps+1});
CF3BDDNPoints=length(CF3points{steps+1});
CF4BDDNPoints=length(CF4points{steps+1});
totalPointsBDD = VP1BDDNPoints + VP2BDDNPoints + CF1BDDNPoints + CF2BDDNPoints ...
+ VP3BDDNPoints + VP4BDDNPoints + CF3BDDNPoints + CF4BDDNPoints
if ~isequal(VP1PZdata,VP1points{steps+1})
disp('VP1 problem')
else
disp('VP1 success')
end
if ~isequal(VP2PZdata,VP2points{steps+1})
disp('VP2 problem')
else
disp('VP2 success')
end
if ~isequal(VP3PZdata,VP3points{steps+1})
disp('VP3 problem')
else
disp('VP3 success')
end
if ~isequal(VP4PZdata,VP4points{steps+1})
disp('VP4 problem')
else
disp('VP4 success')
end
if ~isequal(CF1PZdata,CF1points{steps+1})
disp('CF1 problem')
else
disp('CF1 success')
end
if ~isequal(CF2PZdata,CF2points{steps+1})
disp('CF2 problem')
else
disp('CF2 success')
end
if ~isequal(CF3PZdata,CF3points{steps+1})
disp('CF3 problem')
else
disp('CF3 success')
end
if ~isequal(CF4PZdata,CF4points{steps+1})
disp('CF4 problem')
else
disp('CF4 success')
end