Creating a Discrete-Event Simulation Model Programmatically

Date: 10/27/2016
Author: Descreye Solutions

Most simulation models are created manually, because their goal is to get insight into a specific problem. However, sometimes it becomes necessary to create a discrete-event simulation model programmatically. This could be for any of the following reasons:

  • The simulation model is being built and run using real-time data
  • The simulation software is being used to analyze raw data for a user that is unfamiliar with the software
  • The maintenance of the model is a critical factor in the success of the project

In many cases these reasons make it worthwhile to make the effort to create the means whereby a simulation model can be created programmatically.

To create a simulation model automatically there are a few process steps. This image shows the various steps in model creation that must be defined to programmatically create and run a model.

When first creating a simulation programmatically it is often useful to first create the model manually to better understand how each step is accomplished manually before it is done through code. The following is a description of the importance of each step in the process:

Raw Data

The raw data definition is a critical part of creating a model programmatically. The raw data must contain all the information that is needed to completely build the model. For example, if the user was creating a production line model, then the raw data might need to contain the cycle times, flow, process step capacities, resource requirements, arrival times, etc. The raw data definition step is to make sure that all the data that is used in the model can be found in the raw data. Additionally, if any GUIs will be used for user input of various characteristics, then this would also be defined in the raw data definition.

Data Translator

The data translator plays the important role of transforming the raw data into data that the simulation software can use to build the model. For example, the raw data might have observations on the cycle time of a machine in the system. The data translator might fit those observations into a sampling distribution that the simulation software can use to estimate the variation occurring in that machine’s cycle time. The data translator step can be found within the simulation software or in an external program. Often Excel or Access are used to create the data translator, because they can create connections to external data sources. They also have analytical capabilities for summarizing the data in a way the simulation software can use it. Also, many simulation software packages can import the data from these programs.

Model Creator

The model creator is the step in the automatic simulation creation that is used to take the translated data and create the model within the simulation software. This step is usually done within the simulation software. Usually the software will import the translated data, if it wasn’t translated within the software, and then run a loop through the various items to create the objects and flow that is necessary for the model. Once this step is complete, then a executable simulation model should be built.

Simulation Model

This is the result of the programmatic simulation builder that is made from the previous steps. Some automatic simulation building will only go to this step where the model is built. The user is then expected to run the experiments and export the experiment data to get insight. In some cases, the model will be built with GUIs that show the user some critical information. In those cases, it is basically a compressed version of the next couple steps.

Model Experimenter

In some cases the programming with include the actual experimentation of the scenarios that are created in the model. For instance, the model might be run for 100 replications to determine how it compares to a baseline that has been created previously.

Statistics Provider

When the modeler wants to make the analysis completely automated, then they would include a way to write the experiment data back to a file that the user can use to gain insight.

If the complete solution is created, then it could look like this:

  • Raw Data
    • Process data is pulled from an MES system into a spreadsheet
    • The user changes certain values in the spreadsheet to gain insight into how it will affect the system
    • The user presses a button to run the analysis
  • Data Translator
    • The data translator creates a spreadsheet using the MES data and user input that is formatted in a defined manner for the simulation software
    • The data translator adds additional assumption data to the spreadsheet
    • The data translator launches a template file in the simulation software
  • Model Creator
    • Once the template file in the simulation software is launched, it automatically runs a model creation function.
    • The model creation function imports the information from the spreadsheet
    • The model creation function creates all the necessary objects with their characteristics for the model
    • The model creation function creates the flow for the model
  • Simulation Model
    • The model is complete
  • Model Experimenter
    • The model is run for 100 replications and the data for each replication is stored in an external file
  • Statistics Provider
    • The original spreadsheet is prompted to look for the external data file and import it
    • The user gains insight into how the changes affected the system

Each of these steps will be discussed in detail in future blog posts.

Back to blog

© Descreye Solutions, 2022