Genetic Algorithm: Failure in initial supplied Fitness Function
Mostrar comentarios más antiguos
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 comentarios
Stephan
el 4 de Jun. de 2020
Please attach all files and all code needed to reproduce the error. Without we can not help.
Ozgun Karatas
el 4 de Jun. de 2020
Ozgun Karatas
el 4 de Jun. de 2020
Editada: Ozgun Karatas
el 4 de Jun. de 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.
Ozgun Karatas
el 4 de Jun. de 2020
Respuestas (0)
Categorías
Más información sobre Genetic Algorithm en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!