Genetic Algorithm OPTIMTOOL Error

3 次查看(过去 30 天)
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

回答(2 个)

Steven Lord
Steven Lord 2017-8-17
"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 个评论
Alan Weiss
Alan Weiss 2017-8-17
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
Thanks very much guys.
The code is working.
tq

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by