| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
学习型 ASP/PHP/ASP.NET 主机 35元/年全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
赛孚耐:软件保护加密专家身份认证令牌USB KEY  
共有 397 人关注过本帖
标题:[求助]一些基于matlab的遗传算法程序,请大家赐教!!很多不懂!
收藏  订阅  推荐  打印 
zhixuli
Rank: 1
等级:新手上路
帖子:21
积分:320
注册:2006-5-27
[求助]一些基于matlab的遗传算法程序,请大家赐教!!很多不懂!

这里有几个基于matlab的遗传算法程序,很多地方看不明白,想请大家帮助!
%程序1
function xoverKids = crossoverpmx(parents,options,GenomeLength,FitnessFcn,unused,thisPopulation)
nKids = length(parents);
xoverKids = zeros(nKids,GenomeLength);
index = 1;
for i=1:fix(nKids/2)
parent1 = parents(index);
index = index + 1;
parent2 = parents(index);
index = index + 1;
sz = length(parent1) - 1;
xOverPoint1 = ceil(sz * rand);
xOverPoint2 = ceil(sz * rand);
while(xOverPoint2 == xOverPoint1)
xOverPoint2 = ceil(sz * rand);
end
if(xOverPoint1 < xOverPoint2)
left = xOverPoint1;
right = xOverPoint2;
else
left = xOverPoint2;
right = xOverPoint1;
end
for i=left:right
t=parent1;
parent1=parent2;
parent2=t;
end
for i=left:right
j=find(parent1==parent1(i));
if (size(j,2)==2)
parent1(j(find(j~=i)))=parent2(i);
end
end
for i=left:right
k=find(parent2==parent2(i))
if (size(k,2)==2)
parent2(k(find(k~=i)))=parent1(i);
end
end
xoverKids(i,:) = parent1;
xoverKids(nKids-i+1,:) = parent2;
end
请问,这个程序主要执行的是不是交叉操作,能否详细说明一下??不少地方看不大懂!谢谢

%程序2
function Population = myfun1(nvars, FitnessFcn, options)
totalpopulation = sum(options.PopulationSize);
for i=1:totalpopulation
Population(i,:)=randperm(40);
end
请问这个程序又主要在执行什么操作??谢谢了!

%程序3
function mutationChildren = myfun2(parents, options, nvars, FitnessFcn, state, thisScore, thisPopulation)
if(nargin < 8)
mutationRate = 0.01; % default mutation rate
end
mutationChildren = zeros(length(parents),nvars);
for i=1:length(parents)
child = thisPopulation(parents(i),:);
mutationPoint1=floor(rand*40+1);
mutationPoint2=floor(rand*40+1);
t=child(mutationPoint1);
child(mutationPoint1)=child(mutationPoint2);
child(mutationPoint2)=t;
mutationChildren(i,:) = child;
end
这个程序是不是在执行变异操作?怎么执行的?能否详细说说?谢谢了!

搜索更多相关主题的帖子: matlab  算法  遗传  
2007-5-25 09:39
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.068052 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved