Get parallel simulations in objective function of optimization Tool (GA,PSO)
Afficher commentaires plus anciens
Hey Guys
i have an optimization problem using the constrainted PSO:
The syntax and general working of the constrainted PSO is the same as GA.
In my objective function, i have to generate a simOut with data from a simulink simulation. One calculation needs about 7 hours of time, since the simulation needs about 3 seconds.To increase the algorithm speed, i want the simulations to run parallel. But it doesnt seem to work if i use "parpool('local')". So far ich changed the settings to "UseVectorized" so have the whole population in one objective function. My code looks like this:
parpool('local')
options = psooptimset('Display','iter','OutputFcns',@myoutputFunc,'UseParallel',true,...
'Generations',200,'PopulationSize',40,'Vectorized','on');
[xopt,fval,exitflag,output,population,scores] = pso(@objective,9,[],[],[],[],lb,ub,@constraint,options);
function obj = objective(x)
% WANT TO: check the number of workers , in my case 6
% WANT TO: set parallel simulations equal to work number
for p=1:length(x(:,1)) %WANT TO: set parallel working parfor loop to execute the parallel simulations
SimuGeometrics = calculateGeometrics(x(p,:)); %SimuGeometrics is a structure of lengths and angle of different body that are used for simulink
%start simulation
simOut = sim('Mechanism.slx','CaptureErrors','on','SrcWorkspace','current');
%Result
pos1 = [simOut.xx.data, simOut.yy.data, simOut.zz.data];
obj(p,1) = calculateDeviation(pos1);
disp(['x: ',num2str(x(p,:)) ,' obj: ',num2str(obj(p,1))]);
end
end
I know that there are some functions like parfor or parsim but i dont know how to include them into my Code.
Of cause, my WANTO TO's are only ideas how i think it can work, if for example setting a parfor loop is nonsense, you can suggest another solution
Edit:
i saw your Answer from :https://de.mathworks.com/matlabcentral/answers/595402-how-to-use-the-parallel-computing-toolbox-of-matlab-to-optimize-the-parameters-of-a-simulink-model-w#answer_496378
it seems like you described a possible solution for my problem. I will try out what you described today and will share my solution if i succeed, but it would help me alot if u could share your expertise on this.
I hope somebody can help me with this problem.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Modeling and Prediction dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



