遗传算法GA求解23个基准测试函数(MATLAB)

作品简介

一、遗传算法

遗传算法(Genetic Algorithm,GA)起源于对生物系统所进行的计算机模拟研究,是一种随机全局搜索优化方法,它模拟了自然选择和遗传中发生的复制、交叉(crossover)和变异(mutation)等现象,从任一初始种群(Population)出发,通过随机选择、交叉和变异操作,产生一群更适合环境的个体,使群体进化到搜索空间中越来越好的区域,这样一代一代不断繁衍进化,最后收敛到一群最适应环境的个体(Individual),从而求得问题的优质解。

二、GA求解23个测试函数

23个测试函数简介

测试集:23组基本测试函数简介及图像(提供python代码)_IT猿手的博客-CSDN博客

部分代码

close all
clc
SearchAgents_no=100; % Number of search agents


Function_name='F1';%F1-F23
   
Max_iteration=300; % Maximum number of iterations


[lb,ub,dim,fobj]=Get_Functions_details(Function_name);


[Best_score,Best_pos,Convergence_curve]=GA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);




figure('Position',[500 400 700 290])
subplot(1,2,1);
func_plot(Function_name);
title('Function Topology')
xlabel('x_1');
ylabel('x_2');
zlabel([Function_name,'( x_1 , x_2 )'])


% Convergence curve
subplot(1,2,2);
semilogy(Convergence_curve,'Color','r','linewidth',3)
title(Function_name)
xlabel('Iteration');
legend('GA')
ylabel('Best score obtained so far');




display(['The best solution obtained is : ', num2str(Best_pos,10)]);
display(['The best optimal value of the objective  is : ', num2str(Best_score,10)]);

部分结果

三、参考代码

文件夹内包含GA求解23个函数完整MATLAB代码,点击main.m即可运行。



创作时间: