0

I've recently started to use pymoo for a university project to optimize production parameters. Before implementing the actual problem, I tried to realize a simple proof of concept using the NSGA-III with more or less random functions/constraints and a small number of variables. However, I keep bumping into the same error for quite a while now: "ValueError: Buffer dtype mismatch, expected 'double' but got 'long'".

The error message marks the last line in my code below:

from pymoo.algorithms.moo.nsga3 import NSGA3
from pymoo.core.problem import ElementwiseProblem
from pymoo.optimize import minimize
from pymoo.termination import get_termination
import pymoo.gradient.toolbox as anp





intercepts = [1, 4, 10]

class MyProblem(ElementwiseProblem):
    def __init__(self):
        super().__init__(n_var=3, n_obj=3, n_ieq_constr=6, vtype=float)
        #xl = np.array([0.5, 0.7, 0.4]), xu = np.array([10, 12]))
        self.xu= anp.array([10,12,25]) #input ('Maximum Value Perfomance Parameter:')
        self.xl= anp.array([0.5,0.7, 0.4]) #input ('Minimum Value Perfomance Parameter:')
    
        
    def _evaluate(self, x, out, *args, **kwargs):
        
        
        f1 = intercepts[0] + 0.5 * x[0] + 2 * x[1] + x[2] * 10
        f2 = intercepts[1] + 1.5 * x[0] + 2.5 * x[1] + x[2] * 8
        f3 = intercepts[2] + 2 * x[0] + 3 * x[1] + x[2] * 4
        out["F"] = np.column_stack([f1, f2, f3])
    
        g1 = 1 - (intercepts[0] + 0.5 * x[0] + 2 * x[1] + x[2] * 10)
        g2 = 2 - (intercepts[1] + 1.5 * x[0] + 2.5 * x[1])
        g3 = 3 - (intercepts[2] + 2 * x[0] + 3 * x[1])
        g4 = (intercepts[0] + 0.5 * x[0] + 2 * x[1]+ x[2] * 10) - 8
        g5 = (intercepts[1] + 1.5 * x[0] + 2.5 * x[1] + x[2] * 8) -16
        g6 = (intercepts[2] + 2 * x[0] + 3 * x[1] + x[2] * 4) -24
        out["G"] = np.column_stack([g1,g2,g3,g4,g5,g6])

# create the reference directions to be used for the optimization
ref_dirs = np.array([[10, 0, 0], [0, 10, 0], [0,0,10]])

problem = MyProblem()

# create the algorithm object
algorithm = NSGA3(pop_size=100, ref_dirs=ref_dirs)


termination=get_termination('n_gen', 300)

# execute the optimization
res = minimize(problem, algorithm, termination, verbose = False, seed=1)

Strangely it is possible to run the same code using NSGA-II, but as I am planning on optimizing 3 or more objectives on a later stage, NSGA-III would be more suitable.

Thanks in advance!

0 Answers0