`
reymont
  • 浏览: 530249 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Matlab遗传算法学习-recint.m

 
阅读更多

 

看书学习笔记

 

function NewChrom = recint(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);

%冒号运算符默认总是增序排列,
%冒号运算符可以指定增量步长值,(first:step:last),1:2:Nind-1将产生1,3,5等等
% Performs recombination
   odd = 1:2:Nind-1;
   even= 2:2:Nind;

   % position of value of offspring compared to parents
   Alpha = -0.25 + 1.5 * rand(Xops,Nvar);

   %利用冒号本身可以引用矩阵某行或列的所有元素
   % 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,Nvar);
   NewChrom(even,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:));

% If the number of individuals is odd, the last individual cannot be mated
% but must be included in the new population
%最后一个奇数行不参与交配,直接加入到NewChrom的末尾
%余项函数,取余rem(10,3)=1
   if rem(Nind,2),  NewChrom(Nind,:)=OldChrom(Nind,:); end

% End of function
 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics