gamultiobj - Not enough input arguments

3 views (last 30 days)
I am trying to run gamultiobj for one objective (later, I will add more objectives) but I am getting an error 'Not enough input arguments' (fitness and gamultiobj functions are attached). I would appreciate if you have a look at the code attached. Thanks.
The detailed error:
Not enough input arguments.
Error in myfitnessfunction (line 114)
SOC(i,j)=SOC_n(i)+((cop(i)*E_max(i)*x(i)*T_s/E_cap(i)))*F(i,j)+((E_max(i)*y(i)*T_s/(cop(i)*E_cap(i))))*H(i,j);
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in gamultiobjMakeState (line 28)
Score = FitnessFcn(state.Population(1,:));
Error in gamultiobjsolve (line 8)
state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);
Error in gamultiobj (line 276)
[x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ...
Error in mymainfunction (line 8)
[x,y,fval,exitflag]=gamultiobj(FitnessFunction,nvars,[],[],[],[],Lb,Ub);
Caused by:
Failure in initial fitness function evaluation. GAMULTIOBJ cannot continue.

Accepted Answer

Geoff Hayes
Geoff Hayes on 6 Apr 2020
olga_vm - the signature for your fitness function is
function z=myfitnessfunction(x,y)
with two inputs, x and y. The error message is telling you that there are not enough input parameters being provided to your fitness function. This makes sense since the genetic algorithm code will only pass in a single parameter or array with (in your case two elements). You will need to change your signature and first couple of lines to
function z = myfitnessfunction(data)
x = data(1);
y = data(2);
  3 Comments
Geoff Hayes
Geoff Hayes on 6 Apr 2020
The signature is still
function z=myfitnessfunction(x,y)
... Looking more closly at your code, you are indicating that there are 20 variables to optimize over. If x is your array of 20 variables then what is y? But your fitness function assumes that there are 10 elements in x and ten elements in y. Is this the case? Do you need to change the signature and first couple of lines to
function z=myfitnessfunction(data)
x = data(1:10);
y = data(11:20);
The above is a guess...I don't know what your x and y are or how they are to be used. But I strongly recommend you read to Genetic Algorithm documentation to understand how the fitnes function is used so that you modify your code to what it is expecting.
olga_vm
olga_vm on 9 Apr 2020
Geoff, thanks a lot for the help. It worked :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!