How to deliver the values got from the objective function to the non-linear constraint function when use the genetic algorithm?
Show older comments
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)
Alan Weiss
on 1 Dec 2015
0 votes
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
Guochao Bian
on 2 Dec 2015
Alan Weiss
on 2 Dec 2015
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
Guochao Bian
on 7 Dec 2015
Edited: Guochao Bian
on 7 Dec 2015
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!