Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
aalanwar committed Oct 13, 2022
1 parent 9437c8e commit eff3c1d
Show file tree
Hide file tree
Showing 31 changed files with 1,520 additions and 45 deletions.
11 changes: 11 additions & 0 deletions @logicalZonotope/and.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
% 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 = Z1.c & Z2.c;
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Z = enclosePoints(points,varargin)
function Z = enclosePoints2(points,varargin)
% enclosePoints - enclose a point cloud with a zonotope
%
% Syntax:
Expand Down Expand Up @@ -51,33 +51,34 @@ cen = points(:,1);
if numOfPoints > 1
containsZeroFlag=0;
newPoints = [];
for i =1:numOfPoints

for i =1:numOfPoints
if points(:,i) == zeros(dim,1)
containsZeroFlag =1;
saveI = i;
break;

els
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

if containsZeroFlag ==1
cen = points(:,saveI);
for i =1:numOfPoints
if i==saveI

else
gen{index} = xor(cen,points(:,i));
index = index +1;
end
end
else
index =1;
for i =2:numOfPoints
gen{index} = xor(cen,points(:,i));
index = index +1;
end
end
Z =logicalZonotope(cen,gen);
else
Expand Down
90 changes: 90 additions & 0 deletions @logicalZonotope/enclosePoints2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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(newPoints(:,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 --------------
1 change: 1 addition & 0 deletions @logicalZonotope/logicalZonotope.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
methods (Static = true)
%Z = generateRandom(varargin) % generate random zonotope
Z = enclosePoints(points,varargin) % enclose point cloud with zonotope
Z = enclosePoints2(points,varargin) % enclose point cloud with zonotope
Z = encloseMany(Zcell)
end

Expand Down
10 changes: 10 additions & 0 deletions @logicalZonotope/or.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@
% Last revision: ---

%------------- BEGIN CODE --------------
if ~isa(Z1,'logicalZonotope')
Z1=logicalZonotope.enclosePoints(Z1);
end

if ~isa(Z2,'logicalZonotope')
Z2=logicalZonotope.enclosePoints(Z2);
end

[crows1,~] = size(Z1.c);
[crows2,~] = size(Z2.c);
Z1 = reduce(Z1);
Z2 = reduce(Z2);

done=0;
if ~isempty( Z1.G)
Expand Down
2 changes: 1 addition & 1 deletion LFSR1Bits.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [z,A] = LFSR1(A,N)
function [z,A] = LFSR1Bits(A,N)
%TRIVIUM Summary of this function goes here
% Detailed explanation goes here

Expand Down
2 changes: 1 addition & 1 deletion Logical_Zono_XOR.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
c2 = [0;1];
g1 = {[1;0]};
%g1 = {[0 1;1 1]};
g2 = {[1;1],[1;0]};
g2 = {[1;1]};
%g2 = {[1 0;0 1]};
dim =20;
c3= [randi([0 1],dim,1) ];
Expand Down
80 changes: 80 additions & 0 deletions pursuit_evader_main.asv
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

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} =0;
v{i} =0;
c{i} =0;
end
u_state = cell(n_pursuers*n_regions, 1);
%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)} = 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;
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;
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} = 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;
end
end
96 changes: 96 additions & 0 deletions pursuit_evader_main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

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
Loading

0 comments on commit eff3c1d

Please sign in to comment.