Linking

From Support

Jump to: navigation, search

Contents

Generating an External Application for SIGMA Models and Running Simulations from a Spreadsheet

One of SIGMA’s most powerful features is its ability to automatically generate source code for a simulation program from a graphical model, and compile that into a high speed simulation application that can be used outside of SIGMA. This page discusses how to generate these external applications, as well as the generation of very fast source code in C that you can use to alter the simulations and link them to other applications. Also discussed are ways to run large experiments using batch files, how to put your simulator into a spreadsheet and run simulations from a spreadsheet interface, how to run large experiments using batch files, and how to replace SIGMA's pseudo-random number generator. You do not have to know C to use this feature. If, however, you wish to understand the details, refer to Reading SIGMA-Generated C Programs, which contains suggestions for how to read and understand the syntax of a SIGMA-generated C program.

Generating External Simulation Applications from SIGMA Models

SIGMA's ability to generate an external application that runs outside of SIGMA itself gives you the flexibility to incorporate your simulation into other applications, Excel spreadsheets or even websites without having to know a programming language. Of course, SIGMA event graph models can be run directly from within SIGMA. Neither a compiler nor knowledge of C is needed to use SIGMA. However, SIGMA executes models interpretively (translating code as it goes); this is good for interactive model debugging but slow compared to compiled code. In fact, experienced SIGMA users will often rough out the logic of a model graphically, translate the model to an external application, and sometimes even work directly with the generated source code. The compiled simulation application can also be attached to a spreadsheet interface as discussed later in this page.

You create external simulation applications from your SIGMA model simply by clicking your mouse on the Fast ( C Source ) command under the Run menu. The application automatically generates source code based on your model and, after a second, presents you with a dialog box showing the application running.

Image:Carwash_running.png

Editing C Code, or Compiling your own SIGMA-generated C code

There is also the flexibility to be able to edit the C code you generate, and recompile the toolset to see the changes.

Changing the source code in your simulation: Editing Source Code
Compiling your own simulation application: Compiling Simulations with Microsoft C
Understanding C syntax: Reading SIGMA-Generated C Programs

Running Large Experiments using Batch Files

It is easy to use a SIGMA-generated C simulation to make an unattended series of runs with different input settings and place the outputs in different output files. This allows you to run large experiments with many different input conditions automatically (semi-automatically if you have an unlicensed copy of SIGMA). You can let SIGMA execute the required runs while you do something else. Input specification files are sometimes called "experimental frames" and they are simple to use. You simply create a text file with one line holding the input responses you would have typed into the keyboard for each run in your batch of experiments.

Further information: Running Large Experiments using Batch Files

Running a SIGMA simulation from a Spreadsheet

The direct approach to running experiments explained in Running Large Experiments using Batch Files is cumbersome and not satisfactory if the simulation is to be run by people who would like to use your simulator, but are not really interested in the details. A professional, commercial-grade, simulator needs to have an easy-to-use interface. Such an interface is relatively simple to create using Excel.

What you will produce is an Excel spreadsheet with the distinction of having a “run” button that runs a simulation in the background using information from the spreadsheet and producing results that are read back into the spreadsheet. The schematic for such an interface is given in below.

Excel interface: the user sees only a dynamic spreadsheet
Excel interface: the user sees only a dynamic spreadsheet

Here the user only sees their Excel spreadsheet and not the messy details of the simulation experiments, which are hidden behind the spreadsheet.

You can think of a simulation spreadsheet interface as like any other spreadsheet with the significant difference that it is dynamic. That is, the “run” button executes one or more simulators behind the scenes using information from the spreadsheet as input. You then update the spreadsheet by displaying the results of the simulation experiments. Comparing the figure in Running Large Experiments using Batch Files and the figure shown above, shows the obvious advantages of creating an Excel user interface to run your simulation experiments.

A Simple Spreadsheet User Interface

The spreadsheet interface for your simulation can be as simple or elegant as you desire; however, it must perform three essential functions: (1) writing the data files from the spreadsheet for the input to your simulation, (2) running the simulation code using these input files, and (3) reading the simulation output files back into Excel for analysis. Our first spreadsheet interface will perform these three tasks for our carwash simulator, MySigmaSimulation.exe, compiled from the C code, MySigmaSimulation.c translated by SIGMA from the model, carwash.mod. All three tasks will be done by simply clicking on a command button called “Simulate”.

Further information: A Simple Spreadsheet User Interface

A More Elegant Spreadsheet Interface using VBA

A simple customer service center is used to demonstrate how to build an Excel spreadsheet interface for running experiments with a simulation using Visual Basic for Applications (VBA) forms. This interface has all the essential features needed for creating a commercial special-purpose dynamic spreadsheet. It can be used as a template for building other spreadsheet interfaces for SIGMA-generated simulation executables by copying and pasting code from this example into spreadsheet code modules. The source codes for this example are in the XLDEMO2 subfolder that is included with SIGMA. In this section, we first develop a simple SIGMA model of a customer service center. We will then go through a tutorial on how to use a dynamic spreadsheet interface for running experiments with this service center simulator. We will then show how to build the spreadsheet interface using VBA. Visual Basic is an extensive and ever expanding collection of objects for Microsoft Office programs. One does not actually “learn” VBA, like one might learn the language C. The best most users do is to “get acquainted” with the fundamentals of this language, and search the VBA help file or the web for objects that do what they want. This section introduces VBA through the following example.

Further information: A More Elegant Spreadsheet Interface using VBA

Tutorial for using the Service Center Spreadsheet Simulator

The spreadsheet interface used in A More Elegant Spreadsheet Interface using VBA was created using Visual Basic for Applications (VBA) code. VBA is distributed with Excel. The VBA codes included in the XLDEMO2 subdirectory can be used as a template for creating dynamic spreadsheets. Professional spreadsheet interfaces for SIGMA models have been developed that are much more sophisticated than this one, controlling the execution of several different simulators for different scenarios; however, all have the same basic function of writing data and experiment files and calling the simulation executable compiled from the automatically generated C code using the VBA “shell” command. The relationships between different pieces of software (circles) and program types (boxes) involved in creating a dynamic spreadsheet are illustrated below

Software and Program Types Involved In Creating a Dynamic Spreadsheet
Software and Program Types Involved In Creating a Dynamic Spreadsheet

SIGMA runs a model (*.MOD) file and sometimes reads a data (*.DAT) file using the DISK function described in Reading Data File Functions. SIGMA can automatically generate a simulation executable (*.EXE) to run. The simulation executable will read the same data files as SIGMA. The simulation executable can also run a batch of experiments defined in an experimental (*.EXP) file. Excel can be used to create a spreadsheet (*.XLS) that writes any data and experiment files before calling the simulation executable. Details for creating such an interface are given after the service center simulator spreadsheet is explained. The Excel interface for this example is composed of three worksheets and two forms.

Further Example: Tutorial for using the Service Center Spreadsheet Simulator

Creating the Interface

A comprehensive tutorial in creating an Excel interface for a simulation.

Further information: Creating the Interface


Back to Main Page

Personal tools
Navigation