To create a variable or a parameter:
Choose KB Workspace > New Object > variable-or-parameter
where variable-or-parameter is either variable or parameter from the New Object menu. After you select either choice, G2 displays a secondary menu from which to choose a particular type.
![]() |
Specifying Forward and Backward Chaining
For parameters and variables, the Options attribute controls whether a new value causes forward chaining. For variables only, the attribute also controls whether G2 can data seek and use backward chaining. If backward chaining is in use, the attribute specifies the type to use (breadth first- or depth first-backward chaining).
The allowable values for each type of variable or parameter are:
Use caution when setting or changing the value of the
Options attribute. Whatever you specify in this attribute, or whatever default value it provides, should correspond directly with any rule that references the parameter or variable.
do forward chain
Tracing-and-breakpoints attribute defines the level of tracing and breakpoints for the variable or parameter. This attribute and its values are described in Chapter 42, Debugging and Tracing.
The
Tracing-and-breakpoints-enabled? attribute of the system table must have a value of yes for this attribute to take effect. Specifying the Type
The Data-type attribute specifies the type for the variable or parameter. You cannot edit this attribute for symbolic, logical, and text variables and parameters. These are the allowable values for each variable and parameter. The default in each case appears in bold.
Specifying an Initial Value
The Initial-value attribute specifies an initial value for the variable or parameter, which is dependent on the type. If you do not specify an initial value for a variable, G2 supplies the value none. Here is the default initial value for each type of parameter:
| This item... | Has this initial value... |
|---|---|
|
quantitative parameter
|
0.0
|
|
float parameter
|
0.0
|
|
integer parameter
|
0
|
|
symbolic parameter
|
g2
|
|
logical parameter
|
false
|
|
text parameter
|
""
|
Hint: If you are maintaining historical data on a parameter or variable (using the History-keeping-spec attribute), the value you provide in the Initial-value attribute is used as an initial historical data point.
You can supply initial values in individual instances of variables or parameters, or in user-defined object definitions.
For variables, G2 concludes the initial value as the value of the variable, with its collection time set to the activation time. Activating a variable with an initial value, therefore, causes forward chaining. If the variable is keeping history, the initial value is inserted into the history as if it had been collected from a data server.
Note: When using a variable as an external output, an activate event does not have the same effect as a set action. While a set action can transmit a value to the external facility, G2 does not transmit the initial value when an activate event occurs.
Parameters have an initial value by default, even if you do not provide one, because they are guaranteed to have a value at all times. When a KB is reset, parameters revert to their initial value, and do nothing upon activation. Thus, parameters do not forward chain from activation. If the parameter is keeping history, activating the parameter inserts the initial value into history as the first collected value. Obtaining the Last Recorded Value
The Last-recorded-value attribute displays the value that G2 last concluded, collected, calculated, inferred, or received for the variable or parameter. You cannot change this attribute. Validity-interval, the Last-recorded-value may not be current. If the value has expired, it is has an Expired suffix, and if it is current, it is suffixed by the word Expires, followed by the expiration time. no value, G2 has not yet found a value for the variable.
Hint: Expiration of a variable's value does not cause data seeking. G2 seeks for a value only upon request when the value has expired. For the causes of data seeking, see Obtaining Values for Variables.
Specifying Whether to Keep a History of Values
The History-keeping-spec attribute indicates whether to keep a history of values for the variable or parameter. If the item is keeping a history of values, the attribute can also specify the maximum number of values to keep, and how long to keep each value.
All variables have these additional attributes:
Validity-interval
Formula
Simulation-details
Initial-value-for-simulation
Data-server
Default-update-interval
Specifying a Validity Interval
For variables, the Validity-interval attribute specifies the length of time that the value of the Last-recorded-value remains current. Enter a value for this attribute as follows:
Caution: If you are using a Default-update-interval for the variable and you set the Validity-interval to less than the update interval, the variable will constantly expire.
Effect of Validity Interval on Expiration Time Stamp
When a value is concluded into a variable, G2 stores two time stamps:
conclude action.
Validity-interval attribute.
You can detect interactively that a value has expired by examining an attribute table showing the variable value. G2 updates attribute tables when a variable expires, so you can leave the table on display and watch for changes.
You can detect programmatically that a value variable has expired with the statement:
if variable has a current value
if variable has a value
false if the variable has failed to receive a value or if the expression has timed out and is making its final evaluation attempt.
Validity-interval of a variable by explicitly providing an expiration time as part of a conclude action. Validity interval attribute affects the variable's expiration time stamp:
Setting the
Validity-interval attribute also has a direct effect on the variable's forward chaining capabilities, if the variable permits forward chaining. Using a Specific Interval
A specific validity interval, indicating that a current value expires at some point, always causes forward chaining to occur when the variable receives a value. Using an Indefinite Interval
An indefinite validity interval causes forward chaining only if the new value received is different than the previous value. Forward chaining then becomes a response only to new information. indefinite validity interval, create a whenever rule with a statement such as:
whenevervariablereceives a value...
The reason for this is that G2 only invokes a
whenever variable receives a value rule when the time stamp of any new value is later than that of the current value. A value whose time stamp is identical to or earlier than that of the current value is not considered new. If the variable is maintaining history, G2 stores older time stamp values in history, but does not invoke the whenever rule.
supplied validity interval is applicable when G2 computes the value of the current variable using other variables. The data server for a supplied validity interval must be inference engine. When the validity interval is
supplied, the inference engine obtains a validity interval from the variables used to calculate or infer a value. Specifically, the inference engine uses the shortest available value. For example, consider that the volume of a tank-1 object is given by a float variable with a supplied validity interval, and G2 uses this expression to compute a value for volume:
the area of tank-1 * the level of tank-1
volume variable, G2 checks the intervals of the area and level variables, and then uses the shorter interval of the two. If a variable has a
supplied validity interval, but is not getting its value from other variables, G2 infers that the validity interval is indefinite. An exception to this is when an update source for a variable with a
supplied validity interval includes a conclude statement specifying a validity interval, using a with expiration statement such as:
conclude that level = 100 with expiration 10 seconds
Formula attribute includes a specific formula that G2 uses to compute a value for the variable. When a variable includes a formula, G2 calculates it only when the variable needs a new value.
Determining the Initial Simulation Value
The G2 Simulator is a superseded capability. For more information, see Appendix F, Superseded Practices.
Specifying a Data Server
For variables only, the Data-server attribute specifies which data server G2 uses to obtain a value for the variable. If you are using a formula, you must use inference-engine as the data-server.
Specifying a Default Update Interval
For variables only, the Default-update-interval attribute directs G2 to obtain a value for a variable at regular time intervals. For example, if the variable's Default update interval is 2 minutes, G2 obtains a value for the variable every two minutes, independent of whether it needs to for some other reason. .5 seconds, setting a variable's update interval to less than that will not have any effect.