Typically, subscripted constants will take on a number of values. For example:
birth fraction[MEXICO] = 0.03 ~~|
birth fraction[USA] = 0.02 ~~|
birth fraction[CANADA] = 0.02
~ | fraction |
~ | Fertility as a fraction of population. |
|
You can replace these three equations with:
BIRTH FRACTION[country]=0.03,0.02,0.02 ~ fraction ~|
In this notation the order is that of the defining equation for country.
It is also possible to define two dimensional arrays of values by separating the rows with semi colons. For example:
blood type : A, B, O, AB ~~|
initial population[country,blood type] = 1,2,3,4;5,6,7,8; |
9,10,11,12; ~Person~| |
This is a compact way of setting up arrays of numbers. There are also two functions that can make it convenient to set up arrays of numbers from spreadsheets. One is the TABBED ARRAY function. It allows you to write an array list using tabs between numbers and carriage returns between rows as in:
initial population[country,blood type] = TABBED ARRAY( |
1 2 3 4 |
5 6 7 8 |
9 10 11 12) ~Person~| |
This has the same meaning as the first equation but has the advantage that it can simply be pasted from a spreadsheet into the inside of the TABBED ARRAY function.
Closely related to this are the functions GET 123 CONSTANTS, GET XLS CONSTANTS and GET DIRECT CONSTANTS that allow you to query Lotus 123 or Microsoft Excel to get values to fill an array. These constants are updated whenever the model is simulated so that any changes in the source spreadsheets will be seen in the simulation.
initial population[country,blood type] = GET XLS DATA( 'mymod.xls','PopTab','G8') ~Person~|
This will read values from the tab 'PopTab' in the spreadsheet mymod.xls starting in cell G8. Just as for the earlier examples blood type will be read across (columns G, H, I and J) and country will be read down (rows 8,9 and 10).
If you have a constant with more than 2 subscripts it will be necessary to write multiple equations for it with each equation having no more than 2 subscript ranges. For example:
sex : female,male ~~|
ini population[country,blood type,female] = 1,2,3,4;5,6,7,8; |
9,10,11,12; ~~| |
ini population[country,blood type,male] = 1,2,3,4;5,6,7,8; |
9,10,11,12; ~ Person ~| |
The position of the Subscript Ranges is arbitrary. male/female could have gone first, second or last as it does above. The last Subscript Range (blood type) determines the meaning of the values within a group or row, the first (country) the meaning of the different groups or rows.
Unchangeable Constants
All of the above discussion applies to Unchangeable Constants as well. In each case the = assignment is replace by == as in:
initial population[country,blood type]
== GET XLS CONSTANTS( 'mymod.xls','PopTab','G8') ~Person~|
Note that when defined this way initial population will only be read from the spreadsheet when the model is checked. If, for example, the model is saved as a .vmf file then Vensim will not even open the spreadsheet when the model is simulated.