mutate.m

来自「这个程序是用遗传算法解决车辆路径问题的.程序完整」· M 代码 · 共 27 行

M
27
字号
function [new,nmut] = mutate(pop,pm)
% MUTATE perform mutation on population of chromsomes
% new = mutate(pop,pm)
% 
% set constants
%
[popsize,ndim] = size(pop);
nmut = 0;
%
% loop through population testing whether to mutate
%
for i = 1:popsize
	for j = 1:ndim
		test = rand;
		if test < pm
			pop(i,j) = abs(pop(i,j)-1);
			nmut = nmut + 1;
		end
	end
end
%
% return new population
%
new = pop;

		

⌨️ 快捷键说明

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