Example #1
0
MAXGEN = 1000  # 最大遗传代数
GGAP = 1  # 代沟:子代与父代的重复率为(1-GGAP),由于后面使用NSGA2算法,因此该参数无用
selectStyle = 'tour'  # 遗传算法的选择方式
recombinStyle = 'xovdprs'  # 遗传算法的重组方式,设为使用代理的两点交叉
recopt = 0.9  # 交叉概率
pm = 0.1  # 变异概率
SUBPOP = 1  # 设置种群数为1
maxormin = 1  # 设置标记表明这是最小化目标
MAXSIZE = 1000  # 帕累托最优集最大个数
FieldDR = ga.crtfld(ranges, borders, precisions)  # 生成区域描述器
"""=======================调用编程模板进行种群进化==================="""
# 得到帕累托最优解集NDSet以及解集对应的目标函数值NDSetObjV
[ObjV, NDSet, NDSetObjV, times] = ga.q_sorted_templet(AIM_M,
                                                      AIM_F,
                                                      None,
                                                      None,
                                                      FieldDR,
                                                      'R',
                                                      maxormin,
                                                      MAXGEN,
                                                      MAXSIZE,
                                                      NIND,
                                                      SUBPOP,
                                                      GGAP,
                                                      selectStyle,
                                                      recombinStyle,
                                                      recopt,
                                                      pm,
                                                      distribute=False,
                                                      drawing=1)
Example #2
0
MAXGEN = 500  # 最大遗传代数
GGAP = 1
# 代沟:子代与父代的重复率为(1-GGAP)
selectStyle = 'tour'  # 遗传算法的选择方式
recombinStyle = 'xovdprs'  # 遗传算法的重组方式,设为两点交叉
recopt = 0.9  # 交叉概率
pm = None  # 变异概率
SUBPOP = 1  # 设置种群数为1f
maxormin = 1  # 设置标记表明这是最小化目标
MAXSIZE = 1000  # 帕累托最优集最大个数
"""=======================调用编程模板进行种群进化==================="""
# 调用编程模板进行种群进化,得到种群进化和变量的追踪器以及运行时间
[ObjV, NDSet, times] = ga.q_sorted_templet(AIM_M,
                                           AIM_F,
                                           None,
                                           None,
                                           ranges,
                                           borders,
                                           precisions,
                                           maxormin,
                                           MAXGEN,
                                           MAXSIZE,
                                           NIND,
                                           SUBPOP,
                                           GGAP,
                                           selectStyle,
                                           recombinStyle,
                                           recopt,
                                           pm,
                                           drawing=1)
"""sortedParetoGA_main.py"""
import numpy as np
import geatpy as ga  # 导入geatpy库

# 获取函数接口地址
AIM_M = __import__('aimfuc')
"""============================变量设置============================"""
ranges = np.vstack([np.zeros((1, 6)), np.ones((1, 6))])  # 生成自变量的范围矩阵
borders = np.vstack([np.ones((1, 6)), np.ones((1, 6))])  # 生成自变量的边界矩阵
precisions = [4] * 30  # 自变量的编码精度
"""=======================调用编程模板进行种群进化==================="""
[ObjV, NDSet, times] = ga.q_sorted_templet(AIM_M,
                                           'aimfuc',
                                           None,
                                           None,
                                           ranges,
                                           borders,
                                           precisions,
                                           maxormin=1,
                                           MAXGEN=1000,
                                           MAXSIZE=1000,
                                           NIND=50,
                                           SUBPOP=1,
                                           GGAP=1,
                                           selectStyle='tour',
                                           recombinStyle='xovdprs',
                                           recopt=0.9,
                                           pm=None,
                                           drawing=1)
Example #4
0
AIM_M = __import__('aimfuc')  # get the address of objective function
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  # define the precisions of variables, just set any values optionally that is bigger than 0 because variables are successive and we use real-code in the algorithm templet
FieldDR = ga.crtfld(ranges, borders)  # create the FieldDR
"""=======================use sga2_templet to find the Pareto front==================="""
[ObjV, NDSet, NDSetObjV, times] = ga.q_sorted_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)