Variables
Contents:
Introduction
Synopsis
Variables: are possibly time varying user defined numerical values.
Variables are possibly time varying numerical values. They have an initial value and may periodically reset. Variables may be used in a Trigger condition, as the target or as the right hand side of an operation (see Action Ensemble). Variables which can be computed by a single process individually are marked as local. Local variables do not have any communication overhead. Global variables are updated and read by all process. Note, this may introduce race conditions and the identical reproduction of a simulation can not be guaranteed for identical seeds if the the simulation process depends on the variables value during execution phase.
Specification
Synopsis
Specification: how to define custom variables.
Variables can be defined in Initialization and Interventions
variables: list(variable) [annotation]
variable: id scope initialValue [reset] [annotation]
scope: local | global
Name
|
Type
|
Description
|
|---|---|---|
id
|
An id which has to be unique within the list of variables
|
|
scope
|
local|global
|
The scope for computing a variable (local | global).
|
initialValue
|
\(x \in \mathbb{R}\)
|
The initial value of the variable.
|
reset
|
\(n \in \mathbb{N}\)
|
Optionally the variable may be reset to the initial value ever \(n\)
simulation steps
|
ann:*
|
Optional annotation of the variable
|
The normative JSON schema can be found at: variable
Examples
Local variable:
Maintaining a weekday. The variable week_day is incremented by one every tick is reset every 7 days.
"variables": [
{
"id": "week_day",
"initialValue": 0,
"scope": "local",
"reset": 7
}
],
"interventions": [
{
"ann:id": "maintain_week_day",
"ann:label": "update the week_day",
"trigger": {
"value": true
},
"target": {
"set": {
"idRef": "%empty%"
}
},
"once": [
{
"operations": [
{
"target": {
"variable": {
"idRef": "week_day"
}
},
"operator": "+=",
"value": {
"number": 1
}
}
]
}
]
}
]
Global variable:
30% of symptomatic individuals are receiving a prophylactic treatment which reduces the infectivity to 20%. If and only if the daily limit (500) and total limit (20,000) is not surpassed. This example introduces the above mentioned race condition when computed in more that one process/thread.
"variables": [
{
"id": "totalTreatments",
"ann:label": "Total Treatments",
"scope": "global",
"initialValue": 0
},
{
"id": "dailyTreatments",
"ann:label": "Daily Treatments",
"scope": "global",
"initialValue": 0,
"reset": 1
}
],
"interventions": [
{
"$comment": "Treatment",
"trigger": {
"operator": ">",
"left": {
"sizeof": {
"set": {
"idRef": "enteredIsymp"
}
}
},
"right": {
"value": {
"number": 0
}
}
},
"target": {
"set": {
"idRef": "enteredIsymp"
}
},
"sampling": {
"type": "individual",
"number": 30,
"sampled": {
"foreach": [
{
"delay": 1,
"condition": {
"and": [
{
"left": {
"variable": {
"idRef": "dailyTreatments"
}
},
"operator": "<",
"right": {
"value": {
"number": 500
}
}
},
{
"left": {
"variable": {
"idRef": "totalTreatments"
}
},
"operator": "<",
"right": {
"value": {
"number": 20000
}
}
}
]
},
"operations": [
{
"target": {
"variable": {
"idRef": "dailyTreatments"
}
},
"operator": "+=",
"value": {
"number": 1
}
},
{
"target": {
"variable": {
"idRef": "totalTreatments"
}
},
"operator": "+=",
"value": {
"number": 1
}
},
{
"target": {
"node": {
"property": "infectivityFactor"
}
},
"operator": "*=",
"value": {
"number": 0.2
}
},
{
"target": {
"node": {
"property": "nodeTrait",
"feature": "treatment"
}
},
"operator": "=",
"value": {
"trait": "nodeTrait",
"feature": "treatment",
"enum": "true"
}
}
]
},
{
"delay": 6,
"condition": {
"left": {
"node": {
"property": "nodeTrait",
"feature": "treatment"
}
},
"operator": "==",
"right": {
"value": {
"trait": "nodeTrait",
"feature": "treatment",
"enum": "true"
}
}
},
"operations": [
{
"target": {
"node": {
"property": "infectivityFactor"
}
},
"operator": "/=",
"value": {
"number": 0.2
}
},
{
"target": {
"node": {
"property": "nodeTrait",
"feature": "treatment"
}
},
"operator": "=",
"value": {
"trait": "nodeTrait",
"feature": "treatment",
"enum": "false"
}
}
]
}
]
}
}
}
]