Variables

A variable is a constant or dynamically calculated value and is represented by an oval in the model.

Variables can be useful to synthesize data or supply calibration variables to your model. For instance, in a demographic model, a variable could be created to specify the birth rate. Alternatively, if you have a population model that has multiple age groups, you could dynamically calculate a variable to add up all the age groups and determine the total population size. The model below is an aging chain that does both: Birth Rate is a constant variable, and Total Population sums the three age-group stocks. Note that Total Population is connected with links to each of the three stocks. Without those links it could not reference them (see the next section for more information on links).

{ "engine": "SIMULATION_PACKAGE", "name": "Total Population", "simulation": { "algorithm": "RK1", "time_start": 0, "time_length": 50, "time_step": 0.5, "time_units": "YEARS" }, "elements": [ { "type": "STOCK", "name": "Young Population", "behavior": { "initial_value": "4000", "non_negative": true } }, { "type": "STOCK", "name": "Middle Aged Population", "behavior": { "initial_value": "3000", "non_negative": true } }, { "type": "STOCK", "name": "Old Population", "behavior": { "initial_value": "1500", "non_negative": true } }, { "type": "VARIABLE", "name": "Total Population", "behavior": { "value": "[Young Population] + [Middle Aged Population] + [Old Population]" } }, { "type": "VARIABLE", "name": "Birth Rate", "behavior": { "value": "0.02" }, "display": { "interactive": true, "interactive_min": 0, "interactive_max": 0.05 } }, { "type": "FLOW", "name": "Births", "from": null, "to": "Young Population", "behavior": { "value": "[Total Population] * [Birth Rate]", "non_negative": true } }, { "type": "FLOW", "name": "Maturing", "from": "Young Population", "to": "Middle Aged Population", "behavior": { "value": "[Young Population] / 20", "non_negative": true } }, { "type": "FLOW", "name": "Aging", "from": "Middle Aged Population", "to": "Old Population", "behavior": { "value": "[Middle Aged Population] / 30", "non_negative": true } }, { "type": "FLOW", "name": "Deaths", "from": "Old Population", "to": null, "behavior": { "value": "[Old Population] / 15", "non_negative": true } }, { "type": "LINK", "from": "Young Population", "to": "Total Population" }, { "type": "LINK", "from": "Middle Aged Population", "to": "Total Population" }, { "type": "LINK", "from": "Old Population", "to": "Total Population" }, { "type": "LINK", "from": "Total Population", "to": "Births" }, { "type": "LINK", "from": "Birth Rate", "to": "Births" } ], "visualizations": [ { "name": "Total Population", "type": "TIME_SERIES", "elements": [ "Total Population" ] }, { "name": "Young Population", "type": "TIME_SERIES", "elements": [ "Young Population" ] } ] }

Variables can also be used to create forcing functions which are based on the current time. Insight Maker supports a number of functions that return the current time in the specified units. These functions are: seconds, minutes, hours, days, weeks, and years. The following equation could be used to create a variable that returns the square of the current simulation time as measured in hours:

{"time_units": "HOURS", "time_length": 20} Hours()^2

Sometimes it is hard to decide which parts of your model should be simulated using stocks and which parts with variables. Generally stocks should only be used to model items that have inflows or outflows. If you have a stock in your model without either an inflow or an outflow, it would likely be modeled better with a variable.