简体   繁体   English

使用整数进行鸭嘴兽优化

[英]Platypus optimization using integers

I want to perform multiobjective optimization with Platypus using just integers (not floats) with 2 objectives, 3 variables and no constraints, and I need to maximize the objectives values. 我想用Platypus进行多目标优化,只使用2个目标,3个变量和没有约束的整数(不是浮点数),我需要最大化目标值。 I defined it like this: 我这样定义:

problem = Problem(3, 2)
problem.directions[:] = Problem.MAXIMIZE
problem.types[:] = [Integer(-50, 50), Integer(-50, 50), Integer(-50, 50)]

algorithm = NSGAII(problem)
algorithm.run(10000)

for solution in algorithm.result:
    print solution

But I keep getting results like this: 但我一直得到这样的结果:

Solution[[False, True, False, True, False, True, True],[False, True, False, True, False, True, False],[True, True, True, False, True, False, True]|-12.2,629.8|0]
Solution[[False, True, False, True, False, True, True],[True, True, False, True, False, True, False],[True, False, True, False, True, True, False]|-28.0,1240.0|0]

Could you please help me? 请你帮助我好吗?

Thanks in advance. 提前致谢。

Try this: 试试这个:

from platypus import Problem, Integer, NSGAII

def my_function(x):
    """ Some objective function"""
    return -x[0] ** 2 - x[2] ** 2  # we expect the result x[0] = 0, x[1] = whatever, and x[2] = 0

problem = Problem(3, 1)  # define 3 inputs and 1 objective (and no constraints)
problem.directions[:] = Problem.MAXIMIZE
int1 = Integer(-50, 50)
int2 = Integer(-50, 50)
int3 = Integer(-50, 50)
problem.types[:] = [int1, int2, int3]
problem.function = my_function
algorithm = NSGAII(problem)
algorithm.run(10000)

# grab the variables (note: we are just taking the ones in the location result[0])
first_variable = algorithm.result[0].variables[0]
second_variable = algorithm.result[0].variables[1]
third_variable = algorithm.result[0].variables[2]

print(int1.decode(first_variable))
print(int2.decode(second_variable))
print(int3.decode(third_variable))

Basically, in this case since the ranges are the same for all the inputs (int1, int2, and int3 have same ranges) we could have also done "int1.decode(second_variable)" etc., but I left it general here in case you want to change the range of each integer to something different. 基本上,在这种情况下,由于所有输入的范围都是相同的(int1,int2和int3具有相同的范围),我们也可以完成“int1.decode(second_variable)”等,但我在这里保留了它的一般情况您想要将每个整数的范围更改为不同的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM