cec2013(python):粒子群优化算法PSO求解cec2013(提供python代码)

一、PSO求解cec2013

cec2013函数简介

CEC 2013 Special Session on Real-Parameter Optimization中共有28个测试函数维度可选择为10/30/50/100。

每个测试函数的详细信息如下表所示:

参考文献:1 Liang J J , Qu B Y , Suganthan P N , et al. Problem Definitions and Evaluation Criteria for the CEC 2013 Special Session on Real-Parameter Optimization. 2013.

部分代码

复制代码
from CEC2013.cec2013 import *
from PSO import PSO
import matplotlib.pyplot as plt
import numpy as np
#主程序
function_name =20 #测试函数1-28
SearchAgents_no = 50#种群大小
Max_iter = 100#迭代次数
dim=10#维度 10/30/50/100
lb=-100*np.ones(dim)#下限
ub=100*np.ones(dim)#上限
cec_functions = cec2013(dim,function_name)
fobj=cec_functions.func#目标函数
BestX,BestF,curve = PSO(SearchAgents_no, Max_iter,lb,ub,dim,fobj)#问题求解


#画收敛曲线图
if BestF>0:
    plt.semilogy(curve,color='r',linewidth=2,label='PSO')
else:
    plt.plot(curve,color='r',linewidth=2,label='PSO')
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))

部分结果

二、完整python代码

相关推荐
夏幻灵14 分钟前
每日一题:LeetCode 20:有效的括号——栈与哈希映射详解
算法·leetcode·哈希算法
神仙别闹20 分钟前
基于C语言开发的捕捉流星小游戏
c语言·开发语言
程序员Sunday32 分钟前
Promise.all、allSettled、race、any 怎么选,失败后其他请求会怎样
开发语言·前端·javascript
小静AI工程实验室1 小时前
Python 爬虫解析 JSON-LD:多块 script、@graph 与坏数据的 9 个边界
爬虫·python·json
hetao17338371 小时前
2026-10-07 hetao1733837 的刷题记录
c++·算法
daxiangxm1 小时前
GEO策略:让AI直接引用你的内容
开发语言·团队开发·运维开发·个人开发·数据库开发
jason.zeng@15022071 小时前
(八)现有架构上新增一个通用Excel导出工具
python·架构·langchain·excel·llama
袁袁袁袁满1 小时前
AI Agent 如何“看懂“互联网?
爬虫·python·自动化·爬虫实战·多线程爬虫
泡海椒1 小时前
JQuick-Excel 实战:用 VALIDATION 建立可维护的 Excel 导入校验
开发语言·python·excel
Nil2081 小时前
leetcode 279完全平方数
算法·leetcode·职场和发展