簡體   English   中英

使用 Platypus (Python) 進行整數、多目標優化

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

我正在探索用於 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 等......似乎正在運行。

有沒有人遇到過這樣的問題? 也許我以錯誤的方式指定了問題?

預先感謝您的任何建議。

安德烈亞。

嘗試改變你添加問題類型的方式

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

可以這樣工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM