geatpy模板sga_real_templet簡單應用
阿新 • • 發佈:2018-12-08
實值編碼[1]
實值編碼遺傳演算法(RCGA)的染色體空間和問題解空間是同一個空間,較好的解決了二進位制編碼遺傳演算法(BCGA)存在的求解精度和冗餘程式碼等問題。
程式碼(aimfuc)
import numpy as np
def aimfuc(Phen, LegV):
x = Phen[:, [0]]
f = x + 10 * np.sin(5 * x) + 7 * np.cos(4 * x)
return [f, LegV]
程式碼(main)
import numpy as np import geatpy as ga AIM_M = __import__('aimfuc') x = [0, 10] b = [1, 1] # codes = [1] precisions = [6] # scales = [0] ranges = np.vstack([x]).T borders = np.vstack([b]).T fieldd = ga.crtfld(ranges, borders, precisions) # , codes, scales) problem = 'R' maxormin = -1 MAXGEN = 100 NIND = 50 SUBPOP = 1 GGAP = 0.65 pm = 0.05 selectStyle = 'rws' recombinStyle = 'xovsp' drawing = 1 [pop_trace, var_trcae, times] = ga.sga_real_templet(AIM_M, AIM_F="aimfuc", PUN_M=None, PUN_F=None, FieldDR=fieldd, problem=problem, maxormin=-1, MAXGEN=MAXGEN, NIND=NIND, SUBPOP=SUBPOP, GGAP=GGAP, selectStyle=selectStyle, recombinStyle=recombinStyle, recopt=None, pm=pm, distribute=True, drawing=1)
結果
參考文獻
[1]GB/T 7714
張東民, 廖文和. 基於實值編碼遺傳演算法的起重機伸縮臂結構優化[J]. 南京航空航天大學學報, 2004, (2):185-189.