• 大小: 25KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: Matlab
  • 标签: 进化策略  MATLAB  

资源简介

进化策略算法实现公交车调度,人工智能课程设计,自己原创,在MATLAB上调试通过

资源截图

代码片段和文件信息

%进化策略算法 (μλ)-ES
%μ个父代进化产生λ个子代,新产生的λ个新个体中择优选择μ个个体作为下一代群体
%f(x)=x1+x2+x3+x4+x5+x6
clear all;
close all;
clc
%变量初始化
populationSize = 15;       %种群大小及子代个数 比例1/7
childrenSize = 100;
best=0;                    %存放父代最优值及所在列
bestIndex=1;
fitness = zeros( childrenSize 13);    %存放子代 其中(1:6)存放子代个体6个分量,(7:12)存放子代个体6个方差,(113)存放子代的适应度函数
population=zeros(populationSize 13);  %存放父代
% 初始化父代
for i = 1 : populationSize
    population(i 1) = round(rand * 60);
    population(i 2) = round(rand * 70);
    population(i 3) = round(rand * 60);
    population(i 4) = round(rand * 50);
    population(i 5) = round(rand * 20);
    population(i 6) = round(rand * 30);
    
    while (population(i 1)+population(i 6))<60||(population(i 1)+population(i 2))<70||...
          (population(i 3)+population(i 2))<60||(population(i 4)+population(i 3))<50||...
       (population(i 5)+population(i 4))<20 || (population(i 6)+population(i 5))<30
        population(i 1) = round(rand * 60);
        population(i 2) = round(rand * 70);
        population(i 3) = round(rand * 60);
        population(i 4) = round(rand * 50);
        population(i 5) = round(rand * 20);
        population(i 6) = round(rand * 30);
    end
    for j=7:13
        population(ij)=3.0;%sigma初始化
        if j==13
            population(i 13) = population(i 1)+population(i 2)+population(i 3)+population(i 4)+population(i 5)+ population(i 6);
        end
    end
    if best>population(i 13)
       best=population(i13);
       bestIndex=i;
    end
end
bestFitness=population(bestIndex:);%精英保留
% 进行100次迭代
for t = 1 : 100
    % 产生childrenSize个子代,并计算其方差、适应度保存到fitness数组中
    for i=1:childrenSize
        populationIndex = round(rand * (populationSize-1))+1;% 从父代中随机挑选一个用于产生子代 
        
        for j=1:6
            fitness(i6+j)=population(populationIndex6+j) * exp(1 * normrnd(0 1) + 1 * normrnd(0 1)); % 调整sigma参数
            fitness(ij)=round(population(populationIndex j) + fitness(i6+j) *normrnd(0 1));
        end
        fitness(i13)=fitness(i1)+fitness(i2)+fitness(i3)+fitness(i4)+fitness(i5)+fitness(i6);
        %根据条件产生符合条件的子代
        while fitness(i1) < 0 || fitness(i1) > 60 || fitness(i6) < 0 || fitness(i6) > 60 || (fitness(i1)+fitness(i6))<60 ||...
            (fitness(i1)+fitness(i2))<70 || fitness(i2)<0 || fitness(i2)>70 || (fitness(i3)+fitness(i2))<60 || fitness(i3)<0 || fitness(i3)>60||...
            (fitness(i3)+fitness(i4))<50 || fitness(i4)<0 || fitness(i4)>50 || (fitness(i5)+fitness(i4))<20 ||... 
            (fitness(i6)+fitness(i5))<30 || fitness(i5)<0 || fitness(i5)>30
            for j=1:6
            fitness(i6+j)=population(populationIndex6+j) * exp(1 * normrnd(0 1) + 1 * normrnd(0 1)); % 调整sigma参数
            fitness(ij)=round(population(populationIndex j) + fitness(i6+j) *normrnd(0 1));
            end  
            fitness(i13)=fitness(i1)+fitness(i2)+fitness(i3

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      91648  2014-03-21 19:37  EvolutionStrategy\BusDispatch.doc

     文件       3624  2013-06-19 21:54  EvolutionStrategy\EvolutionStrategy.m

     目录          0  2014-03-21 19:51  EvolutionStrategy

----------- ---------  ---------- -----  ----

                95272                    3


评论

共有 条评论