Clear Filters
Clear Filters

What is the meaning of function count in the genetic algorithm in matlab optimization?

5 views (last 30 days)
Where is the function count coming from? Why does it not increase the same amount between generations?
Function:
function y = fitness(x)
a=1;
b=1;
c=1;
y =sin(a*x(1)^2+b*x(2)+c);
Constraint Function:
function [c, ceq] = constraint(x)
c = [];
ceq = [];
Optimization Code:
ObjectiveFunction = @fitness;
nvars = 2; % Number of variables
LB = [,]; % Lower bound
UB = [,]; % Upper bound
ConstraintFunction = @constraint;
for i=1:5
options = gaoptimset('MutationFcn',{@mutationuniform, .01}, 'Display','iter',...
'Generations',100,'FitnessLimit', -.9999,...
'PopulationSize',127);
[x,fval,exitflag, output] = ga(ObjectiveFunction,nvars,[],[],[],[],LB,UB,...
ConstraintFunction,[],options)
%record = [record; fval];
z(i)=output.generations
k(i)=output.funccount
end

Accepted Answer

Alan Weiss
Alan Weiss on 12 Jun 2015
Edited: Alan Weiss on 12 Jun 2015
When you use a nonlinear constraint in ga, the solution algorithm is different than without the nonlinear constraint. See nonlinear constraint solver. In particular, note the paragraph:
Each subproblem solution represents one generation.
The number of function evaluations per generation is
therefore much higher when using nonlinear constraints
than otherwise.
Even though your constraint function is not calculating anything, the fact that you have a nonlinear constraint function means that ga uses the nonlinear constraint solver. If you really don't have a nonlinear constraint, set the ConstraintFunction argument to [].
Alan Weiss
MATLAB mathematical toolbox documentation
  3 Comments
Alan Weiss
Alan Weiss on 15 Jun 2015
No, you misunderstand how the nonlinear constraint solver works. Read the link that I gave. There can be many iterations in each subproblem solution, so the number of function evaluations can be large.
Alan Weiss
MATLAB mathematical toolbox documentation
Emily Senay
Emily Senay on 15 Jun 2015
I see now. So if I get rid of the nonlinear constraint shouldn't what I stated above be true..that the function count should equal or be less than the number of generations multiplied by the population size?

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!