Genetic Algorithm OPTIMTOOL Error

3 views (last 30 days)
Shaik Dawood Hussain
Shaik Dawood Hussain on 17 Aug 2017
Commented: Mohammed Bakr on 26 Sep 2020
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

Answers (2)

Steven Lord
Steven Lord on 17 Aug 2017
"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 Comment
Alan Weiss
Alan Weiss on 17 Aug 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

Sign in to comment.


Shaik Dawood Hussain
Shaik Dawood Hussain on 18 Aug 2017
Thanks very much guys.
The code is working.
tq
  1 Comment
Mohammed Bakr
Mohammed Bakr on 26 Sep 2020
hi
i have the same problem now can you tell me what can i do

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!