【问题标题】:Integer, multi-objective optimization with Platypus (Python)使用鸭嘴兽 (Python) 进行整数、多目标优化
【发布时间】:2019-02-04 10:55:08
【问题描述】:

我正在探索Platypus 库以在 Python 中进行多目标优化。在我看来,Platypus 应该支持开箱即用的整数变量(优化参数),但是这个简单的问题(两个目标,三个变量,无约束和 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)

结果成:

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):

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 等算法似乎正在运行。

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

提前感谢您的任何建议。

安德烈亚。

【问题讨论】:

    标签: python evolutionary-algorithm particle-swarm platypus-optimizer


    【解决方案1】:

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

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

    可以这样工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-12
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 2018-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多