Pb Genetic algorithm

Dear all,
I have a problem with the genetic algorithm in Matlab. I tried to create a custom function in order to save the "state" at each generation, but I have a lot of problems. By chance do you have an example of a code ?
Thank you very much,
Best regards,
Aymeric

Answers (2)

Alan Weiss
Alan Weiss on 30 Aug 2011

0 votes

To quote my own answer there:
You can certainly write an output function. The basic syntax is here: http://www.mathworks.com/help/releases/R2010b/toolbox/gads/f6174dfi10.html#f17837
(There is an error in the description of the syntax in the R2011a documentation, sorry, that's why I am pointing to R2010b.)
For examples of using an output function (albeit with a different syntax than ga uses), see http://www.mathworks.com/help/techdoc/math/bsgpq6p-23.html#bsgpq6q-31 http://www.mathworks.com/help/toolbox/optim/ug/brhkghv-56.html
Alan Weiss MATLAB mathematical toolbox documentation
aymeric
aymeric on 30 Aug 2011
Hi Alan,
Thank you for your message.
My function is:
optchanged=false
switch flag
case {'init'}
store=zeros(1,1)
case {'iter'}
store(state.Generation,1).details=state.Population
save store
end
end
But I get just the population of the last generation. Do you have a function which save the state at each generation?
Thank you very much.
Aymeric

Asked:

on 27 Aug 2011

Community Treasure Hunt

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

Start Hunting!