Multi-dimensional Arrays
SIMUL8 2008 was released last week. It contains lots of great new features but we're particularly excited about multidimensional arrays.
SIMUL8 has had 2 dimensional arrays in the form of Information Store spreadsheets for many years. What is new, however, is the ability to specify more than 2 dimensions. In fact, now you can have as many as you want!
What is an array?
An array is a variable type. Officially its "a series of elements placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier". You create an array, say myarray, and specify how many positions are available in the array, so perhaps 5. Then for each position 1 to 5 you set the value. Then at any time you can reference the position in the array to get the value stored, so myarray[4] would get me the value stored in position 4.
Translated that means they're very like tables.If you imagine a table with only 1 row and 5 columns, then each bit of information typed in the column is my data at position x, then this is like the array described above.
What is a multi-dimensional array?
A multi-dimensional array is the same as an array but they have more than one index. So instead of having just one row in my table, I have multiple rows and then I'd have to reference it at say myarray[2,3]. That's where the table example ends beyond this arrays get very difficult to visualize so I've tried to provide examples below:
- 2 dimensional arrays: A spreadsheet!
- 3 dimensional arrays: A Rubik Cube! Or a Microsoft Workbook with multiple Worksheets!
- 4 dimensional arrays: Boxes of Rubik’s Cubes!
So what's so great about multi-dimensional arrays? Now we can organize our data and collect results in a much more consolidated way!
Creating your Multi-dimensional Array
You can create an array in SIMUL8 from the Information Store. Here you can specify the number of dimensions you need. We've provided a viewing tool so that you can see and edit your array values directly from the Information Store. Alternatively you can set the values through Visual Logic using the general SET command. You can also empty and alter the dimensions of your array through Visual Logic.
An Example
Collecting time based results is probably the most common use of multi-dimensional arrays. If you wanted to collect the throughput of 10 products by hour of day, by day of week, by month of year etc. you could set up an array with these dimensions e.g. 10, 24, 7, 53 (10 products by 24 hours in a day by 7 days a week by a maximum of 53 weeks in a year). To collect the results all we need to do is set up a single line of Visual Logic in the object we wish to record the throughput.
SET ra_Throughput[lbl_Product,HOUR[Simulation Time]+1,DAY[Simulation Time], WEEK[Simulation Time]] = ra_Throughput[lbl_Product,HOUR[Simulation Time]+1,DAY[Simulation Time], WEEK[Simulation Time]] + 1
Where ra_Throughput is a multi-dimensional array and lbl_Product is a number label holding a value between 1 and 10.
Then at the end of the scenario we could create a flat-file version of the array by writing the data to a spreadsheet using loops.
Clear Sheet ss_Results[1,1]
' Set the value of a local variable to hold the row in the spreadsheet we are writing the data to
' Write headers to the spreadsheet
SET lcl_Row = 1
SET ss_Results[1,1] = "Product"
SET ss_Results[2,1] = "Week"
SET ss_Results[3,1] = "Day"
LOOP 1 >>> LoopHour >>> 24
SET ss_Results[3 + LoopHour,1] = LoopHour
' Now write out results to sheet
' Loop through each product
LOOP 1 >>> LoopProduct >>> 10
' Loop through each week
LOOP 1 >>> LoopWeek >>> 53
' Loop through each day
LOOP 1 >>> LoopDay >>> 7
' Write out results for each day in the row
SET lcl_Row = lcl_Row + 1
SET ss_Results[1,lcl_Row] = LoopProduct
SET ss_Results[2,lcl_Row] = LoopWeek
SET ss_Results[3,lcl_Row] = LoopDay
' Loop through each hour
LOOP 1 >>> LoopHour >>> 24
SET ss_Results[3+LoopHour, lcl_Row] = ra_Throughout[LoopProduct,LoopHour,LoopDay,LoopWeek] |
This code will write out the result illustrated below.

Each row provides the results for throughput of a single product for a particular day in a week. The hours of the day are shown in the columns of the spreadsheet.
Therefore for 10 products over 53 weeks with 7 days per week, there are 3710 (10 * 53 * 7) rows of results.
These results can then be exported/copied to Microsoft EXCEL for further analysis. Using Filters, Pivot Tables or the clever use of the OFFSET function can allow significant analysis on these types of results to be performed.
If you have any questions about multi-dimensional arrays email support@SIMUL8.com we're happy to help.

SIMUL8 2008 Released
Upgrade today for:
- 30% faster - SIMUL8 has always been fast but now it's even faster!
- Results Manager - centralized results and fully customizable reports .
- Better Resource Handling - Assign by matrix and new waiting for resource result.
See the 2008 Feature Tour for full details.

|