Get multiple solutions from genetic algorithm (ga)

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.

回答 (1 件)

Alan Weiss
Alan Weiss 2013 年 6 月 12 日

1 投票

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 件のコメント

Craig Cowled
Craig Cowled 2013 年 6 月 14 日
Jakob, I wrote an output function for a GA that saves only relevant information. It might help you ...
function [state, options, optchanged] = GAGenSave(options, state, flag)
global parastring
FileName = ['GenData_', parastring, '.mat'];
if (exist(FileName)) == 2
load(FileName);
if state.Generation == 0
iter = GenData.Generation;
else
iter = GenData.Generation + 1;
end
else
iter = 1;
end
GenData.x(iter, :) = state.Population(1, :);
GenData.Generation = iter;
GenData.FunEval(iter, :) = state.FunEval;
GenData.Population(:, :, iter) = state.Population;
GenData.Score(:, iter) = state.Score;
save(FileName, 'GenData');
% standard template code follows
optchanged = false;
switch flag
case 'init'
disp('Starting the algorithm');
case {'iter','interrupt'}
disp('Iterating ...')
case 'done'
disp('Performing final task');
end % GAGenSave()
Morteza
Morteza 2013 年 10 月 26 日
Hi Alan, How this code could be changed to give the best fitness value for each population? Thanks
Walter Roberson
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
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);

サインインしてコメントする。

カテゴリ

質問済み:

2013 年 6 月 12 日

編集済み:

2017 年 8 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by