Get multiple solutions from genetic algorithm (ga)
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Alan Weiss
2013-6-12
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 个评论
Walter Roberson
2013-10-27
编辑:Walter Roberson
2017-8-14
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
2017-8-14
编辑:Walter Roberson
2017-8-14
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);
另请参阅
类别
在 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!