How to deliver the values got from the objective function to the non-linear constraint function when use the genetic algorithm?

I'm doing my project using the genetic algorithm(a algorithm in the Optimization Tool), and I meet a problem.
The syntax is
[x,fval]=ga(@objfun,5,[],[],Aeq,beq,LB,UB,@nonlconstr,options);
The function nonlconstr is
[c,ceq]= nonlconstr(x);
and
ceq=[],c=[a;b;f];
In this case, the objfun function is complex, and it takes some seconds to execute it. But during executing the objfun, I can get the parameters a and b. I know the genetic algorithm execute the objfun and nonlconstr separately, and it will waste a lot of time to calculate the values of a,b one more time in the nonlconstr. So is there any method that I can take to deliver the values of a,b that got from the objfun to the matrix c.

Answers (1)

If you can use vectorized objective and constraint functions, then I expect that this technique would work. But, if you don't vectorize the functions, then I do not believe that the technique would work, because I believe that ga evaluates all the objective functions of the population members, and then all the constraint functions. But you could give it a try in any case, just in case I am wrong.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

3 Comments

@Alan: Thank you for your answer. It's a good idea to vectorize the objective and constraint functions. But in my objective function, the variable x is used to change some elements of a matrix named A, and the matrix A will be used to do the following calculation. It seems difficult to vectorize such a objective function.
In this context, vectorize does not mean you have to do the calculations without loops. It just means that ga passes full matrices of populations to your objective and nonlinear constraint functions. Inside those functions you can have a for loop execute the calculations. And it is possible that the technique I linked to would enable you to skip some recalculation of the expensive function.
I am not sure that the technique will work in any case, but you could give it a try.
Alan Weiss
MATLAB mathematical toolbox documentation
@Alan: I have tried as you said, but it didn't work. Because ga passes different matrices to the objective and nonlinear constraint functions.The image below shows this problem, the nonlconstr x is the matrix passed to the nonlinear constraint function, the c_non is the values of the nonlinear constraints, and objfun x is the matrix passed to the objective function. (ps:the release of MTLAB that I used is R2009a)
Maybe this technique can't solve this problem very well, but still thank you for your help.

Sign in to comment.

Asked:

on 1 Dec 2015

Edited:

on 7 Dec 2015

Community Treasure Hunt

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

Start Hunting!