Get multiple solutions from genetic algorithm (ga)
6 views (last 30 days)
Show older comments
Hi
I'm using the genetic algorithm in the optimization toolbox. As for now I get one solution (the best) but is would like to get a range of solutions that is within a certain percentage of the best.
Is there a way to do that?
Example: Solution has a penalty score of 100. Return all solutions with a penalty socre less than 110.
0 Comments
Answers (1)
Alan Weiss
on 12 Jun 2013
You can use an output function to get whatever you want. There are examples of output functions in the Optimization Toolbox documentation, and in MATLAB documentation. Be careful, those examples use a different syntax than an output function for ga.
Alan Weiss
MATLAB mathematical toolbox documentation
4 Comments
Walter Roberson
on 27 Oct 2013
Edited: Walter Roberson
on 14 Aug 2017
Morteza commented,
works fine great code for output, the minor problem is that we need best fitness value in each generation. But this code gives score for each population! Anyway, it works fine Thanks Alan
Mostapha Dakhchoune
on 14 Aug 2017
Edited: Walter Roberson
on 14 Aug 2017
Thanks Alan and Craig for the help, anyone can help me why it gives this error while trying to run my GA coupled with Craig script? One more thing: I am interested only in x vectors so if I comment the other lines and run the code for a population of 20 it shows all the 7 variables (I am not sure also here because for the first half population of x vectors the last 3 variables are taken all as zeros), while if I run it, for instance, with a population of 50 it shows only the first 4 variables!
Thank you very much
Subscripted assignment dimension mismatch.
Error in GAGenSave (line 21)
GenData.Population(:, :, iter) = state.Population;
Error in gaoutput (line 39)
[state,optnew,changed] = feval(functions{i},opti |monospaced| ons.OutputPlotFcnOptions,state,flag,args{i}{:});
Error in galincon (line 31)
[state,options] = gaoutput(FitnessFcn,options,state,currentState);
Error in ga (line 374)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in main_tem (line 47)
[x,fval,exitflag,output,population,scores]=ga(@delete6provadelete,7,[],[],[],[],lb,ub,[],opts);
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!