Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
aalanwar committed Sep 23, 2022
1 parent a856ac9 commit 9437c8e
Show file tree
Hide file tree
Showing 45 changed files with 3,371 additions and 842 deletions.
78 changes: 78 additions & 0 deletions @logicalZonotope/cartProd.asv
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
function Z = cartProd(Z1,Z2)
% cartProd - Returns the cartesian product of two zonotopes
%
% Syntax:
% Z = cartProd(Z1,Z2)
%
% Inputs:
% Z1 - zonotope object
% Z2 - zonotope object
%
% Outputs:
% Z - zonotope object
%
% Example:
% zono1 = zonotope.generateRandom(2);
% zono2 = zonotope.generateRandom(3);
%
% zono = cartProd(zono1,zono2);
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: none

% Author: Matthias Althoff
% Written: 18-May-2011
% Last update: 27-Aug-2019
% 05-May-2020 (MW, standardized error message)
% Last revision:---

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

% first or second set is zonotope


if(~isempty(Z1.c) & ~isempty(Z2.c))
newCen = [ Z1.c;Z2.c ];
elseif (isempty(Z1.c) & isempty(Z2.c))
newCen =[];
elseif isempty(Z1.c)
newCen = Z2.c ;
elseif isempty(Z2.c)
newCen = Z1.c ;
end

if(isempty(Z1.G))
newGen = Z2.G;
elseif(isempty(Z2.G))
newGen = Z1.G;
elseif(isempty(Z2.G) & isempty(Z2.G))
newGen ={};
elseif(~isempty(Z2.G) & ~isempty(Z2.G))
g1Len = length(Z1.G);
g2Len = length(Z2.G);
sizeOfCen = length(newCen);


for i =1:g1Len
newGen{i} = [Z1.G{i};
end


index =1;
for i=g1Len+1:g1Len+g2Len
newGen{i} = Z2.G{index};
index = index +1;
end
end

Z=logicalZonotope(newCen,newGen);
Z =unique(Z);

end



%------------- END OF CODE --------------
74 changes: 33 additions & 41 deletions @logicalZonotope/cartProd.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,55 +32,47 @@
%------------- BEGIN CODE --------------

% first or second set is zonotope
if isa(Z1,'zonotope')

% different cases for different set representations
if isa(Z2,'zonotope')

c = [center(Z1);center(Z2)];
G = blkdiag(generators(Z1),generators(Z2));

Z = zonotope([c,G]);

elseif isnumeric(Z2)

c = [center(Z1);Z2];
G = [generators(Z1);zeros(size(Z2,1),size(Z1.Z,2)-1)];

Z = zonotope([c,G]);

if(~isempty(Z1.c) & ~isempty(Z2.c))
newCen = [ Z1.c;Z2.c ];
elseif (isempty(Z1.c) & isempty(Z2.c))
newCen =[];
elseif isempty(Z1.c)
newCen = Z2.c ;
elseif isempty(Z2.c)
newCen = Z1.c ;
end

elseif isa(Z2,'interval')
Z = cartProd(Z1,zonotope(Z2));
elseif isa(Z2,'conZonotope')
Z = cartProd(conZonotope(Z1),Z2);
elseif isa(Z2,'zonoBundle')
Z = cartProd(zonoBundle(Z1),Z2);
elseif isa(Z2,'mptPolytope')
Z = cartProd(mptPolytope(Z1),Z2);
elseif isa(Z2,'polyZonotope')
Z = cartProd(polyZonotope(Z1),Z2);
else
% throw error for given arguments
error(noops(Z1,Z2));
if(isempty(Z1.G))
newGen = Z2.G;
elseif(isempty(Z2.G))
newGen = Z1.G;
elseif(isempty(Z2.G) & isempty(Z2.G))
newGen ={};
elseif(~isempty(Z2.G) & ~isempty(Z2.G))
g1Len = length(Z1.G);
g2Len = length(Z2.G);
sizeOfGen1 = length(Z1.G{1});
sizeOfGen2 = length(Z2.G{1});

for i =1:g1Len
newGen{i} = [Z1.G{i};zeros(sizeOfGen2,1)];
end

else

% different cases for different set representations
if isnumeric(Z1)
index =1;
for i=g1Len+1:g1Len+g2Len
newGen{i} = [zeros(sizeOfGen1,1);Z2.G{index}];
index = index +1;
end
end

c = [Z1;center(Z2)];
G = [zeros(size(Z1,1),size(Z2.Z,2)-1);generators(Z2)];
Z = zonotope([c,G]);
Z=logicalZonotope(newCen,newGen);
Z =unique(Z);

else
% throw error for given arguments
error(noops(Z1,Z2));
end

end


end


%------------- END OF CODE --------------
59 changes: 43 additions & 16 deletions @logicalZonotope/containsPoint.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
function res = containsPoint(Z,p,varargin)
% containsPoint - determines if the point p is inside the zonotope Z1
%
% Syntax:
% Syntax:
% res = containsPoint(Z,p)
% res = containsPoint(Z,p,tolerance)
%
% Inputs:
% Z - zonotope object
% p - point specified as a vector
% tolerance - numerical tolerance up to which the point is allowed to
% tolerance - numerical tolerance up to which the point is allowed to
% outside the zonotope
%
% Outputs:
% res - boolean whether the point is inside the zonotope or not
%
% Example:
% Example:
% Z = zonotope([1;0],[1 0; 0 1]);
% p = [1;0];
% res = containsPoint(Z,p);
%
%
% plot(Z); hold on;
% scatter(p(1),p(2),16,'r');
%
Expand All @@ -29,28 +29,55 @@
% See also: ---

% Author: Niklas Kochdumper
% Written: 30-January-2018
% Written: 30-January-2018
% Last update: ---
% Last revision:---

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

% parse input arguments
if nargin == 3
tolerance = varargin{1};
points = [];
if ~isempty(Z.G)
numOfgen = length( Z.G );
L=2^numOfgen;
%T = zeros(L,N);
for i=1:L

table = de2bi(i-1,numOfgen,'left-msb');

onePoint=[ table(1,1)&Z.G{1}];

for j=2:numOfgen
onePoint =xor( onePoint, (table(1,j)&Z.G{j}) );
end
if ~isempty(Z.c)
points = [ points xor(Z.c,onePoint)];
else
points = [ points onePoint];
end


if ismember(p',points','rows')
res = true;
return;
end




end

else
tolerance = 0;
points = Z.c;
end

% generate halfspace representation if empty
if isempty(Z.halfspace)
Z = halfspace(Z);
end

%simple test: Is point inside the zonotope?
N = length(Z.halfspace.K);
inequality = (Z.halfspace.H*p - Z.halfspace.K <= tolerance * ones(N,1));
points=unique(points','rows')';

res = (all(inequality));
if ismember(p',points','rows')
res = true;
else
res = false;
end

%------------- END OF CODE --------------
78 changes: 0 additions & 78 deletions @logicalZonotope/evaluate.asv

This file was deleted.

Loading

0 comments on commit 9437c8e

Please sign in to comment.