In this module we will learn how to simulate a model using the facilities provided by the library. Besides, we will describe the errors detected by EOSimulator.
The process of simulate models is not as trivial as it appears. It is very important to design set of runs varying seeds in those streams used by the model. Otherwise all the experimentation done with the model will not be statistically valid. Remember, one simulation run is not enough to draw any conclusions about a system. Luckily, EOSimulator makes this running process quite easy. The core::Experiment class handles the execution of a simulation. It contains a calendar, an executive and the streams.
To run a simulation you have to write a program. In this program, create an instance of your system model and an experiment. Then connect them with the operation core::Model::connectToExp. In that operation, the model is initialized (with the operation core::Model::init) and connected to the experiment. Then use Experiment::run to run the simulation. This operation makes the initial schedules in the model (core::Model::doInitialSchedules) and simulates the model. For example:
using namespace eosim::core;
int main () {
Model my_model;
Experiment exp;
m.connectToExp(e); // the experiment is connected to the model
e.run(5); // we simulate for 5 time units
// do some report
}
After the simulation is finished generally the data collected is reported. For more information see Data Collectors.
As we said above, one run is not enough to draw conclusions. So in order to make more runs, after the simulation is finished, create a new model and experiment. Then connect them and set a new seed in the experiment using core::Experiment::setSeed. This operation change the seed of every registered distribution in the model, and it let you have a different run (the default seed is 251182). Finally, run the simulation (core::Experiment::run).
using namespace eosim::core;
int main () {
for(int i = 0; i < 4; i++) { // we will make 4 runs
Model my_model; // a new Model is created for every iteration
Experiment exp; // a new Experiment is created for every iteration
m.connectToExp(e); // the experiment is connected to the model
e.run(5); // we simulate for 5 time units
// do some report
}
}
But why we didn’t keep the old experiment and model? Another possibility may be keep them, set a new seed and simulate again. This is possible because Experiment doesn’t reset the simulation time. Check if the system you are modeling let you do that.
We could create a new model and connect it the old experiment. But, in the old experiment there may be some entities which are scheduled to arrive or to leave the system. If an entity is schedule to leave, it may return some units of bins causing errors in the output or even aborts the simulation. If we make a new experiment and connect it with an old model, the queues of the model will full of entities. In this case the model has already started (and if it can reach steady state) it may be stable. But, the clocks of the entities waiting in a queue have not been updated , so they still contain older values and cause errors collecting waiting times.
Classes | |
class | eosim::core::BCalendar |
B Events Calendar. More... | |
class | eosim::core::CCalendar |
C Events Calendar. More... | |
class | eosim::core::Experiment |
Experiment Manager. More... | |
class | eosim::core::Model |
System Model. More... | |
class | eosim::dist::DistManager |
Distribution Manager. More... |