MATLAB: Does the “ga” function violate a linear constraint even though the exitflag was 1

constraintgalinearMATLABnonlinearoptimizationviolation

I am using the "ga" function to use a genetic algorithm for my optimization problem. 
The "exitflag" returned is 1, which I think indicates that the optimization was successful. However, it consistently violates one of my linear constraints. Is this a bug?

Best Answer

Although the "exitflag" is 1, this does not necessarily mean that all of the constraints are satisfied. The "ga" function uses the "ConstraintTolerance" setting to determine the "exitflag" of 1. For more detail on this, please refer to the documentation page for "ga" at the following link:https://www.mathworks.com/help/gads/ga.html#outputarg_fvalI recommend tightening the "ConstrantTolerance" setting to see if it fixes the violation. You can do this using the "optimoptions" function. Please see the following example:
options = optimoptions('ga','ConstraintTolerance',1.0000e-06)
For more information on what options you can set, please refer to this documentation link: