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

📄 ga_ex24a.m

📁 其中提到遺傳學的程式碼與應用提供給次淚相向的研究者參考下載
💻 M
字号:
% GA_ex24A.m file
% Fin min(MIN_offset<>0) or
%     max(MIN_offset=0) of a function of 2 varaibles

% PenChen Chou, 7-1-2001

%**********************************************************/
%       User can modify the following in blocks
%**********************************************************/
global MIN_offset MUL_factor LOCUS x_data y_data
MIN_offset=2; % For finding MIN value
MIN_offset=0; % For finding MAX value
if MIN_offset==0
    MUL_factor=100;
else    
    MUL_factor=100;
end;    
LOCUS=1; x_data=[]; y_data=[];
obj_fcn = 'GA_f24';	% Objective function
range = 1*[-2 -2
          2  2];	% Range of the input variables
IC=[]; elite=1; 
gen_no=500;
popuSize=70;
bit_n=40;
xover_rate=0.9;
mutate_rate=0.04;
x=-2:0.1:2; y=x; [x y]=meshgrid(x,y);
A1=(sin(sqrt(x^2+y^2)))^2-0.5;
A2=(1+0.001*(x^2+y^2))^2;
z=0.5-A1./A2;
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, ...
BEST_popu, 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',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 + -