Genetic Algorithm: Failure in initial supplied Fitness Function
2 views (last 30 days)
Show older comments
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 Comments
Stephan
on 4 Jun 2020
Edited: Stephan
on 4 Jun 2020
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.
Answers (0)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!