diff --git a/@logicalZonotope/cartProd.asv b/@logicalZonotope/cartProd.asv deleted file mode 100644 index 37e28ad..0000000 --- a/@logicalZonotope/cartProd.asv +++ /dev/null @@ -1,78 +0,0 @@ -function Z = cartProd(Z1,Z2) -% cartProd - Returns the cartesian product of two zonotopes -% -% Syntax: -% Z = cartProd(Z1,Z2) -% -% Inputs: -% Z1 - zonotope object -% Z2 - zonotope object -% -% Outputs: -% Z - zonotope object -% -% Example: -% zono1 = zonotope.generateRandom(2); -% zono2 = zonotope.generateRandom(3); -% -% zono = cartProd(zono1,zono2); -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: none - -% Author: Matthias Althoff -% Written: 18-May-2011 -% Last update: 27-Aug-2019 -% 05-May-2020 (MW, standardized error message) -% Last revision:--- - -%------------- BEGIN CODE -------------- - -% first or second set is zonotope - - -if(~isempty(Z1.c) & ~isempty(Z2.c)) - newCen = [ Z1.c;Z2.c ]; -elseif (isempty(Z1.c) & isempty(Z2.c)) - newCen =[]; -elseif isempty(Z1.c) - newCen = Z2.c ; -elseif isempty(Z2.c) - newCen = Z1.c ; -end - -if(isempty(Z1.G)) - newGen = Z2.G; -elseif(isempty(Z2.G)) - newGen = Z1.G; -elseif(isempty(Z2.G) & isempty(Z2.G)) - newGen ={}; -elseif(~isempty(Z2.G) & ~isempty(Z2.G)) - g1Len = length(Z1.G); - g2Len = length(Z2.G); - sizeOfCen = length(newCen); - - - for i =1:g1Len - newGen{i} = [Z1.G{i}; - end - - - index =1; - for i=g1Len+1:g1Len+g2Len - newGen{i} = Z2.G{index}; - index = index +1; - end -end - -Z=logicalZonotope(newCen,newGen); -Z =unique(Z); - -end - - - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalZonotope/cartProd.m b/@logicalZonotope/cartProd.m index c2478d0..1f4945f 100644 --- a/@logicalZonotope/cartProd.m +++ b/@logicalZonotope/cartProd.m @@ -12,10 +12,6 @@ % Z - zonotope object % % Example: -% zono1 = zonotope.generateRandom(2); -% zono2 = zonotope.generateRandom(3); -% -% zono = cartProd(zono1,zono2); % % Other m-files required: none % Subfunctions: none @@ -23,15 +19,14 @@ % % See also: none -% Author: Matthias Althoff -% Written: 18-May-2011 -% Last update: 27-Aug-2019 -% 05-May-2020 (MW, standardized error message) +% Author: Amr Alanwar +% Written: 16-October-2022 +% Last update: +% % Last revision:--- %------------- BEGIN CODE -------------- -% first or second set is zonotope if(~isempty(Z1.c) & ~isempty(Z2.c)) diff --git a/@logicalZonotope/containsPoint.m b/@logicalZonotope/containsPoint.m index 2b97f55..1ab7616 100644 --- a/@logicalZonotope/containsPoint.m +++ b/@logicalZonotope/containsPoint.m @@ -1,15 +1,12 @@ -function res = containsPoint(Z,p,varargin) -% containsPoint - determines if the point p is inside the zonotope Z1 +function res = containsPoint(Z,p) +% containsPoint - determines if the point p is inside the logical zonotope Z1 % % Syntax: % res = containsPoint(Z,p) -% res = containsPoint(Z,p,tolerance) % % Inputs: % Z - zonotope object % p - point specified as a vector -% tolerance - numerical tolerance up to which the point is allowed to -% outside the zonotope % % Outputs: % res - boolean whether the point is inside the zonotope or not @@ -19,8 +16,6 @@ % p = [1;0]; % res = containsPoint(Z,p); % -% plot(Z); hold on; -% scatter(p(1),p(2),16,'r'); % % Other m-files required: none % Subfunctions: none @@ -28,8 +23,8 @@ % % See also: --- -% Author: Niklas Kochdumper -% Written: 30-January-2018 +% Author: Amr Alanwar +% Written: 16-October-2022 % Last update: --- % Last revision:--- @@ -62,9 +57,6 @@ return; end - - - end else diff --git a/@logicalZonotope/enclosePoints.m b/@logicalZonotope/enclosePoints.m index 681194e..e79a2e8 100644 --- a/@logicalZonotope/enclosePoints.m +++ b/@logicalZonotope/enclosePoints.m @@ -8,7 +8,7 @@ % points - matrix storing point cloud (dimension: [n,p] for p points) % % Outputs: -% Z - zonotope object +% Z - logical zonotope object % % Example: % @@ -17,7 +17,7 @@ % Subfunctions: none % MAT-files required: none % -% See also: interval, polytope +% See also: % Author: Amr Alanwar % Written: 11-Aug-2020 @@ -25,26 +25,7 @@ % Last revision: --- %------------- BEGIN CODE -------------- -% [dim,numOfPoints] = size(points); -% cen = []; -% newpoints = []; -% for i = 1:numOfPoints -% if zeros(dim,1) ==points(:,i) -% cen =zeros(dim,1); -% else -% newpoints= [newpoints points(:,i)]; -% end -% end -% newpoints=unique(newpoints','rows')'; -% -% [row,cols] = size(newpoints); -% for i = 1:cols -% gen{i} = newpoints(:,i); -% end -%points=unique(points','rows')'; -% cen =zeros(dim,1); -% gen = {points}; points=unique(points','rows')'; [dim,numOfPoints] = size(points); cen = points(:,1); diff --git a/@logicalZonotope/enclosePoints2.asv b/@logicalZonotope/enclosePoints2.asv deleted file mode 100644 index 5dc04da..0000000 --- a/@logicalZonotope/enclosePoints2.asv +++ /dev/null @@ -1,91 +0,0 @@ -function Z = enclosePoints2(points,varargin) -% enclosePoints - enclose a point cloud with a zonotope -% -% Syntax: -% Z = enclosePoints(points) -% -% Inputs: -% points - matrix storing point cloud (dimension: [n,p] for p points) -% -% Outputs: -% Z - zonotope object -% -% Example: -% -% References: -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: interval, polytope - -% Author: Amr Alanwar -% Written: 11-Aug-2020 -% Last update: --- -% Last revision: --- - -%------------- BEGIN CODE -------------- -% [dim,numOfPoints] = size(points); -% cen = []; -% newpoints = []; -% for i = 1:numOfPoints -% if zeros(dim,1) ==points(:,i) -% cen =zeros(dim,1); -% else -% newpoints= [newpoints points(:,i)]; -% end -% end -% newpoints=unique(newpoints','rows')'; -% -% [row,cols] = size(newpoints); -% for i = 1:cols -% gen{i} = newpoints(:,i); -% end - -%points=unique(points','rows')'; -% cen =zeros(dim,1); -% gen = {points}; -points=unique(points','rows')'; -[dim,numOfPoints] = size(points); -cen = points(:,1); -if numOfPoints > 1 - containsZeroFlag=0; - newPoints = []; - for i =1:numOfPoints - if points(:,i) == zeros(dim,1) - containsZeroFlag =1; - else - newPoints =[newPoints points(:,i)]; - end - end - gen ={}; - if containsZeroFlag ==1 - cen = zeros(dim,1); - index =1; - for i =1:numOfPoints-1 - - tempZ = logicalZonotope(cen,gen); - if(~tempZ.containsPoint(points(:,i))) - gen{index} =newPoints(:,i); - index = index +1; - end - end - else - index =1; - for i =2:numOfPoints - tempZ = logicalZonotope(cen,gen); - if(~tempZ.containsPoint(points(:,i))) - gen{index} = xor(cen,points(:,i)); - index = index +1; - end - end - end - Z =logicalZonotope(cen,gen); -else - Z =logicalZonotope(cen,{}); -end -Z=unique(Z); - -end - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalZonotope/isempty.m b/@logicalZonotope/isempty.m index 1860d30..e59d904 100644 --- a/@logicalZonotope/isempty.m +++ b/@logicalZonotope/isempty.m @@ -11,12 +11,6 @@ % res - result in {0,1} % % Example: -% Z1 = zonotope([]); -% Z2 = zonotope([0;0]); -% Z3 = zonotope([1;0],[1 -2 1; 0 1 -2]); -% isempty(Z1); % true -% isempty(Z2); % false -% isempty(Z3); % false % % Other m-files required: none % Subfunctions: none diff --git a/@logicalZonotope/map2D.asv b/@logicalZonotope/map2D.asv deleted file mode 100644 index 776ce5a..0000000 --- a/@logicalZonotope/map2D.asv +++ /dev/null @@ -1,51 +0,0 @@ -function [location2D , hX,hY,numXGrids]= map2D(Z) -%MAP2D Summary of this function goes here -% Detailed explanation goes here -dim = length(Z.c); - -binaryPoints=evaluate(Z); -[rows,cols]=size(binaryPoints); -decPoints=[]; -for i =1:cols - strPoint= num2str( binaryPoints(:,i) ); - temp=''; - for j =1:length(strPoint) - temp = strcat(temp,strPoint(j)); - end - d=bin2dec( temp ); - decPoints = [decPoints,d]; -end - -%adding one to avoid zeros -decPoints = decPoints +1; - -ndigit= length(binaryPoints(:,1)); -if ndigit <5 -numXGrids=2^(ndigit-1); -numYGrids=2^(ndigit-1); -else - -end - -hX=linspace(1,max(decPoints)/2,numXGrids);%for 128 resolution -hY=linspace(1,max(decPoints)/2,numYGrids);%for 128 resolution - - -for i=1:length(decPoints) - if(rem(decPoints(i),numXGrids)==0) - Ydata(i) = decPoints(i)/numXGrids; - else - Ydata(i) = floor( decPoints(i)/numXGrids) +1; - end -end - -% [flag, index] = ismember(numYGrids+1,Ydata); -% if flag -% Ydata(index) = length(hY); -% end - - -Xdata = decPoints - numXGrids.*(Ydata -1); -location2D = [hX(Xdata) ; hY(Ydata) ]; -end - diff --git a/@logicalZonotope/map2D.m b/@logicalZonotope/map2D.m deleted file mode 100644 index 8276a02..0000000 --- a/@logicalZonotope/map2D.m +++ /dev/null @@ -1,52 +0,0 @@ -function [location2D , hX,hY,numXGrids]= map2D(Z) -%MAP2D Summary of this function goes here -% Detailed explanation goes here -dim = length(Z.c); - -binaryPoints=evaluate(Z); -[rows,cols]=size(binaryPoints); -decPoints=[]; -for i =1:cols - strPoint= num2str( binaryPoints(:,i) ); - temp=''; - for j =1:length(strPoint) - temp = strcat(temp,strPoint(j)); - end - d=bin2dec( temp ); - decPoints = [decPoints,d]; -end - -%adding one to avoid zeros -decPoints = decPoints +1; - -ndigit= length(binaryPoints(:,1)); -if ndigit <5 -numXGrids=ndigit; -numYGrids=ndigit; -else -numXGrids=127; -numYGrids=127; -end - -hX=linspace(1,max(decPoints)/2,numXGrids);%for 128 resolution -hY=linspace(1,max(decPoints)/2,numYGrids);%for 128 resolution - - -for i=1:length(decPoints) - if(rem(decPoints(i),numXGrids)==0) - Ydata(i) = decPoints(i)/numXGrids; - else - Ydata(i) = floor( decPoints(i)/numXGrids) +1; - end -end - -% [flag, index] = ismember(numYGrids+1,Ydata); -% if flag -% Ydata(index) = length(hY); -% end - - -Xdata = decPoints - numXGrids.*(Ydata -1); -location2D = [hX(Xdata) ; hY(Ydata) ]; -end - diff --git a/@logicalZonotope/mtSum.m b/@logicalZonotope/mtSum.m deleted file mode 100644 index e6f2e59..0000000 --- a/@logicalZonotope/mtSum.m +++ /dev/null @@ -1,115 +0,0 @@ -function Z = mtSum(factor1,factor2) -% mtimes - Overloaded '*' operator for the multiplication of a matrix or an -% interval matrix with a zonotope -% -% Syntax: -% Z = mtimes(matrix,Z) -% -% Inputs: -% matrix - numerical or interval matrix -% Z - zonotope object -% -% Outputs: -% Z - Zonotpe after multiplication of a matrix with a zonotope -% -% Example: -% Z=zonotope([1 1 0; 0 0 1]); -% matrix=[0 1; 1 0]; -% plot(Z); -% hold on -% Z=matrix*Z; -% plot(Z); -% -% References: -% [1] M. Althoff. "Reachability analysis and its application to the -% safety assessment of autonomous cars", Dissertation, TUM 2010 -% [2] M. Althoff et al. "Modeling, Design, and Simulation of Systems -% with Uncertainties". 2011 -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: plus - -% Author: Matthias Althoff -% Written: 30-September-2006 -% Last update: 07-September-2007 -% 05-January-2009 -% 06-August-2010 -% 01-February-2011 -% 08-February-2011 -% 18-November-2015 -% Last revision:--- - -%------------- BEGIN CODE -------------- - -%Find a zonotope object -%Is factor1 a zonotope? -if isa(factor1,'logicalZonotope') - %initialize resulting zonotope - Z=factor1; - %initialize other summand - matrix=factor2; - %Is factor2 a zonotope? -elseif isa(factor2,'logicalZonotope') - %initialize resulting zonotope - Z=factor2; - %initialize other summand - matrix=factor1; -end - -%numeric matrix -%if isnumeric(matrix) - - -[mrows,mcols]=size(matrix); - - -if ~isempty(Z.c) - for k =1:mrows - temp =0; - for ii =1:mcols - temp=or(temp,(matrix(k,ii) & Z.c(ii) )); - %temp=temp + matrix(k,ii) * Z.c(ii) ; - end - result.c(k,1) = temp; - end -else - result.c ={}; -end -%result.c=matrix * Z.c; - -if ~isempty(Z.G) - for i =1:length(Z.G) - - [mrows,mcols]=size(matrix); - [grows,gcols]=size(Z.G{i}); - - % for j=1:gcols - - for k =1:mrows - temp = 0; - for ii =1:grows - %temp=temp + matrix(k,ii) * Z.G{i}(ii,1) ; - temp=or(temp,(matrix(k,ii) & Z.G{i}(ii,1) )); - end - result.G{i}(k,1) = temp; - end - % result.G{i} = mod(result.G{i},2); - % end - end - - Z = logicalZonotope(result.c,result.G); - Z = unique(Z); -else - Z = logicalZonotope(result.c,{}); -end - -end - -% - - - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalZonotope/mtimes.m b/@logicalZonotope/mtimes.m deleted file mode 100644 index edd6142..0000000 --- a/@logicalZonotope/mtimes.m +++ /dev/null @@ -1,115 +0,0 @@ -function Z = mtimes(factor1,factor2) -% mtimes - Overloaded '*' operator for the multiplication of a matrix or an -% interval matrix with a zonotope -% -% Syntax: -% Z = mtimes(matrix,Z) -% -% Inputs: -% matrix - numerical or interval matrix -% Z - zonotope object -% -% Outputs: -% Z - Zonotpe after multiplication of a matrix with a zonotope -% -% Example: -% Z=zonotope([1 1 0; 0 0 1]); -% matrix=[0 1; 1 0]; -% plot(Z); -% hold on -% Z=matrix*Z; -% plot(Z); -% -% References: -% [1] M. Althoff. "Reachability analysis and its application to the -% safety assessment of autonomous cars", Dissertation, TUM 2010 -% [2] M. Althoff et al. "Modeling, Design, and Simulation of Systems -% with Uncertainties". 2011 -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: plus - -% Author: Matthias Althoff -% Written: 30-September-2006 -% Last update: 07-September-2007 -% 05-January-2009 -% 06-August-2010 -% 01-February-2011 -% 08-February-2011 -% 18-November-2015 -% Last revision:--- - -%------------- BEGIN CODE -------------- - -%Find a zonotope object -%Is factor1 a zonotope? -if isa(factor1,'logicalZonotope') - %initialize resulting zonotope - Z=factor1; - %initialize other summand - matrix=factor2; - %Is factor2 a zonotope? -elseif isa(factor2,'logicalZonotope') - %initialize resulting zonotope - Z=factor2; - %initialize other summand - matrix=factor1; -end - -%numeric matrix -%if isnumeric(matrix) - - -[mrows,mcols]=size(matrix); - - -if ~isempty(Z.c) - for k =1:mrows - temp =0; - for ii =1:mcols - %temp=or(temp,(matrix(k,ii) & Z.c(ii) )); - temp=temp + matrix(k,ii) * Z.c(ii) ; - end - result.c(k,1) = temp; - end -else - result.c ={}; -end -%result.c=matrix * Z.c; - -if ~isempty(Z.G) - for i =1:length(Z.G) - - [mrows,mcols]=size(matrix); - [grows,gcols]=size(Z.G{i}); - - % for j=1:gcols - - for k =1:mrows - temp = 0; - for ii =1:grows - temp=temp + matrix(k,ii) * Z.G{i}(ii,1) ; - %temp=or(temp,(matrix(k,ii) & Z.G{i}(ii,1) )); - end - result.G{i}(k,1) = temp; - end - result.G{i} = mod(result.G{i},2); - % end - end - - Z = logicalZonotope(mod(result.c,2),result.G); - Z = unique(Z); -else - Z = logicalZonotope(result.c,{}); -end - -end - -% - - - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalZonotope/nand.m b/@logicalZonotope/nand.m index 20e2889..7a69487 100644 --- a/@logicalZonotope/nand.m +++ b/@logicalZonotope/nand.m @@ -1,27 +1,17 @@ function Z = nand(Z1,Z2) -% and - overloads & operator, computes the nor of two logical zonotopes +% nand - computes the nand of two logical zonotopes % % Syntax: -% Z = nor(Z1,Z2) +% Z = nand(Z1,Z2) % % Inputs: % Z1 - zonotope % Z2 - zonotope, % % Outputs: -% Z - zonotope object enclosing the and zonotope +% Z - zonotope object enclosing the nand zonotope % % Example: -% zono1 = zonotope([4 2 2;1 2 0]); -% zono2 = zonotope([3 1 -1 1;3 1 2 0]); -% -% res = nor(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 diff --git a/@logicalZonotope/not.m b/@logicalZonotope/not.m index 8deeca0..f764693 100644 --- a/@logicalZonotope/not.m +++ b/@logicalZonotope/not.m @@ -1,27 +1,16 @@ function Z = not(Z1) -% and - overloads & operator, computes the intersection of two zonotopes +% and - overloads ~ operator, computes not of a logical zonotope % % Syntax: -% Z = not(Z1,Z2) +% Z = not(Z1) % % 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 @@ -38,11 +27,11 @@ %------------- BEGIN CODE -------------- if (~isempty(Z1.c)) -[rows,cols] = size(Z1.c); + [rows,cols] = size(Z1.c); else -[rows,cols] = size(Z1.G{1}); + [rows,cols] = size(Z1.G{1}); end -Zone = logicalZonotope(ones(rows,1),[]); +Zone = logicalZonotope(ones(rows,1),{}); Z = xor(Zone,Z1); Z =unique(Z); end diff --git a/@logicalZonotope/or.asv b/@logicalZonotope/or.asv deleted file mode 100644 index c3b0a71..0000000 --- a/@logicalZonotope/or.asv +++ /dev/null @@ -1,108 +0,0 @@ -function Z = or(Z1,Z2,varargin) -% or - overloads | operator, computes the OR of two logical zonotopes -% -% Syntax: -% Z = or(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: 8-Aug-2022 -% Last update: -% -% -% Last revision: --- - -%------------- BEGIN CODE -------------- - -if ~isa(Z1,'logicalZonotope') -Z1=logicalZonotope.enclosePoints(Z1); -end - -if ~isa(Z2,'logicalZonotope') -Z2=logicalZonotope.enclosePoints(Z2); - -end - -if(~isempty(Z1.c) & ~isempty(Z2.c)) -newcen = or(Z1.c, Z2.c); -else -newcen =[]; -end - -if(~isempty(Z1.G) & ~isempty(Z2.G)) - %c2 * G1 - index =1; -% if(~isempty(Z2.c)) -% for i=1:length(Z1.G) -% newGen{index} = or(Z2.c,Z1.G{i}); -% index=index+1; -% end -% end -% if(~isempty(Z1.c)) -% for i=1:length(Z2.G) -% newGen{index} = or(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) - newGen{index} = or(Z1.G{i}, Z2.G{k}); - 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; -% newGen ={}; -% if(~isempty(Z2.c)) -% for i=1:length(Z1.G) -% newGen{index} = or(Z2.c, Z1.G{i}); -% index=index+1; -% end -% end - - Z = logicalZonotope(newcen,Z1.G); -elseif (isempty(Z1.G)) - %c2 * G1 -% newGen = Z2.G; -% -% index =length(newGen)+1; -% if(~isempty(Z1.c)) -% for i=1:length(Z2.G) -% newGen{index} = or(Z1.c,Z2.G{i}); -% index=index+1; -% end -% end -% -% newGen{index} = Z2.c ; - - - Z = logicalZonotope(newcen,Z2.G); - -end -Z = unique(Z); -end - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalZonotope/or.m b/@logicalZonotope/or.m index 7c57077..275f997 100644 --- a/@logicalZonotope/or.m +++ b/@logicalZonotope/or.m @@ -1,5 +1,5 @@ function Z = or(Z1,Z2) -% and - overloads & operator, computes the intersection of two zonotopes +% and - overloads | operator, computes the or of two zonotopes % % Syntax: % Z = or(Z1,Z2) @@ -12,16 +12,6 @@ % 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 @@ -30,7 +20,7 @@ % See also: none % Author: Amr Alanwar -% Written: 8-Sept-2022 +% Written: 16-October-2022 % Last update: % % diff --git a/@logicalZonotope/plot.asv b/@logicalZonotope/plot.asv deleted file mode 100644 index 73459fc..0000000 --- a/@logicalZonotope/plot.asv +++ /dev/null @@ -1,81 +0,0 @@ -function han = plot(Z,varargin) -% plot - Plots 2-dimensional projection of a zonotope -% -% Syntax: -% h = plot(Z) plots the zonotope Z for the first two dimensions -% h = plot(Z,dims) plots the zonotope Z for the two dimensions i,j: -% "dims=[i,j]" and returns handle to line-plot object -% h = plot(Z,dims,'Color','red',...) adds the standard plotting preferences -% -% Inputs: -% Z - zonotope object -% dims - (optional) dimensions that should be projected -% type - (optional) plot settings (LineSpec and name-value pairs) -% -% Outputs: -% han - handle of graphics object -% -% Example: -% Z=zonotope([1 1 0; 0 0 1]); -% plot(Z) -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: polygon - -% Author: Matthias Althoff -% Written: 27-July-2016 -% Last update: 14-July-2020 (merge with plotFilled) -% Last revision:--- - -%------------- BEGIN CODE -------------- - -% default values -dims = [1,2]; -linespec = 'b'; -filled = false; -height = []; -NVpairs = {}; - -%If two arguments are passed -if nargin==2 - dims=varargin{1}; - -%If three or more arguments are passed -elseif nargin>=3 - dims = varargin{1}; - % parse plot options - [linespec,NVpairs] = readPlotOptions(varargin(2:end)); - [NVpairs,filled] = readNameValuePair(NVpairs,'Filled','islogical'); - [NVpairs,cont] = readNameValuePair(NVpairs,'Cont','islogical'); - [NVpairs,height] = readNameValuePair(NVpairs,'Height','isscalar'); -end - -% project zonotope -Z = project(Z,dims); - -% convert zonotope to polygon -p = evalute(Z); - -%plot and output the handle -if filled - if isempty(height) % no 3D plot - han = fill(p(1,:),p(2,:),linespec,NVpairs{:}); - else - zCoordinates = height*ones(length(p(1,:)),1); - han = fill3(p(1,:),p(2,:),zCoordinates,linespec,NVpairs{:}); - end -else - if isempty(height) % no 3D plot - han = plot(p(1,:),p(2,:),linespec,NVpairs{:}); - else - zCoordinates = height*ones(length(p(1,:)),1); - han = plot3(p(1,:),p(2,:),zCoordinates,linespec,NVpairs{:}); - end -end - - - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalZonotope/reduce.asv b/@logicalZonotope/reduce.asv deleted file mode 100644 index 16fe1ee..0000000 --- a/@logicalZonotope/reduce.asv +++ /dev/null @@ -1,115 +0,0 @@ -function Zred = reduce(Z,varargin) -% reduce - Reduces the order of a zonotope -% -% Syntax: -% Zred = reduce(Z,option,order) -% -% Inputs: -% Z - zonotope object -% option - string specifying the reduction method. The available options -% are: -% - 'cluster' Sec. III.B in [3] -% - 'combastel' Sec. 3.2 in [4] -% - 'constOpt' Sec. III.D in [3] -% - 'girard' Sec. 4 in [2] -% - 'methA' Sec. 2.5.5 in [1] -% - 'methB' Sec. 2.5.5 in [1] -% - 'methC' Sec. 2.5.5 in [1] -% - 'pca' Sec. III.A in [3] -% - 'scott' Appendix of [5] -% - 'redistribute' -% order - order of reduced zonotope -% -% Outputs: -% Zred - reduced zonotope -% -% Example: -% Z=zonotope(rand(2,10)); -% plot(Z,[1,2],'g'); -% hold on -% Zred=reduce(Z,'girard',2); -% plot(Zred,[1,2],'r'); -% Zred=reduce(Z,'combastel',2); -% plot(Zred,[1,2],'b'); -% -% -% See also: none - -% Author: Matthias Althoff -% Written: 24-January-2007 -% Last update: 15-September-2007 -% 27-June-2018 -% Last revision: --- - -%------------- BEGIN CODE -------------- - -%2 inputs - -cen = Z.c; -gen = Z.G; - -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 - genMatcell2mat(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); - - -% [location2D , hX,hY,numXGrids]= map2D(Z); -% zCont= zonotope.enclosePoints(location2D,'stursberg'); -% %zCont = reduce(zCont,'girard',3); -% vert = vertices(zCont); -% vert = unique(vert','rows')'; -% binaryVector = getGridIndex(vert); -% -% Zred = logicalZonotope.enclosePoints(binaryVector); -% -% -% -% function binaryVector = getGridIndex(locPoints) -% -% -% locPoints = locPoints-1; -% [~,~,binxR]=histcounts(locPoints(1,:),hX); -% [~,~,binyR]=histcounts(locPoints(2,:),hY); -% -% point = (binyR+1)*numXGrids + binxR+1; -% -% % convert to binary -% -% pointB = dec2bin(point); -% -% -% [rows,cols]=size(pointB); -% for i =1:rows -% row=[]; -% for j =1:cols -% if j==cols -% row=[ row, pointB(i,j)]; -% else -% row=[ row, pointB(i,j), ' ']; -% end -% end -% newpointB(i,:) = row; -% end -% binaryVector=str2num(newpointB)'; -% -% end -end -%------------- END OF CODE -------------- diff --git a/@logicalZonotope/reduce.m b/@logicalZonotope/reduce.m index d142b52..c156f21 100644 --- a/@logicalZonotope/reduce.m +++ b/@logicalZonotope/reduce.m @@ -6,39 +6,19 @@ % % Inputs: % Z - zonotope object -% option - string specifying the reduction method. The available options -% are: -% - 'cluster' Sec. III.B in [3] -% - 'combastel' Sec. 3.2 in [4] -% - 'constOpt' Sec. III.D in [3] -% - 'girard' Sec. 4 in [2] -% - 'methA' Sec. 2.5.5 in [1] -% - 'methB' Sec. 2.5.5 in [1] -% - 'methC' Sec. 2.5.5 in [1] -% - 'pca' Sec. III.A in [3] -% - 'scott' Appendix of [5] -% - 'redistribute' -% order - order of reduced zonotope % % Outputs: % Zred - reduced zonotope % % Example: -% Z=zonotope(rand(2,10)); -% plot(Z,[1,2],'g'); -% hold on -% Zred=reduce(Z,'girard',2); -% plot(Zred,[1,2],'r'); -% Zred=reduce(Z,'combastel',2); -% plot(Zred,[1,2],'b'); % % % See also: none -% Author: Matthias Althoff -% Written: 24-January-2007 -% Last update: 15-September-2007 -% 27-June-2018 +% Author: Amr Alanwar +% Written: 16-October-2022 +% Last update: 16-October-2022 +% % Last revision: --- %------------- BEGIN CODE -------------- @@ -74,47 +54,5 @@ Zred = logicalZonotope(cen,{}); end - - -% [location2D , hX,hY,numXGrids]= map2D(Z); -% zCont= zonotope.enclosePoints(location2D,'stursberg'); -% %zCont = reduce(zCont,'girard',3); -% vert = vertices(zCont); -% vert = unique(vert','rows')'; -% binaryVector = getGridIndex(vert); -% -% Zred = logicalZonotope.enclosePoints(binaryVector); -% -% -% -% function binaryVector = getGridIndex(locPoints) -% -% -% locPoints = locPoints-1; -% [~,~,binxR]=histcounts(locPoints(1,:),hX); -% [~,~,binyR]=histcounts(locPoints(2,:),hY); -% -% point = (binyR+1)*numXGrids + binxR+1; -% -% % convert to binary -% -% pointB = dec2bin(point); -% -% -% [rows,cols]=size(pointB); -% for i =1:rows -% row=[]; -% for j =1:cols -% if j==cols -% row=[ row, pointB(i,j)]; -% else -% row=[ row, pointB(i,j), ' ']; -% end -% end -% newpointB(i,:) = row; -% end -% binaryVector=str2num(newpointB)'; -% -% end end %------------- END OF CODE -------------- diff --git a/@logicalZonotope/semiKron.asv b/@logicalZonotope/semiKron.asv deleted file mode 100644 index 6764880..0000000 --- a/@logicalZonotope/semiKron.asv +++ /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,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); - -end - - -end - diff --git a/@logicalZonotope/tensorMultiplication.m b/@logicalZonotope/tensorMultiplication.m deleted file mode 100644 index 4e1f43c..0000000 --- a/@logicalZonotope/tensorMultiplication.m +++ /dev/null @@ -1,49 +0,0 @@ -function Zres = tensorMultiplication(Z,M) -% tensorMultiplication - computes \{M_{ijk...l}*x_j*x_k*...*x_l|x \in Z\} -% when the center of Z is the origin -% -% Syntax: -% Zres = tensorMultiplication(Z,M) -% -% Inputs: -% Z - zonotope object -% M - tensor -% -% Outputs: -% Zres - zonotope object -% -% Example: -% --- -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: none - -% Author: Amr Alanwar -% Written: 19-Aug-2022 -% Last update: --- -% Last revision:--- - -%------------- BEGIN CODE -------------- -% points = evaluate(Z); -% pM= kron(points,M); -% Zres = logicalZonotope.enclosePoints(pM); -% Zres = unique(Zres); - - -%points = evaluate(Z); -newc= kron(Z.c,M); -gen=[]; -for i =1:length(Z.G) - gen = [gen, Z.G{i}]; -end -newGMat= kron(gen,M); -for i =1:length(newGMat(1,:)) - newGenCell{i} = newGMat(:,i); -end -Zres = logicalZonotope(newc,newGenCell); -Zres = unique(Zres); - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/@logicalZonotope/xnor.m b/@logicalZonotope/xnor.m index 0e00768..8e8b946 100644 --- a/@logicalZonotope/xnor.m +++ b/@logicalZonotope/xnor.m @@ -9,7 +9,7 @@ % Z2 - zonotope, % % Outputs: -% Z - zonotope object enclosing the and zonotope +% Z - zonotope object enclosing the xnor zonotope % % Example: % @@ -20,7 +20,7 @@ % See also: none % Author: Amr Alanwar -% Written: 8-Sept-2022 +% Written: 16-October-2022 % Last update: 16-October-2022 % % diff --git a/@logicalZonotope/xor.asv b/@logicalZonotope/xor.asv deleted file mode 100644 index 75f6f7d..0000000 --- a/@logicalZonotope/xor.asv +++ /dev/null @@ -1,61 +0,0 @@ -function Z = xor(Z1,Z2,varargin) -% and - overloads & operator, computes the intersection of two zonotopes -% -% Syntax: -% Z = and(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 -------------- -newCen = xor( Z1.c,Z2.c ); - -if(isempty(Z1.G)) - -elseif(isempty(Z2.G)) - -elseif(~isempty(Z2.G) & ~isempty(Z2.G)) -g1Len = length(Z1.G); -g2Len = length(Z2.G); -newGen = Z1.G; -index =1; -for i=g1Len+1:g1Len+g2Len - newGen{i} = Z2.G{index}; - index = index +1; -end - -Z=logicalZonotope(newCen,newGen); -Z =unique(Z); - -end - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/AStreamCipher.m b/AStreamCipher.m deleted file mode 100644 index b2fe7d0..0000000 --- a/AStreamCipher.m +++ /dev/null @@ -1,50 +0,0 @@ -function [z,A,B,C] = AStreamCipher(K,N) -%TRIVIUM Summary of this function goes here -% Detailed explanation goes here - -index =1; -for i=1:19 - A{i} = K{index}; - index = index +1; -end - -for i=1:22 - B{i} = K{index}; - index = index +1; -end - -for i=1:23 - C{i} = K{index}; - index = index +1; -end - - - - - -for ii =1:N - - - cpA = A; - for i =2:19 - A{i}=cpA{i-1}; - end - A{1}=xor(cpA{19},xor(cpA{18},xor(cpA{17},cpA{14}))); - cpB = B; - for i =2:22 - B{i}=cpB{i-1}; - end - B{1}=xor(cpB{21},cpB{22}); - - cpC =C; - for i =2:23 - C{i}=cpC{i-1}; - end - C{1}=xor(cpC{23},xor(cpC{22},xor(cpC{21},cpC{7}))); - z{ii} = xor(A{19},xor(B{22},C{23})); -end - - - -end - diff --git a/AStreamCipherABC.asv b/AStreamCipherABC.asv deleted file mode 100644 index a4c0a24..0000000 --- a/AStreamCipherABC.asv +++ /dev/null @@ -1,94 +0,0 @@ -function [z,A,B,C] = AStreamCipherABC(A,B,C,N) -%TRIVIUM Summary of this function goes here -% Detailed explanation goes here - -% index =1; -% for i=1:19 -% A{i} = K{index}; -% index = index +1; -% end -% -% for i=1:22 -% B{i} = K{index}; -% index = index +1; -% end -% -% for i=1:23 -% C{i} = K{index}; -% index = index +1; -% end - -for i =1:19 - A{i}=cpA{19}; -end - - - -for ii =1:N - -% Max0 = 0; -% Max1 = 0; -% if(A{9}.containsPoint(1)) -% Max1 = Max1 + 1; -% else -% MAx0 = Max0 + 1; -% end -% if(B{11}.containsPoint(1)) -% Max1 = Max1 + 1; -% else -% Max0 = Max0 + 1; -% end -% if(C{11}.containsPoint(1)) -% Max1 = Max1 + 1; -% else -% Max0 = Max0 + 1; -% end -% -% if(Max1 > Max0) -% CK = 1; -% else -% CK = 0; -% end - - - z{ii} = xor(A{19},xor(B{22},C{23})); - cpA = A; - tempA = xor(cpA{19},xor(cpA{18},xor(cpA{17},cpA{14}))); - %if cpA{9}.containsPoint(CK) - % if (isempty(tempA.G) & isempty(cpA{8}.G) ) || (~isempty(tempA.G) & ~isempty(cpA{8}.G) ) - for i =2:19 - A{i}=cpA{i-1}; - end - A{1}=tempA; - %end - %end - - - cpB = B; - tempB = xor(cpB{21},cpB{22}); - %if cpB{11}.containsPoint(CK) - % if (isempty(tempB.G) & isempty(cpB{10}.G) ) || (~isempty(tempB.G) & ~isempty(cpB{10}.G) ) - for i =2:22 - B{i}=cpB{i-1}; - end - B{1}=tempB; - % end - % end - - cpC =C; - tempC = xor(cpC{23},xor(cpC{22},xor(cpC{21},cpC{7}))); - %if cpC{10}.containsPoint(CK) - % if (isempty(tempC.G) & isempty(cpC{10}.G) ) || (~isempty(tempC.G) & ~isempty(cpC{10}.G) ) - for i =2:23 - C{i}=cpC{i-1}; - end - C{1}=tempC; - % end - % end - -end - - - -end - diff --git a/AStreamCipherABC.m b/AStreamCipherABC.m deleted file mode 100644 index 9993d2a..0000000 --- a/AStreamCipherABC.m +++ /dev/null @@ -1,103 +0,0 @@ -function [z,A,B,C] = AStreamCipherABC(A,B,C,N) -%TRIVIUM Summary of this function goes here -% Detailed explanation goes here - -% index =1; -% for i=1:19 -% A{i} = K{index}; -% index = index +1; -% end -% -% for i=1:22 -% B{i} = K{index}; -% index = index +1; -% end -% -% for i=1:23 -% C{i} = K{index}; -% index = index +1; -% end -cpA = A; -for i =1:19 - A{i}=cpA{19-i+1}; -end - -cpB = B; -for i =1:22 - B{i}=cpB{22-i+1}; -end - -cpC = C; -for i =1:23 - C{i}=cpC{23-i+1}; -end - - -for ii =1:N - -% Max0 = 0; -% Max1 = 0; -% if(A{9}.containsPoint(1)) -% Max1 = Max1 + 1; -% else -% MAx0 = Max0 + 1; -% end -% if(B{11}.containsPoint(1)) -% Max1 = Max1 + 1; -% else -% Max0 = Max0 + 1; -% end -% if(C{11}.containsPoint(1)) -% Max1 = Max1 + 1; -% else -% Max0 = Max0 + 1; -% end -% -% if(Max1 > Max0) -% CK = 1; -% else -% CK = 0; -% end - - - z{ii} = xor(A{19},xor(B{22},C{23})); - cpA = A; - tempA = xor(cpA{19},xor(cpA{18},xor(cpA{17},cpA{14}))); - %if cpA{9}.containsPoint(CK) - % if (isempty(tempA.G) & isempty(cpA{8}.G) ) || (~isempty(tempA.G) & ~isempty(cpA{8}.G) ) - for i =2:19 - A{i}=cpA{i-1}; - end - A{1}=tempA; - %end - %end - - - cpB = B; - tempB = xor(cpB{21},cpB{22}); - %if cpB{11}.containsPoint(CK) - % if (isempty(tempB.G) & isempty(cpB{10}.G) ) || (~isempty(tempB.G) & ~isempty(cpB{10}.G) ) - for i =2:22 - B{i}=cpB{i-1}; - end - B{1}=tempB; - % end - % end - - cpC =C; - tempC = xor(cpC{23},xor(cpC{22},xor(cpC{21},cpC{7}))); - %if cpC{10}.containsPoint(CK) - % if (isempty(tempC.G) & isempty(cpC{10}.G) ) || (~isempty(tempC.G) & ~isempty(cpC{10}.G) ) - for i =2:23 - C{i}=cpC{i-1}; - end - C{1}=tempC; - % end - % end - -end - - - -end - diff --git a/AStreamCipherABCBits.m b/AStreamCipherABCBits.m deleted file mode 100644 index 95b47eb..0000000 --- a/AStreamCipherABCBits.m +++ /dev/null @@ -1,91 +0,0 @@ -function [z,A,B,C] = AStreamCipherABCBits(A,B,C,N) -%TRIVIUM Summary of this function goes here -% Detailed explanation goes here - -% index =1; -% for i=1:19 -% A{i} = K{index}; -% index = index +1; -% end -% -% for i=1:22 -% B{i} = K{index}; -% index = index +1; -% end -% -% for i=1:23 -% C{i} = K{index}; -% index = index +1; -% end - - - - -for ii =1:N - -% Max0 = 0; -% Max1 = 0; -% if(A{9}==1) -% Max1 = Max1 + 1; -% else -% MAx0 = Max0 + 1; -% end -% if(B{11}==1) -% Max1 = Max1 + 1; -% else -% Max0 = Max0 + 1; -% end -% if(C{11}==1) -% Max1 = Max1 + 1; -% else -% Max0 = Max0 + 1; -% end -% -% if(Max1 > Max0) -% CK = 1; -% else -% CK = 0; -% end - - - - cpA = A; - tempA = xor(cpA{19},xor(cpA{18},xor(cpA{17},cpA{14}))); - %if cpA{9}==CK - % if (isempty(tempA.G) & isempty(cpA{8}.G) ) || (~isempty(tempA.G) & ~isempty(cpA{8}.G) ) - for i =2:19 - A{i}=cpA{i-1}; - end - A{1}=tempA; - %end - %end - - - cpB = B; - tempB = xor(cpB{21},cpB{22}); - %if cpB{11}==CK - % if (isempty(tempB.G) & isempty(cpB{10}.G) ) || (~isempty(tempB.G) & ~isempty(cpB{10}.G) ) - for i =2:22 - B{i}=cpB{i-1}; - end - B{1}=tempB; - % end - %end - - cpC =C; - tempC = xor(cpC{23},xor(cpC{22},xor(cpC{21},cpC{7}))); - %if cpC{10}==CK - % if (isempty(tempC.G) & isempty(cpC{10}.G) ) || (~isempty(tempC.G) & ~isempty(cpC{10}.G) ) - for i =2:23 - C{i}=cpC{i-1}; - end - C{1}=tempC; - % end - %end - z{ii} = xor(A{19},xor(B{22},C{23})); -end - - - -end - diff --git a/BoolExample.m b/BoolFunctionExample.m similarity index 100% rename from BoolExample.m rename to BoolFunctionExample.m diff --git a/testLFSR_auto_g.m b/FindLFSRkeyExample.m similarity index 79% rename from testLFSR_auto_g.m rename to FindLFSRkeyExample.m index 84c6923..61d3097 100644 --- a/testLFSR_auto_g.m +++ b/FindLFSRkeyExample.m @@ -18,24 +18,6 @@ -% for i =1:63 -% testK{i} = logicalZonotope.enclosePoints([0 1]); -% end -% testK{64} = logicalZonotope.enclosePoints([0]); -% -% [testz,A,B,C] =AStreamCipher(testK,10); -% -% for i =1:10 -% m{i} = randi([0 1]); -% testc{i}= xor(testz{i},logicalZonotope.enclosePoints(m{i})) -% end -% -% for i =1:10 -% if ~testc{i}.containsPoint(c{i}) -% flag =1; -% end -% end - index=1; disp('start') index=index+1; @@ -111,13 +93,13 @@ -% sum=0; -% for i =1:Aleng -% sum = sum + abs(tempA{i}-A{i}) ; -% end -% %if sum == 0 -% sprintf("sum key =%d , j =%d ",sum,j) -% %end + sum=0; + for i =1:Aleng + sum = sum + abs(tempA{i}-A{i}) ; + end + + sprintf("sum key =%d , j =%d ",sum,j) + % % [testz2,~] =LFSR1(tempA,numOfmessages); % sum2=0; @@ -128,7 +110,7 @@ % sprintf("sum message =%d",sum2) end -execTime = toc +%execTime = toc diff --git a/Logical_Zono_example.m b/Logical_Zono_example.m deleted file mode 100644 index 947b379..0000000 --- a/Logical_Zono_example.m +++ /dev/null @@ -1,25 +0,0 @@ -clear all -c1 = [0;1]; -c2 = [0;1]; -g1 = [1;1]; -g2 = [1;0]; - -% manually -cAnd = (c1+c2)/2; -gAnd = [g1/2 g2/2]; -AAndB=[xor(cAnd,[-1 -1]*gAnd),xor(cAnd,[-1 0]*gAnd),xor(cAnd,[0 -1]*gAnd),xor(cAnd,[0 0]*gAnd),xor(cAnd,[0 1]*gAnd),xor(cAnd,[1 0]*gAnd),xor(cAnd,[1 1]*gAnd)] - -cXor = xor(c1,c2); -g1Xor = g1; -g2Xor = g2; -AXorB=[xor(cXor,xor(-1*g1Xor,-1*g2Xor)) xor(cXor,xor(-1*g1Xor,0*g2Xor)) xor(cXor,xor(0*g1Xor,-1*g2Xor)) xor(cXor,xor(0*g1Xor,0*g2Xor)) xor(cXor,xor(0*g1Xor,1*g2Xor)) xor(cXor,xor(1*g1Xor,0*g2Xor)) xor(cXor,xor(1*g1Xor,1*g2Xor))] - - -% using CORA - -Z1 = logicalZonotope(c1,g1); -Z2 = logicalZonotope(c2,g2); - -Z1norZ2 = nor(Z1 , Z2) - -Z1AndZ2 = and(Z1, Z2) \ No newline at end of file diff --git a/Logical_Zono_nand.m b/Logical_Zono_nand.m deleted file mode 100644 index b12f27c..0000000 --- a/Logical_Zono_nand.m +++ /dev/null @@ -1,48 +0,0 @@ -clear all -c1 = [0;1]; -c2 = [0;1]; -g1 = {[1;1]}; -g2 = {[1;0]}; - -Z1 = logicalZonotope(c1,g1); -Z2 = logicalZonotope(c2,g2); - -% manually -p1=evaluate(Z1) -p2=evaluate(Z2) -[~,p1Col]=size(p1); -[~,p2Col]=size(p2); -andPoints=[]; -orPoints =[]; -norPoints =[]; -nandPoints =[]; -for i =1:p1Col - for j=1:p2Col - andPoints = [andPoints, p1(:,i)&p2(:,j)]; - orPoints = [orPoints, p1(:,i)|p2(:,j)]; - norPoints = [norPoints, norLogic(p1(:,i),p2(:,j))]; - nandPoints = [nandPoints, nandLogic(p1(:,i),p2(:,j))]; - end -end - -andPoints = unique(andPoints','rows')' -orPoints = unique(orPoints','rows')' -norPoints = unique(norPoints','rows')' -nandPoints = unique(nandPoints','rows')' -% using CORA -Z1NorZ2 = nor(Z1 , Z2) -Z1AndZ2 = and(Z1, Z2) -Z1OrZ2 = or(Z1, Z2) -Z1NandZ2 = nand(Z1, Z2) -Z1AndZ2Points= evaluate(Z1AndZ2) -Z1OrZ2Points= evaluate(Z1OrZ2) -Z1NorZ2Points= evaluate(Z1NorZ2) -Z1NandZ2Points= evaluate(Z1NandZ2) - - - -cNor = ~norLogic(~c1,~c2); -g1Nor = g1{1}; -g2Nor = g2{1}; -ANorB=[ norLogic(~cNor,norLogic(0*g1Nor,0*g2Nor)) norLogic(~cNor,norLogic(0*g1Nor,1*g2Nor)) norLogic(~cNor,norLogic(1*g1Nor,0*g2Nor)) norLogic(~cNor,norLogic(1*g1Nor,1*g2Nor))] - diff --git a/Logical_Zono_XOR.m b/TestLogicalFunctions.m similarity index 86% rename from Logical_Zono_XOR.m rename to TestLogicalFunctions.m index f5ce4d1..7af53fb 100644 --- a/Logical_Zono_XOR.m +++ b/TestLogicalFunctions.m @@ -14,17 +14,8 @@ g3{i} = randi([0 1],dim,1); end - - Z3 = logicalZonotope(c3,g3); - -%plot(Z3,[1:3],'r','Cont',true); -%Z3red = reduce(Z3); -%hold on -%plot(Z3red,[1:3],'k'); - - Z1 = logicalZonotope(c1,g1); res = containsPoint(Z1,c1) @@ -33,7 +24,7 @@ Z2 = logicalZonotope(c2,g2); -%plot(Z1,[1 2],'r','Cont',true); +%plot(Z1,[1 2 3],'r*'); % manually p1=evaluate(Z1) p2=evaluate(Z2) @@ -91,11 +82,6 @@ Z1XorZ2Points= evaluate(Z1XorZ2) Z1SemiKronZ2Points = evaluate(Z1SemiKronZ2) -cNor = xor(c1,c2); -g1Nor = g1{1}; -g2Nor = g2{1}; -AXorB=[ xor(cNor,xor(0*g1Nor,0*g2Nor)) xor(cNor,xor(0*g1Nor,1*g2Nor)) xor(cNor,xor(1*g1Nor,0*g2Nor)) xor(cNor,xor(1*g1Nor,1*g2Nor))] - %%% points = [1 0 0; 0 0 1]; pointsZono = logicalZonotope.enclosePoints(points) diff --git a/useLVehLogicZono_2Veh_g.m b/VechIntersectionExample.m similarity index 97% rename from useLVehLogicZono_2Veh_g.m rename to VechIntersectionExample.m index 84f90e4..eae7caf 100644 --- a/useLVehLogicZono_2Veh_g.m +++ b/VechIntersectionExample.m @@ -2,16 +2,14 @@ load('cache\L.mat') -steps = 1000; +steps = 3; VPl{1}{1} = 1; VPl{1}{2} = [0]; -% VPl{3} = [1;0]; -% VPl{4} = [1;0]; + CFl{1}{1} = 1; CFl{1}{2} = [0]; -% CFl{3} = [1;0]; -% CFl{4} = [1;0]; + Ul{1} = logicalZonotope.enclosePoints([0,1]); Ul{2} = logicalZonotope.enclosePoints([0,1]); diff --git a/inverseTest.m b/inverseTest.m deleted file mode 100644 index 40d991f..0000000 --- a/inverseTest.m +++ /dev/null @@ -1,41 +0,0 @@ -clear all -L =[zeros(1,4) 1 0 0 0;... - zeros(1,8);... - 1 zeros(1,7);... - zeros(1,8);... - zeros(1,5) 1 1 0;... - zeros(1,7) 1;... - 0 1 1 zeros(1,5);... - zeros(1,8)]; - - -II = eye(8); -X0 = [II(:,[5 7 1 2 4 3 8 6])]; -U0 = [II(:,[4 1 3 2 5 7 8 6])]; -for i =1:length(X0) -%X1(:,i) = semiKron(L,semiKron(U0(:,i),X0(:,i))); -X1(:,i) = semiKron(L,U0(:,i)); -end - -for i =1:length(X0) -%X1(:,i) = semiKron(L,semiKron(U0(:,i),X0(:,i))); -X11(:,i)=semiKron(X1,X0(:,i)); -end - -XU = [X0]; -bb=invBol([mod(XU*XU',2),eye(size(mod(XU*XU',2)))]); -[rows,cols] = size(bb); -invX0X0 = bb(:,cols/2+1:end); -invX0 = mod(XU'* invX0X0,2); -iseye= mod(XU*invX0,2) - -XU = [U0]; -bb=invBol([mod(XU*XU',2),eye(size(mod(XU*XU',2)))]); -[rows,cols] = size(bb); -invX0X0 = bb(:,cols/2+1:end); -invU0 = mod(XU'* invX0X0,2); -iseye= mod(XU*invU0,2) - -compL = mod(X11*invX0*invU0,2); - -differ = L - compL \ No newline at end of file diff --git a/pursuit_evader_main.m b/pursuit_evader_main.m deleted file mode 100644 index b987d13..0000000 --- a/pursuit_evader_main.m +++ /dev/null @@ -1,96 +0,0 @@ - -clear all -% get environment constraints -[neigh_set, vis_set] = env(); - -% state -n_pursuers = 2; -n_regions = 21; -l = cell(n_regions, 1); -v = cell(n_regions, 1); -c = cell(n_regions, 1); -for i =1:n_regions -l{i} =logicalZonotope.enclosePoints([0]); -v{i} =logicalZonotope.enclosePoints([0]); -c{i} =logicalZonotope.enclosePoints([0]); -end -u_state = cell(n_pursuers*n_regions, 1); -for i =1:n_pursuers*n_regions -u_state{i}=logicalZonotope.enclosePoints([0]); -end -%state = [has_pursuer; visible; cleared; inputs]; -%size(state) - -l_idx = 1:n_regions; -v_idx = n_regions+1:2*n_regions; -c_idx = 2*n_regions+1:3*n_regions; - -u_start = 3*n_regions; -u_starts = []; -for i = 1:n_pursuers - % u_starts = [u_starts u_start + (i-1)*n_regions]; - u_starts = [u_starts (i-1)*n_regions]; -end - -% initialization -pursuer_init_locations = [12 15]; -for pursuer = 1:n_pursuers - u_state{ u_starts(pursuer) + pursuer_init_locations(pursuer)} =logicalZonotope.enclosePoints([1]); -end - -% forward simulation w/ randomly chosen u -n_steps = 10; -num_sat_steps=0; -last_num_sat_steps = 0; -for step = 1:n_steps - % evaluate boolean function until state reaches new steady-state - last_l = 0; - last_v = 0 ; - last_c = 0; - steps = 0; - last_num_sat_steps = max(last_num_sat_steps,num_sat_steps); - num_sat_steps =0; - %while ~isequal(last_l,l)|| ~isequal(last_v,v) || ~isequal(last_c,c) - % dynamics - % l = state(l_idx); - % v = state(v_idx); - % c = state(c_idx); - % u = state(u_start+1:end); - % last_state = state; - for i =1:30 - last_l = l; - last_v = v ; - last_c = c; - [l,v ,c] = dynamics(l, v, c, u_state, u_starts, vis_set, neigh_set); - steps = steps + 1; - num_sat_steps = num_sat_steps +1; - if i ==29 - i - end - end - %end - - % find valid inputs for current inputs - %u = state(u_start+1:end); - [valid_u] = input_constraint(u_state, u_starts, neigh_set); - - % set new input (should be replaced by logical zonotopes) - - for i =1:length(u_state) - u_state{i} =logicalZonotope.enclosePoints([0]); - end - - for pursuer = 1:n_pursuers -% u_perm = randperm(size(valid_u{pursuer}, 2)); -% pursuer_u = valid_u{pursuer}(u_perm(1)); -% u_state{u_starts(pursuer) + pursuer_u} = 1; - for vj = 1:length(valid_u{pursuer}) - pursuer_u = valid_u{pursuer}(vj); - u_state{u_starts(pursuer) + pursuer_u} = logicalZonotope.enclosePoints([0 1]); - end - - end - - - -end diff --git a/randGraphExample.asv b/randGraphExample.asv deleted file mode 100644 index 896a145..0000000 --- a/randGraphExample.asv +++ /dev/null @@ -1,83 +0,0 @@ -clear all - -close all - - -n_x = 800; -n_u = 100; -G = []; -for i =1:n_u - G = [G round(rand(n_x))]; -end - -indexu=1; - -numbOfInputs = [10 30 50]; -numbOfstates =[10 100:100:600]; -for ptu = numbOfInputs - index=1; - for pt =numbOfstates - - % number of points in x - n_x_points = pt; - pointx =[]; - for i =1 :n_x_points - xx = zeros(n_x,1); - xx(randi(n_x,1)) =1; - pointx = [pointx xx]; - end - logX= logicalZonotope.enclosePoints(pointx); - - % number of points in u - n_u_points = ptu; - pointu =[]; - for i =1 :n_u_points - uu = zeros(n_u,1); - uu(randi(n_u,1)) =1; - pointu = [pointu uu]; - end - logU= logicalZonotope.enclosePoints(pointu); - - stateNormal = []; - for ii =1:length(pointx(1,:)) - for jj =1:length(pointu(1,:)) - stateNormal = [ stateNormal semiKron(semiKron(G,pointu(:,jj)),pointx(:,ii))]; - end - end - tic - nextx2= semiKron(semiKron(G,logU),logX); - execTim(indexu,index) = toc - index = index +1; - end - indexu = indexu +1; -end - - -% plot reachable sets from data -figure('Renderer', 'painters', 'Position', [10 10 800 900]) -hold on -box on -handleplot{1}= plot(numbOfstates,execTim(1,:),'rx-'); -handleplot{2}= plot(numbOfstates,execTim(2,:),'b*-'); -handleplot{3}= plot(numbOfstates,execTim(3,:),'k+-'); - -% label plot -xlabel('Number of starting states $p_x$','Interpreter','latex'); -ylabel('Execution time (sec)','Interpreter','latex'); -%axis(axx{plotRun}); -% skip warning for extra legend entries -warOrig = warning; warning('off','all'); -legend([handleplot{1},handleplot{2},handleplot{3}],... - '$p_u=10$','$p_u=30$','$p_u=50$','Location','northwest','Interpreter','latex'); -warning(warOrig); -ax = gca; -ax.FontSize = 22; -%set(gcf, 'Position', [50, 50, 800, 400]) -ax = gca; -outerpos = ax.OuterPosition; -ti = ax.TightInset; -left = outerpos(1) + ti(1); -bottom = outerpos(2) + ti(2); -ax_width = outerpos(3) - ti(1) - ti(3)-0.01; -ax_height = outerpos(4) - ti(2) - ti(4); -ax.Position = [left bottom ax_width ax_height]; diff --git a/randGraphExample.m b/randGraphExample.m deleted file mode 100644 index 4e359dd..0000000 --- a/randGraphExample.m +++ /dev/null @@ -1,86 +0,0 @@ -clear all - -close all - - -n_x = 800; -n_u = 100; -G = []; -for i =1:n_u - G = [G round(rand(n_x))]; -end - -indexu=1; - -numbOfInputs = [10 30 50]; -numbOfstates =[10 100:100:600]; -for ptu = numbOfInputs - index=1; - for pt =numbOfstates - - % number of points in x - n_x_points = pt; - pointx =[]; - for i =1 :n_x_points - xx = zeros(n_x,1); - xx(randi(n_x,1)) =1; - pointx = [pointx xx]; - end - logX= logicalZonotope.enclosePoints(pointx); - - % number of points in u - n_u_points = ptu; - pointu =[]; - for i =1 :n_u_points - uu = zeros(n_u,1); - uu(randi(n_u,1)) =1; - pointu = [pointu uu]; - end - logU= logicalZonotope.enclosePoints(pointu); - - tic - stateIter = []; - for ii =1:length(pointx(1,:)) - for jj =1:length(pointu(1,:)) - stateIter = [ stateIter semiKron(semiKron(G,pointu(:,jj)),pointx(:,ii))]; - end - end - execTimIter(indexu,index) = toc - - tic - nextx2= semiKron(semiKron(G,logU),logX); - execTim(indexu,index) = toc - index = index +1; - end - indexu = indexu +1; -end - - -% plot reachable sets from data -figure('Renderer', 'painters', 'Position', [10 10 800 900]) -hold on -box on -handleplot{1}= plot(numbOfstates,execTim(1,:),'rx-'); -handleplot{2}= plot(numbOfstates,execTim(2,:),'b*-'); -handleplot{3}= plot(numbOfstates,execTim(3,:),'k+-'); - -% label plot -xlabel('Number of starting states $p_x$','Interpreter','latex'); -ylabel('Execution time (sec)','Interpreter','latex'); -%axis(axx{plotRun}); -% skip warning for extra legend entries -warOrig = warning; warning('off','all'); -legend([handleplot{1},handleplot{2},handleplot{3}],... - '$p_u=10$','$p_u=30$','$p_u=50$','Location','northwest','Interpreter','latex'); -warning(warOrig); -ax = gca; -ax.FontSize = 22; -%set(gcf, 'Position', [50, 50, 800, 400]) -ax = gca; -outerpos = ax.OuterPosition; -ti = ax.TightInset; -left = outerpos(1) + ti(1); -bottom = outerpos(2) + ti(2); -ax_width = outerpos(3) - ti(1) - ti(3)-0.01; -ax_height = outerpos(4) - ti(2) - ti(4); -ax.Position = [left bottom ax_width ax_height]; diff --git a/runCARlogic.m b/runCARlogic.m deleted file mode 100644 index 45c64a8..0000000 --- a/runCARlogic.m +++ /dev/null @@ -1,220 +0,0 @@ - -%rng(6); -clc; -close all ; -keepvars = {'ii'}; -clearvars('-except', keepvars{:}); - -addpath('classes'); -addpath('utilities'); - -%% Supress warnings -warning('off', 'MATLAB:nearlySingularMatrix'); - -%% Raw Data Log Folder -logname='ped0'; -%other logs are ped02,ped03,ped04 -logfolder = strcat('logs/',logname,'/'); - - -%% Node/Network configuration -configfile = 'config/car'; - - -%% Create Network Manager -nm = Manager(configfile, logfolder); -node_ids = nm.getNodeIds(); -node_names = nm.getNodeNames(); -moreInputData=nm.dataparser.inputlogs(:,[2,5]); -%% Rigid body IDs -nm.setRigidBodyId('car-mobile', 1); - - -%% Data Driven reachability Raw Data Log Folder -lognameRA='ped1'; -%other logs are ped2,ped3,ped4 -logfolderRA = strcat('logs/',lognameRA,'/'); -DRA= DataDrivenRA( logfolderRA ); -ZepsFlag =1; -%DRA.prepareUWLip(ZepsFlag,moreInputData); - - -%% Bootstrap the node positions and clock params before filter starts -% use first second of measurements to bootstrap node states - -% - -fig = cfigure(25,25); grid on; hold on; axis equal; - - -%% Save as movie -SAVEMOVIE = false; -if SAVEMOVIE - vidObj = VideoWriter('video/car.avi'); - vidObj.FrameRate=20; - open(vidObj); -end - - -% rigid bodies in mocap -rigid_bodies = nm.dataparser.getRigidBodyIds(); -[Xdim, Ydim] = nm.dataparser.getMaxDimension(); -hrigidbodies = zeros( length(rigid_bodies),1 ); -for i=1:length(rigid_bodies) - hrigidbodies(i) = plot(0, 0, 'sb', 'MarkerSize', 5, 'MarkerFaceColor', 'k', 'LineWidth', 2); -end - -xlim([Xdim{1}-0.5 Xdim{2}+0.5]); -ylim([Ydim{1}-0.5 Ydim{2}+0.5]); -%zlim([Ydim{1}-0.5 Ydim{2}+0.5]); -xlabel('X Position (m)', 'FontSize',14); -ylabel('Y Position (m)', 'FontSize',14); -%zlabel('Y Position (m)', 'FontSize',14); -htitle = title('KTH Car (t = 0.00s)','FontSize',12); -%view(180,0); -%legend(herr, nm.getNodeNames()); -drawnow; - -%% Replay data and run EKF -% analysis stop time -%t_stop = 200; -t_stop = 35; -% state, time, and transformed position history -%s_history = []; -p_history = []; -%cov_history = []; -% pDKAL_history =[]; -% P_big_history = []; -t_history = []; -timeUpdateFlag_history = []; -% DiffFlag_history = []; -% MeasFlag_history = []; - -nm.skipTime(7); -% last global time update -meas1 = nm.getNextMeasurement(); -t_start = meas1.getTime(); -t_last = t_start; -k = 0; - - -% plotting -plot_delay = 0*0.100; % sec -plot_last = t_start; - -tlast_twr = 0; -period_twr = 5.00; - - -MOBILEID = 1; - - - - stepsReach = 1; -% for i =1:stepsReach -% h_reach(i) = plotZono(zonotope([zeros(2,1),0.1*diag(ones(2,1))]),[1,2],'r'); -% end - - -for i =1:stepsReach - h_logic(i) = plotZono(zonotope([zeros(2,1),0.1*diag(ones(2,1))]),[1,2],'k'); -end - -plotZonotime = t_start; -R_history = {}; -R_history_index=1; -while (t_last - t_start) < t_stop - k = k + 1; - - % get next measurement object - for i=1:DRA.dataStep - meas = nm.getNextMeasurement(); - end - if isempty(meas) - break; - end - walltime = meas.getTime(); - z = meas.vectorize(); - - - - % delta-time uses wallclock (desktop timestamp) for now - dt_ref = meas.getTime() - t_last; - t_last = walltime; - t_history = [t_history; walltime]; - - - - - if walltime - plot_last >= plot_delay - plot_last = walltime; - % update rigid bodies - %for i=1:length(rigid_bodies) -% rb = rigid_bodies(i); -% [xy, latency] = nm.dataparser.getMocapPos(rb, walltime); - % if latency < 0.250 - set(hrigidbodies(1), 'XData', z(1), 'YData', z(2)); - % end - % end - - - % update plot title - tstr = sprintf('CAR Reachable sets (t = %.2fs)', (t_last - t_start)); - set(htitle, 'String', tstr); - drawnow; - end - if walltime >= plotZonotime + DRA.timeStepDataIn*stepsReach -% loc = [z(1) z(1)+0.05 z(1) z(1)+0.05 z(1)-0.05 z(1) z(1)-0.05 ; ... -% z(2) z(2) z(2)+0.05 z(2)+0.05 z(2) z(2)-0.05 z(2)-0.05]; - loc = [ z(1)-0.2 z(1)-0.2 z(1)+0.2 z(1)+0.2 ; ... - z(2)-0.2 z(2)+0.2 z(2)-0.2 z(2)+0.2 ]; - R_logic=DRA.reachLogic(loc,stepsReach); - locations=DRA.getPoints(R_logic); - for ii =1:stepsReach - ZLoc{ii} = zonotope.enclosePoints([locations{ii} locations{ii}+0.2 locations{ii}-0.2]); - updatePlotZono(h_logic(ii),ZLoc{ii}); - end - - -% R_data=DRA.reachDataLip(zonotope([z(1);z(2)]),stepsReach); -% for ii =1:stepsReach -% updatePlotZono(h_reach(ii),R_data{ii},[1,2],'r'); -% R_history{R_history_index}=R_data{ii}; -% R_history_index=R_history_index+1; -% end - plotZonotime = walltime; - - end - % append state estimate & measurement to history - % s_history = [s_history; s']; - p_history = [p_history; z(1) z(2)]; - - %fprintf('t = %.2f / %.2f \n', meas.getTime()-meas1.getTime(), t_stop); - - if SAVEMOVIE - f = getframe(fig); - writeVideo(vidObj,f); - end - - %pause(); -end - -if SAVEMOVIE - close(vidObj); -end - -% save data -figure; hold on -plot(p_history(:,1),p_history(:,2)) -for i=1:7:length(R_history) - plot( R_history{i},[1 2],'r'); -end - -%saveName ='cache/temp'; -%save(saveName,'nm','DRA', 'k', 'p_history', 'R_history'); - - - - - - diff --git a/semiTenBCN.m b/semiTenBCN.m deleted file mode 100644 index a7df432..0000000 --- a/semiTenBCN.m +++ /dev/null @@ -1,108 +0,0 @@ -% x1=[0,0,1,1,1;... -% 1,1,0,0,0;... -% 0,1,0,1,1;... -% 1,0,1,0,0]; -% -% P= [1;0]; -% Q= [0;1]; -% s=[semiKron([Q;Q],[Q;Q]),semiKron([Q;P],[Q;P]),semiKron([P;Q],[P;Q]),semiKron([P;P],[Q;Q]),semiKron([P;P],[P;P])]; -% -% -% -% tt = x1*pinv(s) - -Md = [ 1 1 1 0; 0 0 0 1 ]; -Mc = [ 1 0 0 0; 0 1 1 1]; -Mi = [ 1 0 1 1; 0 1 0 0]; -Me= [ 1 0 0 1;0 1 1 0]; -Mn = [0 1 ; 1 0]; -A1= [0;1]; -B1 = [1;0]; -C1 = [0;1]; -x1=semiKron(A1,semiKron(B1,C1)); - -A2= [1;0]; -B2 = [0;1]; -C2 = [0;1]; -x2=semiKron(A2,semiKron(B2,C2)); - -An = semiKron(Mc,semiKron(B1,C1)); -Bn = semiKron(Mn,A1); -Cn = semiKron(Md,semiKron(B1,C1)); - -x1=semiKron(A1,semiKron(B1,C1)); - -xn1_v1 = semiKron(Mc,semiKron(semiKron(B1,C1),semiKron(Mn,semiKron(A1,semiKron(Md,semiKron(B1,C1)))))) - - -xn1_v2=semiKron(An,semiKron(Bn,Cn)); - -%A Linear Representation of Dynamics of Boolean Networks -L =[zeros(1,4) 1 0 0 0;... - zeros(1,8);... - 1 zeros(1,7);... - zeros(1,8);... - zeros(1,5) 1 1 0;... - zeros(1,7) 1;... - 0 1 1 zeros(1,5);... - zeros(1,8)]; - - - -logzono = logicalZonotope.enclosePoints([x1,x2]); -xn1 = semiKron(L,x1); -xn2 = semiKron(L,x2); - -x3= mod(x1+x2,2); -xn3 = semiKron(L,x3) - -[xn1,xn2] - -evaluate(semiKron(L,logzono)) - -%%%%%%%%%%%%%%%%%%%%%%%%% - -AlogZono = logicalZonotope.enclosePoints([[0;1],[1;0]]); -BlogZono = [0;1];%logicalZonotope.enclosePoints([[0;1],[1;0]]); -C = [0,1]; - -xlogZono=semiKron(AlogZono,semiKron(BlogZono,C)); - -evaluate(semiKron(L,xlogZono)) - - -A1= [0;1]; -B1 = [0;1]; -C1 = [0;1]; -x11=semiKron(A1,semiKron(B1,C1)); - -A2= [1;0]; -B2 = [0;1]; -C2 = [0;1]; -x22=semiKron(A2,semiKron(B2,C2)); - -xn11 = semiKron(L,x11); -xn22 = semiKron(L,x22); -[xn11,xn22] -xlogZono2=logicalZonotope.enclosePoints([x11,x22]); - -evaluate(semiKron(L,xlogZono2)) - - -% W24 = [1 zeros(1,7);... -% zeros(1,4) 1 zeros(1,3);... -% 0 1 zeros(1,6); ... -% zeros(1,5) 1 zeros(1,2);... -% 0 0 1 zeros(1,5);... -% zeros(1,6) 1 0;... -% 0 0 0 1 zeros(1,4);... -% zeros(1,7) 1]; -% -% W2 = [ 1 0 0 0; -% 0 0 1 0; -% 0 1 0 0; -% 0 0 0 1]; -% -% Mr = [1 0;0 0 ; 0 0;0 1]; - - diff --git a/semiTenExampleUzon.m b/semiTenExampleUzon.m deleted file mode 100644 index 0417694..0000000 --- a/semiTenExampleUzon.m +++ /dev/null @@ -1,58 +0,0 @@ - -clear all; -F = zeros(5,20); -F(2,1)=1; -F(3,7) =1; -F(3,13) =1; -F(4,3) =1; -F(4,12) =1; -F(5,18)=1; -F(5,19) =1; - -xx = zeros(5,1); -xx(4) =1; -xx2 = zeros(5,1); -xx2(3) =1; -logZ= logicalZonotope.enclosePoints([xx,xx2]); - -uu = zeros(4,1); -uu(2) =1; -uu2 = zeros(4,1); -uu2(4) =1; -%uu3 = zeros(4,1); -%uu3(2) =1; -logU= logicalZonotope.enclosePoints([uu,uu2]); - - -xd = zeros(5,1); -xd(1)=1; -xd(4)=1; -xd(3)=1; - -ud = zeros(4,1); -ud(1) =1; -ud(4) =1; -semiKron(semiKron(F,ud),xd) -% res{1} =semiKron(semiKron(F,logU.c),logZ); -% index=2; -% for i =1:length(logU.G) -% res{index} = semiKron(semiKron(F,logU.G{i}),logZ) ; -% index=index+1; -% end -% nextx= logicalZonotope.encloseMany(res); - - -plogU = evaluate(logU); - -res =[]; -for i =1:length(plogU(1,:)) - res = [res , evaluate(semiKron(semiKron(F,plogU(:,i)),logZ)) ]; -end -nextx= logicalZonotope.enclosePoints(res); -nextxP=evaluate(nextx) - -nextx2= semiKron(semiKron(F,logU),logZ); -%nextx2= semiKron(F,semiKron(logU,logZ)); - -nextxP=evaluate(nextx2) -%nextxLogUP =evaluate(nextxLogU) \ No newline at end of file diff --git a/semiTenExampleXzono.m b/semiTenExampleXzono.m deleted file mode 100644 index 934d89d..0000000 --- a/semiTenExampleXzono.m +++ /dev/null @@ -1,37 +0,0 @@ - -clear all; -F = zeros(5,20); -F(2,1)=1; -F(3,7) =1; -F(3,13) =1; -F(4,3) =1; -F(4,12) =1; -F(5,18)=1; -F(5,19) =1; - -Fu4 = zeros(5); -Fu4(5,3)=1; -Fu4(5,4)=1; - - -xx = zeros(5,1); -xx(4) =1; -xx2 = zeros(5,1); -xx2(3) =1; -logZ= logicalZonotope.enclosePoints([xx,xx2]); - - - -uu = zeros(4,1); -uu(4) =1; -nextx= semiKron(semiKron(F,uu),logZ); - - - - - - -semiKron(F,uu) - - -evaluate(nextx) \ No newline at end of file diff --git a/testExhSearch_auto_g.asv b/testExhSearch_auto_g.asv deleted file mode 100644 index f69054a..0000000 --- a/testExhSearch_auto_g.asv +++ /dev/null @@ -1,94 +0,0 @@ - -clear all -close all -rng(254) - -Aleng = 30; -for i =1:Aleng - A{i} = randi([0 1]); -end - -numOfmessages =121; -[z,~] =LFSR1(A,numOfmessages); -for i =1:numOfmessages - m{i} = randi([0 1]); - c{i}= xor(z{i},m{i}); -end - - - - -% for i =1:63 -% testK{i} = logicalZonotope.enclosePoints([0 1]); -% end -% testK{64} = logicalZonotope.enclosePoints([0]); -% -% [testz,A,B,C] =AStreamCipher(testK,10); -% -% for i =1:10 -% m{i} = randi([0 1]); -% testc{i}= xor(testz{i},logicalZonotope.enclosePoints(m{i})) -% end -% -% for i =1:10 -% if ~testc{i}.containsPoint(c{i}) -% flag =1; -% end -% end - -index=1; -disp('start') -index=index+1; -setIndex =1; -compA=truth_table(setIndex); - -tic - -L=2^Aleng; -%T = zeros(L,N); -for i=1:L - - testA = de2bi(i-1,Aleng,'left-msb'); - - for - - [testz,~] =LFSR1Bits(testA,numOfmessages); - - for j =1:numOfmessages - testc{j}= xor(testz{j},logicalZonotope.enclosePoints(m{j})); - end - - - - flag{kk} =0; - for j =1:numOfmessages - if ~testc{j} == c{j} - flag{kk} =1; - break; - end - end - - - - - % sum=0; - % for i =1:Aleng - % sum = sum + abs(tempA{i}-A{i}) ; - % end - % %if sum == 0 - % sprintf("sum key =%d , j =%d ",sum,j) - % %end - % - % [testz2,~] =LFSR1(tempA,numOfmessages); - % sum2=0; - % for i =1:numOfmessages - % cRecover{i}= xor(testz2{i},m{i}); - % sum2 = sum2 + abs(cRecover{i} - c{i}); - % end - % sprintf("sum message =%d",sum2) - -end -execTime = toc - - - diff --git a/testExhSearch_auto_g.m b/testExhSearch_auto_g.m deleted file mode 100644 index 9c303e0..0000000 --- a/testExhSearch_auto_g.m +++ /dev/null @@ -1,96 +0,0 @@ - -clear all -close all -rng(254) - -Aleng = 60; -for i =1:Aleng - A{i} = randi([0 1]); -end - -numOfmessages =121; -[z,~] =LFSR1(A,numOfmessages); -for i =1:numOfmessages - m{i} = randi([0 1]); - c{i}= xor(z{i},m{i}); -end - - - - -% for i =1:63 -% testK{i} = logicalZonotope.enclosePoints([0 1]); -% end -% testK{64} = logicalZonotope.enclosePoints([0]); -% -% [testz,A,B,C] =AStreamCipher(testK,10); -% -% for i =1:10 -% m{i} = randi([0 1]); -% testc{i}= xor(testz{i},logicalZonotope.enclosePoints(m{i})) -% end -% -% for i =1:10 -% if ~testc{i}.containsPoint(c{i}) -% flag =1; -% end -% end - -index=1; -disp('start') -index=index+1; -setIndex =1; -compA=truth_table(setIndex); - -tic - -L=2^Aleng; -%T = zeros(L,N); -for i=1:1000 - - testAmat = de2bi(i-1,Aleng,'left-msb'); - - for j=1:length(testAmat) - testA{j} = testAmat(j); - end - - [testz,~] =LFSR1Bits(testA,numOfmessages); - - for j =1:numOfmessages - testc{j}= xor(testz{j},m{j}); - end - - - - flag =0; - for j =1:numOfmessages - if ~testc{j} == c{j} - flag =1; - break; - end - end - - - - - % sum=0; - % for i =1:Aleng - % sum = sum + abs(tempA{i}-A{i}) ; - % end - % %if sum == 0 - % sprintf("sum key =%d , j =%d ",sum,j) - % %end - % - % [testz2,~] =LFSR1(tempA,numOfmessages); - % sum2=0; - % for i =1:numOfmessages - % cRecover{i}= xor(testz2{i},m{i}); - % sum2 = sum2 + abs(cRecover{i} - c{i}); - % end - % sprintf("sum message =%d",sum2) - -end -execTime = toc/1000 - - - diff --git a/testLVehLogic_2Veh.m b/testLVehLogic_2Veh.m deleted file mode 100644 index 0ae2196..0000000 --- a/testLVehLogic_2Veh.m +++ /dev/null @@ -1,87 +0,0 @@ -clear all - -TF = {[1],[0]}; - -numOfVeh = 2; -Len=2^(numOfVeh*2+4); -for i=1:Len - table = de2bi(i-1,numOfVeh*2+4,'left-msb'); - - - for j =1:numOfVeh - if table(j)==1 - VP{j}= TF{1}; - else - VP{j}= TF{2}; - end - end - - index =1; - for j =numOfVeh+1:numOfVeh*2 - if table(j)==1 - CF{index}= TF{1}; - else - CF{index}= TF{2}; - end - index = index +1; - end - - index =1; - for j =numOfVeh*2+1:length(table) - if table(j)==1 - U{index}= TF{1}; - else - U{index}= TF{2}; - end - index = index +1; - end - - [x(:,i),xn(:,i),xu(:,i),xnu(:,i),u(:,i)] = vehLogic(U,VP,CF); - -end - - -[invXu,iseyex] = pseudoInvBol(xu); -isequal( iseyex,eye(Len) ) - - - -Lcomp = mod(xn*invXu,2); - - -for i=1:length(x) - xncomp = semiKron(Lcomp,semiKron(u(:,i),x(:,i))); - if xncomp ~= xn(:,i) - disp('wrong') - end -end - -for i=1:length(Lcomp) - if sum(Lcomp(:,i)) ~= 1 - disp('wrongL') - end -end - - -% VPl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -% VPl{2} = VPl{1}; -% VPl{3} = [1;0]; -% VPl{4} = [1;0]; -% -% CFl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -% CFl{2} = CFl{1}; -% CFl{3} = [1;0]; -% CFl{4} = [1;0]; -% -% Ul{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -% Ul{2} = Ul{1}; -% -% -% xVP = semiKron(VP{1},semiKron(VP{2},semiKron(VP{3},VP{4}))); -% xCF = semiKron(CF{1},semiKron(CF{2},semiKron(CF{3},CF{4}))); -% xl{1} = semiKron(xVP,xCF); -% ul{1} = semiKron(Ul{1},Ul{2}); -% %x = reduce(x); -% for i=1:10 -% xl{i+1} = semiKron(Lcomp,ul{1},xl{i}); -% end diff --git a/testLVehLogic_g.m b/testLVehLogic_g.m deleted file mode 100644 index 1241e65..0000000 --- a/testLVehLogic_g.m +++ /dev/null @@ -1,89 +0,0 @@ -clear all - -TF = {[1],[0]}; - -numOfVeh = 4; -Len=2^(numOfVeh*2+2); -for i=1:Len - table = de2bi(i-1,numOfVeh*2+2,'left-msb'); - - - for j =1:numOfVeh - if table(j)==1 - VP{j}= TF{1}; - else - VP{j}= TF{2}; - end - end - - index =1; - for j =numOfVeh+1:numOfVeh*2 - if table(j)==1 - CF{index}= TF{1}; - else - CF{index}= TF{2}; - end - index = index +1; - end - - index =1; - for j =numOfVeh*2+1:length(table) - if table(j)==1 - U{index}= TF{1}; - else - U{index}= TF{2}; - end - index = index +1; - end - - [x(:,i),xn(:,i),xu(:,i),xnu(:,i),u(:,i)] = vehLogic(U,VP,CF); - -end - - -[invXu,iseyex] = pseudoInvBol(xu); -isequal( iseyex,eye(Len) ) - -[invU,iseyeu] = pseudoInvBol(u); -isequal( iseyeu,eye(Len) ) - - -Lcomp = mod(xn*invXu,2); - - -for i=1:length(x) - xncomp = semiKron(Lcomp,semiKron(u(:,i),x(:,i))); - if xncomp ~= xn(:,i) - disp('wrong') - end -end - -for i=1:length(Lcomp) - if sum(Lcomp(:,i)) ~= 1 - disp('wrong' + i) - end -end - - -% VPl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -% VPl{2} = VPl{1}; -% VPl{3} = [1;0]; -% VPl{4} = [1;0]; -% -% CFl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -% CFl{2} = CFl{1}; -% CFl{3} = [1;0]; -% CFl{4} = [1;0]; -% -% Ul{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -% Ul{2} = Ul{1}; -% -% -% xVP = semiKron(VP{1},semiKron(VP{2},semiKron(VP{3},VP{4}))); -% xCF = semiKron(CF{1},semiKron(CF{2},semiKron(CF{3},CF{4}))); -% xl{1} = semiKron(xVP,xCF); -% ul{1} = semiKron(Ul{1},Ul{2}); -% %x = reduce(x); -% for i=1:10 -% xl{i+1} = semiKron(Lcomp,ul{1},xl{i}); -% end diff --git a/useLVehLogic.asv b/useLVehLogic.asv deleted file mode 100644 index 07b9ec2..0000000 --- a/useLVehLogic.asv +++ /dev/null @@ -1,75 +0,0 @@ -clear all - -load('cache\L.mat') - - -VPl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -VPl{2} = [0;1]; -VPl{3} = [1;0]; -VPl{4} = [1;0]; - -CFl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -CFl{2} = [1;0]; -CFl{3} = [1;0]; -CFl{4} = [1;0]; - -Ul{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -Ul{2} = Ul{1}; - - -xVPl = semiKron(VPl{1},semiKron(VPl{2},semiKron(VPl{3},VPl{4}))); -xCFl = semiKron(CFl{1},semiKron(CFl{2},semiKron(CFl{3},CFl{4}))); -xl1{1} = semiKron(xVPl,xCFl); -ul{1} = semiKron(Ul{1},Ul{2}); -%x = reduce(x); -for i=1:10 - xl1{i+1} = semiKron(semiKron(Lcomp,ul{1}),xl1{i}); - xl1{i+1} = reduce(xl1{i+1}); -end - -%%--------------------%% - -VP{1} = [[0;1],[1;0]]; -VP{2} = [0;1]; -VP{3} = [1;0]; -VP{4} = [1;0]; - -CF{1} = [[0;1],[1;0]]; -CF{2} = [1;0]; -CF{3} = [1;0]; -CF{4} = [1;0]; - -U{1} = [[0;1],[1;0]]; -U{2} = U{1}; - -xlist{1}= []; -for i=1:length(VP{1}(1,:)) - for j = 1:length(CF{1}(1,:)) - xVP = semiKron(VP{1}(:,i),semiKron(VP{2},semiKron(VP{3},VP{4}))); - xCF = semiKron(CF{1}(:,i),semiKron(CF{2},semiKron(CF{3},CF{4}))); - xlist{1} = [ xlist{1} semiKron(xVP,xCF)]; - end -end - - -for s = 2:10 -xlist{s} = []; -for i=1:length(xlist{s}(1,:)) - for j=1:length(U{1}(1,:)) - for k = 1:length(U{2}(1,:)) - usemi = semiKron(Ul{1}(:,j),Ul{2}(:,k)); - newx = semiKron(semiKron(Lcomp,usemi),xlist{s}(:,i)); - xlist{s} = [ xlist{2} newx]; - end - end -end -xlist{s} = unique(xlist{s}','rows')'; -end - - -ul{1} = semiKron(Ul{1},Ul{2}); -%x = reduce(x); -for i=1:10 - x1{i+1} = semiKron(semiKron(Lcomp,ul{1}),xl1{i}); - x1{i+1} = reduce(xl1{i+1}); -end diff --git a/useLVehLogic.m b/useLVehLogic.m deleted file mode 100644 index 3d44a39..0000000 --- a/useLVehLogic.m +++ /dev/null @@ -1,69 +0,0 @@ -clear all - -load('cache\L2.mat') - - -VPl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -VPl{2} = [0;1]; -VPl{3} = [1;0]; -VPl{4} = [1;0]; - -CFl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -CFl{2} = [1;0]; -CFl{3} = [1;0]; -CFl{4} = [1;0]; - -Ul{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -Ul{2} = Ul{1}; - - -xVPl = semiKron(VPl{1},semiKron(VPl{2},semiKron(VPl{3},VPl{4}))); -xCFl = semiKron(CFl{1},semiKron(CFl{2},semiKron(CFl{3},CFl{4}))); -xl{1} = semiKron(xVPl,xCFl); -ul{1} = semiKron(Ul{1},Ul{2}); -%x = reduce(x); -% for i=1:3 -% xl{i+1} = semiKron(semiKron(Lcomp,ul{1}),xl{i}); -% xl{i+1} = reduce(xl{i+1}); -% end - -%%--------------------%% - -VP{1} = [[0;1],[1;0]]; -VP{2} = [0;1]; -VP{3} = [1;0]; -VP{4} = [1;0]; - -CF{1} = [[0;1],[1;0]]; -CF{2} = [1;0]; -CF{3} = [1;0]; -CF{4} = [1;0]; - -U{1} = [[0;1],[1;0]]; -U{2} = U{1}; - -xpoints{1}= []; -for i=1:length(VP{1}(1,:)) - for j = 1:length(CF{1}(1,:)) - xVP = semiKron(VP{1}(:,i),semiKron(VP{2},semiKron(VP{3},VP{4}))); - xCF = semiKron(CF{1}(:,i),semiKron(CF{2},semiKron(CF{3},CF{4}))); - xpoints{1} = [ xpoints{1} semiKron(xVP,xCF)]; - end -end - - -for s = 1:5 - xpoints{s+1} = []; - for i=1:length(xpoints{s}(1,:)) - for j=1:length(U{1}(1,:)) - for k = 1:length(U{2}(1,:)) - usemi = semiKron(U{1}(:,j),U{2}(:,k)); - newx = semiKron(semiKron(Lcomp,usemi),xpoints{s}(:,i)); - xpoints{s+1} = [ xpoints{s+1} newx]; - end - end - end - xpoints{s+1} = unique(xpoints{s+1}','rows')'; -end - - diff --git a/useLVehLogicZono_2Veh.asv b/useLVehLogicZono_2Veh.asv deleted file mode 100644 index 281fc7d..0000000 --- a/useLVehLogicZono_2Veh.asv +++ /dev/null @@ -1,146 +0,0 @@ -clear all - -load('cache\L.mat') - -steps = 100; -VPl{1}{1} = logicalZonotope.enclosePoints([0,1]); -VPl{1}{2} = [0]; -% VPl{3} = [1;0]; -% VPl{4} = [1;0]; - -CFl{1}{1} = logicalZonotope.enclosePoints([0,1]); -CFl{1}{2} = [0]; -% CFl{3} = [1;0]; -% CFl{4} = [1;0]; - -Ul{1} = logicalZonotope.enclosePoints([0,1]); -Ul{2} = logicalZonotope.enclosePoints([0,1]); -Ul{3} = logicalZonotope.enclosePoints([0,1]); -Ul{4} = logicalZonotope.enclosePoints([0,1]); - -tic -for i=1:steps - [VPl{i+1},CFl{i+1}] = vehLogicZono(Ul,VPl{i},CFl{i}); -end -execlogicZono = toc - -%%----------- BCN ---------%% - -VP{1} = [[0;1],[1;0]]; -VP{2} = [0;1]; - - -CF{1} = [[0;1],[1;0]]; -CF{2} = [1;0]; - - -U{1} = [[0;1],[1;0]]; -U{2} = U{1}; -U{3} = U{1}; -U{4} = U{1}; -tic -xpoints{1}= []; -for i=1:length(VP{1}(1,:)) - for j = 1:length(CF{1}(1,:)) - xVP = semiKron(VP{1}(:,i),VP{2}); - xCF = semiKron(CF{1}(:,i),CF{2}); - xpoints{1} = [ xpoints{1} semiKron(xVP,xCF)]; - end -end - - -for s = 1:steps - xpoints{s+1} = []; - for i=1:length(xpoints{s}(1,:)) - for j=1:length(U{1}(1,:)) - for j2 = 1:length(U{2}(1,:)) - for j3=1:length(U{3}(1,:)) - for j4 = 1:length(U{4}(1,:)) - usemi = semiKron(U{1}(:,j),semiKron(U{2}(:,j2),semiKron(U{3}(:,j3),U{4}(:,j4)))); - newx = semiKron(semiKron(Lcomp,usemi),xpoints{s}(:,i)); - xpoints{s+1} = [ xpoints{s+1} newx]; - end - end - end - end - end - xpoints{s+1} = unique(xpoints{s+1}','rows')'; -end -execBCN = toc - - - -%%----------- BDD ---------%% - -VP{1} = [[0],[1]]; -VP{2} = [0]; - - -CF{1} = [[0],[1]]; -CF{2} = [1]; - - -U{1} = [[0;1],[1;0]]; -U{2} = U{1}; -U{3} = U{1}; -U{4} = U{1}; -tic -xpoints{1}= []; -for i=1:length(VP{1}(1,:)) - for j = 1:length(CF{1}(1,:)) - xVP = semiKron(VP{1}(:,i),VP{2}); - xCF = semiKron(CF{1}(:,i),CF{2}); - xpoints{1} = [ xpoints{1} semiKron(xVP,xCF)]; - end -end -VP1points{1}=VP{1}; -VP2points{1}=VP{2}; - -CF1points{1}=CF{1}; -CF2points{1}=CF{2}; - -for s = 1:steps - xpoints{s+1} = []; - xpoints{s+1} = []; - for iVP1=1:length(VP1points{s}(1,:)) - for iVP2=1:length(VP2points{s}(1,:)) - for iCF1=1:length(CF1points{s}(1,:)) - for iCF2=1:length(CF2points{s}(1,:)) - for j=1:length(U{1}(1,:)) - for j2 = 1:length(U{2}(1,:)) - for j3=1:length(U{3}(1,:)) - for j4 = 1:length(U{4}(1,:)) - Ul{1}=U{1}(:,j); - Ul{2}=U{2}(:,j2); - Ul{3}=U{3}(:,j3); - Ul{4}= U{4}(:,j4); - - VPl{1}=VP1points{s}(:,iVP1); - VPl{2}=VP1points{s}(:,iVP2); - VPl{1}=VP1points{s}(:,iVP1); - VPl{2}=VP1points{s}(:,iVP2); - - [VPl,CFl] = vehLogicBDD(Ul,VPl,CFl) - VP1points{s+1} = [ VP1points{s+1} VPl{1}]; - VP2points{s+1} = [ VP2points{s+1} VPl{2}]; - CF1points{s+1} = [ CF1points{s+1} CFl{1}]; - CF2points{s+1} = [ CF2points{s+1} CFl{2}]; - - 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')'; -CF1points{s+1} = unique(CF1points{s+1}','rows')'; -CF2points{s+1} = unique(CF2points{s+1}','rows')'; -end -execBCN = toc - - - diff --git a/useLVehLogic_2Veh.asv b/useLVehLogic_2Veh.asv deleted file mode 100644 index afe67f9..0000000 --- a/useLVehLogic_2Veh.asv +++ /dev/null @@ -1,76 +0,0 @@ -clear all - -load('cache\L2.mat') - - -VPl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -VPl{2} = [0;1]; -% VPl{3} = [1;0]; -% VPl{4} = [1;0]; - -CFl{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -CFl{2} = [1;0]; -% CFl{3} = [1;0]; -% CFl{4} = [1;0]; - -Ul{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -Ul{2} = Ul{1}; -Ul{3} = Ul{1}; -Ul{4} = Ul{1}; - -xVPl = semiKron(VPl{1},VPl{2}); -xCFl = semiKron(CFl{1},CFl{2}); -xl{1} = semiKron(xVPl,xCFl); -ul{1} = semiKron(Ul{1},semiKron(Ul{2},reduce(semiKron(Ul{3},Ul{4})))); -xl{1} = reduce(xl{1}); -ul{1} = reduce(ul{1}); -for i=1:3 - LU = reduce(semiKron(Lcomp,ul{1})); - xl{i+1} = semiKron(LU,xl{i}); - xl{i+1} = reduce(xl{i+1}); -end - -%%--------------------%% - -VP{1} = [[0;1],[1;0]]; -VP{2} = [0;1]; - - -CF{1} = [[0;1],[1;0]]; -CF{2} = [1;0]; - - -U{1} = [[0;1],[1;0]]; -U{2} = U{1}; -U{3} = U{1}; -U{4} = U{1}; - -xpoints{1}= []; -for i=1:length(VP{1}(1,:)) - for j = 1:length(CF{1}(1,:)) - xVP = semiKron(VP{1}(:,i),VP{2}); - xCF = semiKron(CF{1}(:,i),CF{2}); - xpoints{1} = [ xpoints{1} semiKron(xVP,xCF)]; - end -end - - -for s = 1:5 - xpoints{s+1} = []; - for i=1:length(xpoints{s}(1,:)) - for j=1:length(U{1}(1,:)) - for j2 = 1:length(U{2}(1,:)) - for j3=1:length(U{3}(1,:)) - for j4 = 1:length(U{4}(1,:)) - usemi = semiKron(U{1}(:,j),semiKron(U{2}(:,j2),semiKron(U{3}(:,j3),U{4}(:,j4)))); - newx = semiKron(semiKron(Lcomp,usemi),xpoints{s}(:,i)); - xpoints{s+1} = [ xpoints{s+1} newx]; - end - end - end - end - end - xpoints{s+1} = unique(xpoints{s+1}','rows')'; -end - - diff --git a/useLVehLogic_2Veh.m b/useLVehLogic_2Veh.m deleted file mode 100644 index 08b9b64..0000000 --- a/useLVehLogic_2Veh.m +++ /dev/null @@ -1,76 +0,0 @@ -clear all - -load('cache\L2.mat') - - -VPl{1} = [0;1];%logicalZonotope.enclosePoints([[0;1],[1;0]]); -VPl{2} = [0;1]; -% VPl{3} = [1;0]; -% VPl{4} = [1;0]; - -CFl{1} = [1;0];%logicalZonotope.enclosePoints([[0;1],[1;0]]); -CFl{2} = [1;0]; -% CFl{3} = [1;0]; -% CFl{4} = [1;0]; - -Ul{1} = logicalZonotope.enclosePoints([[0;1],[1;0]]); -Ul{2} = Ul{1}; -Ul{3} = [0;1]; -Ul{4} = [0;1]; - -xVPl = semiKron(VPl{1},VPl{2}); -xCFl = semiKron(CFl{1},CFl{2}); -xl{1} = semiKron(xVPl,xCFl); -ul{1} = semiKron(Ul{1},reduce(semiKron(Ul{2},semiKron(Ul{3},Ul{4})))); -%xl{1} = reduce(xl{1}); -ul{1} = reduce(ul{1}); -for i=1:2 - LU = semiKron(Lcomp,ul{1}); - xl{i+1} = semiKron(LU,xl{i}); - xl{i+1} = reduce(xl{i+1}); -end - -%%--------------------%% - -VP{1} = [0;1];%[[0;1],[1;0]]; -VP{2} = [0;1]; - - -CF{1} = [1;0];%[[0;1],[1;0]]; -CF{2} = [1;0]; - - -U{1} = [[0;1],[1;0]]; -U{2} = U{1}; -U{3} = [0;1]; -U{4} = [0;1]; - -xpoints{1}= []; -for i=1:length(VP{1}(1,:)) - for j = 1:length(CF{1}(1,:)) - xVP = semiKron(VP{1}(:,i),VP{2}); - xCF = semiKron(CF{1}(:,i),CF{2}); - xpoints{1} = [ xpoints{1} semiKron(xVP,xCF)]; - end -end - - -for s = 1:5 - xpoints{s+1} = []; - for i=1:length(xpoints{s}(1,:)) - for j=1:length(U{1}(1,:)) - for j2 = 1:length(U{2}(1,:)) - for j3=1:length(U{3}(1,:)) - for j4 = 1:length(U{4}(1,:)) - usemi = semiKron(U{1}(:,j),semiKron(U{2}(:,j2),semiKron(U{3}(:,j3),U{4}(:,j4)))); - newx = semiKron(semiKron(Lcomp,usemi),xpoints{s}(:,i)); - xpoints{s+1} = [ xpoints{s+1} newx]; - end - end - end - end - end - xpoints{s+1} = unique(xpoints{s+1}','rows')'; -end - - diff --git a/LFSR1.m b/utilities/LFSR1.m similarity index 100% rename from LFSR1.m rename to utilities/LFSR1.m diff --git a/LFSR1Bits.m b/utilities/LFSR1Bits.m similarity index 100% rename from LFSR1Bits.m rename to utilities/LFSR1Bits.m diff --git a/utilities/boolFun.asv b/utilities/boolFun.asv deleted file mode 100644 index c7669cc..0000000 --- a/utilities/boolFun.asv +++ /dev/null @@ -1,8 +0,0 @@ -function [f] = boolFun(A) -% Summary of this function goes here -% Detailed explanation goes here -A{1} = xor(A{1},xnor(A{2},or(A{3},,)))); -A{2}= and(A{6},xnor(A{2},A{7})); -A{3}= nand(A{4},nor(A{5},A{1}); -end - diff --git a/utilities/cfigure.m b/utilities/cfigure.m deleted file mode 100644 index 623edca..0000000 --- a/utilities/cfigure.m +++ /dev/null @@ -1,33 +0,0 @@ -function h=cfigure(width,height) -%function h=cfigure(width,height) -% Customized figure function. Opens a figure with -% specified width and height (in centimeters) centered -% on the screen. -% The properties are set such that Matlab won't resize the -% figure while printing or exporting to graphics files (eps, -% tiff, jpeg, ...). -% - -% Get the screen size in centimeters -set(0,'units','centimeters') -scrsz=get(0,'screensize'); -% Calculate the position of the figure -position=[scrsz(3)/2-width/2 scrsz(4)/2-height/2 width height]; -h=figure; -set(h,'units','centimeters') -% Place the figure -set(h,'position',position) -% Do not allow Matlab to resize the figure while printing -set(h,'paperpositionmode','auto') -% Set screen and pigure units back to pixels -set(0,'units','pixel') -set(h,'units','pixel') - -% -% Note: in order to avoid Matlab recalculating the axes ticks -% you will need to set the following commands in you program: -% -% set(gca,'xtickmode','manual') -% set(gca,'ytickmode','manual') -% set(gca,'ztickmode','manual') % IF you have a third axis -% \ No newline at end of file diff --git a/utilities/getcondvects.m b/utilities/getcondvects.m deleted file mode 100644 index 67ad215..0000000 --- a/utilities/getcondvects.m +++ /dev/null @@ -1,29 +0,0 @@ -function [condvects] = getcondvects(i) - % GETCONDVECTS returns a matrix of binary condition vectors. - % GETCONDVECTS(I) returns a matrix of all possible binary condition - % vectors for a logical system with (I) inputs. - % INPUT: (I) shall be an integer >= 1 - % OUTPUT: CONDVECTS is a binary matrix of size [2^I,I] - % METHOD: The method uses three nested FOR loops that work to target - % only those cells whose value should be true (which of course is 50% - % of the matrix). Therefore, the algorithm scales as [0.5*i*2^i] - % which is optimal. Furthermore, the algorithm has low memory - % footprint and overhead. - % Copyright 2011, Paul Metcalf - % Acknowledgements: James Tursa and Nico Schlömer - - g = 2; - i2 = 2^i; - condvects = zeros(i2,i); - for m = 1 : 1 : i - m2 = 2^m; - m3 = (m2/2)-1; - i3 = i-m+1; - for g = g : m2 : i2 - for k = 0 : 1 : m3 - condvects(g+k,i3) = 1; - end - end - g = m2+1; - end -end \ No newline at end of file diff --git a/utilities/hangle.m b/utilities/hangle.m deleted file mode 100644 index f8e6809..0000000 --- a/utilities/hangle.m +++ /dev/null @@ -1,16 +0,0 @@ -function h = hangle(x,u) - -% y = r cos theta -% x = r sin theta -% So -%| acos( x(2)/r) - pi | < pi/12 -% r= sqrt(x(1)^2 + x(2)^2) ; -%h = acos( x(2)/r) - pi ; -% r = sqrt((x(1)-100.14)^2+(x(2)-100.7)^2); -% h = (x(2)-100.7)/r- 0.9829; - r= sqrt(x(1)^2 + x(2)^2) ; -sinn = x(1) /r; -coss = x(2)/r; -tann = sinn/sqrt(1-sinn^2); -end - diff --git a/utilities/intersectCZNonLinearH.m b/utilities/intersectCZNonLinearH.m deleted file mode 100644 index a4fc63f..0000000 --- a/utilities/intersectCZNonLinearH.m +++ /dev/null @@ -1,79 +0,0 @@ -function [Rout] = intersectCZNonLinearH(hDisc,a,Rinit,options) -%INTERSECTNONLINEARH Summary of this function goes here - -% options preprocessing -%options = params2options(params,options); -%options = checkOptionsReach(obj,options,0); -% compute symbolic derivatives -derivatives(hDisc,options); -%linearization point p.u of the input is the center of the input u -p.u = center(options.U) ;%+ options.uTrans; - -%linearization point p.x and p.y -x0 = center(Rinit); -p.x = x0; - -%substitute p into the system equation in order to obtain the constant -%input - f0 = options.fun(p.x, p.u); -% -% options.jacobians = jacobian(options.fun,[x,u]); -% %get jacobian matrices -[A_lin,B_lin] = hDisc.jacobian(p.x, p.u); -% [A_lin] = options.jacobians(p.x, p.u); - - - -% uTrans = f0; %B*Ucenter from linOptions.U not added as the system is linearized around center(U) -% Udelta = B_lin*(options.U+(-center(options.U))); -% U = Udelta + uTrans; - -%save linearization point -%hDisc.linError.p=p; - -%translate Rinit by linearization point -Rdelta = Rinit + (-p.x); -options.p = p; -% if options.tensorOrder > 2 -% Verror = linError_thirdOrder_DT(hDisc, options, Rdelta); -% else -% Verror = linError_mixed_noInt_DT(hDisc, options, Rdelta); -% end -Verror = linearizeOpt(hDisc, options, Rdelta); - -% initialize lambda -lambda0=zeros(options.dim_x,1); -optionsfmin = optimoptions(@fminunc,'Algorithm', 'quasi-newton','Display','off'); -%find optimal lambda -lambda = fminunc(@fun,lambda0, optionsfmin); -% resulting zonotope -%Zres = zonotopeFromLambda(Z,R,h,y,lambda); - -lambda =[0;0]; -newCen = Rinit.Z(:,1) - lambda*f0 - lambda*A_lin*Rinit.Z(:,1) + lambda*A_lin*p.x - lambda*Verror.Z(1,1); - -newGen = [(eye(options.dim_x)-lambda*A_lin)*Rinit.Z(:,2:end),- lambda*a,- lambda*Verror.Z(1,2:end)]; -newA = [A_lin*Rinit.Z(:,2:end) , -a, Verror.Z(1,2:end) ]; -newb = [-f0 - A_lin*(Rinit.Z(:,1) - p.x) - Verror.Z(1,1)]; -%Rout = zonotope(newCen,newGen);% + (p.x); - -Rout = conZonotope(newCen,newGen,newA,newb); -Rout = Rout; - - -% embedded function to be minimized for optimal lambda -function nfro = fun(lambda) -newGen = [(eye(options.dim_x)-lambda*A_lin)*Rinit.Z(:,2:end), -lambda*a,- lambda*Verror.Z(1,2:end)]; - -if strcmp(options.method,'normGen') - nfro = norm(newGen,'fro'); -elseif strcmp(options.method,'svd') - nfro = sum(svd(newGen)); -elseif strcmp(options.method,'radius') - nfro = radius(zonotope([zeros(options.dim_x,1) newGen])); -elseif strcmp(options.method,'volume') - nfro = volume(zonotope([zeros(options.dim_x,1) newGen])); -end - -end -end \ No newline at end of file diff --git a/utilities/intersectConZonoStrip1.m b/utilities/intersectConZonoStrip1.m deleted file mode 100644 index 1759e56..0000000 --- a/utilities/intersectConZonoStrip1.m +++ /dev/null @@ -1,98 +0,0 @@ -function [zResult]=intersectConZonoStrip1(z,hl,rl,yl,varargin) -% intersectZonoStrip : computes the intersection between one constrained zonotope and list of strips -% one strip is defined as | hx-y | <= r -% -% Syntax: -% res_conzonotope=intersectConZonoStrip(z1,hl,rl,yl) -% -% Inputs: -% z - intial constrained zonotope -% hl - list of measurement functions -% rl - list of r values -% yl - list of y values -% -% Outputs: -% zResult - constrained zonotope object -% -% -%% example with three strips and one constrained zonotope: -% hl{1} = [1 0]; -% Rl{1} = 5; -% yl{1} = -2; -% -% hl{2} = [0 1]; -% Rl{2} = 3; -% yl{2} = 2; -% -% hl{3} = [1 1]; -% Rl{3} = 3; -% yl{3} = 2; -% -% Z = [0 3 0 1;0 0 2 1]; -% A = [1 0 1]; -% b = 1; -% z = conZonotope(Z,A,b); -% zResult = intersectConZonoStrip(z,hl,Rl,yl); -% -%%just for plotting strips -% poly = mptPolytope([1 0;-1 0; 0 1;0 -1; 1 1;-1 -1],[3;7;5;1;5;1]); -% figure; hold on -% plot(z,[1 2],'r-+'); -% plot(poly,[1 2],'r-*'); -% plot(zResult,[1 2],'b-*'); -% -% legend('zonotope','strips','czonoStrips'); -% -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: none -% -% Author: Amr Alanwar -% Written: 9-Mar-2020 -% Last update: --- -% -% Last revision: --- - -%------------- BEGIN CODE -------------- - -if nargin==4 - %free parameter as multiple zonotopes Z can contain the constrained - %zonotope - lambda = zeros(length(z.center),length(rl)); -end - -%prepare center -c_new=z.Z(:,1); -for i=1:length( rl) - c_new = c_new + lambda(:,i)*( yl{i} - hl{i}*z.Z(:,1) ); -end - -%prepare generators -part1 = eye(length(z.Z(:,1))); -if isempty(z.A) - A_new =[]; - b_new =[]; -else - A_new = [ z.A zeros(size(z.A,1),length( rl))]; - b_new = z.b; -end - -for ii=1:length(rl) - part1 = part1 - lambda(:,ii)*hl{ii}; - part2(:,ii) = rl{ii}*lambda(:,ii); - A_new = [A_new ; hl{ii}*z.Z(:,2:end) , zeros(1,ii-1),-rl{ii},zeros(1,length(rl)-ii)]; - b_new = [b_new; yl{ii}-(hl{ii}*z.Z(:,1))]; -end -part1 = part1 * z.Z(:,2:end); -H_new = [part1 part2]; - -zResult = conZonotope([c_new H_new],A_new,b_new); - - - - - -end diff --git a/utilities/intersectNonLinearH.m b/utilities/intersectNonLinearH.m deleted file mode 100644 index 29eb59c..0000000 --- a/utilities/intersectNonLinearH.m +++ /dev/null @@ -1,79 +0,0 @@ -function [Rout] = intersectNonLinearH(hDisc,a,Rinit,options) -%INTERSECTNONLINEARH Summary of this function goes here - -% compute symbolic derivatives -derivatives(hDisc,options); -%linearization point p.u of the input is the center of the input u -p.u = center(options.U) ;%+ options.uTrans; - -%linearization point p.x and p.y -x0 = center(Rinit); -p.x = x0; - -%substitute p into the system equation in order to obtain the constant -%input - f0 = options.fun(p.x, p.u); -% -% options.jacobians = jacobian(options.fun,[x,u]); -% %get jacobian matrices -[A_lin,B_lin] = hDisc.jacobian(p.x, p.u); -% [A_lin] = options.jacobians(p.x, p.u); - - - -% uTrans = f0; %B*Ucenter from linOptions.U not added as the system is linearized around center(U) -% Udelta = B_lin*(options.U+(-center(options.U))); -% U = Udelta + uTrans; - -%save linearization point -%hDisc.linError.p=p; - -%translate Rinit by linearization point -Rdelta = Rinit + (-p.x); -options.p = p; - -% if options.tensorOrder > 2 -% Verror = linError_thirdOrder_DT(hDisc, options, Rdelta); -% else -% Verror = linError_mixed_noInt_DT(hDisc, options, Rdelta); -% end -%Verror = linearizeOpt(hDisc, options, Rdelta); -Verror = linError_mixed_noInt_DT(hDisc, options, Rdelta); - - -% initialize lambda -lambda0=zeros(options.dim_x,options.dim_h); -optionsfmin = optimoptions(@fminunc,'Algorithm', 'quasi-newton','Display','off'); -%find optimal lambda -lambda = fminunc(@fun,lambda0, optionsfmin); -% resulting zonotope -%Zres = zonotopeFromLambda(Z,R,h,y,lambda); -newCen = Rinit.Z(:,1) - lambda*f0 - lambda*A_lin*Rinit.Z(:,1) + lambda*A_lin*p.x - lambda*Verror.Z(:,1); -newGen = [(eye(options.dim_x)-lambda*A_lin)*Rinit.Z(:,2:end), lambda*a, - lambda*Verror.Z(:,2:end)]; -%newCen = Rinit.Z(:,1) - lambda*f0 - lambda*A_lin*Rinit.Z(:,1) + lambda*A_lin*p.x ; -%newGen = [(eye(options.dim_x)-lambda*A_lin)*Rinit.Z(:,2:end),- lambda*a]; - -%Rout = zonotope(newCen,newGen) +lambda*Verror ; - -Rout = zonotope(newCen,newGen); - - - -% embedded function to be minimized for optimal lambda -function nfro = fun(lambda) -newGen = [(eye(options.dim_x)-lambda*A_lin)*Rinit.Z(:,2:end), lambda*a, -lambda*Verror.Z(:,2:end) ]; -%newGen = [(eye(options.dim_x)-lambda*A_lin)*Rinit.Z(:,2:end), -lambda*a]; - - -if strcmp(options.method,'normGen') - nfro = norm(newGen,'fro'); -elseif strcmp(options.method,'svd') - nfro = sum(svd(newGen)); -elseif strcmp(options.method,'radius') - nfro = radius(zonotope([zeros(options.dim_x,1) newGen])); -elseif strcmp(options.method,'volume') - nfro = volume(zonotope([zeros(options.dim_x,1) newGen])); -end - -end -end \ No newline at end of file diff --git a/utilities/intersectZonoStrip1.m b/utilities/intersectZonoStrip1.m deleted file mode 100644 index adfb9ec..0000000 --- a/utilities/intersectZonoStrip1.m +++ /dev/null @@ -1,124 +0,0 @@ -function [res_zonotope]=intersectZonoStrip1(z1,hl,Rl,yl,varargin) -% intersectZonoStrip - computes the intersection between one zonotope and list of strips -% options: methods to calculate the weights -% 'normGen' default and has analytical solution -% 'svd' -% 'radius' -% -%% the strip is defined as | hx-y | <= d -%% example with three strips and one zonotope: -% hl{1} = [1 0]; -% Rl{1} = 5; -% yl{1} = -2; -% -% hl{2} = [0 1]; -% Rl{2} = 3; -% yl{2} = 2; -% -% hl{3} = [1 1]; -% Rl{3} = 3; -% yl{3} = 2; -% -% -% z = zonotope([1 2 2 2 6 2 8;1 2 2 0 5 0 6 ]); -% res_zono= intersectZonoStrip(z,hl,Rl,yl); -% -%%just for comparison -% poly = mptPolytope([1 0;-1 0; 0 1;0 -1; 1 1;-1 -1],[3;7;5;1;5;1]); -% zpoly = z& poly; -% -% figure; hold on -% plot(z,[1 2],'r-+'); -% plot(poly,[1 2],'r-*'); -% plot(zpoly,[1 2],'b-+'); -% plot(res_zono,[1 2],'b-*'); -% -% legend('zonotope','strips','zono&poly','zonoStrips'); -% -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: none -% -% Author: Amr Alanwar -% Written: 9-Mar-2020 -% Last update: --- -% -% Last revision: --- - -%------------- BEGIN CODE -------------- - -if nargin==4 - %The optimization function is based on norm of the generators - method='volume'; -elseif nargin==5 - method =varargin{1}; -end - - H = generators(z1); -if strcmp(method,'svd') || strcmp(method,'radius') || strcmp(method,'volume') - lambda0=zeros(length(z1.center),length(Rl)); - options = optimoptions(@fminunc,'Algorithm', 'quasi-newton','Display','off'); - %find the weights - lambda = fminunc(@fun,lambda0, options); -elseif strcmp(method,'normGen') - % Find the analytical solution - h_combined=[]; - for i=1:length(hl) - h_combined = [ h_combined ; hl{i}]; - end - gamma=eye(length(hl)); - num= H*H'*h_combined'; - den = h_combined * H*H' * h_combined' ; - for i=1:length(hl) - den = den + gamma(:,i) *Rl{i}^2* gamma(:,i)'; - end - - lambda = num * den^-1; -else - disp('Method is not supported'); - return; -end - - - -%prepare center -c_new=z1.center; -for i=1:length( Rl) - c_new = c_new + lambda(:,i)*( yl{i} - hl{i}*z1.center ); -end - -%prepare generators -part1 = eye(length(z1.center)); -for ii=1:length(Rl) - part1 = part1 - lambda(:,ii)*hl{ii}; - part2(:,ii) = Rl{ii}*lambda(:,ii); -end -part1 = part1 * H; -H_new = [part1 part2]; -res_zonotope = zonotope([c_new H_new]); - - - - function nfro = fun(lambda) - part1 = eye(length(z1.center)); - for ii=1:length(Rl) - part1 = part1 - lambda(:,ii)*hl{ii}; - part2(:,ii) = Rl{ii}*lambda(:,ii); - end - part1 = part1 * H; - H_new = [part1 part2]; - if strcmp(method,'svd') - nfro = sum(svd(H_new)); - elseif strcmp(method,'radius') - nfro = radius(zonotope([zeros(length(z1.center),1) H_new])); - elseif strcmp(method,'volume') - nfro = radius(zonotope([zeros(length(z1.center),1) H_new])); - end - - end - - -end diff --git a/utilities/invBol.m b/utilities/invBol.m deleted file mode 100644 index 16f9827..0000000 --- a/utilities/invBol.m +++ /dev/null @@ -1,68 +0,0 @@ -function [A, jb] = invBol(A, tol) -%RREF Reduced row echelon form. -% R = RREF(A) produces the reduced row echelon form of A. -% -% [R,jb] = RREF(A) also returns a vector, jb, so that: -% r = length(jb) is this algorithm's idea of the rank of A, -% x(jb) are the bound variables in a linear system, Ax = b, -% A(:,jb) is a basis for the range of A, -% R(1:r,jb) is the r-by-r identity matrix. -% -% [R,jb] = RREF(A,TOL) uses the given tolerance in the rank tests. -% -% Roundoff errors may cause this algorithm to compute a different -% value for the rank than RANK, ORTH and NULL. -% -% Class support for input A: -% float: double, single -% -% See also RANK, ORTH, NULL, QR, SVD. - -% Copyright 1984-2017 The MathWorks, Inc. - -[m,n] = size(A); - -% Does it appear that elements of A are ratios of small integers? -[num, den] = rat(A); -rats = isequal(A, num./den); - -% Compute the default tolerance if none was provided. -if (nargin < 2) - tol = max(m,n)*eps(class(A))*norm(A,inf); -end - -% Loop over the entire matrix. -i = 1; -j = 1; -jb = zeros(1,0); -while i <= m && j <= n - % Find value and index of largest element in the remainder of column j. - [p, k] = max(abs(A(i:m,j))); - k = k+i-1; - if p <= tol - % The column is negligible, zero it out. - A(i:m,j) = 0; - j = j + 1; - else - % Remember column index - jb = [jb j]; %#ok - % Swap i-th and k-th rows. - A([i k],j:n) = A([k i],j:n); - % Divide the pivot row by the pivot element. - A(i,j:n) = A(i,j:n)./A(i,j); - % Subtract multiples of the pivot row from all the other rows. - for k = [1:i-1 i+1:m] - % A(k,j:n) = A(k,j:n) - A(k,j).*A(i,j:n); - %A(k,j:n) = xor(A(k,j:n) , A(k,j)&A(i,j:n)); - A(k,j:n) = mod(A(k,j:n) + (A(k,j).*A(i,j:n)),2); - end - i = i + 1; - j = j + 1; - end -end - -% % Return "rational" numbers if appropriate. -if rats - [num, den] = rat(A); - A = num./den; -end diff --git a/utilities/invIntMatrixAuto.m b/utilities/invIntMatrixAuto.m deleted file mode 100644 index 5ff5842..0000000 --- a/utilities/invIntMatrixAuto.m +++ /dev/null @@ -1,31 +0,0 @@ -function [intMatOut] = invIntMatrixAuto(intMatIn) -%INVMATRIX Summary of this function goes here -% Detailed explanation goes here - -Acenter = (intMatIn.Sup + intMatIn.Inf)/2; -Adelta = (intMatIn.Sup - intMatIn.Inf)/2; - - -M = pinv(eye(size(pinv(Acenter)*Adelta)) - abs(pinv(Acenter))*Adelta); -mu = diag(M); -Tmu = diag(mu); -Tv = pinv(2*Tmu - eye(size(Tmu))); -Blower = -M*abs(pinv(Acenter)) +Tmu*( pinv(Acenter) + abs(pinv(Acenter))) ; -Bupper = M*abs(pinv(Acenter)) +Tmu* (pinv(Acenter) - abs(pinv(Acenter))) ; - -Blowerlower =min(Blower,Tv*Blower); -Bupperupper =max(Bupper,Tv*Bupper); - -intMatOut = intervalMatrix((Bupperupper+Blowerlower)/2,(Bupperupper-Blowerlower)/2); - -% M = pinv(eye(size(Acenter)) - abs(pinv(Acenter))*Adelta); -% mu = diag(M); -% Tmu = diag(mu); -% Tv = pinv(2*Tmu - eye(size(Acenter))); -% Blower = -M*abs(pinv(Acenter)) +Tmu*( pinv(Acenter) + abs(pinv(Acenter))) ; -% Bupper = M*abs(pinv(Acenter)) +Tmu* (pinv(Acenter) - abs(pinv(Acenter))) ; -% -% Blowerlower =min(Blower,Tv*Blower); -% Bupperupper =max(Bupper,Tv*Bupper); -end - diff --git a/utilities/logIntMatrixCar.m b/utilities/logIntMatrixCar.m deleted file mode 100644 index 05fc0ea..0000000 --- a/utilities/logIntMatrixCar.m +++ /dev/null @@ -1,54 +0,0 @@ -function [intMatOut] = logIntMatrix(varargin) -%INVMATRIX Summary of this function goes here -% Detailed explanation goes here -% eAmI = expm(intMatIn + -1* eye(6)); -% intMatOut = exp(-1)*(eAmI + -1*eye(6)); -%intMatOut = (eAmI + -1* (intMatIn + -1*eye(6))); - -maxOrder =1; -initialOrder = 0; -intMat = varargin{1}; -maxabs = varargin{2}; -initialPower =eye(4);% intervalMatrix(eye(6),zeros(6)); %intMat^0; - - -%compute powers -iPow=powers(intMat,maxOrder); -% -% if nargin==2 -% intMat = varargin{1}; -% maxOrder = varargin{2}; -% initialOrder = 0; -% initialPower = intMat^0; -% -% %compute powers -% iPow=powers(intMat,maxOrder); -% elseif nargin==4 -% intMat = varargin{1}; -% maxOrder = varargin{2}; -% initialOrder = varargin{3}; -% initialPower = varargin{4}; -% -% %compute powers -% iPow=powers(intMat,maxOrder,initialOrder,initialPower); -% end - -%compute finite Taylor series -%initialize matrix zonotope -eI=0;%initialPower*(1/factorial(initialOrder)); - -%compute Taylor series -for i=(initialOrder+2):maxOrder - eI = eI + iPow{i}*(1/factorial(i)); -end - -%compute exponential remainder -E = logRemainder(intMat,maxOrder,maxabs); - -%final result -%eI = eI+E; - -intMatOut = intMat + -1*initialPower +-1*E ;%+ -1*eI ; -%intMatOut = intMat + -1*E ; -end - diff --git a/utilities/mtimesAndOr.m b/utilities/mtimesAndOr.m deleted file mode 100644 index c649dab..0000000 --- a/utilities/mtimesAndOr.m +++ /dev/null @@ -1,19 +0,0 @@ -function [result] = mtimesAndOr(M,G) -%MTIMESANDOR Summary of this function goes here -% Detailed explanation goes here - -[mrows,mcols]=size(M); -[grows,gcols]=size(G); - -for j=1:gcols - for k =1:mrows - temp = 0; - for ii =1:grows - %temp=temp + matrix(k,ii) * Z.G{i}(ii,1) ; - temp=or(temp,(M(k,ii) & G(ii,j) )); - end - result(k,j) = temp; - end -end -end - diff --git a/utilities/plotCZono.m b/utilities/plotCZono.m deleted file mode 100644 index d025042..0000000 --- a/utilities/plotCZono.m +++ /dev/null @@ -1,65 +0,0 @@ -function h=plotCZono(varargin) -% plot - Plots 2-dimensional projection of a zonotope -% -% Syntax: -% h = plot(Z) plots the zonotope Z for the first two dimensions -% h = plot(Z,dims) plots the zonotope Z for the two dimensions i,j: "dims=[i,j]" and returns handle to line-plot object -% h = plot(Z,dims,'Color','red',...) adds the standard plotting preferences -% -% Inputs: -% Z - zonotope object -% dims - dimensions that should be projected (optional) -% -% Outputs: -% handle -% -% Example: -% Z=zonotope([1 1 0; 0 0 1]); -% plot(Z) -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: polygon - -% Author: Matthias Althoff -% Written: 27-July-2016 -% Last update: --- -% Last revision:--- - -%------------- BEGIN CODE -------------- - -%If only one argument is passed -if nargin==1 - CZ=varargin{1}; - dims=[1,2]; - type{1}='b'; - -%If two arguments are passed -elseif nargin==2 - CZ=varargin{1}; - dims=varargin{2}; - type{1}='b'; - -%If three or more arguments are passed -elseif nargin>=3 - CZ=varargin{1}; - dims=varargin{2}; - type(1:length(varargin)-2)=varargin(3:end); -end - -%h = plot(CZ,[1 2],'r','Template',256); -%plot(CZ,[1,2],'b','Filled',false,'Splits',4); -h=plot(CZ,[1 2],'r','Template',256); -% % project zonotope -% Z = project(Z,dims); -% -% % delete zero generators -% p = polygon(Z); -% -% %plot and output the handle -% %h = line(p(1,:),zeros(size(p(1,:))),p(2,:),'Color', [0.5 0.5 0.5]); -% h = line(p(1,:),p(2,:),'Color', [0.5 0.5 0.5]); - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/utilities/plotPoly.m b/utilities/plotPoly.m deleted file mode 100644 index 8d4f490..0000000 --- a/utilities/plotPoly.m +++ /dev/null @@ -1,67 +0,0 @@ -function h=plotPoly(varargin) -% plot - Plots 2-dimensional projection of a zonotope -% -% Syntax: -% h = plot(Z) plots the zonotope Z for the first two dimensions -% h = plot(Z,dims) plots the zonotope Z for the two dimensions i,j: "dims=[i,j]" and returns handle to line-plot object -% h = plot(Z,dims,'Color','red',...) adds the standard plotting preferences -% -% Inputs: -% Z - zonotope object -% dims - dimensions that should be projected (optional) -% -% Outputs: -% handle -% -% Example: -% Z=zonotope([1 1 0; 0 0 1]); -% plot(Z) -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: polygon - -% Author: Matthias Althoff -% Written: 27-July-2016 -% Last update: --- -% Last revision:--- - -%------------- BEGIN CODE -------------- - -%If only one argument is passed -if nargin==1 - Z=varargin{1}; - dims=[1,2]; - type{1}='b'; - -%If two arguments are passed -elseif nargin==2 - Z=varargin{1}; - dims=varargin{2}; - type{1}='b'; - -%If three or more arguments are passed -elseif nargin>=3 - Z=varargin{1}; - dims=varargin{2}; - type(1:length(varargin)-2)=varargin(3:end); -end - - -% compute vertices -V = vertices(Z); - -% plot projected vertices - -if length(varargin) ==4 -h = plotPolygon(V(dims,:),'Color', varargin{3},'Marker',varargin{4}); -else -h = plotPolygon(V(dims,:),'Color', varargin{3}); -end - - - - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/utilities/plotZono.m b/utilities/plotZono.m deleted file mode 100644 index 2c3d02d..0000000 --- a/utilities/plotZono.m +++ /dev/null @@ -1,66 +0,0 @@ -function h=plotZono(varargin) -% plot - Plots 2-dimensional projection of a zonotope -% -% Syntax: -% h = plot(Z) plots the zonotope Z for the first two dimensions -% h = plot(Z,dims) plots the zonotope Z for the two dimensions i,j: "dims=[i,j]" and returns handle to line-plot object -% h = plot(Z,dims,'Color','red',...) adds the standard plotting preferences -% -% Inputs: -% Z - zonotope object -% dims - dimensions that should be projected (optional) -% -% Outputs: -% handle -% -% Example: -% Z=zonotope([1 1 0; 0 0 1]); -% plot(Z) -% -% Other m-files required: none -% Subfunctions: none -% MAT-files required: none -% -% See also: polygon - -% Author: Matthias Althoff -% Written: 27-July-2016 -% Last update: --- -% Last revision:--- - -%------------- BEGIN CODE -------------- - -%If only one argument is passed -if nargin==1 - Z=varargin{1}; - dims=[1,2]; - type{1}='b'; - -%If two arguments are passed -elseif nargin==2 - Z=varargin{1}; - dims=varargin{2}; - type{1}='b'; - -%If three or more arguments are passed -elseif nargin>=3 - Z=varargin{1}; - dims=varargin{2}; - type(1:length(varargin)-2)=varargin(3:end); -end - -% project zonotope -Z = project(Z,dims); - -% delete zero generators -p = polygon(Z); - -%plot and output the handle -%h = line(p(1,:),zeros(size(p(1,:))),p(2,:),'Color', [0.5 0.5 0.5]); -if length(varargin) ==4 -h = line(p(1,:),p(2,:),'Color', varargin{3},'Marker',varargin{4}); -else - h = line(p(1,:),p(2,:),'Color', varargin{3}); -end - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/utilities/pseudoInvBol.m b/utilities/pseudoInvBol.m deleted file mode 100644 index f26b149..0000000 --- a/utilities/pseudoInvBol.m +++ /dev/null @@ -1,8 +0,0 @@ -function [invX0,iseye] = pseudoInvBol(XU) -bb=invBol([mod(XU*XU',2),eye(size(mod(XU*XU',2)))]); -[rows,cols] = size(bb); -invX0X0 = bb(:,cols/2+1:end); -invX0 = mod(XU'* invX0X0,2); -iseye= mod(XU*invX0,2); -end - diff --git a/utilities/readNameValuePair.m b/utilities/readNameValuePair.m new file mode 100644 index 0000000..00e8f0c --- /dev/null +++ b/utilities/readNameValuePair.m @@ -0,0 +1,72 @@ +function [NVpairs,value] = readNameValuePair(NVpairs,name,varargin) +% readNameValuePair - searches through plotOptions to find name from name-value +% pair, returns corresponding value and plotOptions where searched +% name-value pair is deleted +% +% Syntax: +% [plotOptions,value] = readNameValuePair(plotOptions,name) +% [plotOptions,value] = readNameValuePair(plotOptions,name,check) +% [plotOptions,value] = readNameValuePair(plotOptions,name,check,def) +% +% Inputs: +% NVpairs - Name-Value pairs +% name - name of name-value pair +% check - (optional) functions that value should be check with +% def - (optional) default values +% +% Outputs: +% NVpairs - LineSpecification options + Name-Value pairs +% value - value of name-value pair +% +% Example: +% plotOptions = {'r','Filled',true}; +% [plotOptions,value] = ... +% readNameValuePair(plotOptions,'Filled','islogical'); +% +% Other m-files required: none +% Subfunctions: none +% MAT-files required: none +% +% See also: global/functions/readPlotOptions, polyZonotope/plot + +% Author: Mark Wetzlinger, Niklas Kochdumper +% Written: 15-July-2020 +% Last update: --- +% Last revision: --- + +%------------- BEGIN CODE -------------- + +% default empty value (name not found) +if nargin >= 4 + value = varargin{2}; +else + value = []; +end + +% check every second entry +for i=1:2:length(NVpairs)-1 + + % has to be a char + if ischar(NVpairs{i}) + + if strcmp(NVpairs{i},name) + % name found + value = NVpairs{i+1}; + + % check whether name complies with check + if nargin >= 3 + if ~feval(varargin{1},value) + error("Invalid assignment for " + name); + end + end + + % empty the corresponding cells + NVpairs{i} = []; NVpairs{i+1} = []; + % ...and delete empty cells + NVpairs = NVpairs(~cellfun('isempty',NVpairs)); + break + end + end +end + +%------------- END OF CODE -------------- diff --git a/utilities/readPlotOptions.m b/utilities/readPlotOptions.m new file mode 100644 index 0000000..77c568a --- /dev/null +++ b/utilities/readPlotOptions.m @@ -0,0 +1,51 @@ +function [linespec,NVpairs] = readPlotOptions(plotOptions) +% readPlotOptions - separates LineSpecification options from +% name-value pairs in plot options +% +% Syntax: +% [linespec,NVpairs] = readPlotOptions(plotOptions) +% +% Inputs: +% plotOptions - LineSpecification options + Name-Value pairs +% +% Outputs: +% linespec - LineSpecification options for Matlab plots +% NVpairs - Name-Value pairs for Matlab plots +% +% Example: +% - +% +% Other m-files required: none +% Subfunctions: none +% MAT-files required: none +% +% See also: contSet/plot (all classes) + +% Author: Mark Wetzlinger +% Written: 14-July-2020 +% Last update: --- +% Last revision: --- + +%------------- BEGIN CODE -------------- + +% default values +linespec = 'b'; + +% process linespec and Name-Value pairs +allowedChars = '-:.+o*xsd^v>=4 - h = varargin{1}; - CZ=varargin{2}; - dims=varargin{3}; - type(1:length(varargin)-3)=varargin(4:end); -end - -% % project zonotope -% Z = project(Z,dims); -% -% % delete zero generators -% p = polygon(Z); - plot(X_data_cmz_more{iSet},projectedDims{plotRun},'r','Template',256); - -%plot and output the handle -set(h,'XData', p(1,:), 'YData',p(2,:)); - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/utilities/updatePlotCZono.m b/utilities/updatePlotCZono.m deleted file mode 100644 index b25a120..0000000 --- a/utilities/updatePlotCZono.m +++ /dev/null @@ -1,36 +0,0 @@ -function updatePlotZono(varargin) - -%If only two argument is passed -if nargin==2 - h = varargin{1}; - CZ=varargin{2}; - dims=[1,2]; - type{1}='b'; - -%If three arguments are passed -elseif nargin==3 - h = varargin{1}; - CZ=varargin{2}; - dims=varargin{3}; - type{1}='b'; - -%If four or more arguments are passed -elseif nargin>=4 - h = varargin{1}; - CZ=varargin{2}; - dims=varargin{3}; - type(1:length(varargin)-3)=varargin(4:end); -end - -% % project zonotope -% Z = project(Z,dims); -% -% % delete zero generators -% p = polygon(Z); -newh= plot(CZ,[1 2],'r','Template',256); -p1=get(newh,'XData'); -p2=get(newh,'YData'); -%plot and output the handle -set(h,'XData', p1, 'YData',p2); - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/utilities/updatePlotPoly.m b/utilities/updatePlotPoly.m deleted file mode 100644 index 81c8924..0000000 --- a/utilities/updatePlotPoly.m +++ /dev/null @@ -1,34 +0,0 @@ -function updatePlotPoly(varargin) - -%If only two argument is passed -if nargin==2 - h = varargin{1}; - Z=varargin{2}; - dims=[1,2]; - type{1}='b'; - -%If three arguments are passed -elseif nargin==3 - h = varargin{1}; - Z=varargin{2}; - dims=varargin{3}; - type{1}='b'; - -%If four or more arguments are passed -elseif nargin>=4 - h = varargin{1}; - Z=varargin{2}; - dims=varargin{3}; - type(1:length(varargin)-3)=varargin(4:end); -end - -% project zonotope -Z = project(Z,dims); - -% delete zero generators -p = vertices(Z);%polygon(Z); -p = [p,p(:,1)]; -%plot and output the handle -set(h,'XData', p(1,:), 'YData',p(2,:)); - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/utilities/updatePlotZono.m b/utilities/updatePlotZono.m deleted file mode 100644 index 94329e7..0000000 --- a/utilities/updatePlotZono.m +++ /dev/null @@ -1,34 +0,0 @@ -function updatePlotZono(varargin) - -%If only two argument is passed -if nargin==2 - h = varargin{1}; - Z=varargin{2}; - dims=[1,2]; - type{1}='b'; - -%If three arguments are passed -elseif nargin==3 - h = varargin{1}; - Z=varargin{2}; - dims=varargin{3}; - type{1}='b'; - -%If four or more arguments are passed -elseif nargin>=4 - h = varargin{1}; - Z=varargin{2}; - dims=varargin{3}; - type(1:length(varargin)-3)=varargin(4:end); -end - -% project zonotope -Z = project(Z,dims); - -% delete zero generators -p = vertices(Z);%polygon(Z); -p = [p,p(:,1)]; -%plot and output the handle -set(h,'XData', p(1,:), 'YData',p(2,:)); - -%------------- END OF CODE -------------- \ No newline at end of file diff --git a/utilities/vehLogic.asv b/utilities/vehLogic.asv deleted file mode 100644 index 6060f30..0000000 --- a/utilities/vehLogic.asv +++ /dev/null @@ -1,79 +0,0 @@ -function [x,xn,xu,xnu,u] = vehLogic(U,VP,CF) - -VPn{1} = U{1} & not(VP{1}) & not(CF{1}) ; - -%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})); - - -for i=1:4 - if U{i}==0 - U{i} = [0;1]; - else - U{i} = [1;0]; - end -end -for i=1:2 -% if U{i}==0 -% U{i} = [0;1]; -% else -% U{i} = [1;0]; -% end - if VP{i}==0 - VP{i} = [0;1]; - else - VP{i} = [1;0]; - end - if VPn{i}==0 - VPn{i} = [0;1]; - else - VPn{i} = [1;0]; - end - if CF{i}==0 - CF{i} = [0;1]; - else - CF{i} = [1;0]; - end - if CFn{i}==0 - CFn{i} = [0;1]; - else - CFn{i} = [1;0]; - end -end - -u= semiKron(U{1},semiKron(U{2},semiKron(U{3},U{4}))); -%u= semiKron(U{1},U{2}); -xVP = semiKron(VP{1},VP{2}); -xCF = semiKron(CF{1},CF{2}); -%xVP = semiKron(VP{1},semiKron(VP{2},semiKron(VP{3},VP{4}))); -%xCF = semiKron(CF{1},semiKron(CF{2},semiKron(CF{3},CF{4}))); - -xu = semiKron(u,semiKron(xVP,xCF)); -x = semiKron(xVP,xCF); - -%xVPn = semiKron(VPn{1},semiKron(VPn{2},semiKron(VPn{3},VPn{4}))); -%xCFn = semiKron(CFn{1},semiKron(CFn{2},semiKron(CFn{3},CFn{4}))); -xVPn = semiKron(VPn{1},VPn{2}); -xCFn = semiKron(CFn{1},CFn{2}); -xnu = semiKron(u,semiKron(xVPn,xCFn)); -xn = semiKron(xVPn,xCFn); - -end \ No newline at end of file diff --git a/vehLogic.asv b/vehLogic.asv deleted file mode 100644 index 8562bcc..0000000 --- a/vehLogic.asv +++ /dev/null @@ -1,23 +0,0 @@ -function [VPn,CFn,x,xn] = vehLogic(VP,CF) - - -VPn{1} =not(VP{2}) & not(VP{4}) & not(VP{1}) & CF{1} & not(CF{2}) & not(CF{4}); -VPn{2} =not(VP{1})¬(VP{3})¬(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}),CF{1}),not(VPn{1})); -CFn{2} =and(or(and(not(VP{2}),VPn{2}),CF{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})); - - - -xVP = semiKron(VP{1},semiKron(VP{2},semiKron({VP{3},VP{4}}))); -xCF = semiKron(CF{1},semiKron(CF{2},semiKron({CF{3},CF{4}}))); -x = semiKron(xVP,xCF); - -xVPn = semiKron(VPn{1},semiKron(VPn{2},semiKron({VPn{3},VPn{4}}))); -xCFn = semiKron(CFn{1},semiKron(CFn{2},semiKron({CFn{3},CFn{4}}))); -xn = semiKron(xVPn,xCFn); - -end \ No newline at end of file