The GA works fine without running it in parallel, but when
I open the matlabpool, the GA then returns the following
error: ??? Error using ==> makeState at 50
GA cannot continue because user supplied fitness function
failed with the following error:
Error using ==> reshape
To RESHAPE the number of elements must not change.
From the debugger, this appears to be happening when it is
trying to score each member of the population:
% Score each member of the population
if strcmpi(options.Vectorized, 'off')
try
Score = fcnvectorizer(state.Population
(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserF
cn);
catch
error('gads:makestate:fitnessCheck', ...
'GA cannot continue because user supplied
fitness function failed with the following error:\n%s',
lasterr)
end
Anyone any ideas why this would be happening? I'm not sure
what details of my code are needed so feel free to ask for
additional information. My version is 2008a (7.6.0.324).
Thanks.
Sorry, the correct url for this is
http://www.mathworks.com/access/helpdesk/help/toolbox/gads/i
ndex.html?/access/helpdesk/help/toolbox/gads/f7928.html
"Persistent or global variables. If your objective or
constraint functions use persistent or global variables,
these variables may take different values on different
worker processors. Furthermore, they may not be cleared
properly on the worker processors."
Does anyone know how to use local variables with the GA
objective function?
I have since solved this problem myself. To pass variables
to a GA the fitness function must be specified as shown in
the example below:
FitnessFcn=@(x)m_file_fitness_calc(x,other variables...)
then the ga is called using as: ga(FitnessFcn,other
options...) etc.
Global variables was indeed causing the initial problem and
once changed into local varibles using this method, the
errors were eliminated.