⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iauto_part.m

📁 一个matlab的将军模型
💻 M
📖 第 1 页 / 共 3 页
字号:
        if intersect_flag
            curr_states{length(curr_states)+1} = refinement{k};
        end
        %       end %if ~(GLO...
        % >>>>>>>>>>>> -------------- end (State Partition) --------------- <<<<<<<<<<<<
    end %while 1
    GLOBAL_AUTOMATON{rlocation}.interior_region{int_reg}.state = curr_states;
    refinement = {};
end

return

%----------------------------------------------------------------------------

function INV = return_region(cell)

% Get the `invariant` for the given `location`.
%
% Syntax:
%   "INV = return_region(cell)"
%
% Description:
%   Return the "linearcon" object representing the `invariant` polytope for
%   the `location` specified by the "cell".
%
% See Also:
%   piha,linearcon

% The routine is changed by Dong Jia. Instead of return a single linearcon
% object, it returns a set of linearcon objects.

global GLOBAL_PIHA GLOBAL_APPROX_PARAM

% The perform_face_partitioning flag dictates when face partitioning is
% used.  Face partitioning is when a cell region is split up into the
% its center and several sliver regions on the faces of the cell.
% JPK 11/2003
perform_face_partitioning = 0;

boundary = GLOBAL_PIHA.Cells{cell}.boundary;
hpflags = GLOBAL_PIHA.Cells{cell}.hpflags;

C = []; d = [];
for l = 1:length(boundary)
    if hpflags(l)
        C(l,:) = GLOBAL_PIHA.Hyperplanes{boundary(l)}.c;
        d(l,:) = GLOBAL_PIHA.Hyperplanes{boundary(l)}.d;
    else
        C(l,:) = -GLOBAL_PIHA.Hyperplanes{boundary(l)}.c;
        d(l,:) = -GLOBAL_PIHA.Hyperplanes{boundary(l)}.d;
    end
end

if (perform_face_partitioning==0)
    INV{1} = linearcon([],[],C,d);
else
    
    % >>>>>>>>>>>> Patitioning Cell -- DJ -- 06/30/03 <<<<<<<<<<<<
    % Instead creating a state for a cell, currently we create a state for the
    % interior region of the cell and several boundary states.
    % Changed by Dong Jia from
    % INV = linearcon([],[],C,d);
    % to the following codes
    % First, we create a state for the interior region
    INV{1} = linearcon([],[],C,d-GLOBAL_APPROX_PARAM.poly_bloat_tol);
    % Secondly, we create states along each face.
    for i=1:length(d)
        INV{i+1} = clean_up(linearcon([],[],[C;-C(i,:)],[d;-d(i)+GLOBAL_APPROX_PARAM.poly_bloat_tol]));
    end
    % Thirdly, since the states along faces may intersect, we refine those
    % states.
    empty_sets=[];
    i=2;
    while i<length(INV)
        curr_num_inv=length(INV);
        for j=i+1:curr_num_inv
            inter = INV{i} & INV{j};
            if ~isempty(inter)
                if issubset(INV{i},INV{j})
                    INV{i}={};
                    break;
                    empty_sets = [empty_sets; i];
                end
                if issubset(INV{j},INV{i})
                    continue;
                end
                GA1 = INV{i} - inter;
                GA2 = INV{j} - inter;
                INV{i} = GA1{1};
                INV{j} = GA2{1};
                INV{length(INV)+1} = inter;
            end
        end
        i = i + 1;
    end
    
    tmp_INV = {};
    k=0;
    for i=1:length(INV)
        if length(find(empty_sets == i))==0
            k=k+1;
            tmp_INV{k} = INV{i};
        end
    end
    
    INV = tmp_INV;
    % >>>>>>>>>>>> -------------- end (Partitioning Cell) --------------- <<<<<<<<<<<<
end

return

%----------------------------------------------------------------------------

function INV = return_init_region(cell)

% Get the `invariant` for the given `location`.
%
% Syntax:
%   "INV = return_init_region(cell)"
%
% Description:
%   Return the "linearcon" object representing the `invariant` polytope for
%   the `location` specified by the "cell".
%
% See Also:
%   piha,linearcon

% This routine acts the same as the previous return_region routine.

global GLOBAL_PIHA GLOBAL_APPROX_PARAM

boundary = GLOBAL_PIHA.Cells{cell}.boundary;
hpflags = GLOBAL_PIHA.Cells{cell}.hpflags;

C = []; d = [];
for l = 1:length(boundary)
    if hpflags(l)
        C(l,:) = GLOBAL_PIHA.Hyperplanes{boundary(l)}.c;
        d(l,:) = GLOBAL_PIHA.Hyperplanes{boundary(l)}.d;
    else
        C(l,:) = -GLOBAL_PIHA.Hyperplanes{boundary(l)}.c;
        d(l,:) = -GLOBAL_PIHA.Hyperplanes{boundary(l)}.d;
    end
end
INV = linearcon([],[],C,d);

return

%--------------------------------------------------------------------------

function face=get_cell_face(cell,hyperplane)

global GLOBAL_PIHA

%This function takes a GLOBAL_PIHA cell and a hyperplane and returns the polytope that represents
%the face of the cell that is described by the hyperplane.

boundary = GLOBAL_PIHA.Cells{cell}.boundary;
hpflags = GLOBAL_PIHA.Cells{cell}.hpflags;

C = []; d = [];
for l = 1:length(boundary)
    if hpflags(l)
        C(l,:) = GLOBAL_PIHA.Hyperplanes{boundary(l)}.c;
        d(l,:) = GLOBAL_PIHA.Hyperplanes{boundary(l)}.d;
    else
        C(l,:) = -GLOBAL_PIHA.Hyperplanes{boundary(l)}.c;
        d(l,:) = -GLOBAL_PIHA.Hyperplanes{boundary(l)}.d;
    end
end

Ci=C;
Di=d;

ce=GLOBAL_PIHA.Hyperplanes{hyperplane}.c;
de=GLOBAL_PIHA.Hyperplanes{hyperplane}.d;
face=linearcon(ce,de,C,d);
face=clean_up(face);

return

%----------------------------------------------------------------------------

function cell=get_terminal_cell(current_location,transitions,face,face_element,hyp)

global GLOBAL_PIHA

%This function finds the cell that represents the terminal location in the 'face_element' of
%the 'transition' array 

cur_cell=GLOBAL_PIHA.Locations{current_location}.p;
neighbors=GLOBAL_PIHA.Cells{cur_cell}.neighbors;
boundary=GLOBAL_PIHA.Cells{cur_cell}.boundary;
hpflags=GLOBAL_PIHA.Cells{cur_cell}.hpflags;
[dum1,dum2,index]=intersect(hyp,boundary);
hpflag=hpflags(index);

%Create a list of regular destination cells to leave out of search for terminal cells.
%Also create index of terminal cells (number is a list of indices to terminal cells).
used=[];
number=[ ];
for j=1:length(transitions{face})
    if strcmp(transitions{face}(j).type,'regular')
        used=[used transitions{face}(j).destination];
    else
        number=[number j];   
    end
end


for k=1:length(used)
    used_cell(k)=GLOBAL_PIHA.Locations{used(k)}.p;
end
%'term_cells' will be a list of cells which are possible terminal cells on this face.
term_cells=setdiff(neighbors,used_cell);

%Compute ALL neighbors that are neighbors on 'this' hyperplane:
next_p=[];
for i=1:length(neighbors)
    neighbors_hp_index=[];
    for j=1:length(GLOBAL_PIHA.Cells{neighbors(i)}.boundary)
        %Flag the neighbors index of boundary hps if it is the same hp as is being tested
        %AND it is on the opposite side of the hp as the current cell
        if GLOBAL_PIHA.Cells{neighbors(i)}.boundary(j)==hyp&GLOBAL_PIHA.Cells{neighbors(i)}.hpflags(j)~=hpflag
            neighbors_hp_index=j;
        end
    end
    if ~isempty(neighbors_hp_index)
        next_p=[next_p neighbors(i)];
    end
end

term_cells_on_face=intersect(term_cells,next_p);


%'term_cells_on_face' will be the legnth of 'number'.  The index into 'number' that corresponds to 'face_element'
%is also the index into 'term_cell' that corresponds to the current terminal cell.
[dum1,dum2,index]=intersect(face_element,number);
cell=term_cells_on_face(index);

return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -