Mimimize initializing time for SimEvent model

11 views (last 30 days)
I'm working on a project where I'm supposed to simulate a production facility using SimEvent.
The model it self works as intended but as it has grown the initializing time is extremely long in comparison to runtime. At the moment it takes takes about 100-120 seconds to initialize, compiling another 20 seconds and the runtime about 0.2 seconds. So the set simulation time does not affect, e.g. I can simulate one year or 20 years for about the same time.
In the model I make use of multiple "simulink function" (about 35 of them) all of them contains MATLAB Functions, which are called in order to open Entity gates and to keep a certain amount of entities in storage (just like in this example: https://se.mathworks.com/help/simevents/ug/use-an-attribute-queue-to-model-a-storage-tank.html ) or to define the assemle order.
For the assembly I use Composite Entity Creators along with resource Aquires/Releasers and Entity Servers. Each entity is a part of the final product which adds up to a total of 35, that are composed together along the manufacturing. That is the model in a nut shell.
I've tried to use the performance advisor and disabled Zero Crossing, changed to discrete variable step solver and only to compile when dependencies are found/known but it only helped a little. However, when change parameters by just running a few lines like mark and press F9, the initialize time takes just about 20 seconds but if I run the script it will take about 100-120 seconds (the script only contains assignment to variables).
This would be fine if I only wanted to try a few parameter change but my task involves a Sensitivity analysis which takes forever since each iteration takes 100-120 seconds (Parallelization does help thought), here I want to use the Sensitivity Analyzer App (sim. Design Optimization toolbox) since I would like to do a few hundred simulations.
Either way, is there any way for me to speed up the initializing, I'm asking here because I really dont know what Simulink/Matlab is doing while initializing and therefore is it hard to improve.

Accepted Answer

Abdolkarim Mohammadi
Abdolkarim Mohammadi on 2 Sep 2021
Edited: Abdolkarim Mohammadi on 2 Sep 2021
If you are doing a sensitivity analysis and you execute hundreds of simulations, the correct workflow is to use SimulationInput objects.
There you set parameter values for each of your experiments in one SimulationInput object, run all of the simulations with one line of code, and get the results in one SimulatinOutput object.
In addition to this point that this is how multiple Simulink simulations are intended to run, there is a feature that is there for your problem: Fast restart. Turning fast restart on causes Simulink to compile the model once, and use the compiled model for the whole experiments in the SimulationInput object. Since model compilation takes a lot of time, often more than model execution, especially in large complex models, fast restart helps A LOT.
Niklas Larsson
Niklas Larsson on 3 Sep 2021
Thanks a lot! I will try this out.
I did however try another approach mean while. I used the statistics from each block where I before had parameters that I wanted to change and then did the logics/calculation with standard simulink blocks. Now I can use fast restart and the model just compiles/initialize once and runs extremly fast afterwards! This also works with the Sensitivity Analyzer App/toolbox.
I like the thing you said about controlling the random seed and might go for your approach!
Thanks a lot, again!
Abdolkarim Mohammadi
Abdolkarim Mohammadi on 3 Sep 2021
I'm glad your problem is solved. I also learned that using Simulink blocks for calculating statistics makes the model run faster.

Sign in to comment.

More Answers (0)


Find more on Discrete-Event Simulation 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!