<p>Set the value of a variable. If there is a variable or parameter
in scope with a name matching <i>variableName</i>, then that
variable is the one to be set. If there is no such variable,
then one will be created in the container of this actor.
A variable is in scope if it is contained by the container,
the container's container, or any container above in the hierarchy.
<b>NOTE:</b> We recommend always creating a parameter with
a name matching <i>variableName</i>, because then the model is
explicit about which variable will be set. It also makes it easier
to monitor the variable updates.
</p><p>
The update to the variable
may occur at two different times, depending on the value of the
<it>delayed</it> parameter.
If <i>delayed</i> is true, then the change to
the value of the variable is implemented in a change request, and
consequently will not take hold until the end of the current
top-level iteration. This helps ensure that users of value of the
variable will see changes to the value deterministically
(independent of the schedule of execution of the actors),
assuming there is only a single instance of SetVariable writing
to the variable.
If <i>delayed</i> is false, then the change to the value of
the variable is performed immediately in the fire() method.
This allows more frequent
reconfiguration. However, this can result in nondeterminism if
the variable values are observed by any other actor in
the system. If you are trying to communicate with another
actor without wiring, use the Publisher and Subscriber
actors instead.
</p><p>
If <i>delayed</i> is false, then
the <i>output</i> port produces the same token provided at
the <i>input</i> port when the actor fires, after the
specified variable has been set. This can be used, even with
<i>delayed</i> set to false, to ensure determinacy by
triggering downstream actions only after the variable has
been set.
</p><p>
If <i>delayed</i> is true, then
the <i>output</i> port produces the current value
of the referenced variable. If the referenced variable
does not exist on the first firing, or is not an instance
of Variable, then no output is
produced on the first firing.
</p><p>
The variable can be any attribute that implements
the Settable interface, which includes Parameter.
If it is in addition an instance of
Variable or Parameter, then the input token is used directly to set the
value, and the type of the variable is constrained to be
the same as the type of the input. Otherwise, then input
token is converted to a string and the setExpression() method
on the variable is used to set the value.
</p><p>
For efficiency, the variable update does not automatically
trigger a repaint in Vergil. If the variable value is being used
to create an animation in Vergil, then you should include in the model
an instance of RepaintController, which can be found under
Utilities in the library.
Edward A. Lee, Steve Neuendorffer, Contributor: Blanc, Bert Rodiers
$Id: SetVariable.java 70402 2014-10-23 00:52:20Z cxh $
Ptolemy II 4.0
Red (yuhong)
Red (cxh)
The input port.
The output port.
Parameter that determines when reconfiguration occurs.
The name of the variable in the container to set.