• 大小: 8KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-18
  • 语言: Matlab
  • 标签: 遗传算法  matlab  

资源简介

基于ATO的列车速度曲线优化,用matlab遗传算法实现。适合初学者。

资源截图

代码片段和文件信息

function [Saasample]=adjust(sampleavhvm)
%调整函数

[Saasample]=decode(sample);
[cr]=size(S);

index=find(aa(:1)<2|aa(:1)>5);  %初始档位不是加速档的索引修改为加速档
for i=1:length(index)
    ran=ceil(rand()*4);
    ran=dec2bin(ran3);
    sample(index(i)11)=logical(str2double(ran(1)));
    sample(index(i)12)=logical(str2double(ran(2)));
    sample(index(i)13)=logical(str2double(ran(3)));
end

%先计算各点v值
v=zeros(cr);
for i=2:r
    as=a(aa(:i-1));
    as=as‘;
    v(:i)=sqrt(2*as.*(S(:i)-S(:i-1))+v(:i-1).^2);
end
log=angle(v)~=0|v>vm;   %选出速度小于0或大于vm的节点
log(:end-1)=log(:end-1)|v(:end-1)>vh;
log(:end)=log(:end)*0;%忽略末段速度为0,转为修改节点值
logs=sum(sum(log));     %逻辑和

k=1;
while logs              %如果逻辑和不为0,则证明有速度小于0或大于vm
    index=find(log);    %异常速度的索引
    for i=1:length(index)
        [xy]=i2s([cr]index(i));      %异常速度的位置
        if y==r         %如果是结尾段速度小于0,就不改了
            break
        end
        if v(xy)>vm    %如果超速则降档
            ran=bin2dec(num2str(sample(xy*13-15:y*13-13)));
            if ran==0
                ran=8;
            end
                ran=ran-1;
            ran=dec2bin(ran3);
            sample(xy*13-15)=logical(str2double(ran(1)));
            sample(xy*13-14)=logical(str2double(ran(2)));
            sample(xy*13-13)=logical(str2double(ran(3)));
        elseif y>=9&&v(xy)>vh     %如果末段超速则修改上一个档位为减速档111 110 101
            if k>50         %如果实在无法减速,限定他全程惰性档(变相杀死)
%                 aa(x2:end)=0*aa(x2:end)+1;
%                 S(x2)=100;
%                 sample(x:)=d_decode(S(x:)aa(x:));
                sample(x:)=zeros(113*r‘single‘);
            end
            ran=ceil(rand()*3)+4;
            ran=dec2bin(ran3);
            sample(xy*13-15)=logical(str2double(ran(1)));
            sample(xy*13-14)=logical(str2double(ran(2)));
            sample(xy*13-13)=logical(str2double(ran(3)));
        else            %如果没超速,那么速度肯定为负值修改上一个档位为加速档或者惰性档
            ran=floor(rand()*5);
            ran=dec2bin(ran3);
            sample(xy*13-15)=logical(str2double(ran(1)));
            sample(xy*13-14)=logical(str2double(ran(2)));
            sample(xy*13-13)=logical(str2double(ran(3)));
        end
    end
    
    [Saasample]=decode(sample);
    v=zeros(cr);
    for i=2:r
        as=a(aa(:i-1));
        as=as‘;
        v(:i)=sqrt(2*as.*(S(:i)-S(:i-1))+v(:i-1).^2);
    end
    log=angle(v)~=0|v>vm;   %选出速度小于0或大于vm的节点
    log(:end-1)=log(:end-1)|v(:end-1)>vh;
    log(:end)=log(:end)*0;%忽略末段速度为0,转为修改节点值
    logs=sum(sum(log));     %逻辑和
    
    k=k+1;
    if k>60
        disp(‘Error‘)
        pause
    end
end

log=angle(v(:end))~=0;
index=find(log(:end));     %找见所有末段速度小于0的点,修改他们的节点值
for i=1:length(index)
    as=a(aa(index(i)end-1));
    aim=floor(S(index(i)end-1)-v(index(i)end-1)^2/2/as);
    ran=dec2bin(aim10);
    sample(index(i)end-12)=logical(str2double(ran(1)));
    sample(index(i)end-11)=logical(str

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-30 11:02  GA\
     文件        3872  2018-05-18 11:27  GA\GA.m
     文件         807  2018-05-18 11:20  GA\Untitled.m
     文件         348  2018-05-11 10:35  GA\a.mat
     文件        4291  2018-05-18 10:55  GA\adjust.m
     文件         815  2018-05-11 10:26  GA\d_decode.m
     文件         871  2018-05-15 11:35  GA\decode.m
     文件         985  2018-05-11 09:53  GA\fitness.m
     文件        1300  2018-05-11 10:33  GA\fitness_s.m
     文件          83  2018-05-08 14:41  GA\i2s.m
     文件         680  2018-05-15 12:43  GA\myfun.m
     文件         339  2018-05-11 10:32  GA\old.mat
     文件         965  2018-05-10 14:56  GA\picture.m

评论

共有 条评论