Skip to content

Instantly share code, notes, and snippets.

@optiluca
Created September 25, 2020 19:53
Show Gist options
  • Save optiluca/d58f92de8c1560ecc8092994d592e452 to your computer and use it in GitHub Desktop.
Save optiluca/d58f92de8c1560ecc8092994d592e452 to your computer and use it in GitHub Desktop.
import pygmo as pg
class TestProblem:
def fitness(self, x):
param_1 = x[0]
param_2 = x[1]
metric_1 = 2 * param_1
metric_2 = 2 * param_2
constraint_1 = -0.5 # param_1 - 5
return [metric_1, metric_2, constraint_1] # , constraint_1, constraint_2]
def get_nic(self):
return 1
def get_nobj(self):
return 2
def get_bounds(self):
return [-1, -1], [1, 1]
if __name__ == '__main__':
algorithm = pg.algorithm(pg.nspso())
problem = pg.problem(TestProblem())
print(problem)
population = pg.population(problem, size=50)
population = algorithm.evolve(population)
fits, vectors = population.get_f(), population.get_x()
ndf, dl, dc, ndr = pg.fast_non_dominated_sorting(fits)
print(ndf)
@kunyaoli
Copy link

when i use pygmo to deal with muti-label problem, it will meet "Non linear constraints detected" error, if I add Equality or Inequality constraints. I see your code meet the same paroblem, what did you do about this bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment