 | Run Contexts and how World Modeler runs models |
◂ Prev
Next ▸
A simple model in World Modeler
The diagram below is from World Modeler's authoring environment and shows a very simple model.
A very simple World Modeler Model
The model shown in the left panel, above, has two input Attributes, initialized to 5 and 4 respectively via the formulas associated with
each of them, and a single output Attribute whose formula sets its value to the sum of the inputs.
When this model is run, the output value will obviously be 9.
But what if we desire a situation where this is just the first of many runs—in particular, suppose we wish to use
World Modeler's automated
Simulation Timer capability which continuously re-runs the model evaluation until it is explicitly stopped, or a given
condition becomes true. Again, to keep the model simple, suppose we wish each
successive run increment the value of each of the Input Attributes by 1, and re-calculate the Output with the new inputs. To do this, we must somehow
specify that a
second formula is associated with each of the inputs, telling World Modeler how to evaluate the Input
Attributes each time the simulation timer initiates another run. In addition, even if we could add a second formula to each Attribute,
World Modeler stil needs to know which formula to run when. This is handled by introducing the concept of a
Run Context.
Handling different Run Contexts
When World Modeler kicks off an evaluation run of a model, it is always in response to some kind of event. The
type of event is used to set the
Run Context associated with a given evaluation run of the model, and World
Modeler allows different formulas to be used to specify the value of an Attribute in different Run Contexts. By associating
multiple Formulas with a single Attribute, with each Formula bound to a particular Run Context, the value of any Attribute can be set by
a different expression in each context. Looking at the panel on the right of the above diagram, we see that both Input1 and
Input2 now have two formulas associated with them—the original initializer, plus an additional formula associated with
the
Timer Run Context that specifies how each of the attributes should be incremented for each model run initated by
the simulation timer.
The three most common Run Context flows (interactive/programmatic update in blue, simulation timer in orange, and Entity Instance creation in green)
and the events that trigger a model calculation are shown in the diagram below.
The most common Run Context sequences in World Modeler model evaluation.
While there is a lot of richness in this scheme, in practice, almost all formulas are bound either the
Init Run Context (usually for
independent Attributes), or the
All Run Context (for dependent Attributes)—a special value that binds the Formula to all
Run Contexts.