Saving and Restoring Model Snapshots via API
Saving / restoring model snapshot from simulation experiment,
optimization, calibration, parameter variation, sensitivity analysis,
Monte-Carlo, compare runs experiment
You can save and restore model snaphots using API functions which both take one parameter – the
name of the snapshot file.
Call them as follows:
- getExperimentHost().saveSnapshot(String fileName) – pauses experiment if it is
currently running, saves snapshot and
then resumes experiment if it was running.
- getExperimentHost().loadSnapshot(String fileName) – stops experiment and loads
snapshot (in its “not running” state),
doesn’t resume simulation of loaded snapshot. On any error
rollbacks to current
experiment and resumes it if it was running. When snapshot is loaded,
presentation forgets everything about the model which was running
(including the engine, experiment and agents), therefore, it is
recommended not to keep references to model objects after this function
both functions return immediately
(operations are performed in a separate thread). When the function
doesn’t mean that operation is complete – it may
be still in progress. In
order to monitor events of snapshot actual loading/saving (and perform
actions), listeners can be provided (see addSnapshotEventListener
and removeSnapshotEventListener functions of Presentation class).
Saving / restoring model snapshot from custom experiment
You can also save and restore model snapshots from custom experiment code using the following functions of Engine:
When you create a custom experiment, the experiment has default auto-generated code (see the custom experiment's properties, Code section) containing this line of code: Engine engine = createEngine();
This code creates engine and stores it in the local variable engine. Use it to call the functions mentioned above. To call the functions, write the following code:
Main root = (Main)engine.loadRootObjectSnapshot("C:\Model\Model.als");
Or, instead of typing the code, you can automatically insert the load snapshot function call while creating a custom experiment, by selecting the checkbox Load top-level agent from snapshot on the second page of the New Experiment wizard.