注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Mister.Hu(巷里人家)

Go abroad!

 
 
 

日志

 
 
关于我

A campus photograph palyer,an enthusiastic reader,a solitary writer,a future traffic engineer.

网易考拉推荐

Simulation in escalator[Part 1]  

2016-03-05 16:04:55|  分类: Senior |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
function [SAEXIT,SAEXIT1,SAEXIT2,SAEXIT3,SAEXIT4,SAEXIT5,SLSM,FPM0,SASM,SFI,STPP,STSM,TNUM,PM0,STPM,STFRM]=Main_Inlay
tic;
clear;clc;
global TWid;TWid=36;
global Wid;Wid=182;
global Time;Time=100;
global Pedenum;Pedenum=10;
PM=[];SVM=[];SDM=[];PP=[];PM0=[];FSVM=[];%the initialization of other [] matrix.
SM=Build_SM;
%To determine the pedestrains'places which are achievable.
AchiID=SM;
AchiID(2:178,5:19)=1;
AchiID(92:178,20:34)=1;
AchiID(2:178,35:29+TWid)=1;
AchiID(88:91,22:29)=1;
AchiID=find(AchiID==1);
SFI=Static_field_density;%call the function Static_field_density.m to get the Static field density(SFI)
[SPN1,SPN2,SPN3,SPN4,SPN5,SPN6]=Pedes_Create;%call this function to create the pedes in exponential distribution
TNUM1=sum(sum(SPN1));TNUM2=sum(sum(SPN5));TNUM=4*TNUM1+2*TNUM2;
STFRM=cell(TNUM,Time);% the initialization of {} matrix.
%STTRP=cell(TNUM,Time);% the initialization of {} matrix.
KC=zeros(TNUM,1);STPM=zeros(TNUM,Time);STPP=zeros(TNUM,Time);STSM=zeros(182,30+TWid,Time);
%STRM=cell(TNUM,9,Time);STPARM=cell(TNUM,9,Time);
%STSVM=zeros(TNUM,Time);STFSVM=zeros(TNUM,Time);STSDM=zeros(TNUM,Time);
for r=1:Time
    if r<68
        [PM,SM,PP,SVM,SDM,PM0,FSVM]=Comfirm_Initial_Pedes(SM,r,PM,SVM,SDM,PM0,FSVM,SPN1,SPN2,SPN3,SPN4,SPN5,SPN6);
    end
    %the STSM is used to storing the SM at the end of each second.
    STSM(:,:,r)=SM;
    %to store the PM
    ISTPM=zeros(TNUM,1);ISTPM(1:length(PM),1)=PM;STPM(:,r)=ISTPM;
    ISTPP=zeros(TNUM,1);ISTPP(1:length(PP),1)=PP;STPP(:,r)=ISTPP;
    %ISTSVM=zeros(TNUM,1);ISTSVM(1:length(SVM),1)=SVM;STSVM(:,r)=ISTSVM;
    %ISTFSVM=zeros(TNUM,1);ISTFSVM(1:length(FSVM),1)=FSVM;STFSVM(:,r)=ISTFSVM;
    %ISTSDM=zeros(TNUM,1);ISTSDM(1:length(SDM),1)=SDM;STSDM(:,r)=ISTSDM;
    %Each existing peds would get a row in TRP. TRP means the total route matrix.
    TRP=Get_TRP(AchiID,PP,PM,SVM,SDM);
    %sort the TRP by the valuation of The Comprehensive Field Intensity(CFI)
    TRP=Sort_TRP(PM,TRP,SM,SFI,FSVM);
    %now we will define the RM for TRP
    PARM=Get_PARM(TRP,PM,SDM);
    [RM]=Get_RM(TRP,PM,SDM);
    %find the first man in RM.
    fsub= Get_fsub(RM);
    [RM] = RM_Refine(fsub,RM,SM,PM);
    %now we should resolve the conflict.
    [FRM]=Solve(PP,fsub,RM,PARM);
    %store the FRM into STFRM,the FRP into STFRP,and so on.
    ISTFRM=cell(TNUM,1);ISTFRM(1:length(FRM),1)=FRM;STFRM(:,r)=ISTFRM;
    %ISTTRP=cell(TNUM,1);ISTTRP(1:length(TRP),1)=TRP;STTRP(:,r)=ISTTRP;
    % STRM(:,:,r)=RM;STPARM(:,:,r)=PARM;
    %update the direction of pedes.
    [FSVM,SDM]=Update_Direction(PP,FRM,PM,SDM);
    %now we can update the existing pedestrians'status.
    [KC,PM,PM0,SVM,SDM] =Update_Status(PP,FRM,KC,PM,PM0,SVM,SDM);
    SM=Build_SM;
    InPM=Get_InPM(PM);
    SM(InPM(InPM~=0))=1;%update the SM using InPM.
    %     b=r;
    %     b=num2str(b);
    %     A=strcat('result',b);
    %     save(A);
end
[SASM] =GET_SASM1(STSM);
[FPM0] =Get_PM0_Frequency(PM0);
[SLSM] =GET_SLSM(STSM);
[SAEXIT,SAEXIT1,SAEXIT2,SAEXIT3,SAEXIT4,SAEXIT5]=GET_SAEXIT(STPM,PM0,TNUM);
toc;
end

function SFI=Static_field_density
global TWid;
SFI=200*ones(182,30+TWid);%assign the initial value,(182,66)means a 180*64 matrix.
SFI(2:87,22:29)=0;%the escalator
SFI([1,182],:)=NaN;%the insulating layer
SFI(:,[1,30+TWid])=NaN;%the insulating layer
SFI(2:91,[20,21,30,31])=NaN;%the handrail
for j=22:29
    for i=87:181
        SFI=Assign(SFI,i,j);
    end
end
for j=30:29+TWid
    for i=92:181
        SFI=Assign(SFI,i,j);
    end
end
for j=21:-1:2
    for i=92:181
        SFI=Assign(SFI,i,j);
    end
end
for i=91:-1:2
    for j=19:-1:2
        SFI=Assign(SFI,i,j);
    end
end
for i=91:-1:2
    for j=32:29+TWid
        SFI=Assign(SFI,i,j);
    end
end
SFI(2:87,22:29)=NaN;
end

function SFI=Assign(SFI,s,k)
if SFI(s,k+1)>SFI(s,k)+1
    SFI(s,k+1)=SFI(s,k)+1;
end
if SFI(s,k-1)>SFI(s,k)+1
    SFI(s,k-1)=SFI(s,k)+1;
end
if SFI(s-1,k)>SFI(s,k)+1
    SFI(s-1,k)=SFI(s,k)+1;
end
if SFI(s+1,k)>SFI(s,k)+1
    SFI(s+1,k)=SFI(s,k)+1;
end
if SFI(s-1,k-1)>SFI(s,k)+1.5
    SFI(s-1,k-1)=SFI(s,k)+1.5;
end
if SFI(s-1,k+1)>SFI(s,k)+1.5
    SFI(s-1,k+1)=SFI(s,k)+1.5;
end
if SFI(s+1,k-1)>SFI(s,k)+1.5
    SFI(s+1,k-1)=SFI(s,k)+1.5;
end
if SFI(s+1,k+1)>SFI(s,k)+1.5
    SFI(s+1,k+1)=SFI(s,k)+1.5;
end
end

function fsub= Get_fsub(RM)
[fsub,~]=find(~cellfun(@isempty,RM, 'UniformOutput',true)==1);
if ~isempty(fsub)
    fsub=min(fsub);
else
    fsub=0;
end
end

function [DFI1]=Get_DFI1(PM,SM,R,C,FSVM)
%this function can calculate the CFI of each Pedes' Index
DFI1=0;
AIND=SM==1;
IND2=zeros(182,66);IND2(88:91,26:29)=1;IND2=AIND.*IND2;
IND2=find(IND2==1);
if R>=92&&C<=28
    SIZE=(R-88)*(33-C)+16;
    IND1=zeros(182,66);IND1(92:R+3,C-3:29)=1;IND1=AIND.*IND1;
    IND1=find(IND1==1);
    IND=[IND1;IND2];
    NUMC=numel(IND);
    [a,~,c]=intersect(IND,PM);
    NUMP=numel(a);
    SFSVM=sum(FSVM(c));
    DFI1=(NUMC*(log(max(abs(92-C),abs(29-R))))*NUMP)/(SIZE*SFSVM);
elseif R>=92&&C>=29
    SIZE=(R-88)*(C-25)+16;
    IND1=zeros(182,66);IND1(92:R+3,26:C)=1;IND1=AIND.*IND1;
    IND1=find(IND1==1);
    IND=[IND1;IND2];
    NUMC=numel(IND);
    [a,~,c]=intersect(IND,PM);
    NUMP=numel(a);
    SFSVM=sum(FSVM(c));
    DFI1=(NUMC*(log(max(abs(92-C),abs(29-R))))*NUMP)/(SIZE*SFSVM);
elseif R<=91&&C<=19
    SIZE=(92-R)*(23-C)+148-4*C;
    IND1=zeros(182,66);IND1(92:95,C-3:29)=1;IND1=AIND.*IND1;
    IND1=find(IND1==1);
    IND3=zeros(182,66);IND3(R:91,C-3:19)=1;IND3=AIND.*IND3;
    IND3=find(IND3==1);
    IND=[IND1;IND2;IND3];
    NUMC=numel(IND);
    [a,~,c]=intersect(IND,PM);
    NUMP=numel(a);
    SFSVM=sum(FSVM(c));
    DFI1=(NUMC*(log(max(abs(92-C),abs(29-R))))*NUMP)/(SIZE*SFSVM);
elseif R<=91&&C>=35
    SIZE=(92-R)*(C-31)+4*C-84;
    IND1=zeros(182,66);IND1(92:95,26:C)=1;IND1=AIND.*IND1;
    IND1=find(IND1==1);
    IND3=zeros(182,66);IND3(R:91,32:C)=1;IND3=AIND.*IND3;
    IND3=find(IND3==1);
    IND=[IND1;IND2;IND3];
    NUMC=numel(IND);
    [a,~,c]=intersect(IND,PM);
    NUMP=numel(a);
    SFSVM=sum(FSVM(c));
    DFI1=(NUMC*(log(max(abs(92-C),abs(29-R))))*NUMP)/(SIZE*SFSVM);
end
if isnan(DFI1)||isinf(DFI1)
    DFI1=0;
end
end

function [DFI2]=Get_DFI2(PM,SM,R,C,FSVM)
%this function can calculate the CFI of each Pedes' Index
DFI2=0;
AIND=SM==1;
IND2=zeros(182,66);IND2(88:91,22:25)=1;IND2=AIND.*IND2;
IND2=find(IND2==1);
if R>=92&&C<=24
    SIZE=(R-88)*(29-C)+16;
    IND1=zeros(182,66);IND1(92:R+3,C-3:25)=1;IND1=AIND.*IND1;
    IND1=find(IND1==1);
    IND=[IND1;IND2];
    NUMC=numel(IND);
    [a,~,c]=intersect(IND,PM);
    NUMP=numel(a);
    SFSVM=sum(FSVM(c));
    DFI2=(NUMC*(log(max(abs(92-C),abs(29-R))))*NUMP)/(SIZE*SFSVM);
elseif R>=92&&C>=25
    SIZE=(R-88)*(C-21)+16;
    IND1=zeros(182,66);IND1(92:R+3,22:C)=1;IND1=AIND.*IND1;
    IND1=find(IND1==1);
    IND=[IND1;IND2];
    NUMC=numel(IND);
    [a,~,c]=intersect(IND,PM);
    NUMP=numel(a);
    SFSVM=sum(FSVM(c));
    DFI2=(NUMC*(log(max(abs(92-C),abs(29-R))))*NUMP)/(SIZE*SFSVM);
elseif R<=91&&C<=19
    SIZE=(92-R)*(23-C)+132-4*C;
    IND1=zeros(182,66);IND1(92:95,C-3:25)=1;IND1=AIND.*IND1;
    IND1=find(IND1==1);
    IND3=zeros(182,66);IND3(R:91,C-3:19)=1;IND3=AIND.*IND3;
    IND3=find(IND3==1);
    IND=[IND1;IND2;IND3];
    NUMC=numel(IND);
    [a,~,c]=intersect(IND,PM);
    NUMP=numel(a);
    SFSVM=sum(FSVM(c));
    DFI2=(NUMC*(log(max(abs(92-C),abs(29-R))))*NUMP)/(SIZE*SFSVM);
elseif R<=91&&C>=35
    SIZE=(92-R)*(C-31)+4*C-68;
    IND1=zeros(182,66);IND1(92:95,22:C)=1;IND1=AIND.*IND1;
    IND1=find(IND1==1);
    IND3=zeros(182,66);IND3(R:91,32:C)=1;IND3=AIND.*IND3;
    IND3=find(IND3==1);
    IND=[IND1;IND2;IND3];
    NUMC=numel(IND);
    [a,~,c]=intersect(IND,PM);
    NUMP=numel(a);
    SFSVM=sum(FSVM(c));
    DFI2=(NUMC*(log(max(abs(92-C),abs(29-R))))*NUMP)/(SIZE*SFSVM);
end
if isnan(DFI2)||isinf(DFI2)
    DFI2=0;
end
end
  评论这张
 
阅读(12)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016