Hello everyone! this is the first time I am using GA and I encountered with this message:Failure in initial user-supplied fitness function evaluation. GA cannot continue.

3 次查看(过去 30 天)
here is my codes.
k1=0.6;
k2=0.25;
k3=0.15;
[x,fval] = ga(@(f)myfcn(f(1),f(2),f(3)),3)
function t=myfcn(f)
t=(k1*f(1)+k2*f(2)+k3*f(3));
end
%%all f values have been attained in another code
can anyone help me with this?

采纳的回答

Geoff Hayes
Geoff Hayes 2020-3-25
编辑:Geoff Hayes 2020-3-25
amir - you don't need to supply the f, those f values that have been attained in another code. The genetic algorithm will provide those from the initial population and from the subsequent generations (via crossover and mutation). All you need to do is pass in the function handle like
[x,fval] = ga(@myfcn, 3)
Since your myfcn depends upon the k1, k2, and k3, then ensure that your fitness function is nested within the main function
function main
k1=0.6;
k2=0.25;
k3=0.15;
[x,fval] = ga(@myfcn,3)
function t=myfcn(f)
t=(k1*f(1)+k2*f(2)+k3*f(3));
end
end
and saved (in this case) to a file named main.m. (Perhaps you have already done this.)
  12 个评论
Amir Hosseini
Amir Hosseini 2020-3-25
yes thank you that is understandable. I wanted to make an offer of working together and expand my article to publish it soon.
I would really appreciate it if you let me know in case of your willingness by personal email.
yours truly!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by