Genetic Algorithm: Failure in initial supplied Fitness Function

2 次查看(过去 30 天)
Hello everybody!
I am currently having a problem with a genetic algorithm code i am trying to run.
The following is my genetic algorithm, which calls a specific fitness function. The fitness function determines the fitness value according to the variables.
%% sets up the genetic algorithm function handle for the real fitnessfunction
[v,fval,exitflag,output,population,scores]=ga(@FitnessFunktion,2,[],[],[],[],[0.5 2],[2.5 4],[],options)
The fitness function is as follows: (i have taken out the parts irrelevant to the code) From generationsresults.txt we get the curve and time variables, which are then supplied to the Fitness Function.
function Fitness=FitnessFunktion(x)
%%code snippets to obtain the results have been omitted
fitnessresults=importdata('generationresults.txt');
curve =fitnessresults(:,1);
ttime =fitnessresults(:,2);
Fitness=((curve/sum(curve))+ttime/sum(ttime))/sum(curve/sum(curve)+ttime/sum(ttime));
end
I am able to produce the first generation without any problems but when the GA wants to move on forward with the second generation, i get the following error:
I do not know why I cannot create further generations. Any help would be much appreciated, thank you in advance!
  5 个评论
Stephan
Stephan 2020-6-4
编辑:Stephan 2020-6-4
For me there are a lot of open questions, directly starting at the beginning of FitnessFunktion. It doesnt make sense for me. The size of x will always be 2 - why do you ask for it inside an if-statement?
you might want to send me an email, maybe we can discuss directly in german language.
Ozgun Karatas
Ozgun Karatas 2020-6-4
Hey Stephan!
I have sent you an email regarding the question, i can continue answering on the forum if you'd prefer & for other peers' understanding.

请先登录,再进行评论。

回答(0 个)

类别

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

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by