diff --git a/@logicalPolyZonotope/and.m b/@logicalPolyZonotope/and.m index d348241..8c28e02 100644 --- a/@logicalPolyZonotope/and.m +++ b/@logicalPolyZonotope/and.m @@ -28,14 +28,14 @@ %------------- BEGIN CODE -------------- -if ~isa(Z1,'logicalPolyZonotope') -Z1=logicalZonotope.enclosePoints(Z1); -Z1=logicalPolyZonotope(Z1.c,Z1.G,{},[]); +if ~isa(Z1,'logicalPolyZonotope') + Z1=logicalZonotope.enclosePoints(Z1); + Z1=logicalPolyZonotope(Z1.c,Z1.G,eye(length(Z1.G))); end -if ~isa(Z2,'logicalPolyZonotope') -Z2=logicalZonotope.enclosePoints(Z2); -Z2=logicalPolyZonotope(Z2.c,Z2.G,{},[]); +if ~isa(Z2,'logicalPolyZonotope') + Z2=logicalZonotope.enclosePoints(Z2); + Z2=logicalPolyZonotope(Z2.c,Z2.G,eye(length(Z2.G))); end if(~isempty(Z1.c) && ~isempty(Z2.c)) @@ -44,170 +44,20 @@ -% newG1 = Z1.GI; -% for i =1:length(Z1.G) -% newG1{i+length(Z1.GI)} = Z1.G{i}; -% end -% if isempty(Z1.E) -% newE1 = eye(size(Z1.GI,2)); -% elseif isempty(Z1.GI) -% newE1 = Z1.E; -% else -% newE1 = blkdiag(eye(size(Z1.GI,2)),Z1.E); -% end -% -% newG2 = Z2.GI; -% for i =1:length(Z2.G) -% newG2{i+length(Z2.GI)} = Z2.G{i}; -% end -% if isempty(Z2.E) -% newE2 = eye(size(Z2.GI,2)); -% elseif isempty(Z2.GI) -% newE2 = Z2.E; -% else -% newE2 = blkdiag(eye(size(Z2.GI,2)),Z2.E); -% end -% -% -% index =1; -% newE =[]; -% newGen ={}; -% zeroVec = logical(zeros(size(Z1.c))); -% if(~isempty(Z2.c) && ~isempty(newG1)) -% tempE1=newE1 ; -% zerosE2=zeros(size(newE2,1),1); -% tempE = []; -% indexE = 1; -% for i=1:length(newG1) -% vecAnd = Z2.c & newG1{i}; -% if isequal(vecAnd,zeroVec) -% continue; -% end -% newGen{index} = vecAnd; -% tempE(:,indexE) = [(tempE1(:,i));(zerosE2)]; -% index=index+1; -% indexE=indexE+1; -% end -% newE = [newE tempE]; -% end -% if(~isempty(Z1.c) && ~isempty(newG2)) -% zerosE1=zeros(size(newE1,1),1); -% tempE2=newE2 ; -% tempE = []; -% indexE = 1; -% for i=1:length(newG2) -% vecAnd= Z1.c & newG2{i}; -% if isequal(vecAnd,zeroVec) -% continue; -% end -% newGen{index} =vecAnd; -% tempE(:,indexE) = [(zerosE1);(tempE2(:,i))]; -% index=index+1; -% indexE=indexE+1; -% end -% newE = [newE tempE]; -% end -% if(~isempty(newG1) && ~isempty(newG2)) -% %G1 * G1 -% tempE1=newE1 ; -% tempE2=newE2; -% tempE = []; -% indexE = 1; -% for i=1:length(newG1) -% for k=1:length(newG2) -% vecAnd = (newG1{i} & newG2{k}); -% if isequal(vecAnd,zeroVec) -% continue; -% end -% newGen{index} = vecAnd; -% tempE(:,indexE) = [(tempE1(:,i));(tempE2(:,k))]; -% index=index+1; -% indexE=indexE+1; -% end -% end -% newE = [newE tempE]; -% end -% Z = logicalPolyZonotope(newcen,{},newGen,newE); -% Z = unique(Z); -% -% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -q1=length(Z1.GI); h1=length(Z1.G); p1=size(Z1.E,1); -q2=length(Z2.GI); h2=length(Z2.G); p2=size(Z2.E,1); -tempE1=eye(size(Z1.GI,2)) ; -tempE2=eye(size(Z2.GI,2)); zeroVec = logical(zeros(size(Z1.c))); -indexI =1; -newGenI ={}; newE =[]; index =1; newGen ={}; % there is no generators in Z2 to multiply with Z1 -if(~isempty(Z2.c) && ~isempty(Z1.GI) && isempty(Z2.GI) && isempty(Z2.G)) - for i=1:length(Z1.GI) - vecAnd = Z2.c & Z1.GI{i}; - if isequal(vecAnd,zeroVec) - continue; - end - newGenI{indexI} = vecAnd; - indexI=indexI+1; - end -elseif (~isempty(Z2.c) && ~isempty(Z1.GI)) - for i=1:length(Z1.GI) - vecAnd = Z2.c & Z1.GI{i}; - if isequal(vecAnd,zeroVec) - continue; - end - newGen{index} = vecAnd; - newE = [newE [zeros(p1,1);tempE1(:,i);zeros(p2,1);zeros(q2,1)]]; - index=index+1; - end -end - -% there is no generators in Z1 to multiply with Z2 -if(~isempty(Z1.c) && ~isempty(Z2.GI) && isempty(Z1.GI) && isempty(Z1.G)) - for i=1:length(Z2.GI) - vecAnd = Z1.c & Z2.GI{i}; - if isequal(vecAnd,zeroVec) - continue; - end - newGenI{indexI} = vecAnd; - indexI=indexI+1; - end -elseif (~isempty(Z1.c) && ~isempty(Z2.GI)) - for i=1:length(Z2.GI) - vecAnd = Z1.c & Z2.GI{i}; - if isequal(vecAnd,zeroVec) - continue; - end - newGen{index} = vecAnd; - newE = [newE [zeros(p1,1);zeros(q1,1);zeros(p2,1);tempE2(:,i)]]; - index=index+1; - end -end -if(~isempty(Z1.GI) && ~isempty(Z2.GI)) - %GI1 * GI1 - for i=1:length(Z1.GI) - for k=1:length(Z2.GI) - vecAnd = (Z1.GI{i} & Z2.GI{k}); - if isequal(vecAnd,zeroVec) - continue; - end - newGen{index} = vecAnd; - newE = [newE [zeros(p1,1);tempE1(:,i);zeros(p2,1);tempE2(:,k)]]; - index = index +1; - end - - end -end %c2 * G1 if(~isempty(Z2.c) && ~isempty(Z1.G)) @@ -217,7 +67,7 @@ continue; end newGen{index} = vecAnd; - newE = [newE [Z1.E(:,i);zeros(q1,1);zeros(p2,1);zeros(q2,1)]]; + newE = [newE [Z1.E(:,i);zeros(p2,1)]]; index=index+1; end end @@ -230,7 +80,7 @@ continue; end newGen{index} = vecAnd; - newE = [newE [zeros(p1,1);zeros(q1,1);Z2.E(:,i);zeros(q2,1)]]; + newE = [newE [zeros(p1,1);Z2.E(:,i)]]; index=index+1; end end @@ -243,40 +93,14 @@ continue; end newGen{index} = vecAnd; - newE = [newE [Z1.E(:,i);zeros(q1,1);Z2.E(:,k);zeros(q2,1)]]; + newE = [newE [Z1.E(:,i);Z2.E(:,k)]]; index=index+1; end end end -if(~isempty(Z1.GI) && ~isempty(Z2.G)) - for i=1:length(Z1.GI) - for k=1:length(Z2.G) - vecAnd = (Z1.GI{i} & Z2.G{k}); - if isequal(vecAnd,zeroVec) - continue; - end - newGen{index} = vecAnd; - newE = [newE [zeros(p1,1);tempE1(:,i);Z2.E(:,k);zeros(q2,1)]]; - index=index+1; - end - end -end -if(~isempty(Z1.G) && ~isempty(Z2.GI)) - for i=1:length(Z1.G) - for k=1:length(Z2.GI) - vecAnd = (Z1.G{i} & Z2.GI{k}); - if isequal(vecAnd,zeroVec) - continue; - end - newGen{index} = vecAnd; - newE = [newE [Z1.E(:,i);zeros(q1,1);zeros(p2,1);tempE2(:,k)]]; - index=index+1; - end - end -end -Z = logicalPolyZonotope(newcen,newGenI,newGen,newE); +Z = logicalPolyZonotope(newcen,newGen,newE); Z = unique(Z); diff --git a/@logicalPolyZonotope/andE.m b/@logicalPolyZonotope/andE.m deleted file mode 100644 index 8ed8e42..0000000 --- a/@logicalPolyZonotope/andE.m +++ /dev/null @@ -1,133 +0,0 @@ -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: -% -% -% Last revision: --- - -%------------- BEGIN CODE -------------- - -if ~isa(Z1,'logicalPolyZonotope') -Z1=logicalZonotope.enclosePoints(Z1); -Z1=logicalPolyZonotope(Z1.c,Z1.G,{},[]); -end - -if ~isa(Z2,'logicalPolyZonotope') -Z2=logicalZonotope.enclosePoints(Z2); -Z2=logicalPolyZonotope(Z2.c,Z2.G,{},[]); -end - -if(~isempty(Z1.c) && ~isempty(Z2.c)) - newcen = Z1.c & Z2.c; -end - - - -newG1 = Z1.GI; -for i =1:length(Z1.G) - newG1{i+length(Z1.GI)} = Z1.G{i}; -end -if isempty(Z1.E) - newE1 = eye(size(Z1.GI,2)); -elseif isempty(Z1.GI) - newE1 = Z1.E; -else - newE1 = blkdiag(eye(size(Z1.GI,2)),Z1.E); -end - -newG2 = Z2.GI; -for i =1:length(Z2.G) - newG2{i+length(Z2.GI)} = Z2.G{i}; -end -if isempty(Z2.E) - newE2 = eye(size(Z2.GI,2)); -elseif isempty(Z2.GI) - newE2 = Z2.E; -else - newE2 = blkdiag(eye(size(Z2.GI,2)),Z2.E); -end - - -index =1; -newE =[]; -newGen ={}; -zeroVec = logical(zeros(size(Z1.c))); -if(~isempty(Z2.c) && ~isempty(newG1)) - tempE1=newE1 ; - zerosE2=zeros(size(newE2,1),1); - tempE = []; - indexE = 1; - for i=1:length(newG1) - vecAnd = Z2.c & newG1{i}; - if isequal(vecAnd,zeroVec) - continue; - end - newGen{index} = vecAnd; - tempE(:,indexE) = [(tempE1(:,i));(zerosE2)]; - index=index+1; - indexE=indexE+1; - end - newE = [newE tempE]; -end -if(~isempty(Z1.c) && ~isempty(newG2)) - zerosE1=zeros(size(newE1,1),1); - tempE2=newE2 ; - tempE = []; - indexE = 1; - for i=1:length(newG2) - vecAnd= Z1.c & newG2{i}; - if isequal(vecAnd,zeroVec) - continue; - end - newGen{index} =vecAnd; - tempE(:,indexE) = [(zerosE1);(tempE2(:,i))]; - index=index+1; - indexE=indexE+1; - end - newE = [newE tempE]; -end -if(~isempty(newG1) && ~isempty(newG2)) - %G1 * G1 - tempE1=newE1 ; - tempE2=newE2; - tempE = []; - indexE = 1; - for i=1:length(newG1) - for k=1:length(newG2) - vecAnd = (newG1{i} & newG2{k}); - if isequal(vecAnd,zeroVec) - continue; - end - newGen{index} = vecAnd; - tempE(:,indexE) = [(tempE1(:,i));(tempE2(:,k))]; - index=index+1; - indexE=indexE+1; - end - end - newE = [newE tempE]; -end -Z = logicalPolyZonotope(newcen,{},newGen,newE); -Z = unique(Z); - -%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ No newline at end of file diff --git a/@logicalPolyZonotope/cartProd.m b/@logicalPolyZonotope/cartProd.m index 46196c5..0a265af 100644 --- a/@logicalPolyZonotope/cartProd.m +++ b/@logicalPolyZonotope/cartProd.m @@ -27,7 +27,8 @@ %------------- 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 ]; @@ -39,29 +40,6 @@ newCen = Z1.c ; end -if(isempty(Z1.GI)) - newGenI = Z2.GI; -elseif(isempty(Z2.GI)) - newGenI = Z1.GI; -elseif(isempty(Z1.GI) && isempty(Z2.GI)) - newGenI ={}; -elseif(~isempty(Z1.GI) && ~isempty(Z2.GI)) - g1Len = length(Z1.GI); - g2Len = length(Z2.GI); - sizeOfGen1 = length(Z1.GI{1}); - sizeOfGen2 = length(Z2.GI{1}); - - for i =1:g1Len - newGenI{i} = [Z1.GI{i};zeros(sizeOfGen2,1)]; - end - - - index =1; - for i=g1Len+1:g1Len+g2Len - newGenI{i} = [zeros(sizeOfGen1,1);Z2.GI{index}]; - index = index +1; - end -end if(isempty(Z1.G)) newGen = Z2.G; @@ -88,10 +66,10 @@ index = index +1; end - newE = blkdiag(Z1.E,Z2.E); + newE = blkdiag(E1Com,E2Com); end -Z=logicalPolyZonotope(newCen,newGenI,newGen,newE); +Z=logicalPolyZonotope(newCen,newGen,newE,idCom); Z =unique(Z); end diff --git a/@logicalPolyZonotope/display.m b/@logicalPolyZonotope/display.m index d60d10a..6ae21ad 100644 --- a/@logicalPolyZonotope/display.m +++ b/@logicalPolyZonotope/display.m @@ -39,13 +39,6 @@ function display(Z) disp('c: '); disp(center(Z)); -%display generators -disp('GI: '); -if ~isempty(Z.GI) - for i = 1:length(Z.GI) - disp(Z.GI{i}); - end -end disp('G: '); @@ -61,4 +54,9 @@ function display(Z) if ~isempty(Z.G) disp(Z.E); end + +disp('id: '); +if ~isempty(Z.id) +disp(Z.id); +end %------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalPolyZonotope/enclosePoints.m b/@logicalPolyZonotope/enclosePoints.m index f47848d..ee72f34 100644 --- a/@logicalPolyZonotope/enclosePoints.m +++ b/@logicalPolyZonotope/enclosePoints.m @@ -27,7 +27,7 @@ %------------- BEGIN CODE -------------- lZ=logicalZonotope.enclosePoints(points); -Z=logicalPolyZonotope(lZ.c,lZ.G,{},[]); +Z=logicalPolyZonotope(lZ.c,lZ.G,eye(length(lZ.G))); end \ No newline at end of file diff --git a/@logicalPolyZonotope/evaluate.asv b/@logicalPolyZonotope/evaluate.asv deleted file mode 100644 index c541923..0000000 --- a/@logicalPolyZonotope/evaluate.asv +++ /dev/null @@ -1,125 +0,0 @@ -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 -------------- -points = []; - - -newG = Z1.GI; -startIdx = length(Z1.GI); - -for i =1:length(Z1.G) - newG{i+startIdx} = Z1.G{i}; -end -if isempty(Z1.E) - newE = eye(size(Z1.GI,2)); -elseif isempty(Z1.GI) - newE = Z1.E; -else - newE = blkdiag(eye(size(Z1.GI,2)),Z1.E); -end - -if ~isempty(newG) - numOfalphas = size(newE,1);%size( newG,2 ); - numOfGens= size( newG,2 ); - L=2^numOfalphas; - for i=1:L - table = de2bi(i-1,numOfalphas,'left-msb'); - - multAlpha = 1; - for iErow = 1:size(newE,1) - multAlpha = multAlpha & (table(1,iErow)^newE(iErow,1) ); - end - - onePoint=[ multAlpha&newG{1}]; - for j=2:numOfGens - multAlpha = 1; - for iErow = 1:size(newE,1) - multAlpha = multAlpha & (table(1,iErow)^newE(iErow,j) ); - end - - onePoint =xor( onePoint, (multAlpha&newG{j}) ); - end - if ~isempty(Z1.c) - points = [ points xor(Z1.c,onePoint)]; - else - points = [ points onePoint]; - end - end - - points=unique(points','rows')'; -else - points=Z1.c; -end - - -% -% -% numOfgenI = length( Z1.GI ); -% L=2^numOfgen; -% -% %T = zeros(L,N); -% for i=1:L -% -% table = de2bi(i-1,numOfgen,'left-msb'); -% -% onePoint=[ table(1,1)&Z1.G{1}]; -% for j=2:numOfgen -% onePoint =xor( onePoint, (table(1,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 - - - -%end - -% function genBeta = computeGenBeta () -% -% end - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalPolyZonotope/evaluate.m b/@logicalPolyZonotope/evaluate.m index c111541..2d14d27 100644 --- a/@logicalPolyZonotope/evaluate.m +++ b/@logicalPolyZonotope/evaluate.m @@ -1,27 +1,22 @@ function points = evaluate(Z1) -% and - overloads & operator, computes the intersection of two zonotopes +% evaluate - computes the points inside Z1 % % Syntax: -% Z = not(Z1,Z2) +% points = evaluate(Z1) % % Inputs: % Z1 - zonotope -% Z2 - zonotope, % % Outputs: -% Z - zonotope object enclosing the and zonotope +% points inside the polynomial logical 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'); +% c= logical(0); +% g{1} = logical(1); +% id = [1]; +% E =[1]; +% pZ = logicalPolyZonotope(c,g,E,id); +% points = evaluate(pZ); % % Other m-files required: none % Subfunctions: none @@ -40,40 +35,27 @@ points = []; -newG = Z1.GI; -startIdx = length(Z1.GI); - -for i =1:length(Z1.G) - newG{i+startIdx} = Z1.G{i}; -end -if isempty(Z1.E) - newE = eye(size(Z1.GI,2)); -elseif isempty(Z1.GI) - newE = Z1.E; -else - newE = blkdiag(eye(size(Z1.GI,2)),Z1.E); -end -if ~isempty(newG) - numOfalphas = size(newE,1);%size( newG,2 ); - numOfGens= size( newG,2 ); +if ~isempty(Z1.G) + numOfalphas = size(Z1.E,1);%size( Z1.G,2 ); + numOfGens= size( Z1.G,2 ); L=2^numOfalphas; for i=1:L table = de2bi(i-1,numOfalphas,'left-msb'); multAlpha = 1; - for iErow = 1:size(newE,1) - multAlpha = multAlpha & (table(1,iErow)^newE(iErow,1) ); + for iErow = 1:size(Z1.E,1) + multAlpha = multAlpha & (table(1,iErow)^Z1.E(iErow,1) ); end - onePoint=[ multAlpha&newG{1}]; + onePoint=[ multAlpha&Z1.G{1}]; for j=2:numOfGens multAlpha = 1; - for iErow = 1:size(newE,1) - multAlpha = multAlpha & (table(1,iErow)^newE(iErow,j) ); + for iErow = 1:size(Z1.E,1) + multAlpha = multAlpha & (table(1,iErow)^Z1.E(iErow,j) ); end - onePoint =xor( onePoint, (multAlpha&newG{j}) ); + onePoint =xor( onePoint, (multAlpha&Z1.G{j}) ); end if ~isempty(Z1.c) points = [ points xor(Z1.c,onePoint)]; diff --git a/@logicalPolyZonotope/exactAnd.m b/@logicalPolyZonotope/exactAnd.m new file mode 100644 index 0000000..8c64713 --- /dev/null +++ b/@logicalPolyZonotope/exactAnd.m @@ -0,0 +1,142 @@ +function Z = exactAnd(Z1,Z2,varargin) +% exactAnd - overloads & operator, computes the AND of two logical poly zonotopes +% +% Syntax: +% Z = exactAnd(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: +% +% +% Last revision: --- + +%------------- BEGIN CODE -------------- + +if ~isa(Z1,'logicalPolyZonotope') + Z1=logicalZonotope.enclosePoints(Z1); + Z1=logicalPolyZonotope(Z1.c,Z1.G,eye(length(Z1.G))); +end + +if ~isa(Z2,'logicalPolyZonotope') + Z2=logicalZonotope.enclosePoints(Z2); + Z2=logicalPolyZonotope(Z2.c,Z2.G,eye(length(Z2.G))); +end + +if(~isempty(Z1.c) && ~isempty(Z2.c)) + newcen = Z1.c & Z2.c; +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))); +indexI =1; +newE =[]; +index =1; +newGen ={}; + +% bring the exponent matrices to a common representation +[idCom,E1Com,E2Com] = mergeExpMatrix(Z1.id,Z2.id,Z1.E,Z2.E); + + +[rE1,cE1] = size(E1Com); +[rE2,cE2] = size(E2Com); + +if rE1 >rE2 + E2ComZeros = [E2Com;zeros(rE1-rE2,cE2)]; + E1ComZeros = E1Com; +else + E1ComZeros = [E1Com;zeros(rE2-rE1,cE1)]; + E2ComZeros = E2Com; +end + +E1Com = E1ComZeros; +E2Com = E2ComZeros; + + + + + +%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 E1Com(:,i)]; + 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 E2Com(:,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; + tempECom=max([E1Com(:,i),E2Com(:,k)] ,[],2); + newE = [newE tempECom]; + index=index+1; + end + end +end + + +% % and up all generators that belong to identical exponents+ +if ~isempty(newGen) + for i=1:length(newGen) + newGenVec(:,i) = newGen{i}; + end + + [newE,newGenComVec] = removeRedundantExponents(newE,newGenVec); + + for i=1:size(newGenComVec,2) + newGenComCell{i}= newGenComVec(:,i) ; + end + + Z = logicalPolyZonotope(newcen,newGenComCell,newE,idCom); +else + Z = logicalPolyZonotope(newcen,newGen,newE,idCom); +end +%Z = unique(Z); + + +end + +%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalPolyZonotope/exactNand.m b/@logicalPolyZonotope/exactNand.m new file mode 100644 index 0000000..c95c680 --- /dev/null +++ b/@logicalPolyZonotope/exactNand.m @@ -0,0 +1,36 @@ +function Z = exactNand(Z1,Z2) +% nand - computes the nand of two logical zonotopes +% +% Syntax: +% Z = nand(Z1,Z2) +% +% Inputs: +% Z1 - zonotope +% Z2 - zonotope, +% +% Outputs: +% Z - zonotope object enclosing the nand zonotope +% +% Example: +% +% 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 -------------- + + +Z=not(exactAnd(Z1,Z2)); +%Z =unique(Z); +end + +%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalPolyZonotope/exactOr.m b/@logicalPolyZonotope/exactOr.m new file mode 100644 index 0000000..09d89f7 --- /dev/null +++ b/@logicalPolyZonotope/exactOr.m @@ -0,0 +1,45 @@ +function Z = exactOr(Z1,Z2) +% and - overloads | operator, computes the or of two logical poly zonotopes +% +% Syntax: +% Z = exactOr(Z1,Z2) +% +% Inputs: +% Z1 - logical poly zonotope +% Z2 - logical poly zonotope, +% +% Outputs: +% Z - logical poly zonotope object enclosing the exact or logical poly 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: +% +% +% Last revision: --- + +%------------- BEGIN CODE -------------- +if ~isa(Z1,'logicalPolyZonotope') + Z1=logicalZonotope.enclosePoints(Z1); + Z1=logicalPolyZonotope(Z1.c,Z1.G,eye(length(Z1.G))); +end + +if ~isa(Z2,'logicalPolyZonotope') + Z2=logicalZonotope.enclosePoints(Z2); + Z2=logicalPolyZonotope(Z2.c,Z2.G,eye(length(Z2.G))); +end + +Z = exactNand(not(Z1),not(Z2)); + + +end + +%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalPolyZonotope/exactXor.m b/@logicalPolyZonotope/exactXor.m new file mode 100644 index 0000000..3fd37fa --- /dev/null +++ b/@logicalPolyZonotope/exactXor.m @@ -0,0 +1,94 @@ +function Z = exactXor(Z1,Z2) +% exactPlus - computes the XOR of two sets while preserving the +% dependencies between the two sets +% +% Syntax: +% pZ = exactXOR(pZ1,pZ2) +% +% Inputs: +% pZ1 - polyZonotope object +% pZ2 - polyZonotope object +% +% Outputs: +% pZ - polyZonotope object +% +% Example: +% pZ1 = polyZonotope([0;0],[2 1 2;0 2 2],[],[1 0 3;0 1 1]); +% pZ2 = [1 2;-1 1]*pZ1; +% +% pZ = xor(pZ1 + pZ2; +% pZ_ = exactPlus(pZ1,pZ2); +% +% figure +% subplot(1,2,1); +% plot(pZ,[1,2],'FaceColor','r','Splits',10); +% title('Minkowski Sum'); +% subplot(1,2,2); +% plot(pZ_,[1,2],'FaceColor','b'); +% title('Exact Addition'); +% +% Other m-files required: none +% Subfunctions: none +% MAT-files required: none +% +% See also: mtimes, zonotope/plus + +% Authors: Niklas Kochdumper +% Written: 26-March-2018 +% Last update: --- +% Last revision: --- + +% ------------------------------ BEGIN CODE ------------------------------- + +if isempty(Z1.G) + pZ1.G =[]; +end +if isempty(Z2.G) + pZ2.G =[]; +end + +for i=1:length(Z1.G) + pZ1.G(:,i) = Z1.G{i}; +end +for i=1:length(Z2.G) + pZ2.G(:,i) = Z2.G{i}; +end +pZ2.E = Z2.E; +pZ1.E = Z1.E; +pZ2.id = Z2.id; +pZ1.id = Z1.id; +pZ2.c = Z2.c; +pZ1.c = Z1.c; + + +% bring the exponent matrices to a common representation +[id,E1,E2] = mergeExpMatrix(pZ1.id,pZ2.id,pZ1.E,pZ2.E); + +% add up all generators that belong to identical exponents +[Enew,Gnew] = removeRedundantExponents([E1,E2],[pZ1.G,pZ2.G]); + +% assemble the properties of the resulting polynomial zonotope +%pZ = pZ1; +newGen = Gnew; +newE = Enew; + +newCen = xor(pZ1.c, pZ2.c); + + + + + + +for i=1:size(newGen,2) + newGenCell{i} = newGen(:,i) ; +end + +if isempty(newGen) + newGenCell ={}; +end + + +Z = logicalPolyZonotope(newCen,newGenCell,newE,id); +%Z = unique(Z); + +% ------------------------------ END OF CODE ------------------------------ diff --git a/@logicalPolyZonotope/generators.m b/@logicalPolyZonotope/generators.m index f17558b..5404603 100644 --- a/@logicalPolyZonotope/generators.m +++ b/@logicalPolyZonotope/generators.m @@ -25,6 +25,6 @@ %------------- BEGIN CODE -------------- -G = Z.GI; +G = Z.G; %------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalPolyZonotope/logicalPolyZonotope.m b/@logicalPolyZonotope/logicalPolyZonotope.m index d33cd52..5246b9a 100644 --- a/@logicalPolyZonotope/logicalPolyZonotope.m +++ b/@logicalPolyZonotope/logicalPolyZonotope.m @@ -4,22 +4,24 @@ % % Syntax: % obj = zonotope(c,G) -% obj = zonotope(Z) % % Inputs: % c - center vector % G - generator matrix -% Z - center vector and generator matrix Z = [c,G] +% E - Exponent matrix +% id - identifier for each factor (row vector) % % Outputs: -% obj - generated zonotope object +% obj - generated polynoamil logical zonotope object % % Example: -% c = [1;1]; -% G = [1 1 1; 1 -1 0]; -% zono = zonotope(c,G); -% plot(zono,[1,2],'r'); +% c= logical(0); +% g{1} = logical(1); +% id = [1]; +% E =[1]; +% pZ = logicalPolyZonotope(c,g,E,id); % +% % Other m-files required: none % Subfunctions: none % MAT-files required: none @@ -28,33 +30,39 @@ % Author: Amr Alanwar % Written: 16-October-2022 -% Last update: 16-October-2022 +% Last update: 12-December-2023 remove indep generator % % Last revision: --- %------------- BEGIN CODE -------------- -properties (SetAccess = protected, GetAccess = public) +properties (SetAccess = public, GetAccess = public) c = []; - GI = {}; G = {}; E = []; - + id; % identifier vector end methods function Obj = logicalPolyZonotope(varargin) - - Obj.c = varargin{1}; - Obj.GI = varargin{2}; - Obj.G = varargin{3}; - Obj.E = varargin{4}; + Obj.c = varargin{1}; + Obj.G = varargin{2}; + Obj.E = varargin{3}; + + % number of dependent factors + if length(varargin)<4 + p = size(Obj.E,1); + Obj.id = (1:p)'; % column vector + else + Obj.id = varargin{4}; end - + end +end + methods (Static = true) %Z = generateRandom(varargin) % generate random zonotope diff --git a/@logicalPolyZonotope/not.m b/@logicalPolyZonotope/not.m index d2b43cf..255f80a 100644 --- a/@logicalPolyZonotope/not.m +++ b/@logicalPolyZonotope/not.m @@ -28,10 +28,10 @@ %------------- BEGIN CODE -------------- if (~isempty(Z1.c)) [rows,cols] = size(Z1.c); - Z = logicalPolyZonotope(xor(ones(rows,1),Z1.c),Z1.GI,Z1.G,Z1.E); + Z = logicalPolyZonotope(xor(ones(rows,1),Z1.c),Z1.G,Z1.E,Z1.id); else [rows,cols] = size(Z1.G{1}); - Z = logicalPolyZonotope(logical(ones(rows,1)),Z1.GI,Z1.G,Z1.E); + Z = logicalPolyZonotope(logical(ones(rows,1)),Z1.G,Z1.E,Z1.id); end diff --git a/@logicalPolyZonotope/or.m b/@logicalPolyZonotope/or.m index ccbc47b..870f376 100644 --- a/@logicalPolyZonotope/or.m +++ b/@logicalPolyZonotope/or.m @@ -27,16 +27,17 @@ % Last revision: --- %------------- BEGIN CODE -------------- -if ~isa(Z1,'logicalPolyZonotope') -Z1=logicalZonotope.enclosePoints(Z1); -Z1=logicalPolyZonotope(Z1.c,Z1.G,{},[]); +if ~isa(Z1,'logicalPolyZonotope') + Z1=logicalZonotope.enclosePoints(Z1); + Z1=logicalPolyZonotope(Z1.c,Z1.G,eye(length(Z1.G))); end -if ~isa(Z2,'logicalPolyZonotope') -Z2=logicalZonotope.enclosePoints(Z2); -Z2=logicalPolyZonotope(Z2.c,Z2.G,{},[]); +if ~isa(Z2,'logicalPolyZonotope') + Z2=logicalZonotope.enclosePoints(Z2); + Z2=logicalPolyZonotope(Z2.c,Z2.G,eye(length(Z2.G))); end + Z = nand(not(Z1),not(Z2)); %Z = nand(nand(Z1,Z1),nand(Z2,Z2)); diff --git a/@logicalPolyZonotope/project.m b/@logicalPolyZonotope/project.m index 5f8947b..3cc108d 100644 --- a/@logicalPolyZonotope/project.m +++ b/@logicalPolyZonotope/project.m @@ -33,12 +33,9 @@ for i =1:length(Z.G) newG{i}=Z.G{i}(proj,:); end -newGI ={}; -for i =1:length(Z.GI) - newGI{i}=Z.GI{i}(proj,:); -end -pZ =logicalPolyZonotope(cen,newGI,newG,Z.E); + +pZ =logicalPolyZonotope(cen,newG,Z.E); end %------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalPolyZonotope/reduce.asv b/@logicalPolyZonotope/reduce.asv deleted file mode 100644 index be0318d..0000000 --- a/@logicalPolyZonotope/reduce.asv +++ /dev/null @@ -1,75 +0,0 @@ -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; - - -newG = Z1.GI; -startIdx = length(Z1.GI); - -for i =1:length(Z1.G) - newG{i+startIdx} = Z1.G{i}; -end -if isempty(Z1.E) - newE = eye(size(Z1.GI,2)); -elseif isempty(Z1.GI) - newE = Z1.E; -else - newE = blkdiag(eye(size(Z1.GI,2)),Z1.E); -end - - - -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(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 -------------- diff --git a/@logicalPolyZonotope/reduce.m b/@logicalPolyZonotope/reduce.m index be0318d..d024286 100644 --- a/@logicalPolyZonotope/reduce.m +++ b/@logicalPolyZonotope/reduce.m @@ -25,51 +25,65 @@ %2 inputs -cen = Z.c; -gen = Z.G; - -newG = Z1.GI; -startIdx = length(Z1.GI); -for i =1:length(Z1.G) - newG{i+startIdx} = Z1.G{i}; -end -if isempty(Z1.E) - newE = eye(size(Z1.GI,2)); -elseif isempty(Z1.GI) - newE = Z1.E; -else - newE = blkdiag(eye(size(Z1.GI,2)),Z1.E); +points = evaluate(Z); +gen = Z.G; +for i = 1:length(Z.G) + genMat=cell2mat(gen); + newGen = mat2cell(setdiff(genMat', Z.G{i}','rows')',length(Z.c),ones(1,length(Z.G)-1)); + newE = Z.E(:,[1:i-1 i+1:size(Z.E,2)]); + newPolyZono = logicalPolyZonotope(cen,newGen,newE); + newPoints = evaluate(newPolyZono); + if ismember(points',newPoints','rows') + removeGen =[removeGen i]; + gen = newGen; + end end - -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(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 +% +% newG = Z1.GI; +% startIdx = length(Z1.GI); +% +% for i =1:length(Z1.G) +% newG{i+startIdx} = Z1.G{i}; +% end +% if isempty(Z1.E) +% newE = eye(size(Z1.GI,2)); +% elseif isempty(Z1.GI) +% newE = Z1.E; +% else +% newE = blkdiag(eye(size(Z1.GI,2)),Z1.E); +% end +% +% +% +% 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(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 -------------- diff --git a/@logicalPolyZonotope/reduceOneBit.m b/@logicalPolyZonotope/reduceOneBit.m new file mode 100644 index 0000000..75fb512 --- /dev/null +++ b/@logicalPolyZonotope/reduceOneBit.m @@ -0,0 +1,63 @@ +function Zred = reduceOneBit(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 -------------- +Zred = Z; +%2 inputs +if size(Z.c,1) ==1 + %Z=rmZeroGens(Z); + pts=evaluate(Z); + if isequal(pts,[0 1]) + Zred =Z; + % %Zono=logicalZonotope.enclosePoints([0,1]); + % if length(Z.id)==1 + % %Zred=logicalPolyZonotope(0,{1},[1],Z.id); + % Zred= logicalPolyZonotope(Z.c,Z.G,Z.E,Z.id) ; + % elseif length(Z.id)==2 + % %Zred=logicalPolyZonotope(0,{1,0},eye(2),Z.id); + % Zred= logicalPolyZonotope(Z.c,Z.G,Z.E,Z.id) ; + % elseif length(Z.id)==3 + % %Zred=logicalPolyZonotope(0,{1,1,1},eye(3),Z.id); + % Zred= logicalPolyZonotope(Z.c,Z.G,Z.E,Z.id) ; + % elseif length(Z.id)==4 + % %Zred=logicalPolyZonotope(0,{1,1,1.0},eye(4),Z.id); + % Zred= logicalPolyZonotope(Z.c,Z.G,Z.E,Z.id) ; + % elseif length(Z.id)==5 + % %Zred= logicalPolyZonotope(0,{1,1,1,0,0},eye(5),Z.id) ; + % Zred= logicalPolyZonotope(Z.c,Z.G,Z.E,Z.id) ; + % elseif length(Z.id)==8 + % Zred= logicalPolyZonotope(Z.c,Z.G,Z.E,Z.id) ; + % else + % Zred=logicalPolyZonotope(0,{1},[1],Z.id); + % end + elseif isequal(pts,1) + %Zono=logicalZonotope.enclosePoints(1); + Zred=logicalPolyZonotope(1,{},[],Z.id); + elseif isequal(pts,0) + %Zono=logicalZonotope.enclosePoints(0); + Zred=logicalPolyZonotope(0,{},[],Z.id); + end +end + +end +%------------- END OF CODE -------------- diff --git a/@logicalPolyZonotope/rmZeroGens.asv b/@logicalPolyZonotope/rmZeroGens.asv deleted file mode 100644 index 0b04cb2..0000000 --- a/@logicalPolyZonotope/rmZeroGens.asv +++ /dev/null @@ -1,35 +0,0 @@ -function [Zred] = rmZeroGens(Z) -%RMZEROGENS Summary of this function goes here -% Detailed explanation goes here - -zeroVec = zeros(size(Z.c)); -newGI = {}; -index=1; -for i=1:length(Z.GI) - if Z.GI{i} ~= zeroVec - newGI{index}= Z.GI{i}; - index = index +1; - end -end - -newG = {}; -newE = []; -index=1; -for i=1:length(Z.G) - if Z.G{i} ~= zeroVec - newG{index}= Z.G{i}; - newE(:,index)=Z.E(:,index); - index = index +1; - end -end - -zeroRow = zeros(1,size(Z.E,2)); -index = 1; -for i=1:size(Z.E,1) - if Z.E(i,:) ~= zeroRow - newE(:,index)=Z.E(:,index); - end -end - - -Zred = logicalPolyZonotope(Z.c,newGI,newG,newE); \ No newline at end of file diff --git a/@logicalPolyZonotope/rmZeroGens.m b/@logicalPolyZonotope/rmZeroGens.m index 83d5a3f..601c44e 100644 --- a/@logicalPolyZonotope/rmZeroGens.m +++ b/@logicalPolyZonotope/rmZeroGens.m @@ -2,15 +2,8 @@ %RMZEROGENS Summary of this function goes here % Detailed explanation goes here -zeroVec = zeros(size(Z.c)); -newGI = {}; -index=1; -for i=1:length(Z.GI) - if ~isequal(Z.GI{i},zeroVec) - newGI{index}= Z.GI{i}; - index = index +1; - end -end +zeroVec = logical(zeros(size(Z.c))); + newG = {}; newE = []; @@ -18,7 +11,7 @@ for i=1:length(Z.G) if ~isequal(Z.G{i},zeroVec) newG{index}= Z.G{i}; - newE(:,index)=Z.E(:,index); + newE(:,index)=Z.E(:,i); index = index +1; end end @@ -28,10 +21,10 @@ index = 1; for i=1:size(newE,1) if ~isequal(newE(i,:),zeroRow) - newE2(index,:)=newE(index,:); + newE2(index,:)=newE(i,:); index = index +1; end end -Zred = logicalPolyZonotope(Z.c,newGI,newG,newE2); \ No newline at end of file +Zred = logicalPolyZonotope(Z.c,newG,newE,Z.id); \ No newline at end of file diff --git a/@logicalPolyZonotope/semiKron.m b/@logicalPolyZonotope/semiKron.m deleted file mode 100644 index d88b59e..0000000 --- a/@logicalPolyZonotope/semiKron.m +++ /dev/null @@ -1,113 +0,0 @@ -function [C] = semiKron(A,ZB) -%SEMIKRON Summary of this function goes here -% Detailed explanation goes here - -if isa(A,'logicalZonotope') && isa(ZB,'logicalZonotope') - - % res{1} =semiKron(A.c,ZB); - % index=2; - % for i =1:length(A.G) - % res{index} =semiKron(A.G{i},ZB); - % index=index+1; - % end - % C= logicalZonotope.encloseMany(res); - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - [m ,n]=size(A.c); - - [p ,q]=size(ZB.c); - - alpha = lcm(n,p); - - newCen = (kron(A.c,eye(alpha/n)) * kron(ZB.c,eye(alpha/p)) );%>1; - %newCen = mtimesAndOr(kron(A.c,eye(alpha/n)) , kron(ZB.c,eye(alpha/p))); - %newCen = mod(kron(A.c,eye(alpha/n)) * kron(ZB.c,eye(alpha/p)),2); - index =1; - newGen ={}; - for i =1:length(ZB.G) - - newGen{index} = (kron(A.c,eye(alpha/n)) * kron(ZB.G{i},eye(alpha/p)) );%>1; - %newGen{index} = mtimesAndOr(kron(A.c,eye(alpha/n)) , kron(ZB.G{i},eye(alpha/p))); - %newGen{index} = mod(kron(A.c,eye(alpha/n)) * kron(ZB.G{i},eye(alpha/p)),2); - index=index+1; - end - for i =1:length(A.G) - newGen{index} = (kron(A.G{i},eye(alpha/n)) * kron(ZB.c,eye(alpha/p)) );%>1; - %newGen{index} = mtimesAndOr(kron(A.G{i},eye(alpha/n)) , kron(ZB.c,eye(alpha/p))); - %newGen{index} = mod(kron(A.G{i},eye(alpha/n)) * kron(ZB.c,eye(alpha/p)),2); - index=index+1; - end - - for i =1:length(A.G) - for j=1:length(ZB.G) - newGen{index} = (kron(A.G{i},eye(alpha/n)) * kron(ZB.G{j},eye(alpha/p)));%>1; - %newGen{index} = mtimesAndOr(kron(A.G{i},eye(alpha/n)) , kron(ZB.G{j},eye(alpha/p))); - %newGen{index} = mod(kron(A.G{i},eye(alpha/n)) * kron(ZB.G{j},eye(alpha/p)),2); - index=index+1; - end - end - C = logicalZonotope(newCen,newGen); - %C = unique(C); -elseif ~isa(A,'logicalZonotope') - % [m ,n]=size(A); - % - % [p ,q]=size(ZB.c); - % - % alpha = lcm(n,p); - % %C = kron(eye(alpha/n),A) * tensorMultiplication(eye(alpha/p),ZB); - % C = kron(A,eye(alpha/n)) * tensorMultiplication(ZB,eye(alpha/p)); - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - [m ,n]=size(A); - - [p ,q]=size(ZB.c); - - alpha = lcm(n,p); - %C = kron(eye(alpha/n),A) * tensorMultiplication(eye(alpha/p),ZB); - - - Ccen = (kron(A,eye(alpha/n)) * kron(ZB.c,eye(alpha/p)) );%>1; - %Ccen = mtimesAndOr(kron(A,eye(alpha/n)) , kron(ZB.c,eye(alpha/p))); - %Ccen = mod(kron(A,eye(alpha/n)) * kron(ZB.c,eye(alpha/p)),2); - - for i =1:length(ZB.G) - Cgen{i} = (kron(A,eye(alpha/n)) * kron(ZB.G{i},eye(alpha/p)) );%>1; - %Cgen{i} = mtimesAndOr(kron(A,eye(alpha/n)) , kron(ZB.G{i},eye(alpha/p))); - %Cgen{i} = mod(kron(A,eye(alpha/n)) * kron(ZB.G{i},eye(alpha/p)),2); - - end - C = logicalZonotope(Ccen,Cgen); - %C = unique(C); -elseif ~isa(ZB,'logicalZonotope') - % [m ,n]=size(A); - % - % [p ,q]=size(ZB.c); - % - % alpha = lcm(n,p); - % %C = kron(eye(alpha/n),A) * tensorMultiplication(eye(alpha/p),ZB); - % C = kron(A,eye(alpha/n)) * tensorMultiplication(ZB,eye(alpha/p)); - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - [m ,n]=size(A.c); - - [p ,q]=size(ZB); - - alpha = lcm(n,p); - %C = kron(eye(alpha/n),A) * tensorMultiplication(eye(alpha/p),ZB); - - - Ccen = (kron(A.c,eye(alpha/n)) * kron(ZB,eye(alpha/p)) );%>1; - %Ccen = mtimesAndOr(kron(A,eye(alpha/n)) , kron(ZB.c,eye(alpha/p))); - %Ccen = mod(kron(A,eye(alpha/n)) * kron(ZB.c,eye(alpha/p)),2); - - for i =1:length(A.G) - Cgen{i} = (kron(A.G{i},eye(alpha/n)) * kron(ZB,eye(alpha/p)) );%>1; - %Cgen{i} = mtimesAndOr(kron(A,eye(alpha/n)) , kron(ZB.G{i},eye(alpha/p))); - %Cgen{i} = mod(kron(A,eye(alpha/n)) * kron(ZB.G{i},eye(alpha/p)),2); - - end - C = logicalZonotope(Ccen,Cgen); - %C = unique(C); - -end - - -end - diff --git a/@logicalPolyZonotope/unique.m b/@logicalPolyZonotope/unique.m index bc1eda2..5353e6e 100644 --- a/@logicalPolyZonotope/unique.m +++ b/@logicalPolyZonotope/unique.m @@ -25,10 +25,12 @@ % Last revision: --- %------------- BEGIN CODE -------------- + +Z=Z1; %independent generators -gMatI = cell2mat(Z1.GI); -gMatI = unique(gMatI','rows')'; -newGenI = mat2cell( gMatI ,size(gMatI,1),ones(1,size(gMatI,2)) ); +% gMatI = cell2mat(Z1.GI); +% gMatI = unique(gMatI','rows')'; +% newGenI = mat2cell( gMatI ,size(gMatI,1),ones(1,size(gMatI,2)) ); % %dep generators @@ -44,23 +46,10 @@ %if isequal(indexgMat,indexE) % Z = logicalPolyZonotope(Z1.c,newGenI,newGen,newE); %else - Z = logicalPolyZonotope(Z1.c,newGenI,Z1.G,Z1.E); + % Z = logicalPolyZonotope(Z1.c,newGenI,Z1.G,Z1.E,Z1.id); %end -if size(Z1.c,1) ==1 - Z=rmZeroGens(Z); - pts=evaluate(Z); - if isequal(pts,[0 1]) - %Zono=logicalZonotope.enclosePoints([0,1]); - Z=logicalPolyZonotope(0,{1},{},[]); - elseif isequal(pts,1) - %Zono=logicalZonotope.enclosePoints(1); - Z=logicalPolyZonotope(1,{},{},[]); - elseif isequal(pts,0) - %Zono=logicalZonotope.enclosePoints(0); - Z=logicalPolyZonotope(0,{},{},[]); - end -end + end diff --git a/@logicalPolyZonotope/xnor.m b/@logicalPolyZonotope/xnor.m index 5504ac2..5490efe 100644 --- a/@logicalPolyZonotope/xnor.m +++ b/@logicalPolyZonotope/xnor.m @@ -27,14 +27,17 @@ % Last revision: --- %------------- BEGIN CODE -------------- -if ~isa(Z1,'logicalPolyZonotope') -Z1=logicalPolyZonotope.enclosePoints(Z1); +if ~isa(Z1,'logicalPolyZonotope') + Z1=logicalZonotope.enclosePoints(Z1); + Z1=logicalPolyZonotope(Z1.c,Z1.G,eye(length(Z1.G))); end -if ~isa(Z2,'logicalPolyZonotope') -Z2=logicalPolyZonotope.enclosePoints(Z2); +if ~isa(Z2,'logicalPolyZonotope') + Z2=logicalZonotope.enclosePoints(Z2); + Z2=logicalPolyZonotope(Z2.c,Z2.G,eye(length(Z2.G))); end + Z = not(xor(Z1,Z2)); %Z =unique(Z); end diff --git a/@logicalPolyZonotope/xor.m b/@logicalPolyZonotope/xor.m index cbb6f19..6c6b0d9 100644 --- a/@logicalPolyZonotope/xor.m +++ b/@logicalPolyZonotope/xor.m @@ -37,6 +37,16 @@ % Last revision: --- %------------- BEGIN CODE -------------- +if ~isa(Z1,'logicalPolyZonotope') + Z1=logicalZonotope.enclosePoints(Z1); + Z1=logicalPolyZonotope(Z1.c,Z1.G,eye(length(Z1.G))); +end + +if ~isa(Z2,'logicalPolyZonotope') + Z2=logicalZonotope.enclosePoints(Z2); + Z2=logicalPolyZonotope(Z2.c,Z2.G,eye(length(Z2.G))); +end + if(~isempty(Z1.c) && ~isempty(Z2.c)) newCen = xor( Z1.c,Z2.c ); @@ -69,26 +79,15 @@ newE = blkdiag(Z1.E,Z2.E); end -if(isempty(Z1.GI)) - newGenI = Z2.GI; -elseif(isempty(Z2.GI)) - newGenI = Z1.GI; -elseif(isempty(Z1.GI) && isempty(Z2.GI)) - newGenI ={}; -elseif(~isempty(Z1.GI) && ~isempty(Z2.GI)) - g1Len = length(Z1.GI); - g2Len = length(Z2.GI); - newGenI = Z1.GI; - index =1; - for i=g1Len+1:g1Len+g2Len - newGenI{i} = Z2.GI{index}; - index = index +1; - end -end +if isempty(Z1.id) + newId = Z2.id; +else + newId = [Z1.id;max(Z1.id) + Z2.id]; +end -Z = logicalPolyZonotope(newCen,newGenI,newGen,newE); +Z = logicalPolyZonotope(newCen,newGen,newE,newId); Z = unique(Z); end diff --git a/@logicalZonotope/exactXor.m b/@logicalZonotope/exactXor.m new file mode 100644 index 0000000..d43b630 --- /dev/null +++ b/@logicalZonotope/exactXor.m @@ -0,0 +1,60 @@ +function Z = exactXor(Z,Z2,varargin) +% exactPlus - adds two zonotopes by adding all generators of common +% generator factors. Caution: The correspondance of generator factors +% has to be ensured before calling the function; this function is not a +% replacement for the Minkowski sum +% +% Syntax: +% Z = exactPlus(Z,Z2) +% +% Inputs: +% Z - zonotope object +% Z2 - zonotope object +% nrOfGens - (optional) limit on the number of generators that can be +% added exactly +% +% Outputs: +% Z - zonotope object +% +% Example: +% Z1 = zonotope([0;0],[1 2 -1; 1 -1 3]); +% Z2 = zonotope([0;0],[2 4 -1; 2 -2 3]); +% Zexact = exactXor(Z1,Z2); +% Z = Z1 + Z2; +% +% figure; hold on; +% plot(Z1); +% plot(Z2); +% plot(Zexact,[1,2],'g'); +% plot(Z,[1,2],'r--'); +% +% Other m-files required: none +% Subfunctions: none +% MAT-files required: none +% +% See also: zonotope/plus + +% Authors: Matthias Althoff +% Written: 30-August-2013 +% Last update: 06-September-2013 +% Last revision: --- + +% ------------------------------ BEGIN CODE ------------------------------- + +% number of generators +nrOfgens1 = size(Z.G,2); +nrOfgems2 = size(Z2.G,2); + +if nargin == 2 + nrOfGens = min([nrOfgens1, nrOfgems2]); +elseif nargin == 3 + nrOfGens = min([nrOfgens1, nrOfgems2, varargin{1}]); +end + +% resulting zonotope +Z.c = xor(Z.c , Z2.c); +Z.G = [xor(Z.G(:,1:nrOfGens) , Z2.G(:,1:nrOfGens)),... + Z.G(:,nrOfGens+1:end), ... + Z2.G(:,nrOfGens+1:end)]; + +% ------------------------------ END OF CODE ------------------------------ diff --git a/BoolFunctionExample.m b/BoolFunctionExample.m index bed9c34..b978bd9 100644 --- a/BoolFunctionExample.m +++ b/BoolFunctionExample.m @@ -21,7 +21,7 @@ g{j} = logical(randi([0 1],dim,1)); end Az{i} = logicalZonotope(c,g); - Apz{i} = logicalPolyZonotope(c,g,{},[]); + Apz{i} = logicalPolyZonotope(c,g,eye(length(g))); Apt{i} = evaluate(Az{i}); end @@ -32,7 +32,7 @@ g{j} = logical(randi([0 1],dim,1)); end Uz{i} = logicalZonotope(c,g); - Upz{i} = logicalPolyZonotope(c,g,{},[]); + Upz{i} = logicalPolyZonotope(c,g,eye(length(g))); pointsU{i} = evaluate(Uz{i}); end diff --git a/README.md b/README.md index 9488acf..0c1411c 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ Authors: Amr Alanwar, Frank J. Jiang, and Karl Henrik Johansson
1- Logical Zonotope: A Set Representation for the Formal Verification of Boolean Functions
Authors: Amr Alanwar, Frank J. Jiang, Samy Amin and Karl Henrik Johansson
+## +CDC 2023 talk for the +[![CDC 2023 talk](https://img.youtube.com/vi/peyTfhMxBEk/0.jpg)](https://youtu.be/peyTfhMxBEk) ## Abstract In this paper, we introduce a set representation called polynomial logical zonotopes
@@ -55,19 +58,22 @@ Zred = reduce(Z): Reduces the number of generators of a logical zonotope
``` -@article{polylogicalZonotope, +@article{alanwar2023polynomial, title={Polynomial Logical Zonotopes: A Set Representation for Reachability Analysis of Logical Systems}, - author={Alanwar, Amr and Jiang, Frank J. and Johansson, Karl Henrik}, - journal={arXiv preprint }, - year={2022} + author={Alanwar, Amr and Jiang, Frank J and Johansson, Karl H}, + journal={arXiv preprint arXiv:2306.12508}, + year={2023} } ``` ``` -@article{logicalZonotope, - title={Logical Zonotopes: A Set Representation for the Formal Verification of Boolean Functions}, - author={Alanwar, Amr and Jiang, Frank J. and Amin, Samy and Johansson, Karl Henrik}, - journal={arXiv preprint arXiv:2210.08596}, - year={2022} -} +@INPROCEEDINGS{logicalZonotope, + author={Alanwar, Amr and Jiang, Frank J. and Amin, Samy and Johansson, Karl H.}, + booktitle={2023 62nd IEEE Conference on Decision and Control (CDC)}, + title={Logical Zonotopes: A Set Representation for the Formal Verification of Boolean Functions}, + year={2023}, + volume={}, + number={}, + pages={60-66}} + ``` diff --git a/TestExactLogic.m b/TestExactLogic.m new file mode 100644 index 0000000..a6d80c5 --- /dev/null +++ b/TestExactLogic.m @@ -0,0 +1,104 @@ +clear all + +dim=7; +c1= [logical(randi([0 1],dim,1)) ]; +numOfInd1 = 3; +for i=1:numOfInd1 + g1{i} = randi([0 1],dim,1); +end +E1 = [1 0 1;1 1 0]; +id1 = [1;2]; + + +c2= [logical(randi([0 1],dim,1)) ]; +for i=1:2 + g2{i} = logical(randi([0 1],dim,1)); +end +E2 = [1 0;0 1]; +id2 = [3; 4]; + + + + + + +pZ1 = logicalPolyZonotope(c1,g1,E1,id1); +pZ2 = logicalPolyZonotope(c2,g2,E2,id2); + + +% manually +p1=evaluate(pZ1); +p2=evaluate(pZ2); +[~,p1Col]=size(p1); +[~,p2Col]=size(p2); +ExactXorPoints=[]; +ExactAndPoints=[]; +ExactNandPoints=[]; +ExactOrPoints=[]; +ExactAndORFormulaPoints =[] ; +tic +for i =1:p1Col + ExactXorPoints = [ExactXorPoints, xor(p1(:,i),p1(:,i))]; + ExactAndPoints = [ExactAndPoints, and(p1(:,i),p1(:,i))]; + ExactNandPoints =[ExactNandPoints, nand(p1(:,i),p1(:,i))]; + ExactOrPoints =[ExactOrPoints, or(p1(:,i),p1(:,i))]; +end + +for i =1:p1Col + for j=1:p2Col + ExactAndORFormulaPoints = [ExactAndORFormulaPoints, or(p1(:,i),and(not(p1(:,i)),p2(:,j)))]; + end +end +exeTime=toc; + + +ExactXorPoints = unique(ExactXorPoints','rows')'; +ExactAndPoints = unique(ExactAndPoints','rows')'; +ExactNandPoints = unique(ExactNandPoints','rows')'; +ExactOrPoints = unique(ExactOrPoints','rows')'; +ExactAndORFormulaPoints = unique(ExactAndORFormulaPoints','rows')'; + +pZ1ExactXorpZ1 = exactXor(pZ1,pZ1); +pZ1ExactAndpZ1 = exactAnd(pZ1,pZ1); +pZ1ExactOrpZ1 = exactOr(pZ1,pZ1); +pZ1ExactNandpZ1 = exactNand(pZ1,pZ1); + +tempAnd= and(not(pZ1),pZ2); +%tempAnd.id = [1;2;1;2]; +pZ1ExactAndORpZ2 = exactOr(pZ1,tempAnd); + + +pZ1XorpZ1Points= evaluate(pZ1ExactXorpZ1); +pZ1AndpZ1Points= evaluate(pZ1ExactAndpZ1); +pZ1OrpZ1Points= evaluate(pZ1ExactOrpZ1); +pZ1NandpZ1Points= evaluate(pZ1ExactNandpZ1); +pZ1ExactAndORpZ2Points= evaluate(pZ1ExactAndORpZ2); + +%% checks +if isequal(ExactXorPoints,pZ1XorpZ1Points) && isequal(ExactNandPoints,pZ1NandpZ1Points) && isequal(ExactAndPoints,pZ1AndpZ1Points) && isequal(ExactAndORFormulaPoints,pZ1ExactAndORpZ2Points) + disp('All tests passed') +else + disp('Test problem(s)') +end + + +if ~isequal(ExactXorPoints,pZ1XorpZ1Points) + disp('Exact Xor problem') +end + +if ~isequal(ExactNandPoints,pZ1NandpZ1Points) + disp('Exact Nand problem') +end + +if ~isequal(ExactAndPoints,pZ1AndpZ1Points) + disp('Exact And problem') +end + +if ~isequal(ExactOrPoints,pZ1OrpZ1Points) + disp('Exact Or problem') +end + +if ~isequal(ExactAndORFormulaPoints,pZ1ExactAndORpZ2Points) + disp('exactOr(pZ1,and(pZ1,pZ2)) problem') +end + diff --git a/TestExactXor.asv b/TestExactXor.asv new file mode 100644 index 0000000..99d9c16 --- /dev/null +++ b/TestExactXor.asv @@ -0,0 +1,71 @@ +clear all + +dim=3; +c1= [logical(randi([0 1],dim,1)) ]; +for i=1:1 + gI1{i} = randi([0 1],dim,1); +end +gI1 = {};%{randi([0 1],dim,1)}; +g1 ={randi([0 1],dim,1)};; +E1=[]; +% for i=1:2 +% g1{i} = randi([0 1],dim,1); +% end +% E1 = [1 0;1 1]; + + +c2= [logical(randi([0 1],dim,1)) ]; +for i=1:3 + gI2{i} = logical(randi([0 1],dim,1)); +end +%gI2 = {randi([0 1],dim,1)}; +for i=1:2 + g2{i} = logical(randi([0 1],dim,1)); +end +%g2 = {}; +E2 = [1 0;0 1]; + + + +Z1 = logicalZonotope(c1,gI1); +Z2 = logicalZonotope(c2,gI2); +pZ1 = logicalPolyZonotope(c1,gI1,g1,E1); +pZ2 = logicalPolyZonotope(c2,gI2,g2,E2); + +%plot(Z1,[1 2 3],'r*'); +% manually +p1=evaluate(pZ1); +p2=evaluate(pZ2); +[~,p1Col]=size(p1); +[~,p2Col]=size(p2); +ExactXorPoints=[]; + + +tic +for i =1:p1Col + ExactXorPoints = [ExactXorPoints, xor(p1(:,i),p1(:,i))]; +end +exeTime=toc; + + +ExactXorPoints = unique(ExactXorPoints','rows')'; + + +pZ1ExactXorpZ1 = exactXor(pZ1,pZ1); + + +pZ1XorpZ1Points= evaluate(pZ1ExactXorpZ1); + +%% checks +if isequal(ExactXorPoints,pZ1XorpZ1Points) + disp('All tests passed') +else + disp('Test problem(s)') +end + + +if ~isequal(ExactXorPoints,pZ1XorpZ1Points) + disp('Exact Xor problem') +end + + diff --git a/TestLogicalFunctions.m b/TestLogicalFunctions.m index 17ae54e..1e7938f 100644 --- a/TestLogicalFunctions.m +++ b/TestLogicalFunctions.m @@ -2,13 +2,14 @@ close all rng(4); -c1 = [0;0]; -c2 = [0;1]; -g1 = {[1;0]}; +dim =5; +c1 = randi([0 1],dim,1); +c2 = randi([0 1],dim,1); +g1 = {randi([0 1],dim,1)}; %g1 = {[0 1;1 1]}; -g2 = {[1;1]}; +g2 = {randi([0 1],dim,1)}; %g2 = {[1 0;0 1]}; -dim =3; + c3= [randi([0 1],dim,1) ]; for i=1:10 g3{i} = randi([0 1],dim,1); diff --git a/TestPolyLogicalFunctions.m b/TestPolyLogicalFunctions.m index bfa139a..e0c3ab0 100644 --- a/TestPolyLogicalFunctions.m +++ b/TestPolyLogicalFunctions.m @@ -4,54 +4,31 @@ rng(151); for kk=1:1 -dim=3; +dim=4; c1= [randi([0 1],dim,1) ]; -% for i=1:1 -% gI1{i} = randi([0 1],dim,1); -% end -gI1 = {};%{randi([0 1],dim,1)}; -g1 ={}; -E1=[]; -% for i=1:2 -% g1{i} = randi([0 1],dim,1); -% end -% E1 = [1 0;1 1]; +for i=1:2 + g1{i} = randi([0 1],dim,1); +end +E1=[1 1; 0 1]; +id1 = [ 1;2]; c2= [randi([0 1],dim,1) ]; -for i=1:3 - gI2{i} = randi([0 1],dim,1); -end %gI2 = {randi([0 1],dim,1)}; -for i=1:2 +for i=1:1 g2{i} = randi([0 1],dim,1); end %g2 = {}; E2 = [1 0;0 1]; +id2 = [ 3;4]; + + + -% c1 = [0;1;0]; -% gI1 = {[1;0;1]}; -% g1 = {[0;1;1],[1;1;1]}; -% E1 = [1 1;0 1]; -% pZ1 = logicalPolyZonotope(c1,gI1,g1,E1); -% evaluate(pZ1) - -% -% c2 = [1;0;1]; -% gI2 = {[0;1;1],[1;0;0]}; -% g2 = {}; -% E2 = [ ]; - -% dim =20; -% c3= [randi([0 1],dim,1) ]; -% for i=1:10 -% g3{i} = randi([0 1],dim,1); -% end - -Z1 = logicalZonotope(c1,gI1); -Z2 = logicalZonotope(c2,gI2); -pZ1 = logicalPolyZonotope(c1,gI1,g1,E1); -pZ2 = logicalPolyZonotope(c2,gI2,g2,E2); +Z1 = logicalZonotope(c1,g1); +Z2 = logicalZonotope(c2,g2); +pZ1 = logicalPolyZonotope(c1,g1,E1,id1); +pZ2 = logicalPolyZonotope(c2,g2,E2,id2); %plot(Z1,[1 2 3],'r*'); % manually @@ -99,7 +76,8 @@ notpZ1 = not(pZ1); notpZ2 = not(pZ2); pZ1NorpZ2 = nor(pZ1 , pZ2); -pZ1AndpZ2 = and(pZ1, pZ2); +%ExactpZ1AndpZ2 = exactAnd(pZ1, pZ2); +pZ1AndpZ2 = exactAnd(pZ1, pZ2); pZ1OrpZ2 = or(pZ1, pZ2); pZ1NandpZ2 = nand(pZ1, pZ2); pZ1XorpZ2 = xor(pZ1,pZ2); diff --git a/VechIntersection4cars.asv b/VechIntersection4cars.asv new file mode 100644 index 0000000..69b7ae3 --- /dev/null +++ b/VechIntersection4cars.asv @@ -0,0 +1,458 @@ +clear all + +load('cache\L.mat') + +steps = 2; + + +VPl{1}{1} = logical(1); +VPl{1}{2} = logicalZonotope.enclosePoints(logical([0,1])); +VPl{1}{3} = logical(0); +VPl{1}{4} = logicalZonotope.enclosePoints(logical([0,1])); + +VplOrig = VPl; + +CFl{1}{1} = logical(1); +CFl{1}{2} = logical(1);%logicalZonotope.enclosePoints(logical([0,1])); +CFl{1}{3} = logical(0); +CFl{1}{4} = logicalZonotope.enclosePoints(logical([0,1])); + +CFlOrig = CFl; + +Ul{1} = logicalZonotope.enclosePoints(logical([0,1])); +Ul{2} = logical(0); +Ul{3} = logicalZonotope.enclosePoints(logical([0,1])); +Ul{4} = logical(0);logicalZonotope.enclosePoints(logical([0,1])); +Ul{5} = logical(1);%logicalZonotope.enclosePoints(logical([0,1])); +Ul{6} = logical(0); +Ul{7} = logicalZonotope.enclosePoints(logical([0,1])); +Ul{8} = logicalZonotope.enclosePoints(logical([0,1])); + +UlOrig = Ul; +tic +for i=1:steps + [VPl{i+1},CFl{i+1}] = vehLogicZono4(Ul,VPl{i},CFl{i}); +end +execlogicZono = toc + + + +VP1data=evaluate(VPl{steps+1}{1}); +VP2data=evaluate(VPl{steps+1}{2}); +VP3data=evaluate(VPl{steps+1}{3}); +VP4data=evaluate(VPl{steps+1}{4}); + +CF1data=evaluate(CFl{steps+1}{1}); +CF2data=evaluate(CFl{steps+1}{2}); +CF3data=evaluate(CFl{steps+1}{3}); +CF4data=evaluate(CFl{steps+1}{4}); + +VP1NPoints=length(VP1data); +VP2NPoints=length(VP2data); +VP3NPoints=length(VP3data); +VP4NPoints=length(VP4data); +CF1NPoints=length(CF1data); +CF2NPoints=length(CF2data); +CF3NPoints=length(CF3data); +CF4NPoints=length(CF4data); + +totalPointsZono = VP1NPoints + VP2NPoints +VP3NPoints + VP4NPoints ... + + CF1NPoints + CF2NPoints + CF3NPoints + CF4NPoints + + +%%-----------Exact Poly Zonotope ---------%% +%VPl ={}; +%CFl ={}; + +for i =1:4 + if isa(VplOrig{1}{i},'logicalZonotope') + VPl{1}{i}= logicalPolyZonotope(VPl{1}{i}.c,VPl{1}{i}.G,eye(length(VPl{1}{i}.G)),i); + elseif VplOrig{1}{i}== logical(0) + VPl{1}{i}= logical(0); + else + VPl{1}{i}= logical(1); + end +end + +for i =1:4 + if isa(CFlOrig{1}{i},'logicalZonotope') + CFl{1}{i}= logicalPolyZonotope(CFl{1}{i}.c,CFl{1}{i}.G,eye(length(CFl{1}{i}.G)),i+4); + elseif CFlOrig{1}{i}== logical(0) + CFl{1}{i}= logical(0); + else + CFl{1}{i}= logical(1); + end +end + +for i =1:8 + if isa(UlOrig{i},'logicalZonotope') + Ul{i}= logicalPolyZonotope(Ul{i}.c,Ul{i}.G,eye(length(Ul{i}.G)),i+8); + end +end + + +tic +for i=1:steps + [VPl{i+1},CFl{i+1}] = vehLogicExactPolyZono4(Ul,VPl{i},CFl{i}); + + % CFl{i+1}{1}=rmZeroGens(CFl{i+1}{1}); + % CFl{i+1}{2}=rmZeroGens(CFl{i+1}{2}); + % VPl{i+1}{1}=rmZeroGens(VPl{i+1}{1}); + % VPl{i+1}{2}=rmZeroGens(VPl{i+1}{2}); +end +execlogicExactPolyZono = toc + + +VP1PZdata=evaluate(VPl{steps+1}{1}); +VP2PZdata=evaluate(VPl{steps+1}{2}); +VP3PZdata=evaluate(VPl{steps+1}{3}); +VP4PZdata=evaluate(VPl{steps+1}{4}); +CF1PZdata=evaluate(CFl{steps+1}{1}); +CF2PZdata=evaluate(CFl{steps+1}{2}); +CF3PZdata=evaluate(CFl{steps+1}{3}); +CF4PZdata=evaluate(CFl{steps+1}{4}); + +VP1PZNPoints=length(VP1PZdata); +VP2PZNPoints=length(VP2PZdata); +VP3PZNPoints=length(VP3PZdata); +VP4PZNPoints=length(VP4PZdata); +CF1PZNPoints=length(CF1PZdata); +CF2PZNPoints=length(CF2PZdata); +CF3PZNPoints=length(CF3PZdata); +CF4PZNPoints=length(CF4PZdata); + +totalExactPointsPZ = VP1PZNPoints + VP2PZNPoints + CF1PZNPoints + CF2PZNPoints ... + +VP3PZNPoints + VP4PZNPoints + CF3PZNPoints + CF4PZNPoints +%%----------- Poly Zonotope ---------%% +%VPl ={}; +%CFl ={}; + +for i =1:4 + if isa(VplOrig{1}{i},'logicalZonotope') + VPl{1}{i}= logicalPolyZonotope(VPl{1}{i}.c,VPl{1}{i}.G,eye(length(VPl{1}{i}.G)),i); + elseif VplOrig{1}{i}== logical(0) + VPl{1}{i}= logical(0); + else + VPl{1}{i}= logical(1); + end +end + +for i =1:4 + if isa(CFlOrig{1}{i},'logicalZonotope') + CFl{1}{i}= logicalPolyZonotope(CFl{1}{i}.c,CFl{1}{i}.G,eye(length(CFl{1}{i}.G)),i+4); + elseif CFlOrig{1}{i}== logical(0) + CFl{1}{i}= logical(0); + else + CFl{1}{i}= logical(1); + end +end + +for i =1:8 + if isa(UlOrig{i},'logicalZonotope') + Ul{i}= logicalPolyZonotope(Ul{i}.c,Ul{i}.G,eye(length(Ul{i}.G)),i+8); + end +end + + +tic +for i=1:steps + [VPl{i+1},CFl{i+1}] = vehLogicPolyZono4(Ul,VPl{i},CFl{i}); + + % CFl{i+1}{1}=rmZeroGens(CFl{i+1}{1}); + % CFl{i+1}{2}=rmZeroGens(CFl{i+1}{2}); + % VPl{i+1}{1}=rmZeroGens(VPl{i+1}{1}); + % VPl{i+1}{2}=rmZeroGens(VPl{i+1}{2}); +end +execlogicPolyZono = toc + + +VP1PZdata=evaluate(VPl{steps+1}{1}); +VP2PZdata=evaluate(VPl{steps+1}{2}); +VP3PZdata=evaluate(VPl{steps+1}{3}); +VP4PZdata=evaluate(VPl{steps+1}{4}); +CF1PZdata=evaluate(CFl{steps+1}{1}); +CF2PZdata=evaluate(CFl{steps+1}{2}); +CF3PZdata=evaluate(CFl{steps+1}{3}); +CF4PZdata=evaluate(CFl{steps+1}{4}); + +VP1PZNPoints=length(VP1PZdata); +VP2PZNPoints=length(VP2PZdata); +VP3PZNPoints=length(VP3PZdata); +VP4PZNPoints=length(VP4PZdata); +CF1PZNPoints=length(CF1PZdata); +CF2PZNPoints=length(CF2PZdata); +CF3PZNPoints=length(CF3PZdata); +CF4PZNPoints=length(CF4PZdata); + +totalPointsPZ = VP1PZNPoints + VP2PZNPoints + CF1PZNPoints + CF2PZNPoints ... + +VP3PZNPoints + VP4PZNPoints + CF3PZNPoints + CF4PZNPoints +%%----------- BCN ---------%% + +for i =1:4 + if isa(VplOrig{1}{i},'logicalZonotope') + VPl{1}{i}= [[0;1],[1;0]]; + elseif VplOrig{1}{i}== logical(0) + VPl{1}{i}= [0;1]; + else + VPl{1}{i}= [1;0]; + end +end + +for i =1:4 + if isa(CFlOrig{1}{i},'logicalZonotope') + CFl{1}{i}= [[0;1],[1;0]]; + elseif CFlOrig{1}{i}== logical(0) + CFl{1}{i}= [0;1]; + else + CFl{1}{i}= [1;0]; + end +end + +for i =1:8 + if isa(UlOrig{i},'logicalZonotope') + Ul{i}= [[0;1],[1;0]]; + elseif UlOrig{i}== logical(0) + Ul{i}= [0;1]; + else + Ul{i}= [1;0]; + end +end + +tic +xpoints{1}= []; +for i1=1:length(VPl{1}{1}(1,:)) + for i2=1:length(VPl{1}{2}(1,:)) + for i3=1:length(VPl{1}{3}(1,:)) + for i4=1:length(VPl{1}{4}(1,:)) + for j1 = 1:length(CFl{1}{1}(1,:)) + for j2 = 1:length(CFl{1}{2}(1,:)) + for j3 = 1:length(CFl{1}{3}(1,:)) + for j4 = 1:length(CFl{1}{4}(1,:)) + + xVP =semiKron(VPl{1}{1}(:,i1),semiKron(VPl{1}{2}(:,i2), semiKron(VPl{1}{3}(:,i3),VPl{1}{4}(:,i4)))); + xCF =semiKron(CFl{1}{1}(:,j1),semiKron(CFl{1}{2}(:,j2), semiKron(CFl{1}{3}(:,j3),CFl{1}{4}(:,j4)))); + xpoints{1} = [ xpoints{1} semiKron(xVP,xCF)]; + end + end + end + end + end + end + end +end +for s = 1:steps + xpoints{s+1} = []; + for i=1:length(xpoints{s}(1,:)) + for j=1:length(Ul{1}(1,:)) + for j2 = 1:length(Ul{2}(1,:)) + for j3=1:length(Ul{3}(1,:)) + for j4 = 1:length(Ul{4}(1,:)) + for j5=1:length(Ul{5}(1,:)) + for j6 = 1:length(Ul{6}(1,:)) + for j7=1:length(Ul{7}(1,:)) + for j8 = 1:length(Ul{8}(1,:)) + usemi = semiKron(Ul{1}(:,j),semiKron(Ul{2}(:,j2),semiKron(Ul{3}(:,j3),Ul{4}(:,j4)))); + newx = semiKron(semiKron(Lcomp,usemi),xpoints{s}(:,i)); + xpoints{s+1} = [ xpoints{s+1} newx]; + end + end + end + end + end + end + end + end + end + xpoints{s+1} = unique(xpoints{s+1}','rows')'; +end +execBCN = toc + + + +%%----------- BDD ---------%% + +for i =1:4 + if isa(VplOrig{1}{i},'logicalZonotope') + VPl{1}{i}= [[0],[1]]; + elseif VplOrig{1}{i}== logical(0) + VPl{1}{i}= [0]; + else + VPl{1}{i}= [1]; + end +end + +for i =1:4 + if isa(CFlOrig{1}{i},'logicalZonotope') + CFl{1}{i}= [[0],[1]]; + elseif CFlOrig{1}{i}== logical(0) + CFl{1}{i}= [0]; + else + CFl{1}{i}= [1]; + end +end + +for i =1:8 + if isa(UlOrig{i},'logicalZonotope') + Ul{i}= [[0],[1]]; + elseif UlOrig{i}== logical(0) + Ul{i}= [0]; + else + Ul{i}= [1]; + end +end + + +VP1points{1}=VPl{1}{1}; +VP2points{1}=VPl{1}{2}; +VP3points{1}=VPl{1}{3}; +VP4points{1}=VPl{1}{4}; + +CF1points{1}=CFl{1}{1}; +CF2points{1}=CFl{1}{2}; +CF3points{1}=CFl{1}{3}; +CF4points{1}=CFl{1}{4}; +tic +for s = 1:steps + VP1points{s+1} = []; + VP2points{s+1} = []; + VP3points{s+1} = []; + VP4points{s+1} = []; + CF1points{s+1} = []; + CF2points{s+1} = []; + CF3points{s+1} = []; + CF4points{s+1} = []; + for iVP1=1:length(VP1points{s}(1,:)) + for iVP2=1:length(VP2points{s}(1,:)) + for iVP3=1:length(VP3points{s}(1,:)) + for iVP4=1:length(VP4points{s}(1,:)) + for iCF1=1:length(CF1points{s}(1,:)) + for iCF2=1:length(CF2points{s}(1,:)) + for iCF3=1:length(CF3points{s}(1,:)) + for iCF4=1:length(CF4points{s}(1,:)) + for j=1:length(Ul{1}(1,:)) + for j2 = 1:length(Ul{2}(1,:)) + for j3=1:length(Ul{3}(1,:)) + for j4 = 1:length(Ul{4}(1,:)) + for j5=1:length(Ul{5}(1,:)) + for j6 = 1:length(Ul{6}(1,:)) + for j7=1:length(Ul{7}(1,:)) + for j8 = 1:length(Ul{8}(1,:)) + Uin{1}=Ul{1}(j); + Uin{2}=Ul{2}(j2); + Uin{3}=Ul{3}(j3); + Uin{4}= Ul{4}(j4); + Uin{5}=Ul{5}(j5); + Uin{6}=Ul{6}(j6); + Uin{7}=Ul{7}(j7); + Uin{8}= Ul{8}(j8); + + VPin{1}=VP1points{s}(iVP1); + VPin{2}=VP2points{s}(iVP2); + VPin{3}=VP3points{s}(iVP3); + VPin{4}=VP4points{s}(iVP4); + + CFin{1}=CF1points{s}(iCF1); + CFin{2}=CF2points{s}(iCF2); + CFin{3}=CF3points{s}(iCF3); + CFin{4}=CF4points{s}(iCF4); + + %[VPin,CFin] = vehLogicZono4(Uin,VPin,CFin); + [VPin,CFin] = vehLogicBDD4(Uin,VPin,CFin); + VP1points{s+1} = [ VP1points{s+1} VPin{1}]; + VP2points{s+1} = [ VP2points{s+1} VPin{2}]; + VP3points{s+1} = [ VP3points{s+1} VPin{3}]; + VP4points{s+1} = [ VP4points{s+1} VPin{4}]; + + CF1points{s+1} = [ CF1points{s+1} CFin{1}]; + CF2points{s+1} = [ CF2points{s+1} CFin{2}]; + CF3points{s+1} = [ CF3points{s+1} CFin{3}]; + CF4points{s+1} = [ CF4points{s+1} CFin{4}]; + + end + end + end + end + end + end + end + end + end + end + end + end + end + end + end + end + VP1points{s+1} = unique(VP1points{s+1}','rows')'; + VP2points{s+1} = unique(VP2points{s+1}','rows')'; + VP3points{s+1} = unique(VP3points{s+1}','rows')'; + VP4points{s+1} = unique(VP4points{s+1}','rows')'; + CF1points{s+1} = unique(CF1points{s+1}','rows')'; + CF2points{s+1} = unique(CF2points{s+1}','rows')'; + CF3points{s+1} = unique(CF3points{s+1}','rows')'; + CF4points{s+1} = unique(CF4points{s+1}','rows')'; +end +execBDD = toc + + +VP1BDDNPoints=length(VP1points{steps+1}); +VP2BDDNPoints=length(VP2points{steps+1}); +VP3BDDNPoints=length(VP3points{steps+1}); +VP4BDDNPoints=length(VP4points{steps+1}); +CF1BDDNPoints=length(CF1points{steps+1}); +CF2BDDNPoints=length(CF2points{steps+1}); +CF3BDDNPoints=length(CF3points{steps+1}); +CF4BDDNPoints=length(CF4points{steps+1}); + +totalPointsBDD = VP1BDDNPoints + VP2BDDNPoints + CF1BDDNPoints + CF2BDDNPoints ... + + VP3BDDNPoints + VP4BDDNPoints + CF3BDDNPoints + CF4BDDNPoints + + +if ~isequal(VP1PZdata,VP1points{steps+1}) + disp('VP1 problem') +else + disp('VP1 success') +end + +if ~isequal(VP2PZdata,VP2points{steps+1}) + disp('VP2 problem') +else + disp('VP2 success') +end + +if ~isequal(VP3PZdata,VP3points{steps+1}) + disp('VP3 problem') +else + disp('VP3 success') +end + +if ~isequal(VP4PZdata,VP4points{steps+1}) + disp('VP4 problem') +else + disp('VP4 success') +end + +if ~isequal(CF1PZdata,CF1points{steps+1}) + disp('CF1 problem') +else + disp('CF1 success') +end + +if ~isequal(CF2PZdata,CF2points{steps+1}) + disp('CF2 problem') +else + disp('CF2 success') +end + +if ~isequal(CF3PZdata,CF3points{steps+1}) + disp('CF3 problem') +else + disp('CF3 success') +end + +if ~isequal(CF4PZdata,CF4points{steps+1}) + disp('CF4 problem') +else + disp('CF4 success') +end \ No newline at end of file diff --git a/VechIntersection4cars.m b/VechIntersection4cars.m index d77e7b0..9764c08 100644 --- a/VechIntersection4cars.m +++ b/VechIntersection4cars.m @@ -2,7 +2,8 @@ load('cache\L.mat') -steps = 1000; +steps = 5; + VPl{1}{1} = logical(1); @@ -28,6 +29,7 @@ Ul{7} = logicalZonotope.enclosePoints(logical([0,1])); Ul{8} = logicalZonotope.enclosePoints(logical([0,1])); + UlOrig = Ul; tic for i=1:steps @@ -59,39 +61,119 @@ totalPointsZono = VP1NPoints + VP2NPoints +VP3NPoints + VP4NPoints ... + CF1NPoints + CF2NPoints + CF3NPoints + CF4NPoints - %%----------- Poly Zonotope ---------%% %VPl ={}; %CFl ={}; +% for i =1:4 +% if isa(VplOrig{1}{i},'logicalZonotope') +% VPl{1}{i}= logicalPolyZonotope(VPl{1}{i}.c,VPl{1}{i}.G,eye(length(VPl{1}{i}.G)),i); +% elseif VplOrig{1}{i}== logical(0) +% VPl{1}{i}= logical(0); +% else +% VPl{1}{i}= logical(1); +% end +% end +% +% for i =1:4 +% if isa(CFlOrig{1}{i},'logicalZonotope') +% CFl{1}{i}= logicalPolyZonotope(CFl{1}{i}.c,CFl{1}{i}.G,eye(length(CFl{1}{i}.G)),i+4); +% elseif CFlOrig{1}{i}== logical(0) +% CFl{1}{i}= logical(0); +% else +% CFl{1}{i}= logical(1); +% end +% end +% +% for i =1:8 +% if isa(UlOrig{i},'logicalZonotope') +% Ul{i}= logicalPolyZonotope(Ul{i}.c,Ul{i}.G,eye(length(Ul{i}.G)),i+8); +% elseif UlOrig{i}== logical(0) +% Ul{i}= logical(0); +% else +% Ul{i}= logical(1); +% end +% end +% +% +% tic +% for i=1:steps +% [VPl{i+1},CFl{i+1}] = vehLogicPolyZono4(Ul,VPl{i},CFl{i}); +% +% % CFl{i+1}{1}=rmZeroGens(CFl{i+1}{1}); +% % CFl{i+1}{2}=rmZeroGens(CFl{i+1}{2}); +% % VPl{i+1}{1}=rmZeroGens(VPl{i+1}{1}); +% % VPl{i+1}{2}=rmZeroGens(VPl{i+1}{2}); +% end +% execlogicPolyZono = toc +% +% +% VP1PZdata=evaluate(VPl{steps+1}{1}); +% VP2PZdata=evaluate(VPl{steps+1}{2}); +% VP3PZdata=evaluate(VPl{steps+1}{3}); +% VP4PZdata=evaluate(VPl{steps+1}{4}); +% CF1PZdata=evaluate(CFl{steps+1}{1}); +% CF2PZdata=evaluate(CFl{steps+1}{2}); +% CF3PZdata=evaluate(CFl{steps+1}{3}); +% CF4PZdata=evaluate(CFl{steps+1}{4}); +% +% VP1PZNPoints=length(VP1PZdata); +% VP2PZNPoints=length(VP2PZdata); +% VP3PZNPoints=length(VP3PZdata); +% VP4PZNPoints=length(VP4PZdata); +% CF1PZNPoints=length(CF1PZdata); +% CF2PZNPoints=length(CF2PZdata); +% CF3PZNPoints=length(CF3PZdata); +% CF4PZNPoints=length(CF4PZdata); +% +% totalPointsPZ = VP1PZNPoints + VP2PZNPoints + CF1PZNPoints + CF2PZNPoints ... +% +VP3PZNPoints + VP4PZNPoints + CF3PZNPoints + CF4PZNPoints + +%%-----------Exact Poly Zonotope ---------%% +%VPl ={}; +%CFl ={}; + for i =1:4 if isa(VplOrig{1}{i},'logicalZonotope') - VPl{1}{i}= logicalPolyZonotope(VPl{1}{i}.c,VPl{1}{i}.G,{},[]); + VPl{1}{i}= logicalPolyZonotope(VPl{1}{i}.c,VPl{1}{i}.G,eye(length(VPl{1}{i}.G)),i); + elseif VplOrig{1}{i}== logical(0) + VPl{1}{i}= logical(0); + else + VPl{1}{i}= logical(1); end end for i =1:4 if isa(CFlOrig{1}{i},'logicalZonotope') - CFl{1}{i}= logicalPolyZonotope(CFl{1}{i}.c,CFl{1}{i}.G,{},[]); + CFl{1}{i}= logicalPolyZonotope(CFl{1}{i}.c,CFl{1}{i}.G,eye(length(CFl{1}{i}.G)),i+4); + elseif CFlOrig{1}{i}== logical(0) + CFl{1}{i}= logical(0); + else + CFl{1}{i}= logical(1); end end for i =1:8 if isa(UlOrig{i},'logicalZonotope') - Ul{i}= logicalPolyZonotope(Ul{i}.c,Ul{i}.G,{},[]); + Ul{i}= logicalPolyZonotope(Ul{i}.c,Ul{i}.G,eye(length(Ul{i}.G)),i+8); + elseif UlOrig{i}== logical(0) + Ul{i}= logical(0); + else + Ul{i}= logical(1); end end tic for i=1:steps - [VPl{i+1},CFl{i+1}] = vehLogicZono4(Ul,VPl{i},CFl{i}); + [VPl{i+1},CFl{i+1}] = vehLogicExactPolyZono4(Ul,VPl{i},CFl{i}); + % CFl{i+1}{1}=rmZeroGens(CFl{i+1}{1}); % CFl{i+1}{2}=rmZeroGens(CFl{i+1}{2}); % VPl{i+1}{1}=rmZeroGens(VPl{i+1}{1}); % VPl{i+1}{2}=rmZeroGens(VPl{i+1}{2}); end -execlogicPolyZono = toc +execlogicExactPolyZono = toc VP1PZdata=evaluate(VPl{steps+1}{1}); @@ -112,9 +194,10 @@ CF3PZNPoints=length(CF3PZdata); CF4PZNPoints=length(CF4PZdata); -totalPointsPZ = VP1PZNPoints + VP2PZNPoints + CF1PZNPoints + CF2PZNPoints ... +totalExactPointsPZ = VP1PZNPoints + VP2PZNPoints + CF1PZNPoints + CF2PZNPoints ... +VP3PZNPoints + VP4PZNPoints + CF3PZNPoints + CF4PZNPoints + %%----------- BCN ---------%% for i =1:4 @@ -266,26 +349,27 @@ for j6 = 1:length(Ul{6}(1,:)) for j7=1:length(Ul{7}(1,:)) for j8 = 1:length(Ul{8}(1,:)) - Uin{1}=Ul{1}(:,j); - Uin{2}=Ul{2}(:,j2); - Uin{3}=Ul{3}(:,j3); - Uin{4}= Ul{4}(:,j4); - Uin{5}=Ul{5}(:,j5); - Uin{6}=Ul{6}(:,j6); - Uin{7}=Ul{7}(:,j7); - Uin{8}= Ul{8}(:,j8); - - VPin{1}=VP1points{s}(:,iVP1); - VPin{2}=VP2points{s}(:,iVP2); - VPin{3}=VP3points{s}(:,iVP3); - VPin{4}=VP4points{s}(:,iVP4); - - CFin{1}=CF1points{s}(:,iCF1); - CFin{2}=CF2points{s}(:,iCF2); - CFin{3}=CF3points{s}(:,iCF3); - CFin{4}=CF4points{s}(:,iCF4); + Uin{1}=Ul{1}(j); + Uin{2}=Ul{2}(j2); + Uin{3}=Ul{3}(j3); + Uin{4}= Ul{4}(j4); + Uin{5}=Ul{5}(j5); + Uin{6}=Ul{6}(j6); + Uin{7}=Ul{7}(j7); + Uin{8}= Ul{8}(j8); + + VPin{1}=VP1points{s}(iVP1); + VPin{2}=VP2points{s}(iVP2); + VPin{3}=VP3points{s}(iVP3); + VPin{4}=VP4points{s}(iVP4); + + CFin{1}=CF1points{s}(iCF1); + CFin{2}=CF2points{s}(iCF2); + CFin{3}=CF3points{s}(iCF3); + CFin{4}=CF4points{s}(iCF4); [VPin,CFin] = vehLogicZono4(Uin,VPin,CFin); + %[VPin,CFin] = vehLogicBDD4(Uin,VPin,CFin); VP1points{s+1} = [ VP1points{s+1} VPin{1}]; VP2points{s+1} = [ VP2points{s+1} VPin{2}]; VP3points{s+1} = [ VP3points{s+1} VPin{3}]; diff --git a/exactAnd - Copy.txt b/exactAnd - Copy.txt new file mode 100644 index 0000000..fd7a1ab --- /dev/null +++ b/exactAnd - Copy.txt @@ -0,0 +1,316 @@ +function Z = exactAnd(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: +% +% +% Last revision: --- + +%------------- BEGIN CODE -------------- + +if ~isa(Z1,'logicalPolyZonotope') +Z1=logicalZonotope.enclosePoints(Z1); +Z1=logicalPolyZonotope(Z1.c,Z1.G,{},[]); +end + +if ~isa(Z2,'logicalPolyZonotope') +Z2=logicalZonotope.enclosePoints(Z2); +Z2=logicalPolyZonotope(Z2.c,Z2.G,{},[]); +end + +if(~isempty(Z1.c) && ~isempty(Z2.c)) + newcen = Z1.c & Z2.c; +end + + + +% newG1 = Z1.GI; +% for i =1:length(Z1.G) +% newG1{i+length(Z1.GI)} = Z1.G{i}; +% end +% if isempty(Z1.E) +% newE1 = eye(size(Z1.GI,2)); +% elseif isempty(Z1.GI) +% newE1 = Z1.E; +% else +% newE1 = blkdiag(eye(size(Z1.GI,2)),Z1.E); +% end +% +% newG2 = Z2.GI; +% for i =1:length(Z2.G) +% newG2{i+length(Z2.GI)} = Z2.G{i}; +% end +% if isempty(Z2.E) +% newE2 = eye(size(Z2.GI,2)); +% elseif isempty(Z2.GI) +% newE2 = Z2.E; +% else +% newE2 = blkdiag(eye(size(Z2.GI,2)),Z2.E); +% end +% +% +% index =1; +% newE =[]; +% newGen ={}; +% zeroVec = logical(zeros(size(Z1.c))); +% if(~isempty(Z2.c) && ~isempty(newG1)) +% tempE1=newE1 ; +% zerosE2=zeros(size(newE2,1),1); +% tempE = []; +% indexE = 1; +% for i=1:length(newG1) +% vecAnd = Z2.c & newG1{i}; +% if isequal(vecAnd,zeroVec) +% continue; +% end +% newGen{index} = vecAnd; +% tempE(:,indexE) = [(tempE1(:,i));(zerosE2)]; +% index=index+1; +% indexE=indexE+1; +% end +% newE = [newE tempE]; +% end +% if(~isempty(Z1.c) && ~isempty(newG2)) +% zerosE1=zeros(size(newE1,1),1); +% tempE2=newE2 ; +% tempE = []; +% indexE = 1; +% for i=1:length(newG2) +% vecAnd= Z1.c & newG2{i}; +% if isequal(vecAnd,zeroVec) +% continue; +% end +% newGen{index} =vecAnd; +% tempE(:,indexE) = [(zerosE1);(tempE2(:,i))]; +% index=index+1; +% indexE=indexE+1; +% end +% newE = [newE tempE]; +% end +% if(~isempty(newG1) && ~isempty(newG2)) +% %G1 * G1 +% tempE1=newE1 ; +% tempE2=newE2; +% tempE = []; +% indexE = 1; +% for i=1:length(newG1) +% for k=1:length(newG2) +% vecAnd = (newG1{i} & newG2{k}); +% if isequal(vecAnd,zeroVec) +% continue; +% end +% newGen{index} = vecAnd; +% tempE(:,indexE) = [(tempE1(:,i));(tempE2(:,k))]; +% index=index+1; +% indexE=indexE+1; +% end +% end +% newE = [newE tempE]; +% end +% Z = logicalPolyZonotope(newcen,{},newGen,newE); +% Z = unique(Z); +% +% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +q1=length(Z1.GI); +h1=length(Z1.G); +p1=size(Z1.E,1); + +q2=length(Z2.GI); +h2=length(Z2.G); +p2=size(Z2.E,1); +tempE1=eye(size(Z1.GI,2)) ; +tempE2=eye(size(Z2.GI,2)); +zeroVec = logical(zeros(size(Z1.c))); +indexI =1; +newGenI ={}; +newE =[]; +index =1; +newGen ={}; + +% bring the exponent matrices to a common representation +[idCom,E1Com,E2Com] = mergeExpMatrix(Z1.id,Z2.id,Z1.E,Z2.E); +p1Com = size(E1Com,1); +p2Com = size(E2Com,1); + + +idNew=[]; +% there is no generators in Z2 to multiply with Z1 +if(~isempty(Z2.c) && ~isempty(Z1.GI) && isempty(Z2.GI) && isempty(Z2.G)) + for i=1:length(Z1.GI) + vecAnd = Z2.c & Z1.GI{i}; + if isequal(vecAnd,zeroVec) + continue; + end + newGenI{indexI} = vecAnd; + indexI=indexI+1; + end +elseif (~isempty(Z2.c) && ~isempty(Z1.GI)) + for i=1:length(Z1.GI) + vecAnd = Z2.c & Z1.GI{i}; + if isequal(vecAnd,zeroVec) + continue; + end + newGen{index} = vecAnd; + newE = [newE [zeros(p1Com,1);tempE1(:,i);zeros(q2,1)]]; + index=index+1; + end +end + +% there is no generators in Z1 to multiply with Z2 +if(~isempty(Z1.c) && ~isempty(Z2.GI) && isempty(Z1.GI) && isempty(Z1.G)) + for i=1:length(Z2.GI) + vecAnd = Z1.c & Z2.GI{i}; + if isequal(vecAnd,zeroVec) + continue; + end + newGenI{indexI} = vecAnd; + indexI=indexI+1; + end +elseif (~isempty(Z1.c) && ~isempty(Z2.GI)) + for i=1:length(Z2.GI) + vecAnd = Z1.c & Z2.GI{i}; + if isequal(vecAnd,zeroVec) + continue; + end + newGen{index} = vecAnd; + newE = [newE [zeros(p1Com,1);zeros(q1,1);tempE2(:,i)]]; + index=index+1; + end +end + + +if(~isempty(Z1.GI) && ~isempty(Z2.GI)) + %GI1 * GI1 + for i=1:length(Z1.GI) + for k=1:length(Z2.GI) + vecAnd = (Z1.GI{i} & Z2.GI{k}); + if isequal(vecAnd,zeroVec) + continue; + end + newGen{index} = vecAnd; + newE = [newE [zeros(p1Com,1);tempE1(:,i);tempE2(:,k)]]; + index = index +1; + end + + end +end + +%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 [E1Com(:,i);zeros(q1,1);zeros(q2,1)]]; + idNew =[idNew; idCom(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 [E2Com(:,i);zeros(q1,1);zeros(q2,1)]]; + if length(idCom)>1 + idNew =[idNew; idCom(2)]; + elseif length(idCom) == 1 & isempty(idNew) + idNew =[ idCom(1)]; + end + + 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; + tempECom=max([E1Com(:,i),E2Com(:,k)] ,[],2); + newE = [newE [tempECom;zeros(q1,1);zeros(q2,1)]]; + index=index+1; + if isempty(idNew) + idNew = idCom; + end + end + end +end + +if(~isempty(Z1.GI) && ~isempty(Z2.G)) + for i=1:length(Z1.GI) + for k=1:length(Z2.G) + vecAnd = (Z1.GI{i} & Z2.G{k}); + if isequal(vecAnd,zeroVec) + continue; + end + newGen{index} = vecAnd; + newE = [newE [E2Com(:,k);tempE1(:,i);zeros(q2,1)]]; + index=index+1; + end + end +end + +if(~isempty(Z1.G) && ~isempty(Z2.GI)) + for i=1:length(Z1.G) + for k=1:length(Z2.GI) + vecAnd = (Z1.G{i} & Z2.GI{k}); + if isequal(vecAnd,zeroVec) + continue; + end + newGen{index} = vecAnd; + newE = [newE [E1Com(:,i);zeros(q1,1);tempE2(:,k)]]; + index=index+1; + end + end +end + +% for i=1:length(newGen) +% newGenVec(:,i) = newGen{i}; +% end +% +% % and up all generators that belong to identical exponents +% [newE,newGenComVec] = removeRedundantExponentsAnd(newE,newGenVec); +% +% for i=1:size(newGenComVec,2) +% newGenComCell{i}= newGenComVec(:,i) ; +% end + +Z = logicalPolyZonotope(newcen,newGenI,newGen,newE,idNew); + +Z = unique(Z); + + +end + +%------------- END OF CODE -------------- \ No newline at end of file diff --git a/examplesInPapers.asv b/examplesInPapers.asv new file mode 100644 index 0000000..da183fc --- /dev/null +++ b/examplesInPapers.asv @@ -0,0 +1,30 @@ +clear all +% example 1 in polynomial logical zonotope paper + +c1= [0;1;0 ]; +g1{1} = [0;1;1]; +g1{2} = [1;1;1]; +E1=[1 1; 0 1]; +id1 = [ 1;2]; + +pZ1 = logicalPolyZonotope(c1,g1,E1,id1); + +evaluate(pZ1); +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Example 2 +c2= [1;0;0 ]; +g2{1} = [1;0;1]; +g2{2} = [0;1;0]; +E2=[0 1; 1 1]; +id2 = [ 1;3]; +pZ2 = logicalPolyZonotope(c2,g2,E2,id2); + +[id,E1,E2] = mergeExpMatrix(id1,id2,E1,E2) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Example 3 +c3= 0; +g3{1} = 1; +E3=1; +id3 = 1; +pZ3 = logicalPolyZonotope(c3,g3,E3,id3); +evaluate(pZ3) diff --git a/examplesInPapers.m b/examplesInPapers.m new file mode 100644 index 0000000..0cdc8ab --- /dev/null +++ b/examplesInPapers.m @@ -0,0 +1,32 @@ +clear all +% example 1 in polynomial logical zonotope paper + +c1= [0;1;0 ]; +g1{1} = [0;1;1]; +g1{2} = [1;1;1]; +E1=[1 1; 0 1]; +id1 = [ 1;2]; + +pZ1 = logicalPolyZonotope(c1,g1,E1,id1); + +evaluate(pZ1); +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Example 2 +c2= [1;0;0 ]; +g2{1} = [1;0;1]; +g2{2} = [0;1;0]; +E2=[0 1; 1 1]; +id2 = [ 1;3]; +pZ2 = logicalPolyZonotope(c2,g2,E2,id2); + +[id,E1,E2] = mergeExpMatrix(id1,id2,E1,E2); +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Example 3 +c3= 0; +g3{1} = 1; +E3=1; +id3 = 1; +pZ3 = logicalPolyZonotope(c3,g3,E3,id3); +evaluate(pZ3) +pZ3Xor= xor(pZ3,pZ3) +pZ3ExactXor= exactXor(pZ3,pZ3) \ No newline at end of file diff --git a/utilities/mergeExpMatrix.m b/utilities/mergeExpMatrix.m new file mode 100644 index 0000000..3adc322 --- /dev/null +++ b/utilities/mergeExpMatrix.m @@ -0,0 +1,66 @@ +function [id,E1,E2] = mergeExpMatrix(id1,id2,E1,E2) +% mergeExpMatrix - Merge the ID-vectors of two polyZonotope objects +% and adapte the exponent matrices accordingly +% +% Syntax: +% [id,E1,E2] = mergeExpMatrix(id1,id2,E1,E2) +% +% Inputs: +% id1 - ID-vector of the first polynomial zonotope +% id2 - ID-vector of the second polynomial zonotope +% E1 - exponent matrix of the first polynomial zonotope +% E2 - exponent matrix of the second polynomial zonotope +% +% Outputs: +% id - merged ID-vector +% E1 - adapted exponent matrix of the first polynomial zonotope +% E2 - adapted exponent matrix of the second polynomial zonotope +% +% Other m-files required: none +% Subfunctions: none +% MAT-files required: none +% +% See also: --- + +% Authors: Niklas Kochdumper +% Written: 25-June-2018 +% Last update: --- +% Last revision: --- + +% ------------------------------ BEGIN CODE ------------------------------- + +L1 = length(id1); +L2 = length(id2); + +% ID vectors are identical +if L1 == L2 && all(id1 == id2) + + id = id1; + +% ID vectors not identical -> MERGE +else + + % merge the two sets + id = id1; + ind2 = zeros(size(id2)); + for i = 1:length(id2) + ind = find(id == id2(i)); + if isempty(ind) + id = [id;id2(i)]; + ind2(i) = length(id); + else + ind2(i) = ind; + end + end + + % construct the new exponent matrices + L = length(id); + + E1 = [E1;zeros(L-L1,size(E1,2))]; + + temp = zeros(L,size(E2,2)); + temp(ind2,:) = E2; + E2 = temp; +end + +% ------------------------------ END OF CODE ------------------------------ diff --git a/utilities/removeRedundantExponents.m b/utilities/removeRedundantExponents.m new file mode 100644 index 0000000..86f396b --- /dev/null +++ b/utilities/removeRedundantExponents.m @@ -0,0 +1,119 @@ +function [Enew,Gnew] = removeRedundantExponents(E,G) +% removeRedundantExponents - add up all generators that belong to terms +% with identical exponents +% +% Syntax: +% [Enew, Gnew] = removeRedundantExponents(E,G) +% +% Inputs: +% E - matrix containing the exponent vectors +% G - generator matrix +% +% Outputs: +% Enew - modified exponent matrix +% Gnew - modified generator matrix +% +% Other m-files required: none +% Subfunctions: none +% MAT-files required: none +% +% See also: none + +% Authors: Niklas Kochdumper, Tobias Ladner +% Written: 25-June-2018 +% Last update: 21-April-2020 (remove zero-length generators) +% 23-June-2022 (performance optimizations) +% Last revision: --- + +% ------------------------------ BEGIN CODE ------------------------------- + +% return directly if G is empty +if isempty(G) + Enew = E; + Gnew = G; + return; +end + +% remove zero-length generators +idxD = any(G,1); + +% skip if all non-zero +if ~all(idxD) + if all(~idxD) + Enew = zeros(size(E,1),1); + Gnew = zeros(size(G,1),1); + return; + else + G = G(:,idxD); + E = E(:,idxD); + end +end + +% create a deterministic random hash vector +rs = RandStream('mt19937ar', 'Seed', 0); % to not interfer with the outside +hashVec = rs.rand(1, size(E, 1)); +hashMat = (hashVec*E)'; + +% sort the exponent vectors according to the hash value +[hashes, ind] = sortrows(hashMat); +ind = ind'; % row + +% test if all (sorted) hashes are different +uniqueHashIdx = [hashes(1:end-1) ~= hashes(2:end); true] ... % succ + & [true; hashes(1:end-1) ~= hashes(2:end)]; % pred + +% if so, return directly +numUnique = sum(uniqueHashIdx); +if numUnique == size(E, 2) + Enew = E; + Gnew = G; + return +end + +% initialize new matrices +Enew = zeros(size(E)); +Gnew = zeros(size(G)); + +% copy unique hashes +uniqueColumns = ind(uniqueHashIdx); +Enew(:, 1:numUnique) = E(:, uniqueColumns); +Gnew(:, 1:numUnique) = G(:, uniqueColumns); +current = numUnique + 1; + +% continue with potential redundancies +ind = ind(~uniqueHashIdx); + +E = E(:, ind); +G = G(:, ind); +hashMat = hashMat(ind); +ind = 1:length(ind); + +% first entry +ind_i = ind(1); +exp_c = E(:,ind_i); +hash_c = hashMat(ind_i); +Enew(:,current) = exp_c; +Gnew(:,current) = G(:,ind_i); + +% loop over all exponent vectors +for ind_i = ind(2:end) + hash_i = hashMat(ind_i); + exp_i = E(:,ind_i); + + if hash_c == hash_i && all(exp_c == exp_i) + Gnew(:,current) = xor(Gnew(:,current) ,G(:,ind_i)); + else + current = current + 1; + exp_c = exp_i; + hash_c = hash_i; + Enew(:,current) = exp_c; + Gnew(:,current) = G(:,ind_i); + end +end + + +% truncate exponent and generator matrix +Enew(:,current+1:end) = []; +Gnew(:,current+1:end) = []; + +% ------------------------------ END OF CODE ------------------------------ diff --git a/utilities/setDefaultValues.m b/utilities/setDefaultValues.m new file mode 100644 index 0000000..e2324ad --- /dev/null +++ b/utilities/setDefaultValues.m @@ -0,0 +1,44 @@ +function varargout = setDefaultValues(defaultValues,givenValues) +% setDefaultValues - set default values for input arguments; if some value +% is given, then this value is kept (check for admissible values is done +% using inputArgsCheck) +% +% Syntax: +% varargout = setDefaultValues(defaultValues,givenValues) +% +% Inputs: +% defaultValues - default values in a cell-array: {dV1,dV2,...,dVend} +% givenValues - user-provided values in a cell-array +% +% Outputs: +% varargout - values for input arguments (1xn cell-array), where the +% the non-given values are set to default values +% +% Example: +% defValues = {1,'standard','lower',true}; +% givenValues = {10,'gaussian'}; +% [N,type,mode,flag] = setDefaultValues(defValues,givenValues); +% +% Other m-files required: none +% Subfunctions: none +% MAT-files required: none +% +% See also: inputArgsCheck + +% Authors: Mingrui Wang, Mark Wetzlinger +% Written: 30-May-2022 +% Last update: 23-December-2022 (TL, speed up) +% Last revision: --- + +% ------------------------------ BEGIN CODE ------------------------------- + +% number of given input arguments +n_given = length(givenValues); + +% number of default values +n_default = max(size(defaultValues)); + +% assign default values if corresponding values are not provided +varargout = [givenValues(1:n_given), defaultValues(n_given+1:n_default)]; + +% ------------------------------ END OF CODE ------------------------------ diff --git a/utilities/vehLogicBDD4.m b/utilities/vehLogicBDD4.m index 5be89e4..a2ff7db 100644 --- a/utilities/vehLogicBDD4.m +++ b/utilities/vehLogicBDD4.m @@ -1,12 +1,25 @@ function [VPn,CFn] = vehLogicBDD4(U,VP,CF) + + VPn{1} = U{1} & not(VP{1}) & not(CF{1}) ; VPn{2} = U{2} & not(VP{2}) & not(CF{2}) ; -%CFn{1} =and(or(and( not(VP{1}),VPn{1}) ,U{3}),not(VPn{1})); -%CFn{2} =and(or(and(not(VP{2}),VPn{2}),U{4}),not(VPn{2})); +VPn{3} = U{5} & not(VP{4}) & not(CF{3}) ; +VPn{4} = U{6} & not(VP{3}) & not(CF{4}) ; + +CFn{1} =and(or(and( not(VP{1}),VPn{1}) ,U{3}),not(VPn{1})); +CFn{2} =and(or(and(not(VP{2}),VPn{2}),U{4}),not(VPn{2})); +CFn{3} =and(or(and(not(VP{3}),VPn{3}),U{7}),not(VPn{3})); +CFn{4} =and(or(and(not(VP{4}),VPn{4}),U{8}),not(VPn{4})); -CFn{1} =and(U{3},(or(CF{1},(or(not(U{3}),VP{1}))))); -CFn{2} =and(U{3},(or(CF{2},(or(not(U{4}),VP{2}))))); +% +% VPn{1} = U{1} & not(VP{1}) & not(CF{1}) ; +% VPn{2} = U{2} & not(VP{2}) & not(CF{2}) ; +% %CFn{1} =and(or(and( not(VP{1}),VPn{1}) ,U{3}),not(VPn{1})); +% %CFn{2} =and(or(and(not(VP{2}),VPn{2}),U{4}),not(VPn{2})); +% +% CFn{1} =and(U{3},(or(CF{1},(or(not(U{3}),VP{1}))))); +% CFn{2} =and(U{3},(or(CF{2},(or(not(U{4}),VP{2}))))); % VPn{1} = or(U{1} & U{3} & not(CF{2}), U{1}); % VPn{2} =or(U{2} &U{4}¬(CF{1})& VP{1},VP{2}); diff --git a/utilities/vehLogicExactPolyZono4.m b/utilities/vehLogicExactPolyZono4.m new file mode 100644 index 0000000..d92b822 --- /dev/null +++ b/utilities/vehLogicExactPolyZono4.m @@ -0,0 +1,52 @@ +function [VPn,CFn] = vehLogicExactPolyZono4(U,VP,CF) + +% VPn{1} = reduceOneBit(exactAnd(reduceOneBit(exactAnd(U{1} , not(VP{1}))) , not(CF{1}))) ; +% VPn{2} = reduceOneBit(exactAnd(reduceOneBit(exactAnd(U{2} , not(VP{2}))) , not(CF{2}))) ; +% VPn{3} = reduceOneBit(exactAnd(reduceOneBit(exactAnd(U{5} , not(VP{4}))) , not(CF{3}))) ; +% VPn{4} = reduceOneBit(exactAnd(U{6} & not(VP{3}) , not(CF{4}))) ; +% +% +% CFn{1} =reduceOneBit(exactAnd(reduceOneBit(exactOr(reduceOneBit(exactAnd( not(VP{1}),VPn{1})) ,U{3})),not(VPn{1}))); +% CFn{2} =reduceOneBit(exactAnd(reduceOneBit(exactOr(reduceOneBit(exactAnd(not(VP{2}),VPn{2})),U{4})),not(VPn{2}))); +% CFn{3} =reduceOneBit(exactAnd(reduceOneBit(exactOr(reduceOneBit(exactAnd(not(VP{3}),VPn{3})),U{7})),not(VPn{3}))); +% CFn{4} =reduceOneBit(exactAnd(reduceOneBit(exactOr(reduceOneBit(exactAnd(not(VP{4}),VPn{4})),U{8})),not(VPn{4}))); + + +VPn{1} = (exactAnd(exactAnd(U{1} , not(VP{1})) , not(CF{1}))) ; +VPn{2} =(exactAnd(exactAnd(U{2} , not(VP{2})) , not(CF{2}))) ; +VPn{3} = (exactAnd(exactAnd(U{5} , not(VP{4})) , not(CF{3}))) ; +%VPn{4} = reduceOneBit(exactAnd(exactAnd(U{6} , not(VP{3})) , not(CF{4}))) ; +VPn{4} = (exactAnd(U{6} & not(VP{3}) , not(CF{4}))) ; + +CFn{1} =(exactAnd(exactOr(exactAnd( not(VP{1}),VPn{1}) ,U{3}),not(VPn{1}))); +CFn{2} =(exactAnd(exactOr(exactAnd(not(VP{2}),VPn{2}),U{4}),not(VPn{2}))); +CFn{3} =(exactAnd(exactOr(exactAnd(not(VP{3}),VPn{3}),U{7}),not(VPn{3}))); +CFn{4} =(exactAnd(exactOr(exactAnd(not(VP{4}),VPn{4}),U{8}),not(VPn{4}))); + + + +% VPn{1} = or(U{1} & U{3} & not(CF{2}), U{1}); +% VPn{2} =or(U{2} &U{4}¬(CF{1})& VP{1},VP{2}); +% VPn{3} =or(U{3},U{1} &U{2} ¬(VP{2})¬(VP{3})&CF{3}); +% VPn{4} =or(U{4},U{1} &U{2} ¬(VP{1})¬(VP{4})&CF{4}); + +% CFn{1} =or(U{3},and(U{1},not(VPn{1}))); +% CFn{2} =or(U{4},and(U{2},not(VPn{2}))); +% CFn{3} =or(U{1}, and(or(and(not(VP{3}),VPn{3}),U{1}),not(VPn{3}))); +% CFn{4} =or(U{2}, and(or(and(not(VP{4}),VPn{4}),U{2}),not(VPn{4}))); + + +% VPn{1} = not(VP{2}) & not(VP{4}) & not(VP{1}) & CF{1} & not(CF{2}) & not(CF{4}); +% VPn{2} = not(VP{1})& not(VP{3})& not(VP{2})&CF{2}¬(CF{1})¬(CF{3}); +% VPn{3} =not(VP{2})¬(VP{3})&CF{3}; +% VPn{4} =not(VP{1})¬(VP{4})&CF{4}; +% +% CFn{1} =and(or(and( not(VP{1}),VPn{1}) ,U{1}),not(VPn{1})); +% CFn{2} =and(or(and(not(VP{2}),VPn{2}),U{2}),not(VPn{2})); +% CFn{3} = and(or(and(not(VP{3}),VPn{3}),CF{3}),not(VPn{3})); +% CFn{4} = and(or(and(not(VP{4}),VPn{4}),CF{4}),not(VPn{4})); + + + + +end \ No newline at end of file diff --git a/utilities/vehLogicPolyZono4.m b/utilities/vehLogicPolyZono4.m new file mode 100644 index 0000000..dfa176e --- /dev/null +++ b/utilities/vehLogicPolyZono4.m @@ -0,0 +1,51 @@ +function [VPn,CFn] = vehLogicPolyZono4(U,VP,CF) + +% VPn{1} = reduceOneBit(exactAnd(reduceOneBit(exactAnd(U{1} , not(VP{1}))) , not(CF{1}))) ; +% VPn{2} = reduceOneBit(exactAnd(reduceOneBit(exactAnd(U{2} , not(VP{2}))) , not(CF{2}))) ; +% VPn{3} = reduceOneBit(exactAnd(reduceOneBit(exactAnd(U{5} , not(VP{4}))) , not(CF{3}))) ; +% VPn{4} = reduceOneBit(exactAnd(U{6} & not(VP{3}) , not(CF{4}))) ; +% +% +% CFn{1} =reduceOneBit(exactAnd(reduceOneBit(exactOr(reduceOneBit(exactAnd( not(VP{1}),VPn{1})) ,U{3})),not(VPn{1}))); +% CFn{2} =reduceOneBit(exactAnd(reduceOneBit(exactOr(reduceOneBit(exactAnd(not(VP{2}),VPn{2})),U{4})),not(VPn{2}))); +% CFn{3} =reduceOneBit(exactAnd(reduceOneBit(exactOr(reduceOneBit(exactAnd(not(VP{3}),VPn{3})),U{7})),not(VPn{3}))); +% CFn{4} =reduceOneBit(exactAnd(reduceOneBit(exactOr(reduceOneBit(exactAnd(not(VP{4}),VPn{4})),U{8})),not(VPn{4}))); + + +VPn{1} = reduceOneBit(and(and(U{1} , not(VP{1})) , not(CF{1}))) ; +VPn{2} = reduceOneBit(and(and(U{2} , not(VP{2})) , not(CF{2}))) ; +VPn{3} = reduceOneBit(and(and(U{5} , not(VP{4})) , not(CF{3}))) ; +VPn{4} = reduceOneBit(and(U{6} & not(VP{3}) , not(CF{4}))) ; + +CFn{1} =reduceOneBit(and(or(and( not(VP{1}),VPn{1}) ,U{3}),not(VPn{1}))); +CFn{2} =reduceOneBit(and(or(and(not(VP{2}),VPn{2}),U{4}),not(VPn{2}))); +CFn{3} =reduceOneBit(and(or(and(not(VP{3}),VPn{3}),U{7}),not(VPn{3}))); +CFn{4} =reduceOneBit(and(or(and(not(VP{4}),VPn{4}),U{8}),not(VPn{4}))); + + + +% VPn{1} = or(U{1} & U{3} & not(CF{2}), U{1}); +% VPn{2} =or(U{2} &U{4}¬(CF{1})& VP{1},VP{2}); +% VPn{3} =or(U{3},U{1} &U{2} ¬(VP{2})¬(VP{3})&CF{3}); +% VPn{4} =or(U{4},U{1} &U{2} ¬(VP{1})¬(VP{4})&CF{4}); + +% CFn{1} =or(U{3},and(U{1},not(VPn{1}))); +% CFn{2} =or(U{4},and(U{2},not(VPn{2}))); +% CFn{3} =or(U{1}, and(or(and(not(VP{3}),VPn{3}),U{1}),not(VPn{3}))); +% CFn{4} =or(U{2}, and(or(and(not(VP{4}),VPn{4}),U{2}),not(VPn{4}))); + + +% VPn{1} = not(VP{2}) & not(VP{4}) & not(VP{1}) & CF{1} & not(CF{2}) & not(CF{4}); +% VPn{2} = not(VP{1})& not(VP{3})& not(VP{2})&CF{2}¬(CF{1})¬(CF{3}); +% VPn{3} =not(VP{2})¬(VP{3})&CF{3}; +% VPn{4} =not(VP{1})¬(VP{4})&CF{4}; +% +% CFn{1} =and(or(and( not(VP{1}),VPn{1}) ,U{1}),not(VPn{1})); +% CFn{2} =and(or(and(not(VP{2}),VPn{2}),U{2}),not(VPn{2})); +% CFn{3} = and(or(and(not(VP{3}),VPn{3}),CF{3}),not(VPn{3})); +% CFn{4} = and(or(and(not(VP{4}),VPn{4}),CF{4}),not(VPn{4})); + + + + +end \ No newline at end of file