Python实现粒子群(PSO)带惩罚函数多目标优化

大佬们帮我看看,怎么结果都一样

import numpy as np#--------------------------initialization_input--------------------------
Q = 15
H = 20
#--------------------------coefficients of pso--------------------------
dim = 3
wmax = 0.9
wmin = 0.4
c1 = 1.3
c2 = 1.3
itermax = 200
numpop = 20
sigma1 = 100
sigma2 = 10
M = 2
echo = 'on'
lb = [1,0.5,Q/M]
ub = [2,1,Q]
lb_array = np.tile(lb, (numpop, 1))
ub_array = np.tile(ub, (numpop, 1))
r1 = np.random.random((numpop,dim))
r2 = np.random.random((numpop,dim))
# --------------------------initialization--------------------------
t_rand = np.random.random((numpop, dim))x = np.multiply(t_rand, (ub_array - lb_array)) + lb_array
v = np.zeros([numpop, dim], dtype=float)
vmax = 0.1 * (ub_array - lb_array)
row = np.where(x[...,0]<1.5)
x[row,0] = lb_array[row,0]
x[row,2] = Q
row = np.where(x[:,0]>=1.5)
x[row,0] = ub_array[row,0]
x[row,2] = Q/2
# --------------------------initialization calculation--------------------------
Hi = (-0.01712*x[:,2]**2 + 0.07864*x[:,2]*x[:,1] + 40.4421*x[:,1]**2).reshape(20,1)
print(Hi)
Pi = (-1.4286*0.0001*x[:,2]**3 + 0.00618*x[:,2]**2*x[:,1] + 0.04416*x[:,2]*x[:,1]**2 + 0.4402*x[:,1]**3).reshape(20,1)
# 罚函数定义
dita_max = 20
Qr_BEP = 30
Qk_BEP = (x[:,1]*Qr_BEP).reshape(20,1)
dita = (abs((x[:,2]-Qk_BEP)/Qk_BEP))
ditaH = (Hi-H).reshape(20,1)
# 扬程罚函数
[row, col] = np.where(ditaH>=0)
ditaH[row, col] = 0
[row, col] = np.where(ditaH<0)
ditaH[row, col] = ditaH[row, col]**2
# 可靠性罚函数
[row, col] = np.where(abs(dita) <= dita_max)
dita[row, col] = 0
[row, col] = np.where(abs(dita) > dita_max)
dita[row, col] = dita_max-dita[row, col]
# 目标函数求最小值
f_object1 = (-1.4286*0.0001*x[:,2].reshape(20,1)**3 +0.00618*x[:,2].reshape(20,1)**2*x[:,1].reshape(20,1) +0.04416*x[:,2].reshape(20,1)*x[:,1].reshape(20,1)**2 +0.4402*x[:,1].reshape(20,1)**3)*x[:,0].reshape(20,1)+\sigma1*ditaH + sigma2*dita
fbest = np.zeros([itermax,1],dtype=float)
xbest = np.zeros([itermax,3],dtype=float)
f = f_object1
fmin = np.min(f)
fmin_index = np.where(f == np.min(fmin))[0][0]
xgbest = np.multiply(np.ones([numpop, 1]), x[fmin_index, ...])
fgbest = np.multiply(np.ones([numpop, 1]), fmin)
fpbest = f
xpbest = x
j = 0
fbest[j] = fgbest[0]
xbest[j] = xgbest[0,:]while j < itermax - 1:j = j + 1# -------update coefficients, velocity and position of psow = wmax + (wmin - wmax) * j / itermaxv = w * v + c1 * np.multiply(np.random.random((numpop, dim)), (xpbest - x)) + \c2 * np.multiply(np.random.random((numpop, dim)), (xgbest - x))x = x + v# -------constrain the velocity and positionrow = np.where(x[:, 0] < 1.5)x[row, 0] = lb_array[row, 0]x[row, 2] = Qrow = np.where(x[:, 0] >= 1.5)x[row, 0] = ub_array[row, 0]x[row, 2] = Q / 2[row, col] = np.where(v > vmax)v[row, col] = vmax[row, col][row, col] = np.where(v < -vmax)v[row, col] = -vmax[row, col]# -------update the fpbest and fgbest of pso# 罚函数定义Qk_BEP = (x[:, 1] * Qr_BEP).reshape(20, 1)dita = (abs((x[:, 2] - Qk_BEP) / Qk_BEP))ditaH = (Hi - H)# 扬程罚函数[row, col] = np.where(ditaH >= 0)ditaH[row, col] = 0[row, col] = np.where(ditaH < 0)ditaH[row, col] = ditaH[row, col] ** 2# 可靠性罚函数[row, col] = np.where(abs(dita) <= dita_max)dita[row, col] = 0[row, col] = np.where(abs(dita) > dita_max)dita[row, col] = dita_max - dita[row, col]f = f_object1row_min = np.where(f < fpbest)xpbest[row_min,:] = x[row_min,:]fmin = np.min(f)fminindex = np.where(f == np.min(fmin))[0][0]if fmin < fgbest[0]:xgbest = np.multiply(np.ones([numpop, 1]), x[fminindex, ...])fgbest = np.multiply(np.ones([numpop, 1]), fmin)fbest[j] = fgbest[0]xbest[j] = xgbest[0, :]print(xbest)

结果
[[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]
[2. 0.74865334 7.5 ]

Python实现粒子群(PSO)带惩罚函数多目标优化相关推荐

  1. 【智能优化算法】基于粒子群结合NSGA2算法求解多目标优化问题附Matlab代码

    1 内容介绍 为解决高度复杂的热电联合经济排放调度问题,本研究提出了一种将非支配排序遗传算法II和多目标粒子群优化算法相结合的协同混合元启发式算法,以经济地运行电力系统并减少环境污染的影响. .在迭代 ...

  2. 【机器学习】基于粒子群算法的非线性函数寻优

    本微信图文介绍了基于粒子群算法的非线性函数寻优过程,并利用Matlab实现.

  3. matlab代码:基于粒子群算法的智能微电网经济运行优化 智能微电网PSO优化算法

    matlab代码:基于粒子群算法的智能微电网经济运行优化 智能微电网PSO优化算法 基于时段电价差异,制定合理的储能系统充放电运行方式,优化各时段微电网与主网之间的交换功率,从而使得风光储微网系统综合 ...

  4. 基于群智能算法的函数最值优化问题

    基于群智能算法的函数最值优化问题 摘要 针对求解函数的极值问题的群智能算法,大部分函数在定义域内都可以通过微分的方式求得极值点和找到最值.但是存在一些测试函数,他们的最值用求解的微分的方式只能使得计算 ...

  5. 《基于改进粒子群算法的混合储能系统容量优化》完全复现

    <基于改进粒子群算法的混合储能系统容量优化>完全复现 matlab. 以全生命周期费用最低为目标函数,负荷缺电率作为风光互补发电系统的运行指标,得到蓄电池储能和超级电容个数,缺电率和系统最 ...

  6. 基于多目标算法的冷热电联供型综合能源系统运行优化 综合能源 冷热电三联供 粒子群算法 多目标优化 多目标粒子群 冷热电联供 综合能源系统 运行优化

    多目标粒子群 冷热电联供 综合能源系统 运行优化 关键词:综合能源 冷热电三联供 粒子群算法 多目标优化 参考文档:<基于多目标算法的冷热电联供型综合能源系统运行优化> 仿真平台:MATL ...

  7. 参考文档:《基于多目标算法的冷热电联供型综合能源系统运行优化》 多目标粒子群 冷热电联供 综合能源系统 运行优化

    多目标粒子群 冷热电联供 综合能源系统 运行优化 关键词:综合能源 冷热电三联供 粒子群算法 多目标优化 参考文档:<基于多目标算法的冷热电联供型综合能源系统运行优化> 仿真平台:MATL ...

  8. 【微电网优化】基于粒子群算法求解混合储能系统容量优化问题含Matlab源码

    1 简介 为了提高供电的稳定性.可靠性,实现日夜发电,在太阳能.风能资源比较丰富的区域,建立风能.太阳能互补发电系统.但是由于系统投入成本过高,风.光又存在间歇性和不稳定性等问题,需要配置储能系统来平 ...

  9. Python自定义:粒子群优化算法

    Python中的粒子群算法 例子算法又被称作飞鸟觅食算法,是一种常见的现代启发式优化算法.在Python中,处于不同的情况考虑,我们都可能使用到该算法.在这里我给出三种情况下的解决方案或者替代方案. ...

  10. python基于粒子群优化的投资组合优化

    我今年的研究课题是使用粒子群优化(PSO)的货币进位交易组合优化.在本文中,我将介绍投资组合优化并解释其重要性.其次,我将演示粒子群优化如何应用于投资组合优化.第三,我将解释套利交易组合,然后总结我的 ...

最新文章

  1. linux查找特定类型的文件中是否包含特定字段
  2. java 中数组与list_Java中List与数组相互转换实例分析
  3. 代码,绘画,设计常用的颜色名称-16进制HEX编码-RGB编码 对照一览表
  4. linux 我的世界 跨平台联机,我的世界跨平台联机 PC、手机等平台数据互通
  5. prettyping.sh: ping 之美
  6. 速读原著-TCP/IP(端口映射器)
  7. artDialog | 经典的网页对话框组件
  8. wsimport生成Java客户端
  9. 根据拼音首字母进行过滤的combobox
  10. java批量添加注解到所有业务接口
  11. 杰理之汤姆猫录音变声功能参考【篇】
  12. java 位置定位_地图实时定位我的位置
  13. AWE2021:加速拥抱数字化 开启智慧生活新纪元
  14. List/Map 遍历
  15. 【C#:WinForm+ADO.NET+SQL Server实现验证码登录】
  16. 机房服务器安装操作系统
  17. 全国程序员高考卷,开始答题!
  18. 用photoshop制作logo
  19. Android修改user版本默认关闭开发者选项模式,eng版本默认打开开发者选项模式
  20. 牛客剑指offer:题解(51-60)

热门文章

  1. android教务系统框架,基于android的面向学生的移动教务管理系统设计与实现
  2. 深入解析CAS算法原理
  3. 在mac上开启httpServer服务
  4. mindoc源码编译和部署
  5. 使用torch.nn.BatchNorm1d出现Tensor for argument #2 ‘weight‘ is on CPU, but expected it to on GPU错误
  6. 初探PLC 的ST 语言转换成C++ 的方法
  7. 项目管理工具一:职责清晰的6W1H原则
  8. 惠普179fnw打印机使用说明_|惠普HP Color Laser MFP 179fnw一体机驱动下载v1.10官方版 - 欧普软件下载...
  9. Linux消息队列讲解
  10. HardDisk读取速度