Matlab遗传算法学习-reclin

 

中间重组与线性重组相似,然而recint对没对值使用了一新的Alpha值一起重组,而reclin对每队双亲使用一Alpha因子。 

 

 

function NewChrom = reclin(OldChrom, XOVR);
 
% Identify the population size (Nind) and the number of variables (Nvar)
   [Nind,Nvar] = size(OldChrom);
 
% Identify the number of matings
   Xops = floor(Nind/2);% 向左取整
 
% Performs recombination
   odd = 1:2:Nind-1;% 冒号运算符可以指定增量步长值,(first:step:last),1:2:Nind-1将产生1,3,5等等
   even= 2:2:Nind;
 
   % position of value of offspring compared to parents
   Alpha = -0.25 + 1.5 * rand(Xops,1);%rand生成0~1之间均匀分布的随机数
   Alpha = Alpha(1:Xops,ones(Nvar,1));%ones创建m*n的全1矩阵,%每列的Alpha值相同相当于,复制Nvar个Alpha
 
%交配的对是有序的,奇数行与它下一个偶行配对。
   % recombination
   NewChrom(odd,:)  = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:));
 
   % the same ones more for second half of offspring
   Alpha = -0.25 + 1.5 * rand(Xops,1);
   Alpha = Alpha(1:Xops,ones(Nvar,1));
   NewChrom(even,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:));
 
%最后一个奇数行不参与交配,直接加入到NewChrom的末尾  
%余项函数,取余rem(10,3)=1  
% If the number of individuals is odd, the last individual cannot be mated
% but must be included in the new population
   if rem(Nind,2),  NewChrom(Nind,:)=OldChrom(Nind,:); end
 
 
% End of function

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值