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

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
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