anyoptimization / pymoo

NSGA2, NSGA3, R-NSGA3, MOEAD, Genetic Algorithms (GA), Differential Evolution (DE), CMAES, PSO
https://pymoo.org
Apache License 2.0
2.28k stars 392 forks source link

How to set Binary value as constraint for variables #279

Closed prashanthin closed 2 years ago

prashanthin commented 2 years ago

Hi Team,

I am using pymoo NSGA2 algo for one of my optimization problems - However I have a case where a variable can only take 0 or 1. I am not sure how this can be constraint, since it takes lower and upper bound as array, and also in def _evaluate , how to explicitly define a constraint for values ?

For eg- I want x[0] variable to be either 0 or 1 so x=1 or x=0

Below is what I thought of trying but its not working
g1 = x[0] -1 g2 = -x[0] -0

Can you please help me on this? Thanks, Prashant

blankjul commented 2 years ago

You intend to optimized mixed variables types: https://pymoo.org/customization/mixed.html There will be a major update soon that this can be defined more elegant.

I hope this helps.