- Load the model: Use the following line to explicitly load the model file in the base workspace:
Error with using a Simulink model as the objective function in ParetoSearch with options.UseParallel set to True (Global Optimization Tool Box)
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I currently have an optimization problem which involves identifying a set of parameters in a Simulink model that finds the minimum of the model output. The output is the average of a time series data. I an currently using pareto search (it is a multi objective optimization problem) from the Global Optimization Toolbox.
I have a function handle (run_simulink_model()) that calls the simulink model and once the model runs based on the inputs (parameters of the model) given by the pareto search algo and then there is a bit of post processing that involves using the output from the model to compute the target for optimization. Now the whole thing runs fine when the options.UseParallel is set to
. When I set options.UseParallel to
the pareto search fails. In the case when parallel is set to
I use parsim inside the function handle and it still doesnt seem to work. I would like to understand if parallel computing is possible in pareto search when a simulink model is used.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/992490/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/992495/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/992495/image.png)
function fval = run_simulink_model(model_params_fr_optimization, nameSimulinkModel, save_location, evaluation, parallel)
batchSize = size(model_params_fr_optimization, 1);
fval = nan(batchSize, 3);
save_system(nameSimulinkModel);
simulationModelIn(batchSize) = Simulink.SimulationInput;
for idx1 = 1:batchSize
simulationModelIn(idx1).ModelName = nameSimulinkModel;
simulationModelIn(idx1) = simulationModelIn(idx1).setVariable(...
'param_name', model_params_fr_optimization(idx1,:));
end
if parallel == false
youts = sim(simulationModelIn);
elseif parallel == true
youts = parsim(simulationModelIn, 'ShowProgress', 'on', 'TransferBaseWorkspaceVariables','on');
end
fval = post_processing(youts) % Post processing in this section to return the multiple outputs to be optimized
end
%% Function handle and the script for paretosearch
f = @(x)run_simulink_model(x, nameSimulinkModel, save_location, evaluation, parallel_run);
ptions = optimoptions('paretosearch');
options.Display = 'iter';
options.MaxFunctionEvaluations = 10;
options.MaxIterations = 5;
options.InitialPoints.X0 = X; %initial data points
options.ParetoSetSize = 4;
options.UseParallel = true;
[X,fval,exitflag,output,residuals] = paretosearch(f, 2, [], [], [], [], lb, ub, [], options)
Following is the error message i get:
Invalid Simulink object name: simpleSimulinkModel.
The block diagram 'simpleSimulinkModel' is not loaded.
If you need nay further info please do let me know. :) TIA
댓글 수: 0
답변 (1개)
Avadhoot
2024년 1월 23일
Hi Jyotirmaya,
This issue appears because MATLAB cannot find your model in the base workspace before simulating it. You can solve this problem using any of the following steps:
load_system(nameSimulinkModel);
Insert this line instead of the following line
save_system(nameSimulinkModel);
2. Check if the model is on the MATLAB path: Execute the following command to add the model to the MATLAB path
addpath('path_to_the_model');
3. If both of the options don't work, ensure the file is open by excuting the following command:
open_system(nameSimulinkModel);
If the file opens without any issuesd then try re-running your script.
I hope it helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Direct Search에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!