xalt_edges.m

来自「matlab遗传算法工具箱」· M 代码 · 共 56 行

M
56
字号
% alternating edges crossover for TSP% as described in the book by Zbigniew Michalewicz on page 212% this crossover assumes that the ajacency representation is used to represent% TSP tours%% KULeuven, december 2002 % email: Tim.Volodine@cs.kuleuven.ac.be%%% Syntax:  NewChrom = xals_edges(OldChrom, XOVR)%% Input parameters:%    OldChrom  - Matrix containing the chromosomes of the old%                population. Each line corresponds to one individual%                (in any form, not necessarily real values).%    XOVR      - Probability of recombination occurring between pairs%                of individuals.%% Output parameter:%    NewChrom  - Matrix containing the chromosomes of the population%                after mating, ready to be mutated and/or evaluated,%                in the same format as OldChrom.%function NewChrom = xalt_edges(OldChrom, XOVR);if nargin < 2, XOVR = NaN; end   [rows,cols]=size(OldChrom);      maxrows=rows;   if rem(rows,2)~=0	   maxrows=maxrows-1;   end      for row=1:2:maxrows	     	% crossover of the two chromosomes   	% results in 2 offsprings	if rand<XOVR			% recombine with a given probability		NewChrom(row,:) =cross_alternate_edges([OldChrom(row,:);OldChrom(row+1,:)]);		NewChrom(row+1,:)=cross_alternate_edges([OldChrom(row+1,:);OldChrom(row,:)]); 	else		NewChrom(row,:)=OldChrom(row,:);		NewChrom(row+1,:)=OldChrom(row+1,:);	end   end   if rem(rows,2)~=0	   NewChrom(rows,:)=OldChrom(rows,:);   end   % End of function

⌨️ 快捷键说明

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