The following AnyLogic elements can be declared as static:
Please note that static elements are not saved into a snaphot file.
If you do not alter the value of a static element in your model, the state of the restored model will be exactly the same as the previously saved state. However, if you somehow change the value of a static element (e.g. in agent's On startup code), the modified value won't be saved into a snapshot, and therefore the restored state of the model will differ from the state you have previously saved.
There is one more case to be mentioned with the static constant variable and some other variable inside a model referring to the same Java object. As a result, when you check the constant and the variable for equality, you will get true. However, if you save the model state into a snapshot, the constant and the variable in the restored model will refer to different objects, and they won't be considered as equal anymore, thus the restored model behavior will differ.The general conclusion is to avoid using static elements if you plan to save/restore your model state using the AnyLogic snapshot feature.
Some Java objects cannot be serialized, for example objects of class BufferedImage. Variables of such types should be excluded from standard snapshot serialization. If you wish to save and restore these objects anyway, you can write some code in the functions writeCustomData and readCustomData. This code should take care of custom serialization and loading of some base content of a given non-serializable object (of course, it is possible to obtain that base content from the object and setup it back in the future).
For example, for the BufferedImage base content could be: width, height, image type parameters (which are used in the constructor) and int array of pixel colors (which can be retrieved by calling getRGB function). The code restoring BufferedImage (in the readCustomData function) should create an instance by invoking constructor with above parameters and then call setRGB function to restore the picture.
Open database connections and open files cannot save and restore
their states. Therefore after restoring the snapshot the connections
and files will be in closed state. This does not mean you cannot
continue accessing them. For example, if the model writes to a kind of
a log file, it can continue writing there, provided the file is in
“append” mode. Connectivity objects will create their
connections on first access, as they usually do. But Statement and ResultSet objects (if any are opened) cannot be included in the snapshot (they are not serializable). It is recommended to open ResultSets, access and close them entirely within the code of some function body (or any code section). Storing references to Statement and ResultSet
in the variables of agent is not recommended. Also, note that
snapshot cannot affect external data sources and in some cases manual
database backup and restore may be required.
At the moment OptQuest optimization engine cannot save and restore
its state, therefore you cannot save snapshots of Optimization
experiments. In the future however OptTek will release a serializable
version of OptQuest.