jMetal / jMetalPy

A framework for single/multi-objective optimization with metaheuristics
https://jmetal.github.io/jMetalPy/index.html
MIT License
498 stars 150 forks source link

Problem with NSGA-2 #113

Closed Andreas-SM closed 5 months ago

Andreas-SM commented 2 years ago

Hey there! First of all, I would like to say that jMetalPy is an incredible project and it has been helping me for quite some time now. However, I have recently encountered a problem with the NSGA-2, which I am currently using to perform a constrained single-objective optimization. In my case, some instances of decision variables can sometimes raise an error within my cost function, which actually comes from a library I am using. This is why I had to make slight changes in my evaluation function:

` def evaluate(self, solution: FloatSolution) -> FloatSolution:

    try:
        result = self.func_exp(solution=solution)
    except:
        keys = []
        for i in range(0, self.number_of_constraints):
            keys.append(i)
        constraints = dict((el, -1) for el in keys)
        self.constraints_exp = constraints
        result = np.inf

    solution.objectives[0] = result

    self.__evaluate_constraints(solution)

    return solution`

This means that whenever an instance of decision variables raises an error in my code the result to this specific vector will be np.inf, since this is a minimization problem, and none of the constraints are fulfilled ("dummy fitness/points").

While evaluating several instances of my problem and using the BasicObserver class I noticed that some of the runs would generate an initial population filled with these dummy points. Most of the time the dummy points would be sorted as having the best fitness and the final solution would be completely wrong. What should I do?