Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
aalanwar committed Aug 12, 2022
1 parent 6b03ce0 commit 3e934de
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 200 deletions.
50 changes: 31 additions & 19 deletions @logicalZonotope/and.asv
Original file line number Diff line number Diff line change
Expand Up @@ -27,64 +27,76 @@ function Z = and(Z1,Z2,varargin)
% Last revision: ---

%------------- BEGIN CODE --------------
if(~isempty(Z1.c) & ~isempty(Z2.c))
newcen = Z1.c & Z2.c;
else
newcen =[];
end

if(~isempty(Z1.G) & ~isempty(Z2.G))
%c2 * G1
index =1;
for i=1:length(Z1.G)
newGen{index} = Z2.c & Z1.G{i};
index=index+1;
if(~isempty(Z2.c))
for i=1:length(Z1.G)
newGen{index} = Z2.c & Z1.G{i};
index=index+1;
end
end

for i=1:length(Z2.G)
newGen{index} = Z1.c & Z2.G{i};
index=index+1;
if(~isempty(Z1.c))
for i=1:length(Z2.G)
newGen{index} = Z1.c & Z2.G{i};
index=index+1;
end
end

%G1 * G1
for i=1:length(Z1.G)
[rows,cols]=size(Z1.G{i});
for k=1:length(Z2.G)
Gcon=[];
for j=1:cols
gZ1 = Z1.G{i}(:,j);
Gcon = [Gcon (gZ1 & Z2.G{k})];
newGen{index} = (gZ1 & Z2.G{k});
end
newGen{index} = Gcon;

index=index+1;
end
end

Z = logicalZonotope(newcen,newGen);
elseif(isempty(Z1.G) & isempty(Z2.G))
Z = logicalZonotope(newcen,{});

elseif (isempty(Z2.G))
%c2 * G1

index =1;
for i=1:length(Z1.G)
newGen{index} = Z2.c & Z1.G{i};
index=index+1;
newGen ={};
if(~isempty(Z2.c))
for i=1:length(Z1.G)
newGen{index} = Z2.c & Z1.G{i};
index=index+1;
end
end


Z = logicalZonotope(newcen,newGen);
elseif (isempty(Z1.G))
%c2 * G1
newGen = Z2.G;

index =length(newGen)+1;
for i=1:length(Z2.G)
newGen{index} = Z1.c & Z2.G{i};
index=index+1;
if(~isempty(Z1.c))
for i=1:length(Z2.G)
newGen{index} = Z1.c & Z2.G{i};
index=index+1;
end
end


newGen{index} = Z2.c ;


Z = logicalZonotope(newcen,newGen);


end
Z = unique(Z);
end

Expand Down
48 changes: 26 additions & 22 deletions @logicalZonotope/and.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,32 @@
% Last revision: ---

%------------- BEGIN CODE --------------
if(~isempty(Z1.c) & ~isempty(Z2.c))
newcen = Z1.c & Z2.c;
else
newcen =[];
end

if(~isempty(Z1.G) & ~isempty(Z2.G))
%c2 * G1
index =1;
for i=1:length(Z1.G)
newGen{index} = Z2.c & Z1.G{i};
index=index+1;
if(~isempty(Z2.c))
for i=1:length(Z1.G)
newGen{index} = Z2.c & Z1.G{i};
index=index+1;
end
end

for i=1:length(Z2.G)
newGen{index} = Z1.c & Z2.G{i};
index=index+1;
if(~isempty(Z1.c))
for i=1:length(Z2.G)
newGen{index} = Z1.c & Z2.G{i};
index=index+1;
end
end

%G1 * G1
for i=1:length(Z1.G)
[rows,cols]=size(Z1.G{i});
for k=1:length(Z2.G)
Gcon=[];
for j=1:cols
gZ1 = Z1.G{i}(:,j);
Gcon = [Gcon (gZ1 & Z2.G{k})];
end
newGen{index} = Gcon;
newGen{index} = (Z1.G{i} & Z2.G{k});
index=index+1;
end
end
Expand All @@ -64,24 +65,27 @@
%c2 * G1

index =1;
for i=1:length(Z1.G)
newGen{index} = Z2.c & Z1.G{i};
index=index+1;
newGen ={};
if(~isempty(Z2.c))
for i=1:length(Z1.G)
newGen{index} = Z2.c & Z1.G{i};
index=index+1;
end
end


Z = logicalZonotope(newcen,newGen);
elseif (isempty(Z1.G))
%c2 * G1
newGen = Z2.G;

index =length(newGen)+1;
for i=1:length(Z2.G)
newGen{index} = Z1.c & Z2.G{i};
index=index+1;
if(~isempty(Z1.c))
for i=1:length(Z2.G)
newGen{index} = Z1.c & Z2.G{i};
index=index+1;
end
end


newGen{index} = Z2.c ;


Expand Down
13 changes: 10 additions & 3 deletions @logicalZonotope/enclosePoints.asv
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,24 @@ function Z = enclosePoints(points,varargin)

%------------- BEGIN CODE --------------
[dim,numOfPoints] = size(points);

cen = [];
newpoints = [];
for i = 1:numOfPoints
if zeros(dim,1) ==points(:,i)
cen =zeros(dim,1);
else
noCenFlag =1;
newpoints= [newpoints points(:,i)];
end
end
newpoints=unique(newpoints','rows')';

gen = {points};
for i = 1:numOfPoints
gen{i} = newpoints(:,i);
end

%points=unique(points','rows')';
% cen =zeros(dim,1);
% gen = {points};
Z =logicalZonotope(cen,gen);

end
Expand Down
27 changes: 22 additions & 5 deletions @logicalZonotope/enclosePoints.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,37 @@
% Last revision: ---

%------------- BEGIN CODE --------------
[dim,numOfPoints] = size(points);
% [dim,numOfPoints] = size(points);
% cen = [];
% newpoints = [];
% for i = 1:numOfPoints
% for i = 1:numOfPoints
% if zeros(dim,1) ==points(:,i)
% cen =zeros(dim,1);
% else
% newpoints= [newpoints points(:,i)];
% end
% end
%gen = {newpoints};
% 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')';
cen =zeros(dim,1);
gen = {points};
[dim,numOfPoints] = size(points);

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


Z =logicalZonotope(cen,gen);

end
Expand Down
78 changes: 78 additions & 0 deletions @logicalZonotope/evaluate.asv
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
function points = evaluate(Z1)
% and - overloads & operator, computes the intersection of two zonotopes
%
% Syntax:
% Z = not(Z1,Z2)
%
% Inputs:
% Z1 - zonotope
% Z2 - zonotope,
%
% Outputs:
% Z - zonotope object enclosing the and zonotope
%
% Example:
% zono1 = zonotope([4 2 2;1 2 0]);
% zono2 = zonotope([3 1 -1 1;3 1 2 0]);
%
% res = zono1 & zono2
%
% figure
% hold on
% plot(zono1,[1,2],'r');
% plot(zono2,[1,2],'b');
% plot(res,[1,2],'g');
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: none

% Author: Amr Alanwar
% Written: 8-Sept-2022
% Last update:
%
%
% Last revision: ---

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

if ~isempty(Z1.G)
numOfgen = length( Z1.G );



points = [];
%for o=1:numOfgen
%for k=1:numOfgen


table=truth_table(numOfgen);
[rowsTable,colsTable]=size(table);
for i =1:rowsTable

% [rowsGen,colsGen]=size(gen1);
onePoint=[ table(i,1)&Z1.G{1}];
for j=2:numOfgen
onePoint =xor( onePoint, (table(i,j)&Z1.G{j}) );
end
if ~isempty(Z1.c)
points = [ points xor(Z1.c,onePoint)];
else
points = [ points onePoint];
end
end
else
points = Z1.c;
end


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

function genBeta = computeGenBeta ()

end

%------------- END OF CODE --------------
37 changes: 3 additions & 34 deletions @logicalZonotope/evaluate.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,42 +68,11 @@
end


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

% %for o=1:numOfgen
% for k=1:numOfgen
% gen1=Z1.G{k};
% [rowsGen,colsGen]=size(gen1);
% table=truth_table(colsGen);
% [rowsTable,colsTable]=size(table);
% for i =1:rowsTable
% onePoint=[ table(i,1)&gen1(:,1)];
% for j=2:colsGen
% onePoint =[ onePoint, (table(i,j)&gen1(:,j)) ];
% end
% points = [ points onePoint];
% end
% if k ==1
% oldPoints = points;
% elseif k ==numOfgen
% points = xor(Z1.c,points);
% oldPoints = points;
% else
% points = xor(oldPoints,points);
% oldPoints = points;
% end
% end

%end

% cen = ;
% function genBeta = computeGenBeta ()
%
% operand = [ ];
%
%
% for i =1:numOfgen
% points = [ points , norLogic(operand,0&gen1{i} ) , norLogic(operand , 1& gen1{i} )];
% end
points=unique(points','rows')';
end

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

0 comments on commit 3e934de

Please sign in to comment.