📄 ga_ex551.m
字号:
% GA_ex551.m file
% Fin min of a function of 2 varaibles
% PenChen Chou, 8-12-2001
clear all
ans=1;
who
fprintf('>>>Start this program [GA_ex551.m] now. Please wait!\n');
pause(1)
global MIN_offset MUL_factor LOCUS x_data y_data
%**********************************************************/
% User can modify the following in blocks
%**********************************************************/
LOCUS=1; x_data=[]; y_data=[];
MIN_offset=250; MUL_factor=1;
obj_fcn = 'GA_f551'; % Objective function
range = [-1 -1
1 1]; % Range of the input variables
IC=[]; elite=1;
gen_no=140;
popuSize=30;
bit_n=40;
xover_rate=0.77;
mutate_rate=0.01;
x=-1:0.01:1; y=x; [X,Y]=meshgrid(x,y);
Z=X.^2+Y.^2-0.3*cos(3*pi*X)-0.4*cos(4*pi*Y)+0.7;
figure(2);contour(X,Y,Z)
xlabel('x distribution')
ylabel('y distribution')
%************************************************************
% 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 + -