我正在尝试使用鸭嘴兽和 NSGA2 算法解决多目标优化问题。以下是实现的示例代码:
将 [-10,10] 中的 x 最小化 ( x^2 , (x-1)^2 )
from platypus import NSGAII, Problem, Real
def schaffer(x):
return [x[0]**2, (x[0]-2)**2]
problem = Problem(1, 2)
problem.types[:] = Real(-10, 10)
problem.function = schaffer
algorithm = NSGAII(problem)
algorithm.run(10000)
但我的问题是,如果我想最大化 x^2 并最小化 (x-1)^2,我应该如何定义问题以及正确的方法是什么。