morph.m

来自「多目标遗传算法/用法不用多说、要用的赶快下载吧」· M 代码 · 共 68 行

M
68
字号
function n = morph(chr1,chr2,pmut)% MORPH - Metamorphose transforms one design (chromosome) into another.  % %   c=morph(chromosome_1,chromosome_2,pmut) transforms%   chromosome_1 into type 2 keeping only the genes that are common%   between the chromosomes and adds or discards any extra. The%   argument pmut is the probability of mutation.%% See also MUTATE,PROBMUT,UI_MUTATE%----------Check the argumentsif and(~isa(chr1,'chrom'),~isa(chr2,'chrom'))  error('arguments need to be of valid type')end%----------no need for morphingif strcmp(get(chr1,'name'),get(chr2,'name'))  n=chr1;  return;endfor k=1:length(pmut)  if strcmp(pmut(k).name,get(chr1,'name'))    if isempty(pmut(k).trans)      pm_trans=[];    else      pm_trans=pmut(k).trans;    end    break  endendif rand<=pm_trans  %----------Extract data  c1_cdvs=get(chr1,'cdvs');  c1_ddvs=get(chr1,'ddvs');    c2_cdvs=get(chr2,'cdvs');  c2_ddvs=get(chr2,'ddvs');    %----------CDVS  for k=1:length(c2_cdvs)			% chr2 decides     k_ind=find(c1_cdvs,get(c2_cdvs(k),'name')); % common dna    if k_ind      c(k)=c1_cdvs(k_ind);		% yes keep it    else      c(k)=c2_cdvs(k);			% no keep chrom_2    end  end    %----------DDVS  for k=1:length(c2_ddvs)    k_ind=find(c1_ddvs,get(c2_ddvs(k),'name'));    if k_ind      d(k)=c1_ddvs(k_ind);    else      d(k)=c2_ddvs(k);    end  end    %----------Rebuild and return  n=chrom(get(chr2,'name'),c,d);else  n=chr1;end

⌨️ 快捷键说明

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