I am running a genetic algorithm with only nonlinear inequality constraints. The solutions is an array of "nvars" integers that are either 0 or 1.

The setup looks like this:

ObjectiveFunction = @(x) myfunc_objective(x,par);

ConstraintFunction = @(x) myfunc_constraint(x,par);

lb = zeros(1,nvars);

ub = ones(1,nvars);

IntCon = linspace(1,nvars,nvars);

options = gaoptimset(options,'PlotFcns', {@gaplotbestf});

options.Generations = 150;

options.PopulationSize = 1e3;

options.Display = 'iter';

x = ga(ObjectiveFunction,nvars,[],[],[],[],lb,ub,ConstraintFunction,IntCon,options);

When I look at the plot of penalty value vs iterations, a similar pattern seems to appear:

- For the first 35-45 generations, the penalty value decreases from about 100 to 0 or about -0.5.
- These solutions do not satisfy all the constraints (they fail 1~5 constraints out of the ~500 in).
- Then, there is a jump in best and mean penalty from around 0 to 1e4.
- If given enough generations, the plot sometimes returns to values similar to before the jump, but not always.

I think this corresponds to a way to either get out of a local optima, or maybe a way to discard the entirety of the population and apply a drastic change to try to find actual solutions that satisfy the constraints.

If you could help me out understand the method a bit more, here are the three questions I have:

- If ga() prepares an initial solution that is probably different for each case, why is the plot pattern the same for any run? Shouldn't any jumps happen in different iterations for different runs? And maybe for some runs there could be more than one or maybe zero jumps.
- When I check the previous generaitons before the jump, they don't seem to satisfy all the constraints (only a few unsatisfied out of hundreds). However, the first generation after the jump seems to satisfy the constraints. Therefore, why is the penalty value so high after the jump, if the solution is actually more feasible than before the jump?
- With elite counts between 5% to 50% I still get the same pattern. I thought that fixing a 50% elite count would mean keeping a big portion of the previous generation untouched at each iteration. If this is the case, how come the best and mean penalty values are not affected by this restriction in the setup?

Thank you so much for your help!

## 2 Comments

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/561365-understanding-why-ga-s-penalty-profile-is-so-similar-for-any-run#comment_928997

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/561365-understanding-why-ga-s-penalty-profile-is-so-similar-for-any-run#comment_928997

## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/561365-understanding-why-ga-s-penalty-profile-is-so-similar-for-any-run#comment_929003

⋮## Direct link to this comment

https://la.mathworks.com/matlabcentral/answers/561365-understanding-why-ga-s-penalty-profile-is-so-similar-for-any-run#comment_929003

Sign in to comment.