Referencing Large Arrays with Sets, VAR and MEMBER
By Gail Kenny, Simulation Consultant
Published: January 23, 2017
Categories: Tips & Tricks
When developing a model of a large system, you may have multiple large two-dimensional variable arrays that describe equipment parameters, facility characteristics, or other aspects of your system. Many times you can streamline your modeling effort by collecting these two-dimensional arrays under one “umbrella” and then pointing to the specific piece of information where needed in your logic. For instance, let’s say your supply chain model needs to define specific information for several different sites. Each site has up to 1000 SKUs and each SKU has a unique activity time for up to 20 activities. For clarity, you want to have each site’s information stored in its own uniquely-named, two-dimensional variable array. Furthermore, you anticipate the logic for the activities at each site will be similar, regardless of the site. Only the actual data values are expected to be different.
There are two approaches you could take with the above scenario. The first approach is to build logic to represent site A and refer to A’s variable array within the logic, then build almost identical logic to represent site B and refer to B’s variable array within that logic, and so on. This approach is certainly acceptable, but implementing so much repetitive logic gets a little tedious. The second approach leverages the capabilities of Sets, the VAR predefined Arena variable, and the MEMBER predefined Arena variable to streamline the model-building process.
We know that a Set, by definition, can hold multiple elements of the same type so they may be referenced directly by name, or by the Set name and a pointer to the member of the set you’re interested in (called a Set Index in the module prompts). Variables are considered an element type within Arena. So what’s to stop us from having a Set of Variables? Absolutely nothing!
First, define the two-dimensional variable arrays you wish to use. If you want to populate your variables using Arena’s Direct Read functionality, please see Connecting Models to Live Data from Issue #2 of the Arena Newsletter.
Next, you must define a set of variables using the Advanced Set module of type Other. The members of the set are the two-dimensional variables you wish to use.
In order to use the correct variable values in our model logic, we must know about the VAR and MEMBER predefined Arena variables.
To return the desired member of a set, we need to know the name or number of the set and the position of the needed set member. Commonly, we would reference the member of the set as follows:
Set ID (Index)
- Set ID – the name or number of the set to be examined
- Index – position in the set to be examined
Alternatively, you can accomplish the same thing using the MEMBER variable. The MEMBER variable returns the construct number of a particular set member and has the following syntax:
MEMBER (Set ID, Index)
So either All Sites SET (1) or MEMBER (All Sites SET, 1) could be used to point to the v Info Site A variable, which is the first member of the set. However, we have a problem with this. In order to use our variable information in our model logic, we don’t want to point at the variable name, we want to point at the values contained within the variable. To access a value from within one of our variables, we can use the VAR variable. Its syntax is:
VAR(Variable Number [, Index 1, Index 2])
- Variable Number – the construct number of the variable to get or set
- Index 1 – the variable row
- Index 2 – the variable column
Notice that the VAR variable requires the construct number of the variable in its syntax. Since the MEMBER variable returns the construct number of a set member, we can combine VAR and MEMBER in the following way:
VAR (MEMBER (Set Name, Set Index), Row Index, Column Index)
Or, using our example:
VAR (MEMBER (All Sites SET, a Site Point), a SKU Point, a Activity Point)
- a Site Point – attribute storing the set position of the variable we are interested in
- a SKU Point – attribute storing the variable row we are interested in
- a Activity Point – attribute storing the variable column we are interested in
Entities having different values for a Site Point, a SKU Point, and a Activity Point can all flow through the same logic module containing this expression and point to the value contained in the designated row and column of the specified variable. Result? A model with fewer sections of repetitive logic and a more elegant design.
P.S. – If you like using VAR with Variables, try out EXPR with Expressions.
Sign up for the Blog
Arena User Group
Arena has a very active user community on LinkedIn. Ask questions, learn about best practices and connect with other simulation professionals.