简体   繁体   中英

Integer, multi-objective optimization with Platypus (Python)

I am exploring the Platypus library for multi-objective optimization in Python. 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):

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

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). While the algorithms NSGAIII, NSGAII, SPEA2, etc... appear to be working.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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