0

I have a problem of two objective functions, three variables, and zero constraints. I have also a search space for these variables read from CSV. Is it possible to use pymoo to use that search space of variables (instead of xl, and xu) to get the best combination of them that maximize the two functions.

class MyProblem (Problem):
  def __init__(self):
    super().__init__(n_var=3,
                     n_obj=2,
                     n_constr=0,
                     #I want to use the search space of the three variables (I already have)
                     xl=np.array([0.0,0.0,0.0]),
                     xu=np.array([1.0,1.0,1.0])
                     )
  def _evaluate(self,X,out,*args,**kwargs):
    #Maximizing the triangle area of the three variables
    f1=-1*(0.5*math.sin(120)*(X[:,0]*X[:,1] +X[:,2]*X[:,1]+X[:,0]*X[:,2]))

    #maximizing the sum of the variables
    f2 = -1*(X[:,0]+X[:,1]+X[:,2])

    out["F"] = np.column_stack([f1, f2])
    
problem = MyProblem()

When I use the xl and xu, it always gets the combination of ones [1.0,1.0,1.0], but I want to get the best combination out of my numpy multi-dimension array.


import csv
with open("sample_data/dimensions.csv", 'r') as f:
    dimensions = list(csv.reader(f, delimiter=","))

import numpy as np
dimensions = np.array(dimensions[1:])
dimensions=np.array(dimensions[:,1:], dtype=np.float)

dimensions

that looks like the following:

array([[0.27      , 0.45      , 0.23      ],
       [0.        , 0.23      , 0.09      ],
       [0.82      , 0.32      , 0.27      ],
       [0.64      , 0.55      , 0.32      ],
       [0.77      , 0.55      , 0.36      ],
       [0.25      , 0.86      , 0.18      ],
       [0.        , 0.68      , 0.09      ],...])

Thanks for your help!

1 Answers1

0

Have you tried sampling by numpy.array?

class pymoo.algorithms.nsga2.NSGA2(self, pop_size=100, sampling=numpy.array)

where (from pymoo API)

The sampling process defines the initial set of solutions which are the starting point of the optimization algorithm. Here, you have three different options by passing

(i) A Sampling implementation which is an implementation of a random sampling method.

(ii) A Population object containing the variables to be evaluated initially OR already evaluated solutions (F needs to be set in this case).

(iii) Pass a two dimensional numpy.array with (n_individuals, n_var) which contains the variable space values for each individual.

furious_bilbo
  • 176
  • 11
  • Thanks for your answer, actually when I used dimensions as sampling and removing the xl ad xu from the problem, it complains again asking for xl and xu I guess? algorithm = NSGA2(pop_size=100, sampling=my_dimensions) Do I still miss something? – Mohammed Ragab Jul 16 '21 at 12:48