Hey guys, I am a bit lost on this. Any help would be appreciated. Essentially my problem is this: I want to write a custom SelectionFcn for my GA to select the 25 best parents and then select 2 at random to create 25 children. And the children should be the arithmetic mean between the parents.
I have olny gotten as far as this:
function parents = parents(expectation, nParents, options, state)nParents = 25parents = zeros(1,nParents);% get the scores of the current population
curPopScores = state.Score;% get the 25 best parents
if length(curPopScores)>25% created matrix with scores and indices for each parent
if iscolumn(curPopScores) data = [curPopScores'; 1:length(curPopScores)];else data = [curPopScores'; 1:length(curPopScores)];end % now sort the data on the column that corresponds to the scores
% (-1 means sort the first column in descending order)
sortedData = sortrows(data',-1); % get the sorted parent indices from the first 25 elements
parents = sortedData(1:25,2);
That should work except I am unable to access the scores with "state.Score"
Best Answer