July 17, 2010

Simio Elements: Initialize(), Shutdown(), or Constructor?

This post is for everyone, like me, who has ever implemented his own custom element in Simio and asked himself: What are the two methods Intialize() and Shutdown() for?

I asked the Simio team, and I got an answer (as always): The Initialize() method is called before a replication of a scenario within an experiment starts. So what you would do here is to reset any internal statistics, collections, or variables that you use in your elment, and that need to be refreshed for each replication.

The Shutdown() method is the counterpart and is run when a replication ends. Although I cannot think of anything right now, I am sure that there are numerous applications for that.

But what about the constructor then? Well, at this time, the constructor is also called before each replication, so as I understand, for each replication a new instance of the element is created. According to Simio this could change in the future, and the constructor will only be called once, at the beginning of the whole experiment.

This means it is safer if you implement the Initialize() method as if the constructor wasn't called. To name an example, I use this method to clear a Hashtable I use to store statistics in. If I didn't clear it here, the next replication would run with the data from the old replication, and this would lead to unexpected results. So be wise now, and save you trouble later!