| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 835 人关注过本帖
标题:[求助]一些基于matlab的遗传算法程序,请大家赐教!!很多不懂!
只看楼主 加入收藏
zhixuli
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2006-5-27
收藏
 问题点数:0 回复次数:0 
[求助]一些基于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-05-25 09:39
快速回复:[求助]一些基于matlab的遗传算法程序,请大家赐教!!很多不懂!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014091 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved