| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (7 out of 14)

Creating Variables and Parameters

To create a variable or a parameter:

Variables and parameters share similar icons, a separate icon for each 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 default settings for the different kinds of variables and parameters are:

This type... Has this default setting...
quantitative and text parameters
do not forward chain
symbolic and logical parameters
do forward chain
quantitative and text variables
do not forward chain, breadth first backward chain
symbolic and logical
do forward chain, breadth first backward chain

The allowable values for each type of variable or parameter are:

This item... Can have these settings...
parameters
do [not] forward chain
variables
do [not] forward chain
{do not {seek data |
backward chain} | , depth first backward chain |
breadth first backward chain}

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.

For example, if you want a parameter to cause forward chaining to a rule when it receives a value, the default option for the parameter should be:

This setting indicates that the parameter can forward chain to any rules that reference it. If the rule that references the parameter is not itself invocable via forward chaining, the chaining process comes to a halt.

Defining Debugging and Tracing

The 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.

This variable or parameter type... Can have this value...
quantitative
{unit-of-measure | interval | quantity | float | integer | time-stamp | pure number
float
{unit-of-measure | float | time-stamp |
pure number}

integer
{unit-of-measure | interval | integer |
pure number}

symbolic
symbol
logical
truth-value
text
text

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.

Variables with an initial value behave differently from parameters upon activation. In this context, activation refers to starting or restarting the KB, or activating the workspace of the variable or parameter after KB startup. For a complete description of KB run states and their effect upon activating items, see Operating the Current KB.

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.

If the variable specifies a 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.

If no current value exists, an asterisk appears to the right of the value. If the last recorded value reads 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.

For more information about this attribute, see History Keeping in G2.

All variables have these additional attributes:

The G2 Simulator is a superseded capability. For more information, see Appendix F, Superseded Practices.

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:

Value Description
time-expression
Defines a specific amount of time, such as 10 seconds. You cannot use a subsecond interval for the validity interval.
indefinite
Indicates that the last recorded value is valid indefinitely.
supplied
Specifies that the inference engine computes the validity interval. When supplied is the value for this attribute, inference engine is the only valid data server.


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:

  1. The collection time, which is either the time at which the conclude occurred or an explicitly supplied time in a conclude action.

  2. The expiration time, which is computed as the collection time plus the value of the variable's Validity-interval attribute.

A variable value expires when the current time is greater than the expiration time.

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:

which returns the current expiration status of the variable. The expression:

attempts to invoke data seeking to find a value, and only returns false if the variable has failed to receive a value or if the expression has timed out and is making its final evaluation attempt.


Note: You can override the Validity-interval of a variable by explicitly providing an expiration time as part of a conclude action.

This is how the value of the Validity interval attribute affects the variable's expiration time stamp:

If Validity-interval is: Then:
indefinite
The expiration time stamp becomes the symbol never.
supplied
Values concluded from rules and formulas receive an expiration time stamp that is the minimum of the expirations of the values used to execute the rule or formula. If a value is concluded from a procedure, the expiration time stamp is never. This occurs because procedures can only refer to variable values within a collect data or wait until statement, not within a conclude action.

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.

If your KB requires forward chaining to occur whether the variable's value is new or not, but needs to use an indefinite validity interval, create a whenever rule with a statement such as:

G2 invokes this rule even if the new value is the same as the current value. G2 does not invoke the rule if the time stamp of the new value is either the same as or predates the current 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.

Using a Supplied Interval

A 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:

To obtain a validity interval for the 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:

Other possible sources for obtaining a variable value include rules, formulas, and actions buttons.

Creating a Specific Formula

For variables only, the 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.


Note: The variable must use the inference engine as its data server for G2 to evaluate a specific formula.

Specifying Simulation Details

The G2 Simulator is a superseded capability. For more information, see Appendix F, Superseded Practices.

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.

Data server Description
data-server-alias
Is an alias for a particular data server. You specify the data server that each alias name implies in the Data Server Parameters system table by modifying the Data-service-alias attribute.
inference engine
Tells G2 to get a value from a formula, a generic formula, or to data seek for a value using backward chaining in that order.
GSI data server
Indicates that G2 Gateway (GSI) is the data server. This is the data server used for bridges and other external resources. Refer to the G2 Gateway Bridge Developer's Guide for more information.
GFI data server
GFI is a superseded capability. For more information, see Appendix F, Superseded Practices.
G2 meter
This data server is only applicable for a variable that you have created as a g2-meter. For a description of using G2-meters, see Chapter 44, G2-Meters.
G2 simulator
The G2 Simulator is a superseded capability. For further information, see Appendix F, Superseded Practices.
G2 data server
Tells G2 to get a value from another G2 used during a G2 to G2 connection. For information about such connections, see Chapter 51, G2 to G2 Interface.

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.

You can enter a subsecond value as a default update interval. A subsecond update interval is limited by the scheduler's update interval. For example, if the update interval for the scheduler is set to.5 seconds, setting a variable's update interval to less than that will not have any effect.

If a variable does not have a validity interval, G2 obtains a value for the variable only when necessary as the section Obtaining Requested Values describes.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (7 out of 14)

Copyright © 1997 Gensym Corporation, Inc.