You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to implement a multi-objective problem with two objectives and one constraint. However, when I am executing it, I get an error what: Non linear constraints detected in <class '__main__.SimpleProblem'> instance., with which my solver cannot deal (NSGA-||); however my constraint is non-linear.
To reproduce, I created a small example:
import pygmo as pg
class SimpleProblem:
# objective functions and constraints
def fitness(self, x):
fitness_vector = []
# first objective
fitness_vector.append(x[0])
constants = [1,0.5,0.5]
# second objective
fitness_vector.append(-sum([x[i] * constants[i] for i in range(3)]))
# constraint
fitness_vector.append(sum([x[i] for i in range(3)]) -2)
return fitness_vector
# number of objectives
def get_nobj(self):
return 2
# number of inequality constraints
def get_nic(self):
return 1
# real dimension of the problem
def get_ncx(self):
return 1
# integer dimension of the problem
def get_nix(self):
return 3
# bounds of the decision variables
def get_bounds(self):
return ([0] + [0] * 3, [1e6] + [1] * 3)
if __name__ == "__main__":
model = SimpleProblem()
problem = pg.problem(model)
algorithm = pg.algorithm(pg.nsga2(gen=1000))
population = pg.population(problem, size=100)
population = algorithm.evolve(population)
I read drom the documentation, that to add objectives and constraints, one shall return a vector first containing the objectives followed by the constraints in the fitness function. However I do not know if this differs with multi-objectives, as I did not find any example for multi-objective optimization with constraints other than the variable bounds in the documentation. Hence I do not know if this is a bug or if I am supposed to give the objectives/constraints differently.
I am using Version 2.19.5.
Any help would be appreciated
The text was updated successfully, but these errors were encountered:
The error message is indeed a bit misleading, in the sense that as far as PyGMO is concerned all constraints are nonlinear because PyGMO deals with general non-linear optimization problems and it currently has no capability to exploit the linear structure of some optimization problems.
The optimization problem you are trying to solve is quite complicated and there are not many solvers which are able to deal with constrained multi-objective problems. You can take a look at the list of algorithms here:
And indeed I think only "Improved Harmony Search" can solve your problem. You also have the option of turning your multi objective constrained problem into a single-objective and/or unconstrained problem with the help of the decompose and/or unconstrain meta problems:
I want to implement a multi-objective problem with two objectives and one constraint. However, when I am executing it, I get an error
what: Non linear constraints detected in <class '__main__.SimpleProblem'> instance.
, with which my solver cannot deal (NSGA-||); however my constraint is non-linear.To reproduce, I created a small example:
import pygmo as pg
I read drom the documentation, that to add objectives and constraints, one shall return a vector first containing the objectives followed by the constraints in the fitness function. However I do not know if this differs with multi-objectives, as I did not find any example for multi-objective optimization with constraints other than the variable bounds in the documentation. Hence I do not know if this is a bug or if I am supposed to give the objectives/constraints differently.
I am using Version 2.19.5.
Any help would be appreciated
The text was updated successfully, but these errors were encountered: