Azzera filtri
Azzera filtri

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

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Alan Weiss
Alan Weiss il 12 Giu 2015
Modificato: Alan Weiss il 12 Giu 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 Commenti
Alan Weiss
Alan Weiss il 15 Giu 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 il 15 Giu 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?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by