Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
aalanwar committed Mar 27, 2024
1 parent 595a862 commit cd47726
Show file tree
Hide file tree
Showing 35 changed files with 2,495 additions and 316 deletions.
143 changes: 143 additions & 0 deletions @logicalConPolyZonotope/and.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
function Z = and(Z1,Z2,varargin)
% and - overloads & operator, computes the AND of two logical poly zonotopes
%
% Syntax:
% Z = and(Z1,Z2)
%
% Inputs:
% Z1 - zonotope
% Z2 - zonotope,
%
% Outputs:
% Z - zonotope object enclosing the and zonotope
%
% Example:
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: none

% Author: Amr Alanwar
% Written: 7-Jan-2023
% Last update:
%
% HAFEZ AND CENTER WITH GENS ANDING CONSTRAIN WITH CONSTRAIN (EDAFA)
% Last revision: ---

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

if ~isa(Z1,'logicalConPolyZonotope')
Z1=logicalZonotope.enclosePoints(Z1);
Z1=logicalConPolyZonotope(Z1.c,Z1.G,eye(length(Z1.G)));
end

if ~isa(Z2,'logicalConPolyZonotope')
Z2=logicalZonotope.enclosePoints(Z2);
Z2=logicalConPolyZonotope(Z2.c,Z2.G,eye(length(Z2.G)));
end
newCen = [];
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 = [] ;
elseif isempty(Z2.c)
newCen = [] ;
end




h1=length(Z1.G);
p1=size(Z1.E,1);

h2=length(Z2.G);
p2=size(Z2.E,1);
zeroVec = logical(zeros(size(Z1.c)));
newE =[];
index =1;
newGen ={};

% there is no generators in Z2 to multiply with Z1



%c2 * G1
if(~isempty(Z2.c) && ~isempty(Z1.G))
for i=1:length(Z1.G)
vecAnd = Z2.c & Z1.G{i};
if isequal(vecAnd,zeroVec)
continue;
end
newGen{index} = vecAnd;
newE = [newE [Z1.E(:,i);zeros(p2,1)]];
index=index+1;
end
end

%c1 * G2
if(~isempty(Z1.c) && ~isempty(Z2.G))
for i=1:length(Z2.G)
vecAnd = Z1.c & Z2.G{i};
if isequal(vecAnd,zeroVec)
continue;
end
newGen{index} = vecAnd;
newE = [newE [zeros(p1,1);Z2.E(:,i)]];
index=index+1;
end
end
%G1 * G2
if(~isempty(Z1.G) && ~isempty(Z2.G))
for i=1:length(Z1.G)
for k=1:length(Z2.G)
vecAnd = (Z1.G{i} & Z2.G{k});
if isequal(vecAnd,zeroVec)
continue;
end
newGen{index} = vecAnd;
newE = [newE [Z1.E(:,i);Z2.E(:,k)]];
index=index+1;
end
end
end

% to be added % ANDing bet 2 Constrains (2 XOR check CORA paper& Code)

%cPZ = updateConstraints(Z1,Z1,Z2);% summation of constrains

if isempty(Z1.id)
newId = Z2.id;
else
newId = [Z1.id;max(Z1.id) + Z2.id];
end

% newEC = [];
% index=1;
% if(~isempty(Z1.A) && ~isempty(Z2.A))
% for i=1:length(Z1.A)
% for k=1:length(Z2.A)
% vecAnd = (Z1.A(:,i) & Z2.A(:,k));
% %if isequal(vecAnd,zeroVec)
% % continue;
% %end
% newA(:,index) = vecAnd;
% newEC = [newEC [Z1.EC(:,i);Z2.EC(:,k)]];
% index=index+1;
% end
% end
% end

newA = blkdiag(Z1.A,Z2.A);
newb = [Z1.b ; Z2.b];
newEC = blkdiag(Z1.EC,Z2.EC);
Z = logicalConPolyZonotope(newCen,newGen,newE,newA,newb,newEC,newId);
%Z = unique(Z);


end

%------------- END OF CODE --------------
79 changes: 79 additions & 0 deletions @logicalConPolyZonotope/cartProd.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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:
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: none

% Author: Amr Alanwar
% Written: 16-October-2022
% Last update:
%
% Last revision:---

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

% bring the exponent matrices to a common representation
[idCom,E1Com,E2Com] = mergeExpMatrix(Z1.id,Z2.id,Z1.E,Z2.E);

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;
newE = Z2.E;
elseif(isempty(Z2.G))
newGen = Z1.G;
newE = Z1.E;
elseif(isempty(Z1.G) && isempty(Z2.G))
newGen ={};
newE=[];
elseif(~isempty(Z1.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

index =1;
for i=g1Len+1:g1Len+g2Len
newGen{i} = [zeros(sizeOfGen1,1);Z2.G{index}];
index = index +1;
end

newE = blkdiag(E1Com,E2Com);
end

Z=logicalPolyZonotope(newCen,newGen,newE,idCom);
Z =unique(Z);

end



%------------- END OF CODE --------------
29 changes: 29 additions & 0 deletions @logicalConPolyZonotope/center.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function c = center(Z)
% center - Returns the center of a zonotope
%
% Syntax:
% c = center(Z)
%
% Inputs:
% Z - zonotope object
%
% Outputs:
% c - center of the zonotope Z
%
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: none

% Author: Amr Alanwar
% Written: 16-October-2022
% Last update: 16-October-2022
% Last revision:---

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

c = Z.c;

%------------- END OF CODE --------------
41 changes: 41 additions & 0 deletions @logicalConPolyZonotope/containsPoint.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function res = containsPoint(Z,p)
% containsPoint - determines if the point p is inside the logical poly zonotope Z1
%
% Syntax:
% res = containsPoint(Z,p)
%
% Inputs:
% Z - zonotope object
% p - point specified as a vector
%
% Outputs:
% res - boolean whether the point is inside the logical poly zonotope or not
%
%
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: ---

% Author: Amr Alanwar
% Written: 7-Jan-2023
% Last update: ---
% Last revision:---

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

% parse input arguments
points = evaluate(Z);


points=unique(points','rows')';

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

%------------- END OF CODE --------------
32 changes: 32 additions & 0 deletions @logicalConPolyZonotope/dim.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function d = dim(Z)
% dim - return dimension of zonotope
%
% Syntax:
% d = dim(Z)
%
% Inputs:
% Z - zonotope object
%
% Outputs:
% d - dimension of Z
%
% Example:
% Z = zonotope([zeros(3,1),rand(3,5)]);
% d = dim(Z)
%
% Other m-files required: center.m
% Subfunctions: none
% MAT-files required: none
%
% See also: rank.m
%
% Author: Mark Wetzlinger
% Written: 15-Sep-2019
% Last update: ---
% Last revision: ---

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

d = length(center(Z));

%------------- END OF CODE --------------
Loading

0 comments on commit cd47726

Please sign in to comment.