资源简介
遗传算法实现公交车调度,人工智能课程设计,自己原创,在MATLAB上调试通过。

代码片段和文件信息
clear all;
close all;
clc;
%变量初始化
populationSize=80; %群体大小
generationSize=800; %进化代数
codeLength=35; %编码长度
children=zeros(populationSize7); %存储子代分量及适应度
pr=0.15; %复制概率
pm=0.1; %变异概率
pc=0.60; %交叉概率
E=round(rand(populationSizecodeLength)); %随机产生二进制串
%主函数
for k=1:1:generationSize
for s=1:1:populationSize
x=E(s:);
temp=zeros(17);%临时保存子代各分量的十进制值
%编码
for i=1:35
if i<=6
temp(1)=temp(1)+x(i)*2^(i-1);
elseif i>=7 && i<=13
temp(2)=temp(2)+x(i)*2^(i-6-1);
elseif i>=14 && i<=19
temp(3)=temp(3)+x(i)*2^(i-13-1);
elseif i>=20 && i<=25
temp(4)=temp(4)+x(i)*2^(i-19-1);
elseif i>=26 && i<=30
temp(5)=temp(5)+x(i)*2^(i-25-1);
elseif i>=31 && i<=35
temp(6)=temp(6)+x(i)*2^(i-30-1);
end
end
children(s1)=round(60*temp(1)/(2^6-1));
children(s2)=round(70*temp(2)/(2^7-1));
children(s3)=round(60*temp(3)/(2^6-1));
children(s4)=round(50*temp(4)/(2^6-1));
children(s5)=round(20*temp(5)/(2^5-1));
children(s6)=round(30*temp(6)/(2^5-1));
children(s7)=round(children(s1)+children(s2)+children(s3)+children(s4)+children(s5)+children(s6));
while children(s1)+children(s6)<60||children(s1)+children(s2)<70||children(s2)+children(s3)<60||...
children(s3)+children(s4)<50||children(s4)+children(s5)<20||children(s5)+children(s6)<30
E(s:)=round(rand(1codeLength));
x=E(s:);
temp=zeros(17);
for i=1:35
if i<=6
temp(1)=temp(1)+x(i)*2^(i-1);
elseif i>=7 && i<=13
temp(2)=temp(2)+x(i)*2^(i-6-1);
elseif i>=14 && i<=19
temp(3)=temp(3)+x(i)*2^(i-13-1);
elseif i>=20 && i<=25
temp(4)=temp(4)+x(i)*2^(i-19-1);
elseif i>=26 && i<=30
temp(5)=temp(5)+x(i)*2^(i-25-1);
elseif i>=31 && i<=35
temp(6)=temp(6)+x(i)*2^(i-30-1);
end
end
children(s1)=round(60*temp(1)/(2^6-1));
children(s2)=round(70*temp(2)/(2^7-1));
children(s3)=round(60*temp(3)/(2^6-1));
children(s4)=round(50*temp(4)/(2^6-1));
children(s5)=round(20*temp(5)/(2^5-1));
children(s6)=round(30*temp(6)/(2^5-1));
children(s7)=round(children(s1)+children(s2)+children(s3)+children(s4)+children(s5)+children(s6));
end
end
% Step 1 : 确定适应度函数
fitness=1./children(:7);
[orderFitnessindexFitness]=sort(fitness); %orderFitness按行从小到大排序的新矩阵indexFitness元素位置构成的新矩阵
bestFitness=orderFitness(populationSize); %bestFitness=max(fitness)
bestS=E(indexFitness(populationSize):); %bestS 精英保留
%Step 2 : 复制操作
sumFitness=sum(fitness);
fitnessSize=(orderFitness/sumFitness)*populationSize;
fitnessSelect=floor(fitnessSize); %朝负无穷大方向取整
kk=1;
for i=1:1:populationSize
for j=1:1:fitnessSelect(i) %Select and Reproduce
TempE(kk:)=E(indexFitness(i):);
kk=kk+1;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 91648 2014-03-21 19:37 GeneticAlgorithm\BusDispatch.doc
文件 3981 2013-06-20 22:23 GeneticAlgorithm\GeneticAlgorithm.m
目录 0 2014-03-21 19:50 GeneticAlgorithm
----------- --------- ---------- ----- ----
95629 3
- 上一篇:基于MATLAB的单纯形法PID寻优程序
- 下一篇:SFLA_Func01
相关资源
- 基于小波变换的数字水印算法115024
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
评论
共有 条评论