多目标启发式算法(NSGA2, MOEA, MOPSO)python实现
文章目錄
- 1. MODA-多目標(biāo)差分進(jìn)化算法
- 2. NSGA2-非支配排序遺傳算法
- 3. MOPSO-多目標(biāo)粒子群算法
- 4. 測試算例
- 4. 測試結(jié)果
- 4.1. 多目標(biāo)差分進(jìn)化算法求解結(jié)果
- 4.2. NSGA2算法求解結(jié)果
- 4.3 MOPSO算法求解結(jié)果
- 4.4 結(jié)果對比
- 5. 參考文獻(xiàn)
1. MODA-多目標(biāo)差分進(jìn)化算法
基于快速非支配排序算法和擁擠度。
算法主程序
def MODE(nIter, nChr, nPop, F, Cr, func, lb, rb):"""多目標(biāo)差分進(jìn)化算法主程序 Params:nIter: 迭代次數(shù)nPop: 種群規(guī)模 F: 縮放因子 Cr: 交叉概率 func:優(yōu)化函數(shù) lb: 自變量下界 rb:自變量上界 Return:paretoPops: 帕累托解集 paretoFits: 對應(yīng)的適應(yīng)度 """# 生成初始種群 parPops = initPop(nChr, nPop, lb, rb) parFits = fitness(parPops, func) # 開始迭代 iter = 1 while iter <= nIter:# 進(jìn)度條 print("【進(jìn)度】【{0:20s}】【正在進(jìn)行{1}代...】【共{2}代】".\format('▋'*int(iter/nIter*20), iter, nIter), end='\r')mutantPops = mutate(parPops, F, lb, rb) # 產(chǎn)生變異向量 trialPops = crossover(parPops, mutantPops, Cr) # 產(chǎn)生實(shí)驗向量 trialFits = fitness(trialPops, func) # 重新計算適應(yīng)度 pops = np.concatenate((parPops, trialPops), axis=0) # 合并成新的種群fits = np.concatenate((parFits, trialFits), axis=0) ranks = nonDominationSort(pops, fits) # 非支配排序 distances = crowdingDistanceSort(pops, fits, ranks) # 計算擁擠度 parPops, parFits = select1(nPop, pops, fits, ranks, distances) iter += 1 print("\n") # 獲取等級為0,即實(shí)際求解得到的帕累托前沿 paretoPops = pops[ranks==0] paretoFits = fits[ranks==0] return paretoPops, paretoFits由父代種群和經(jīng)過差分變異交叉后的實(shí)驗種群混合成一個新的種群,對新的種群進(jìn)行非支配排序,利用1對1錦標(biāo)賽選擇算子篩選出新的父代種群。
2. NSGA2-非支配排序遺傳算法
采用精英策略,在進(jìn)行交叉變異操作之后對新產(chǎn)生的種群與父代種群混合成新的種群,對新的種群進(jìn)行優(yōu)選。
算法主程序
3. MOPSO-多目標(biāo)粒子群算法
從archive集中更新gBest不僅采用支配解,還利用網(wǎng)格法,統(tǒng)計支配解的密度,選取網(wǎng)格中密度較低的解來更新gBest。
算法主程序
def MOPSO(nIter, nPop, nAr, nChr, func, c1, c2, lb, rb, Vmax, Vmin, M):"""多目標(biāo)粒子群算法Params:nIter: 迭代次數(shù) nPOp: 粒子群規(guī)模 nAr: archive集合的最大規(guī)模 nChr: 粒子大小 func: 優(yōu)化的函數(shù)c1、c2: 速度更新參數(shù) lb: 解下界rb:解上界 Vmax: 速度最大值 Vmin:速度最小值 M: 劃分的柵格的個數(shù)為M*M個Return:paretoPops: 帕累托解集paretoPops:對應(yīng)的適應(yīng)度 """# 種群初始化 pops, VPops = initPops(nPop, nChr, lb, rb, Vmax, Vmin) # 獲取個體極值和種群極值 fits = fitness(pops, func) pBest = pops pFits = fits gBest = pops# 初始化archive集, 選取pops的帕累托面即可archive, arFits = getNonDominationPops(pops, fits) wStart = 0.9 wEnd = 0.4 # 開始主循環(huán) iter = 1 while iter <= nIter:print("【進(jìn)度】【{0:20s}】【正在進(jìn)行{1}代...】【共{2}代】".\format('▋'*int(iter/nIter*20), iter, nIter), end='\r') # 速度更新 w = wStart - (wStart-wEnd) * (iter/nIter)**2 VPops = w*VPops + c1*np.random.rand()*(pBest-pops) + \c2*np.random.rand()*(gBest-pops) VPops[VPops>Vmax] = Vmax VPops[VPops<Vmin] = Vmin # 坐標(biāo)更新 pops += VPops pops[pops<lb] = lb pops[pops>rb] = rb # 防止過界 fits = fitness(pops, func) # 更新個體極值 pBest, pFits = updatePBest(pBest, pFits, pops, fits) # 更新archive集 archive, arFits = updateArchive(pops, fits, archive, arFits) # 檢查是否超出規(guī)模,如果是,那么剔除掉一些個體 archive, arFits = checkArchive(archive, arFits, nAr, M) # 重新獲取全局最優(yōu)解gBest = getGBest(pops, fits, archive, arFits, M) iter += 1 print('\n')paretoPops, paretoFits = getNonDominationPops(archive, arFits) return paretoPops, paretoFits4. 測試算例
FON標(biāo)準(zhǔn)問題:
f1(x1,x2,x3)=1?e?∑i=13(xi?13),f2(x1,x2,x3)=1?e?∑i=13(xi+13)f_1(x_1,x_2,x_3)=1-e^{-\sum_{i=1}^3(x_i-\frac{1}{\sqrt{3}})}, f_2(x_1,x_2,x_3)=1-e^{-\sum_{i=1}^{3}(x_i+\frac{1}{\sqrt{3}})}f1?(x1?,x2?,x3?)=1?e?∑i=13?(xi??3?1?),f2?(x1?,x2?,x3?)=1?e?∑i=13?(xi?+3?1?)
其中:xi∈[?2,2],i=1,2,3x_i\in[-2,2],i=1,2,3xi?∈[?2,2],i=1,2,3
該問題具有極為簡單易于表達(dá)的理論最優(yōu)解集
x1=x2=x3∈[?13,13]x_1=x_2=x_3\in[-\frac{1}{\sqrt3},\frac{1}{\sqrt3}]x1?=x2?=x3?∈[?3?1?,3?1?]
4. 測試結(jié)果
4.1. 多目標(biāo)差分進(jìn)化算法求解結(jié)果
(迭代次數(shù)100,種群規(guī)模50)
4.2. NSGA2算法求解結(jié)果
(迭代次數(shù)50,種群規(guī)模100)
4.3 MOPSO算法求解結(jié)果
(迭代次數(shù)100,種群規(guī)模100)
4.4 結(jié)果對比
- 求解速度:MOPSO > MODA > NSGA2
- 求解質(zhì)量:MOPSO > NSGA2 > MODA
5. 參考文獻(xiàn)
參考文獻(xiàn):多目標(biāo)差分進(jìn)化在熱連軋負(fù)荷分配中的應(yīng)用
參考博客:多目標(biāo)優(yōu)化算法(一)NSGA-Ⅱ(NSGA2)
參考文獻(xiàn):MOPSO算法及其在水庫優(yōu)化調(diào)度中的應(yīng)用
詳細(xì)代碼地址:部分多目標(biāo)啟發(fā)式算法python實(shí)現(xiàn)(github)
總結(jié)
以上是生活随笔為你收集整理的多目标启发式算法(NSGA2, MOEA, MOPSO)python实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 1200兆路由器网速_如何选购路由器才能
- 下一篇: python判断字符串长度_Python