gamultiobj - Not enough input arguments

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

采纳的回答

Geoff Hayes
Geoff Hayes 2020-4-6
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 个评论
Geoff Hayes
Geoff Hayes 2020-4-6
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 2020-4-9
Geoff, thanks a lot for the help. It worked :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by