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일

0 개 추천

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

olga_vm
olga_vm 2020년 4월 6일
Thank you for giving a feedback but it gives me the same error after having made the adjustment to the codes (please see attached). How else can I fix it?
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개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2020년 4월 6일

댓글:

2020년 4월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by