📄 compare.m
字号:
% Compare asexual reproduction and sexual reproduction
clear all
clc
BOAT_NUM = 100; % Number of individuals
ROWER = 100; % Precision of variables
Pc= 0.5; % the probability of crossover
Pm=0.01; % the probability of mutation
MAX_GEN=5000;
Run_Time=30;
sumFitnessAfter30(1,MAX_GEN) = 0;
averageFitnessAfter30(1,MAX_GEN) = 0;
% Sexual reproduction
%[SexBoat] = MainsexualProduction(boat, BOAT_NUM, ROWER, Pm, radius,MAX_GEN);
% Asexual reproduction
for i = 1:Run_Time
% Generate binary boat population: 0 for English and 1 for German
boat = round(rand(BOAT_NUM, ROWER));
[AsexBoat,sumFitnessEachGeneration] = MainAsexualProduction(boat, BOAT_NUM, ROWER, Pm,MAX_GEN);
for n = 1:MAX_GEN
sumFitnessAfter30(1,n) = sumFitnessEachGeneration(1,n) + sumFitnessAfter30(1,n);
end
end
for n = 1:MAX_GEN
averageFitnessAfter30(1,n) = sumFitnessAfter30(1,n) / (BOAT_NUM * Run_Time);
end
b = 1:MAX_GEN;
figure,plot(b,averageFitnessAfter30);
xlabel('generation');
ylabel('the average fitness');
% AsexGen
% SexGen
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -