⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nonunifmutation.m

📁 用matlab编写的实数编码遗传算法
💻 M
字号:
function [parent] = nonUnifMutate(parent,bounds,Ops)
% Non uniform mutation changes one of the parameters of the parent
% based on a non-uniform probability distribution.  This Gaussian
% distribution starts wide, and narrows to a point distribution as the
% current generation approaches the maximum generation.
%
% function [newSol] = nonUnifMutate(parent,bounds,Ops)
% parent  - the first parent ( [solution string function value] )
% bounds  - the bounds matrix for the solution space
% Ops     - Options for nonUnifMutate[gen #nonUnifMutations maxGen b]


cg=Ops(1); 			         	% Current Generation
mg=Ops(3);                    % Maximum Number of Generations
b=Ops(4);                     % Shape parameter
df = bounds(:,2) - bounds(:,1); 	% Range of the variables
numVar = size(parent,2)-1; 		% Get the number of variables
gama=rand*2-1;
%parent
% Pick a variable to mutate randomly from 1 to number of vars
mPoint = round(rand * (numVar-1)) + 1;
for i=1:numVar
   if i==mPoint
      newValue(i)=parent(i)+gama*0.1*df;
      
     % md = round(rand); 			% Choose a direction of mutation
     % if md 					% Mutate towards upper bound
     % newValue(i)=parent(mPoint)+delta(cg,mg,bounds(1,2)-parent(mPoint),b);
     % else 					% Mutate towards lower bound
     % newValue(i)=parent(mPoint)-delta(cg,mg,parent(mPoint)-bounds(1,1),b);
     % end
   
      if newValue(i)<bounds(:,1)
         newValue(i)=(newValue(i)+bounds(:,2))/2.0
      elseif newValue(i)>bounds(:,2)
         newValue(i)=(newValue(i)+bounds(:,1))/2.0
      else
         newValue(i)=newValue(i) 
      end
         

            
   else
      newValue(i)=parent(i);
   end
end

%md = round(rand); 			% Choose a direction of mutation
%if md 					% Mutate towards upper bound
 %% newValue=parent(mPoint)+delta(cg,mg,bounds(mPoint,2)-parent(mPoint),b);
  %newValue=parent(1:numVar)+delta(cg,mg,bounds(1,2)-parent(1:numVar),b);
  
%else 					% Mutate towards lower bound
 %% newValue=parent(mPoint)-delta(cg,mg,parent(mPoint)-bounds(mPoint,1),b);
 %newValue=parent(1:numVar)-delta(cg,mg,parent(1:numVar)-bounds(1,1),b);
%end
%%parent(mPoint) = newValue; 		% Make the child
parent(1:numVar) = newValue
%pause

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -