Genetic Algorithm OPTIMTOOL Error
Mostrar comentarios más antiguos
Hi All,
I am running GA problem via OPTIMTOOL. This is my defined parameters at OPTIMTOOL
Fitness Function:@myff
Number of variables :4
Lower Bound: [1 14 30 12]
Upper Bond : [2 22 60 16]
And @myff code is per below :
function TotalDelay=myff(C,g,x,c)
a=(1-(g/C))^2;
p=1-((g/C)*x);
d1i=(0.38*C*a)/p;
a2=173*(x^2);
ri1=sqrt( (x-1) + (x-1)^2 + ((16*x)/c) );
d2i=a2*ri1;
TotalDelay=(d1i+d2i);

end;
When start the solver the below error pops out : "Input argument "g" is undefined."
Can anyone enlighten me, where did i made a mistakes.
Thanking in advance. Dawood
Respuestas (2)
Steven Lord
el 17 de Ag. de 2017
0 votos
"The fitness function should accept a row vector of length nvars and return a scalar value."
Your function, as defined, requires a row vector of length nvars and other information. For that scenario, see this suggestion in the Tips section on that documentation page:
"To write a function with additional parameters to the independent variables that can be called by ga, see Passing Extra Parameters (Optimization Toolbox)."
You will need to use one of the techniques on the Passing Extra Parameters page to pass additional inputs to your fitness function. The easiest will probably be the anonymous function approach.
1 comentario
Alan Weiss
el 17 de Ag. de 2017
It is possible that your variables C, g, x, and c are all scalars that you want to optimize. In that case, instead of following Steve's suggestion, you would write your objective (fitness) function like this:
function TotalDelay = myff(r)
C = r(1);
g = r(2);
x = r(3);
c = r(4);
a=(1-(g/C))^2; % etc., put the rest of your code here
P.S. For such a smooth objective function, I suggest that you NOT use ga, but instead use a more appropriate solver such as fminunc or fmincon.
Alan Weiss
MATLAB mathematical toolbox documentation
Shaik Dawood Hussain
el 18 de Ag. de 2017
0 votos
1 comentario
Mohammed Bakr
el 26 de Sept. de 2020
hi
i have the same problem now can you tell me what can i do
Categorías
Más información sobre Genetic Algorithm en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!