?? 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 + -