Constraining Dependent Variables in ga Optimization

3 views (last 30 days)
Hi,
I am trying to constrain my optimization for min f(x) by restricting the range allowed for a dependent variable h(x). I am using a the ga optimizer from the Optimization Toolbox. Do I need to write a penalty or barrier function into by objective function, or is there another simpler way that I can apply the constraint? I tried using the nonlcon input in the ga function, however have been unable to get it to converge. The documentation suggests that nonlcon can only take x (independent variable vector) as an input and so I think that reading in dependent variables may be a misuse of the function.
Please help! Any guidance would be greatly appreciated.

Accepted Answer

Matt J
Matt J on 23 Jan 2015
Edited: Matt J on 23 Jan 2015
The documentation suggests that nonlcon can only take x (independent variable vector) as an input and so I think that reading in dependent variables may be a misuse of the function.
Well, nonlcon should be written to accept a vector in the space of x as input, not a vector in the space of h. However, since h is a function of x, that should be straightforward. Something like this,
function [c,ceq] = nonlcon(x)
ub=... %upper bounds
lb=... %lower bounds
hx=h(x);
c=[hx(:)-ub(:); lb(:)-hx(:) ];
ceq=[];
end
Are you sure it's not converging, or might it just be converging to something you don't like? With nonlinear constraints, it can be difficult to find a good initial population, especially if the constraints define a set with several disconnected regions.
  3 Comments
Matt J
Matt J on 23 Jan 2015
and so I am unable to calculate it from the independent variables alone.
I assume that means that there are additional problem constants that the calculation of h(x) depends on. If so, that is covered in Passing Extra Parameters.
dpud12
dpud12 on 26 Jan 2015
Hey Matt,
Thanks for the help, turns out I was not properly passing the parameters as you noted. The specific problem was my assumption for when the constrain functions were evaluated. I was under the impression that the constraints were evaluated at the same time the objective function was evaluated for each member of the population. As a result I was only reading in from my excel sheet and not writing the x variables to the excel. This was resulting in the error I noted:
Also, in each generation it says that my best penalty value is the same as my average penalty value for the population.
I changed it to write to my excel sheet for each variable vector x and the problem is now converging wonderfully! I now just need to figure out whether it evaluating the constraints for the entire population set before or after the objective function, so that I can reduce run time and eliminate unnecessary xlswrite1 commands, but should be able to figure that out easily enough on my own.
Thanks again for your help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!