Archive

Posts Tagged ‘command line’

Connecting iThink and STELLA to a Database

April 28th, 2011 5 comments

A question we periodically get from our customers is: Can iThink or STELLA connect to a database? Saving and pulling information to/from databases presents a lot of advantages for storing, organizing and sharing model data. Thanks to iThink and STELLA’s ability to import and export data via commonly used spreadsheet file formats, it is possible to use comma separated value (CSV) files as a means to create a connection to database applications.

Essentially, data can be moved between a database and iThink/STELLA by using a CSV file as a bridge. CSV files are a widely supported file standard for storing table data, and both iThink/STELLA and many database programs are able to read and write to them.

Process overview

The process of connecting to a database using CSV files as an intermediary

The process can be automated when you use iThink/STELLA’s ability to run models automatically from the command line (Windows only). Most database applications also have command line interfaces, allowing you to create a single macro script that moves data between your model and a database in a single process.

In this post I will use a simple example to demonstrate how to import data from a Microsoft SQL Server database into an iThink model on Windows. The model and all files associated with the import process are available by clicking here. If you don’t have access to Microsoft SQL Server, you can download a free developer’s version called SQL Server Express from the Microsoft web site.

The Model

The model used in this example is a variation of the Beer Game model. The structure shown below represents the ordering process for a simple retailer supply chain.

Retail Supply Chain Model

The model has been set up to import the initial values for On Order with Wholesaler and Unfilled Orders stocks, target inventory and actual customer orders (a graphical function with 21 weeks of data). The source of the imported data is the file named import.csv in the example files.

To set up this example, I manually created the CSV file using the initial model parameters. (Later in this post, you’ll see that this file will be automatically created by the database.) The model has been initialized in a steady state with actual customer orders at a constant level of 4 cases per week over the 21 week period.

Read more…

Running Models from the Command Line

March 20th, 2009 4 comments

Version 9.1.2 introduces the oft-requested ability to run models from the command line outside of iThink or STELLA (Windows only).  This feature opens up a number of possibilities for users who need to automate their modeling tasks.  For example, you could use the command line to automatically run a model multiple times, start a model from a script, or create a shortcut that opens and runs a model when you double-click on the icon.

I have set up a simple example that illustrates how you could run an iThink model multiple times to skirt the 32,767 time step limit that advanced users sometimes run up against.  The model itself does nothing extraordinary, it simply increments the value of a Stock by one at each time step. What makes it worth noticing is that it runs 32,000 iterations three times to mimic a 96,000 step run.

>> Download the Sample Files

This example will open and run the model file named multiple_run.itm, import data at the beginning of each run, and export data at the end of each run.  You can double-click on the “Start batch runs” shortcut to kick things off or you can use the batch file that is provided. Note that you may have to edit these start files to make them work on your computer

Command Line Syntax

"c:\program files\isee systems\iThink 9.1.2\iThink.exe" -rn 3 multiple_run.itm

Shortcut Properties

The command line above was entered into the ”Target” field of the “Start batch runs” Properties dialog.  Note the “Start in” field is intentionally left blank so that the shortcut will run the model from the current directory.  If you move the shortcut file to a different directory,  you’ll need to enter that directory into this field.

The identical command line syntax is used in the supplied batch file named “go.bat” and can be edited using Notepad.

Sample Model and Spreadsheet

The sample model uses a table to report the value of the Stock at the end of each run so that it can be exported to the “multiple_run_data.xls” Excel file. In Excel, I linked the exported value of the Stock to an “Import” worksheet.   This way, one run hands off the final data to start the subsequent run like runners in a relay race passing a baton.  Note the initial Stock value will need to be reset in Excel before starting a new batch of runs.

Running the sample command line puts iThink into a macro mode.  It opens just as if you double-clicked its icon and manually started the runs yourself.   Sit back and watch the model open, and let the model run three times on its own.  Try to leave the process alone while it executes, I did find that if the runs were interrupted the Excel file could sometimes lose its formatting.

For an experiment you could add “-nq” to the command so that the model stays open after running.  After adding the new parameter your command would look like this:

"c:\program files\isee systems\iThink 9.1.2\iThink.exe" -rn 3 -nq multiple_run.itm


There are many more command options available.  View the full list here and experiment with other parameters.

UPDATE:

Another advantage to running from the command line is that you can start and run a model from inside Excel. Not only can you run the model this way, but you can take advantage of all the parameters.

Create a shortcut as described in the post and save it. In Excel, pick a cell and select Insert hyperlink. Browse to and select the shortcut and then click OK. It’s that easy!!