reciprocal_exchange.m
来自「matlab的遗传算法的一个工具箱」· M 代码 · 共 34 行
M
34 行
% low level function for TSP mutation% reciprocal exchange : two random cities in a tour are swapped% Representation is an integer specifying which encoding is used% 1 : adjacency representation% 2 : path representation%function NewChrom = reciprocal_exchange(OldChrom,Representation);NewChrom=OldChrom;if Representation==1 NewChrom=adj2path(NewChrom);end% swap two random cities in the tourrndi=zeros(1,2);while rndi(1)==rndi(2) rndi=randint(1,2,[1 size(NewChrom,2)]);endbuffer=NewChrom(rndi(1));NewChrom(rndi(1))=NewChrom(rndi(2));NewChrom(rndi(2))=buffer;if Representation==1 NewChrom=path2adj(NewChrom);end% End of function
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?