Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
aalanwar committed Aug 29, 2022
1 parent 2a2b3aa commit a856ac9
Show file tree
Hide file tree
Showing 28 changed files with 8,213 additions and 199 deletions.
47 changes: 9 additions & 38 deletions @logicalZonotope/encloseMany.m
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
function [Zenclose,rotMatrixInv] = encloseMany(Z,direction)
function [Zenclose] = encloseMany(Z)
% encloseMany - function for the enclosure of many zonotopes
%
% Syntax:
% [Zenclose,rotMatrixInv] = encloseMany(Z,direction)
%
% Inputs:
% Z - cell array of zonotopes to be enclosed
% direction - mean direction, in which the zonotopes to be enclosed are
% heading to
%
% Outputs:
% Zenclose - enclosing zonotope (which is an oriented rectangular hull)
% rotMatrix - rotation matrix of the oriented rectangular hull
% Zenclose - enclosing zonotope
%
%
% Example:
%
Expand All @@ -21,46 +19,19 @@
%
% See also: dirPolytope

% Author: Matthias Althoff
% Written: 15-January-2008
% Author: Amr Alanwar
% Written: 21-August-2022
% Last update: ---
% Last revision:---

%------------- BEGIN CODE --------------

%get dimension and original axis aligned orientation
dim=length(direction);
orient=eye(dim);

%replace one of the axis aligned vectors
newGen=direction/norm(direction);

%retrieve most aligned generator from orient
for iGen=1:length(orient(1,:))
h(iGen)=abs(newGen'*orient(:,iGen)/norm(orient(:,iGen)));
resp= [];
for i=1:length(Z)
resp= [resp, evaluate(Z{i})];
end
Zenclose = logicalZonotope.enclosePoints(resp);

[~,ind]=sort(h);
pickedIndices=ind(1:(end-1));

rotMatrix=[newGen,orient(:,pickedIndices)];

%obtain and collect vertices
Vsum=[];
for i=1:length(Z)
Zred=reduce(Z{i},'parallelpiped');
Vnew=vertices(Zred);
Vsum=[Vsum,Vnew];
end

%rotate vertices
rotMatrixInv=inv(rotMatrix);
Vtrans=rotMatrixInv*Vsum;
%compute enclosing interval
Itrans=interval.enclosePoints(vertices(Vtrans));
%generate zonotope
Ztrans=zonotope(Itrans);
%rotate zonotope back
Zenclose=rotMatrix*Ztrans;

%------------- END OF CODE --------------
90 changes: 90 additions & 0 deletions @logicalZonotope/enclosePoints.asv
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
function Z = enclosePoints(points,varargin)
% enclosePoints - enclose a point cloud with a zonotope
%
% Syntax:
% Z = enclosePoints(points)
%
% Inputs:
% points - matrix storing point cloud (dimension: [n,p] for p points)
%
% Outputs:
% Z - zonotope object
%
% Example:
%
% References:
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: interval, polytope

% Author: Amr Alanwar
% Written: 11-Aug-2020
% Last update: ---
% Last revision: ---

%------------- BEGIN CODE --------------
% [dim,numOfPoints] = size(points);
% cen = [];
% newpoints = [];
% for i = 1:numOfPoints
% if zeros(dim,1) ==points(:,i)
% cen =zeros(dim,1);
% else
% newpoints= [newpoints points(:,i)];
% end
% end
% newpoints=unique(newpoints','rows')';
%
% [row,cols] = size(newpoints);
% for i = 1:cols
% gen{i} = newpoints(:,i);
% end

%points=unique(points','rows')';
% cen =zeros(dim,1);
% gen = {points};
points=unique(points','rows')';
[dim,numOfPoints] = size(points);
cen = points(:,1);
if numOfPoints > 1
containsZeroFlag=0;
newPoints = [];
for i =1:numOfPoints

if points(:,i) == zeros(dim,1)
containsZeroFlag =1;
saveI = i;
break;

els
end
end

if containsZeroFlag ==1
cen = points(:,saveI);
for i =1:numOfPoints
if i==saveI

else
gen{index} = xor(cen,points(:,i));
index = index +1;
end
end
else
index =1;
for i =2:numOfPoints
gen{index} = xor(cen,points(:,i));
index = index +1;
end
end
Z =logicalZonotope(cen,gen);
else
Z =logicalZonotope(cen,{});
end
Z=unique(Z);

end

%------------- END OF CODE --------------
35 changes: 27 additions & 8 deletions @logicalZonotope/enclosePoints.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,35 @@
% gen = {points};
points=unique(points','rows')';
[dim,numOfPoints] = size(points);

cen = points(:,1);
index =1;
for i =2:numOfPoints
gen{index} = xor(cen,points(:,i));
index = index +1;
if numOfPoints > 1
containsZeroFlag=0;
newPoints = [];
for i =1:numOfPoints
if points(:,i) == zeros(dim,1)
containsZeroFlag =1;
else
newPoints =[newPoints points(:,i)];
end
end

if containsZeroFlag ==1
cen = zeros(dim,1);
for i =1:numOfPoints-1
gen{i} =newPoints(:,i);
end
else
index =1;
for i =2:numOfPoints
gen{index} = xor(cen,points(:,i));
index = index +1;
end
end
Z =logicalZonotope(cen,gen);
else
Z =logicalZonotope(cen,{});
end


Z =logicalZonotope(cen,gen);
Z=unique(Z);

end

Expand Down
1 change: 1 addition & 0 deletions @logicalZonotope/logicalZonotope.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
methods (Static = true)
%Z = generateRandom(varargin) % generate random zonotope
Z = enclosePoints(points,varargin) % enclose point cloud with zonotope
Z = encloseMany(Zcell)
end


Expand Down
39 changes: 23 additions & 16 deletions @logicalZonotope/mtimes.asv → @logicalZonotope/mtSum.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Z = mtimes(factor1,factor2)
function Z = mtSum(factor1,factor2)
% mtimes - Overloaded '*' operator for the multiplication of a matrix or an
% interval matrix with a zonotope
%
Expand Down Expand Up @@ -66,35 +66,42 @@
[mrows,mcols]=size(matrix);


% for k =1:mrows
% temp = 1;
% for ii =1:mcols
% temp=temp| (matrix(k,ii) & Z.c(ii) );
% end
% result.c(k,1) = temp;
% end

if ~isempty(Z.c)
for k =1:mrows
temp =0;
for ii =1:mcols
temp=or(temp,(matrix(k,ii) & Z.c(ii) ));
%temp=temp + matrix(k,ii) * Z.c(ii) ;
end
result.c(k,1) = temp;
end
else
result.c ={};
end
%result.c=matrix * Z.c;

if ~isempty(Z.G)
for i =1:length(Z.G)

[mrows,mcols]=size(matrix);
[grows,gcols]=size(Z.G);
[grows,gcols]=size(Z.G{i});

for j=1:gcols
% for j=1:gcols

for k =1:mrows
temp = 1;
temp = 0;
for ii =1:grows
temp=temp| (matrix(k,ii) & Z.G{i}(ii,j) );
%temp=temp + matrix(k,ii) * Z.G{i}(ii,1) ;
temp=or(temp,(matrix(k,ii) & Z.G{i}(ii,1) ));
end
result.G{i}(k,j) = temp;
result.G{i}(k,1) = temp;
end

end
% result.G{i} = mod(result.G{i},2);
% end
end

Z = logicalZonotope(result.c,result.G);
Z = unique(Z);
else
Z = logicalZonotope(result.c,{});
end
Expand Down
10 changes: 6 additions & 4 deletions @logicalZonotope/mtimes.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
for k =1:mrows
temp =0;
for ii =1:mcols
temp=temp| (matrix(k,ii) & Z.c(ii) );
%temp=or(temp,(matrix(k,ii) & Z.c(ii) ));
temp=temp + matrix(k,ii) * Z.c(ii) ;
end
result.c(k,1) = temp;
end
Expand All @@ -90,15 +91,16 @@
for k =1:mrows
temp = 0;
for ii =1:grows
temp=temp| (matrix(k,ii) & Z.G{i}(ii,1) );
temp=temp + matrix(k,ii) * Z.G{i}(ii,1) ;
%temp=or(temp,(matrix(k,ii) & Z.G{i}(ii,1) ));
end
result.G{i}(k,1) = temp;
end

result.G{i} = mod(result.G{i},2);
% end
end

Z = logicalZonotope(result.c,result.G);
Z = logicalZonotope(mod(result.c,2),result.G);
Z = unique(Z);
else
Z = logicalZonotope(result.c,{});
Expand Down
15 changes: 0 additions & 15 deletions @logicalZonotope/reduce.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@
% Zred=reduce(Z,'combastel',2);
% plot(Zred,[1,2],'b');
%
% References:
% [1] M. Althoff. "Reachability analysis and its application to the
% safety assessment of autonomous cars", 2010
% [2] A. Girard. "Reachability of uncertain linear systems using
% zonotopes". 2005
% [3] A. Kopetzki et al. "Methods for order reduction of zonotopes",
% CDC 2017
% [4] C. Combastel. "A state bounding observer based on zonotopes",
% ECC 2003
% [5] J. Scott et al. "Constrained zonotopes: A new tool for set-based
% estimation and fault detection", Automatica 2016
%
% Other m-files required: none
% Subfunctions: see below
% MAT-files required: none
%
% See also: none

Expand Down
Loading

0 comments on commit a856ac9

Please sign in to comment.