⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ga_gen_p7.asv

📁 其中提到遺傳學的程式碼與應用提供給次淚相向的研究者參考下載
💻 ASV
字号:
% GA_gen_p7.m file
% Fin max of a function of 2 varaibles
% See P.7 of Mistsuo Gen and Runwei Cheng, Genetic Algorithms &
% Engineering Design, Wiley Interscience, 1997.

% PenChen Chou, 3-10-2003

clear all
ans=1;
who
fprintf('>>>Start this program [GA_gen_p7.m] now. Please wait!\n');
pause(1)
global MIN_offset MUL_factor LOCUS x_data y_data
MIN_offset=0; LOCUS=1; x_data=[]; y_data=[];
MUL_factor=100;
%**********************************************************/
%       User can modify the following in blocks
%**********************************************************/
obj_fcn = 'GA_gen_fp7';	% Objective function
range = [-3 4.1
        12.1 5.8];	% Range of the input variables
IC=[]; elite=1; gen_no=1500;
popuSize=50; bit_n=50;
xover_rate=0.8; mutate_rate=0.07;
% Option
x=-3:0.1:12.1; y=4.1:0.02:5.8; [X,Y]=meshgrid(x,y);
Z=21.5+X.*sin(4*pi*X)+Y.*sin(20*pi*Y);
figure(2);contour(X,Y,Z)
figure(3);meshc(X,Y,Z)
%************************************************************
% 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);            
            
% 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')
axis([10 12 4.2 5.8])
% Show the final result
X=para(1); Y=para(2);
PI=21.5+X.*sin(4*pi*X)+Y.*sin(20*pi*Y);
fprintf('===>True final result is:\n');
fprintf('x=%.6f, y=%.6f, MIN PI=%.8f.\n',X,Y,PI);
%%==============================================================
%% The best solution is
%%[Generation #4000], ===>Best_FIT= 3942.27966909
%%    parameter( 1)=  11.62554500
%%    parameter( 2)=   5.72504400
%%The best generation occurred at generation #2911.
%%   x1 =  11.62554500
%%   x2 =   5.72504400
%%==>Best fitness for MAX. problem is (39.42279669)
%%==>  Computation time is (4.74) minutes.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -