Error in parallel computing for optimization of parameters in a simulink model using genetic algorithm
Show older comments
I am trying to optimize 19 parameters of a simulink model of a hybrid electric vehicle using genetic algorithm. The code runs properly in serial computing mode. I want to use parallel computing to speed up the calculations. Please find attached the script files. The function objective_function_4 computes the fitness function value. This function calls the function eq_fuel_eco_calc to run the simulink model and calculate the equivalent fuel economy of the hybrid vehicle over the given drive cycle. I am using MATLAB R2015b. The options in ga are set to 'UseParallel'=true and 'Vectorize'='off'. The fitness function of the first individual of the population evaluated correctly without any error. But after that, this is the error message that I received:
Error using objective_function_3 (line 12)
Struct contents reference from a non-struct array object.
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in fcnvectorizer (line 16)
parfor (i = 1:popSize)
Error in makeState (line 58)
Score =
fcnvectorizer(state.Population(initScoreProvided+2:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in galincon (line 17)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 359)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in ga_optimization_4 (line 87)
[x,fval] = ga(FitnessFcn,nvars,A,B,Aeq,Beq,LB,UB,[],[],options);
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
Please help me in resolving this error. How does ga evaluate the fitness of population in parallel computing? Thank you!
1 Comment
Rakesh Kumar
on 9 Apr 2018
Can you run this code by removing GA from the equation?
fval = zeros(10,1);
parfor ii = 1:10
X = LB + (UB-LB).*rand(1,numel(LB))
fval(ii) = FitnessFcn(X);
end
Answers (0)
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!