简体   繁体   English

使用 Platypus (Python) 进行整数、多目标优化

[英]Integer, multi-objective optimization with Platypus (Python)

I am exploring the Platypus library for multi-objective optimization in Python.我正在探索用于 Python 多目标优化的Platypus库。 It appears to me that Platypus should support variables (optimization parameters) as integers out of the box, however this simple problem (two objectives, three variables, no constraints and Integer variables with SMPSO):在我看来,鸭嘴兽应该支持变量(优化参数)作为开箱即用的整数,但是这个简单的问题(两个目标,三个变量,没有约束和整数变量与 SMPSO):

from platypus import *

def my_function(x):
    """ Some objective function"""
    return [-x[0] ** 2 - x[2] ** 2, x[1] - x[0]]

def AsInteger():

    problem = Problem(3, 2)  # 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 = SMPSO(problem)
    algorithm.run(10000)

Results into:结果变成:

Traceback (most recent call last):
File "D:\MyProjects\Drilling\test_platypus.py", line 62, in 
AsInteger()
File "D:\MyProjects\Drilling\test_platypus.py", line 19, in AsInteger
algorithm.run(10000)
File "build\bdist.win-amd64\egg\platypus\core.py", line 405, in run
File "build\bdist.win-amd64\egg\platypus\algorithms.py", line 820, in step
File "build\bdist.win-amd64\egg\platypus\algorithms.py", line 838, in iterate
File "build\bdist.win-amd64\egg\platypus\algorithms.py", line 1008, in _update_velocities
TypeError: unsupported operand type(s) for -: 'list' and 'list'

Similarly, if I try to use another optimization technique in Platypus (CMAES instead of SMPSO):同样,如果我尝试在 Platypus 中使用另一种优化技术(CMAES 而不是 SMPSO):

Traceback (most recent call last):
File "D:\MyProjects\Drilling\test_platypus.py", line 62, in 
AsInteger()
File "D:\MyProjects\Drilling\test_platypus.py", line 19, in AsInteger
algorithm.run(10000)
File "build\bdist.win-amd64\egg\platypus\core.py", line 405, in run
File "build\bdist.win-amd64\egg\platypus\algorithms.py", line 1074, in step
File "build\bdist.win-amd64\egg\platypus\algorithms.py", line 1134, in initialize
File "build\bdist.win-amd64\egg\platypus\algorithms.py", line 1298, in iterate
File "build\bdist.win-amd64\egg\platypus\core.py", line 378, in evaluate_all
File "build\bdist.win-amd64\egg\platypus\evaluator.py", line 88, in evaluate_all
File "build\bdist.win-amd64\egg\platypus\evaluator.py", line 55, in run_job
File "build\bdist.win-amd64\egg\platypus\core.py", line 345, in run
File "build\bdist.win-amd64\egg\platypus\core.py", line 518, in evaluate
File "build\bdist.win-amd64\egg\platypus\core.py", line 160, in call
File "build\bdist.win-amd64\egg\platypus\types.py", line 147, in decode

File "build\bdist.win-amd64\egg\platypus\tools.py", line 521, in gray2bin
TypeError: 'float' object has no attribute 'getitem'

I get other types of error messages with other algorithms (OMOPSO, GDE3).我使用其他算法(OMOPSO、GDE3)收到其他类型的错误消息。 While the algorithms NSGAIII, NSGAII, SPEA2, etc... appear to be working.虽然算法 NSGAIII、NSGAII、SPEA2 等......似乎正在运行。

Has anyone ever encountered such issues?有没有人遇到过这样的问题? Maybe I am specifying the problem in te wrong way?也许我以错误的方式指定了问题?

Thank you in advance for any suggestion.预先感谢您的任何建议。

Andrea.安德烈亚。

try to change the way u add the problem type尝试改变你添加问题类型的方式

problem.types[:] = [integer(-50,50),integer(-50,50),integer(-50,50)]

could work this way可以这样工作

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

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