# 变量设置
ranges = np.array([[-5, -5], [5, 5]])  # 生成自变量的范围矩阵
borders = np.array([[1, 1], [1, 1]])  # 生成自变量的边界矩阵(1表示变量的区间是闭区间)
precisions = [1, 1
              ]  # 根据crtfld的函数特性,这里需要设置精度为任意正值,否则在生成区域描述器时会默认为整数编码,并对变量范围作出一定调整
FieldDR = ga.crtfld(ranges, borders, precisions)  # 生成区域描述器
# 调用编程模板
[ObjV, NDSet, NDSetObjV, times] = ga.moea_nsga2_templet(AIM_M,
                                                        'aimfuc',
                                                        None,
                                                        None,
                                                        FieldDR,
                                                        'R',
                                                        maxormin=1,
                                                        MAXGEN=500,
                                                        MAXSIZE=200,
                                                        NIND=25,
                                                        SUBPOP=1,
                                                        GGAP=1,
                                                        selectStyle='tour',
                                                        recombinStyle='xovdp',
                                                        recopt=0.9,
                                                        pm=0.6,
                                                        distribute=True,
                                                        drawing=1)

print('其中一个最优解是', ObjV[0])
# 用时:3.41090 秒
# 帕累托前沿点个数:200 个
# 单位时间找到帕累托前沿点个数:58 个
# 其中一个最优解是 [ 90.081716   132.51084595]
예제 #2
0
파일: main.py 프로젝트: zmskye/geatpy
AIM_F = 'DTLZ1'  # You can set DTL1,2,3 or 4
"""==================================variables setting================================"""
ranges = np.vstack([np.zeros((1, 7)), np.ones(
    (1, 7))])  # define the ranges of variables in DTLZ1
borders = np.vstack([np.ones((1, 7)), np.ones(
    (1, 7))])  # define the borders of variables in DTLZ1
precisions = [
    4
] * 7  # set any precision that is bigger than 0, or 'crtfld' would create a Field for integer-code.
FieldDR = ga.crtfld(ranges, borders, precisions)  # create the FieldDR
"""=======================use sga2_templet to find the Pareto front==================="""
[ObjV, NDSet, NDSetObjV,
 times] = ga.moea_nsga2_templet(AIM_M,
                                AIM_F,
                                None,
                                None,
                                FieldDR,
                                problem='R',
                                maxormin=1,
                                MAXGEN=500,
                                MAXSIZE=2000,
                                NIND=50,
                                SUBPOP=1,
                                GGAP=1,
                                selectStyle='tour',
                                recombinStyle='xovdprs',
                                recopt=0.9,
                                pm=None,
                                distribute=False,
                                drawing=1)