首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Platypus (Python)进行整数、多目标优化

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

Stack Overflow用户
提问于 2019-02-04 18:55:08
回答 1查看 652关注 0票数 1

我正在探索Python语言中用于多目标优化的Platypus库。在我看来,Platypus应该支持开箱即用的整数形式的变量(优化参数),然而这个简单的问题(SMPSO的两个目标,三个变量,没有约束和整数变量):

代码语言:javascript
复制
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)

结果为:

代码语言:javascript
复制
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'

类似地,如果我尝试在Platypus中使用另一种优化技术(CMAES而不是SMPSO):

代码语言:javascript
复制
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'

我使用其他算法(OMOPSO,GDE3)获得其他类型的错误消息。而算法NSGAIII,NSGAII,SPEA2等...似乎起作用了。

有没有人遇到过这样的问题?也许我用错误的方式指定了问题?

提前感谢您的任何建议。

安德里亚。

EN

回答 1

Stack Overflow用户

发布于 2019-11-13 13:40:19

尝试更改添加问题类型的方式

代码语言:javascript
复制
problem.types[:] = [integer(-50,50),integer(-50,50),integer(-50,50)]

可以这样工作

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54514635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档