MATLAB: How to prevent GA from violating the non-linear constraints

ganonlinear constraintspatternsearch

I need to optimize a problem using GA (I tried patternsearch but due to various reasons I have to use GA).
My fitness function is evaluated by calling an external application which absolutely does not work when the non-linear constraints are violated. I was perplexed when I found my GA code to be violating the constraints, but after reading Alan Weiss' Answer here, I learned that this was to be expected.
In short, my fitness function cannot be evaluated when nonlinear constraints are violated.
How do you suggest I overcome this problem? How would GA behave if I checked the constraints in the fitness function and if they were violated I just return an arbitrary high number (that is fixed) as the fitness of that individual?

Best Answer

How would GA behave if I checked the constraints in the fitness function and if they were violated I just return an arbitrary high number (that is fixed) as the fitness of that individual?
There's no reason it couldn't work. You could even return Inf. However, I would recommend two things,
  1. In addition to enforcing constraints inside your fitness function, you should continue to specify them to ga outside the fitness function in the usual way, using the nonlcon and other input arguments. That way, even if your entire population violates the constraints, ga will know that it hasn't found a feasible point yet and should continue searching.
  2. If possible, try to include some feasible points (i.e., ones with finite fitness values) in your initial population.
Related Question