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
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!