我正在尝试使用多目标优化包 pymoo 在三个基准问题(DTLZ1 和 DTLZ7)上运行和比较三种算法(NSGAII、NSGAIII 和 MOEAD)。
至于性能指标,我使用的是执行时间(目前看来还可以)和代际距离。后者,无论精度和迭代次数如何,总是得到相同的值。由于三种算法都是进化的,这似乎不合理,因为每次迭代都有一个随机输入。
有机会知道什么是错的吗?
from pymoo.factory import get_problem, get_reference_directions
from pymoo.util.plotting import plot
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.algorithms.moo.nsga3 import NSGA3
from pymoo.algorithms.moo.moead import MOEAD
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter
from pymoo.factory import get_performance_indicator
import json
pop_size = 100
n_gen = 200
n_iter = 200
problem = get_problem("dtlz1") # 3 objs, 7 vars, easy pareto
ref_dirs = get_reference_directions("das-dennis", 3, n_partitions=12)
alg1 = NSGA2(pop_size=pop_size)
alg2 = NSGA3(pop_size=pop_size,
ref_dirs=ref_dirs)
alg3 = MOEAD(ref_dirs,
n_neighbors=15,
prob_neighbor_mating=0.7)
timing1 = []
timing2 = []
timing3 = []
gd1 = []
gd2 = []
gd3 = []
for i in range(n_iter):
sol1 = minimize(problem,
alg1,
('n_gen', n_gen),
seed=42,
verbose=False)
sol2 = minimize(problem,
alg2,
('n_gen', n_gen),
seed=42,
verbose=False)
sol3 = minimize(problem,
alg3,
('n_gen', n_gen),
seed=42,
verbose=False)
timing1.append(sol1.exec_time)
timing2.append(sol2.exec_time)
timing3.append(sol3.exec_time)
gd1_temp = get_performance_indicator("gd", problem.pareto_front())
gd1.append(gd1_temp.do(sol1.F))
gd2_temp = get_performance_indicator("gd", problem.pareto_front())
gd2.append(gd2_temp.do(sol2.F))
gd3_temp = get_performance_indicator("gd", problem.pareto_front())
gd3.append(gd3_temp.do(sol3.F))
print('Iteration ' + str(i) + ' executed.')
output = {'timings_nsga_ii': timing1,
'gd_nsga_ii': gd1,
'timings_nsga_iii': timing2,
'gd_nsga_iii': gd2,
'timings_moead': timing3,
'gd_moead': gd3}
json_string = json.dumps(output)
with open('output_dtlz1.json','w') as outfile:
outfile.write(json_string)
这是 outfile 的一个片段:
{"timings_nsga_ii": [2.1769814491271973, 2.161776065826416, 2.225513219833374], "gd_nsga_ii": [0.43135516556723147, 0.43135516556723147, 0.43135516556723147], "timings_nsga_iii": [2.324997663497925, 2.3156368732452393, 2.3685479164123535], "gd_nsga_iii": [0.021620591196013776, 0.021620591196013776, 0.021620591196013776], "timings_moead": [29.92823576927185, 23.453261375427246, 30.512006282806396], "gd_moead": [0.01792278080458056, 0.01792278080458056, 0.01792278080458056]}