-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,520 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.