📄 ga_ex20a.m
字号:
% GA_ex20.m file
% Fin max of x*x function from 0 to 4095 with a bit length of 12
% PenChen Chou, 3-10-2002
clear all
ans=1;
who
fprintf('>>>Start this program [GA_ex20a.m] to find MAX now. Please wait!\n');
pause(1)
% Define MUL_factor and MIN_offset for GA_plot.m and
% objective function use. If it is a maximum-finding
% problem, set MIN_offset=0; Conversely, set MIN_offset
% a big enough integer. We will use PI=Min_offset-fitness
% to change a max-finding to a min_finding problem in
% objective function file.
global MUL_factor MIN_offset
% FOR CLASSROOM DEMO USE, SEE ALSO GA_print.m at the very last.
%**************************************************************/
% User can modify the following in blocks
%**************************************************************/
MUL_factor=1; MIN_offset=0;
obj_fcn = 'GA_f20'; % Objective function
range = [0 %<== LOW bounds of parameters
4095]; %<== HIGH bounds of parameters
IC=[]; elite=1;
gen_no=200;
popuSize=50;
bit_n=30;
xover_rate=1;
mutate_rate=0.05;
% THE FOLLOWING IS NOT NECESSARY, YOU CAN SKIP IT.
x=0:1:4095;
y=x.^2;
figure(2);plot(x,y);grid;
%************************************************************
% call GA written by Chang
tic
% function
%[popu, popu_real, fcn_value, upper, average,...
% lower, BEST_popu, popuSize, gen_no, para, best_pi]=...
% GA_genetic(obj_fcn, range, IC, elite, gen_no, popuSize,...
% bit_n, xover_rate, mutate_rate);
[popu, popu_real, fcn_value, upper, average,...
lower, BEST_popu, popuSize, gen_no, para, best_pi]=...
GA_genetic(obj_fcn, range, IC, elite, gen_no, popuSize,...
bit_n, xover_rate, mutate_rate);
t=toc/60;
fprintf('==> Computation time is (%.2f) minutes.\n\n',t);
para
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -