📄 ga_ex20_demo.m
字号:
% GA_ex20_demo.m file
% Fin max of a function of 1 varaible
% maximize f(x)=x*x,
% 0<=x<=10,
% PenChen Chou, 7-1-2001
% Revised, 7-1-2002
clear all
ans=1;
who
fprintf('>>>Start this program [GA_ex20_demo.m] now. Please wait!\n');
pause(1)
global MIN_offset MUL_factor LOCUS
MUL_factor=1; % Set it to 1 for the time being.
% MUL_factor must be a positive real number.
LOCUS=0; % Set LOCUS to 1 if the independent variables
% of the problem is 2 and you want to plot
% the 3-dim diagram, otherwise, set LOCUS=0;.
%**********************************************************/
% User can modify the following in blocks
%**********************************************************/
MIN_offset=0; % From the problem description above, max f(x,y)
% is 22, so we set a rather large number such
% as 25 to MIN_offset in this case.
% We will use PI=MIN_offset-PI; statement later
% to convert a MINIMIZATION problem to fit the
% property of GA to a MAXIMIZATION one.
%--------------------------------------------------------------
% IMPORTANT: If you handle a MAXIMIZATION problem, set
% MIN_offset=0;
%--------------------------------------------------------------
obj_fcn = 'GA_f20'; % Objective function
% Range of the input variables x and y
range = [0 % LOWER BOUNDS
10]; % UPPER BOUNDS
IC=[]; elite=1;
gen_no=20;
% If you want more information from GA result, use the following:
popuSize=8;bit_n=12;
xover_rate=0.8; mutate_rate=0.05;
%************************************************************
% call GA_genetic
tic
[popu, popu_real, fcn_value, upper, average,...
lower, BEST_popu, popuSize, gen_no, para, best_pi,...
bit_n, xover_rate, mutate_rate]=...
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);
% END OF THIS MAIN PROGRAM.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -