Using Objective Function with .mat File I/O for Parallel Computing

1 回表示 (過去 30 日間)
Rajmohan
Rajmohan 2019 年 12 月 12 日
Hey Everyone!
I am working on an optimization problem which uses a complied Simulink model. The output of a simulink model is a .mat file that needs to be read and processed to create the output of the objective function. See code:
function y=costfunction(x,rtpstruct,mdlname,Tend)
% Change the tunable variable
rtpstruct=rsimsetrtpparam(rtpstruct,'ini',x);
save Rsim_Params rtpstruct
% Run Model
runname = ['.',filesep,mdlname,' -p Rsim_Params.mat -i Rsim_Input.mat -tf ',num2str(Tend),' -v '];
[~,~] = system(runname);
% Extract Simulation Parameters
simout = RsimOut(mdlname); % RsimOut load the .mat file and creates a more readable output.
% Output to minimize
y=sum(diff(simout.OutSig1));
end
This code generates an error when 'UseParallel' is set to 'true' in fmincon. I believe there is caused due to the fact that all the works are storing the data at the same location. Is there a way to fix this issue?
Thanks :)

回答 (0 件)

カテゴリ

Help Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by