?? ga_ex21.m
字號:
% GA_ex21.m file
% Fin min of a function of 2 varaibles
% PenChen Chou, 7-1-2001
global MIN_offset MUL_factor LOCUS x_data y_data
MIN_offset=250; LOCUS=1; x_data=[]; y_data=[];
MUL_factor=1;
%**********************************************************/
% User can modify the following in blocks
%**********************************************************/
obj_fcn = 'GA_f21'; % Objective function
range = [0 0
10 10]; % Range of the input variables
IC=[]; elite=1;
gen_no=500;
popuSize=60;
bit_n=40;
xover_rate=0.0;
mutate_rate=0.02;
x=0:0.1:10; y=x; [X,Y]=meshgrid(x,y);
Z=X.*sin(4*X)+1.1*Y.*sin(2*Y);
figure(2);contour(X,Y,Z)
%************************************************************
% call GA written by Chang
tic
%GA_genetic(obj_fcn, range, IC, elite,...
% gen_no, popuSize, bit_n, xover_rate, mutate_rate);
[popu, popu_real, fcn_value, upper, average, lower, ...
popuSize, gen_no] = 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);
% Plot locus of optimization process
LAST=length(x_data);
figure(2); hold on
plot(x_data(1),y_data(1),'x');
plot(x_data,y_data);
plot(x_data(LAST),y_data(LAST),'o');
%plot(0,0,'*'); % The best position
hold off
title('*=BEST, x=Starting point, o=Ending point')
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -