Genetic Algorithm OPTIMTOOL Error

2 Ansichten (letzte 30 Tage)
Shaik Dawood Hussain
Shaik Dawood Hussain am 17 Aug. 2017
Kommentiert: Mohammed Bakr am 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

Antworten (2)

Steven Lord
Steven Lord am 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 Kommentar
Alan Weiss
Alan Weiss am 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

Melden Sie sich an, um zu kommentieren.


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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by