-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTestExactLogic.m
104 lines (78 loc) · 2.38 KB
/
TestExactLogic.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
clear all
dim=7;
c1= [logical(randi([0 1],dim,1)) ];
numOfInd1 = 3;
for i=1:numOfInd1
g1{i} = randi([0 1],dim,1);
end
E1 = [1 0 1;1 1 0];
id1 = [1;2];
c2= [logical(randi([0 1],dim,1)) ];
for i=1:2
g2{i} = logical(randi([0 1],dim,1));
end
E2 = [1 0;0 1];
id2 = [3; 4];
pZ1 = logicalPolyZonotope(c1,g1,E1,id1);
pZ2 = logicalPolyZonotope(c2,g2,E2,id2);
% manually
p1=evaluate(pZ1);
p2=evaluate(pZ2);
[~,p1Col]=size(p1);
[~,p2Col]=size(p2);
ExactXorPoints=[];
ExactAndPoints=[];
ExactNandPoints=[];
ExactOrPoints=[];
ExactAndORFormulaPoints =[] ;
tic
for i =1:p1Col
ExactXorPoints = [ExactXorPoints, xor(p1(:,i),p1(:,i))];
ExactAndPoints = [ExactAndPoints, and(p1(:,i),p1(:,i))];
ExactNandPoints =[ExactNandPoints, nand(p1(:,i),p1(:,i))];
ExactOrPoints =[ExactOrPoints, or(p1(:,i),p1(:,i))];
end
for i =1:p1Col
for j=1:p2Col
ExactAndORFormulaPoints = [ExactAndORFormulaPoints, or(p1(:,i),and(not(p1(:,i)),p2(:,j)))];
end
end
exeTime=toc;
ExactXorPoints = unique(ExactXorPoints','rows')';
ExactAndPoints = unique(ExactAndPoints','rows')';
ExactNandPoints = unique(ExactNandPoints','rows')';
ExactOrPoints = unique(ExactOrPoints','rows')';
ExactAndORFormulaPoints = unique(ExactAndORFormulaPoints','rows')';
pZ1ExactXorpZ1 = exactXor(pZ1,pZ1);
pZ1ExactAndpZ1 = exactAnd(pZ1,pZ1);
pZ1ExactOrpZ1 = exactOr(pZ1,pZ1);
pZ1ExactNandpZ1 = exactNand(pZ1,pZ1);
tempAnd= and(not(pZ1),pZ2);
%tempAnd.id = [1;2;1;2];
pZ1ExactAndORpZ2 = exactOr(pZ1,tempAnd);
pZ1XorpZ1Points= evaluate(pZ1ExactXorpZ1);
pZ1AndpZ1Points= evaluate(pZ1ExactAndpZ1);
pZ1OrpZ1Points= evaluate(pZ1ExactOrpZ1);
pZ1NandpZ1Points= evaluate(pZ1ExactNandpZ1);
pZ1ExactAndORpZ2Points= evaluate(pZ1ExactAndORpZ2);
%% checks
if isequal(ExactXorPoints,pZ1XorpZ1Points) && isequal(ExactNandPoints,pZ1NandpZ1Points) && isequal(ExactAndPoints,pZ1AndpZ1Points) && isequal(ExactAndORFormulaPoints,pZ1ExactAndORpZ2Points)
disp('All tests passed')
else
disp('Test problem(s)')
end
if ~isequal(ExactXorPoints,pZ1XorpZ1Points)
disp('Exact Xor problem')
end
if ~isequal(ExactNandPoints,pZ1NandpZ1Points)
disp('Exact Nand problem')
end
if ~isequal(ExactAndPoints,pZ1AndpZ1Points)
disp('Exact And problem')
end
if ~isequal(ExactOrPoints,pZ1OrpZ1Points)
disp('Exact Or problem')
end
if ~isequal(ExactAndORFormulaPoints,pZ1ExactAndORpZ2Points)
disp('exactOr(pZ1,and(pZ1,pZ2)) problem')
end