-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreduce.m
58 lines (52 loc) · 1.23 KB
/
reduce.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
function Zred = reduce(Z)
% reduce - Reduces the number of generators of a logical zonotope
%
% Syntax:
% Zred = reduce(Z)
%
% Inputs:
% Z - zonotope object
%
% Outputs:
% Zred - reduced zonotope
%
% Example:
%
%
% See also: none
% Author: Amr Alanwar
% Written: 16-October-2022
% Last update: 16-October-2022
%
% Last revision: ---
%------------- BEGIN CODE --------------
%2 inputs
cen = Z.c;
gen = Z.G;
if ~isempty(gen)
points = evaluate(Z);
removeGen =[];
index=1;
genMat = unique(cell2mat(gen)','rows')';
gen= mat2cell(genMat,length(cen),ones(1,length(genMat(1,:))));
for i = 1:length(gen)
if gen{index} == cell2mat(gen)
break;
end
genMat=cell2mat(gen);
newgen = mat2cell(logical(setdiff(genMat', gen{index}','rows')'),length(cen),ones(1,length(gen(1,:))-1));
newZ = logicalZonotope(cen,newgen);
newPoints = evaluate(newZ);
if ismember(points',newPoints','rows')
removeGen =[removeGen i];
gen = newgen;
else
index= index +1;
end
end
Zred = logicalZonotope(cen,gen);
else
Zred = logicalZonotope(cen,{});
end
end
%------------- END OF CODE --------------