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

部分代码
- from FunInfo import Get_Functions_details
- from GA import GA
- import matplotlib.pyplot as plt
- #主程序
- function_name =8 #测试函数1-23
- SearchAgents_no = 50#种群大小
- Max_iter = 100#迭代次数
- lb,ub,dim,fobj=Get_Functions_details(function_name)#获取问题信息
- BestX,BestF,curve = GA(SearchAgents_no, Max_iter,lb,ub,dim,fobj)#问题求解
-
-
- #画收敛曲线图
- if BestF>0:
- plt.semilogy(curve,color='r',linewidth=2,label='GA')
- else:
- plt.plot(curve,color='r',linewidth=2,label='GA')
- plt.xlabel("Iteration")
- plt.ylabel("Fitness")
- plt.xlim(0,Max_iter)
- plt.title("F"+str(function_name))
- plt.legend()
- plt.savefig(str(function_name)+'.png')
- plt.show()
- print('\nThe best solution is:\n'+str(BestX))
- print('\nThe best optimal value of the objective funciton is:\n'+str(BestF))
部分结果








