| Prev | Next | Start of Chapter | End of Chapter | Contents | Index | (9 out of 12)

Using Variables and Parameters

You use variables in a diagram to:

In addition, you can use variables or parameters to initiate forward chaining. Thus, use a variable when you need to connect to external data, use the G2 simulator, or use expiration times; otherwise, use a parameter.

Choosing the Type of Variable or Parameter

There are a number of variable and parameter types available. Choose the type that is most specific for the type of data being passed.

The following table describes the various types of variables and parameters:

A variable or
parameter of type...

Passes data in the form of...
Logical
true or false
Quantitative
Floating point number, e.g., 1.2, or integer, e.g., 1
Float
Floating point number, e.g., 1.2
Integer
Integer, e.g., 1
Symbolic
Symbols, e.g., .true, .false, or unknown, high or low, or any class name when connected to an item path
Text
Text strings, e.g., "warning"
Sensor (variables only)
GSI sensor data

Creating a Variable or Parameter

To create a variable or parameter:

Using Variables to Connect to External Data

You can use variables to connect to external data when you use GSI or GFI, either to obtain data from an external source or send data to an external process. See the G2 Standard Interface User's Guide for information about GSI, and the G2 Reference Manual for information about GFI.

To identify the external data source or target:

See the G2 Reference Manual for a discussion of the various types of data servers.

The following figure illustrates a logical variable and its table:



Note: When you set the Data-server attribute to inference engine for a variable, NOL uses the G2 conclude action to change values locally within NOL. When you set the Data-server attribute to anything other than inference engine, however, NOL uses the G2 set action to set the value in the external system.

Creating a Sensor

Sensors are a particular kind of variable that obtains or passes quantitative values from or to external data sources; sensors do not allow the specification of a formula.

To create a sensor:

  1. Select KB Workspace > New Definition > object-definition to create a new class of object.

  2. In the new object's table, specify the Direct-superior-classes as sensor.

  3. Specify the Name of the new object.

  4. Select create instance from the new object's menu to create an instance of the object.

  5. Specify the Data-server for the sensor in the new object's table.

This figure illustrates the sensor class object, a sensor instance, and the default table:


Connecting a Variable or Parameter to a Block

To connect a variable or parameter to a block:

This connection establishes the link between the variable or parameter and the diagram.


Note: Be sure to select Controls > Enable Data Input to enable data to flow into the diagram.
You can connect variables and parameters to the input path of any block, for example, to feed external data into a diagram:


You can also connect variables and parameters to the output path of any block, for example, to send data to an external process or to initiate forward chaining:



Caution: In general, do not create a variable or parameter that both receives data from an input path and sets data onto an output path, because NOL cannot guarantee the order of execution of the variable or parameter relative to other blocks.

Overriding Values of Variables and Parameters

Any variable or parameter connected at the input end of a data, inference, or control path contains two additional menu choices:

To manually override a variable or parameter:

You use this feature to manually feed values into the diagram for testing purposes. For information on the various types of override dialogs that can appear, see "Coercing Data Using Variables and Parameters as Input".

Manually overriding the value of a variable or parameter automatically locks the object, which displays a lock icon associated with the object. A locked object prevents the propagation of values obtained from any data source other than manual. For example, if a rule or procedure concludes a value into a locked variable, or if an external data source passes a new value into the variable, the variable receives the value but does not propagate it onto the path. Manually overriding the value of a locked variable or parameter does propagate the value.

A locked object contains unlock in its menu; an unlocked object contains lock in its menu.

To unlock a locked object:

The following figure illustrates a simple diagram containing a float variable connected to a High Value observation block via a data path. The variable is locked because the user selected override from the menu. The figure also shows the override menu choice and associated dialog box.


Coercing Data Using Variables and Parameters as Input

When using variables and parameters to set values onto a path, the override dialog and the resulting value that appears on the output path depend on two things:

In the simplest case, the value on the path corresponds to the value stored by the variable or parameter to which it is connected. In the example above, the float variable contains a floating point number, which corresponds to the data type passed by the path to which it is connected. Thus, NOL presents the user with a Type-in override dialog for entering a new floating point value.

You can also connect variables and parameters to connection paths where the data types do not correspond. For example, you can connect a float variable to an inference path, which converts the float value to a status and belief value.


Caution: Do not connect more than one output path to a variable or parameter, otherwise the results will be unpredictable.
The following chart summarizes the data coercion that takes place when you use the various types of variables and parameters as input to the four output path types. The cells indicate the type of override dialog that appears and the value on the output path. The shaded cells indicate combinations that cannot exist. See "Examples of Data Coercion Using Variables and Parameters as Input" for examples of the various types of override dialogs.


T y p e
O u t p u t
Data Path Inference Path Control Path
Logical

T/ F Radio Button Discrete belief value (0.0 and 1.0 only)
Output control signal Control signal
Float or Sensor
Type-in Floating point
data value

Belief Slider
Output control signal Control signal
Integer
Type-in Integer data value
Belief Slider
(0 or 1 only)
Discrete belief value (0.0 and 1.0 only)
Output control signal Control signal
Symbolic
Type-in Symbolic data value
T/ F/U Radio Button Discrete belief value (0.0, 0.5, or 1.0)
Output control signal Control signal
Text
Type-in Textual data value

Output control signal Control signal

Examples of Data Coercion Using Variables and Parameters as Input

The following figure illustrates two quantitative parameters connected to a data path using a Summation block. The figure shows the Type-in override dialog for one of the parameters and the table for one of the data paths.


This figure illustrates two logical variables connected to inference paths using an And gate. The figure shows the T/F Radio Button override dialog for one of the variables and the table for one of the inference paths.


This figure illustrates a symbolic variable connected to an inference path using a Not gate. The figure shows the T/F/U Radio Button override dialog for the variable and the table for the inference path.


The next figure illustrates a float variable connected to a control path using a Control Counter block. The figure shows the output control signal dialog for the variable.


Coercing Data Using Variables and Parameters as Output

NOL also coerces data passed into a variable or parameter from a path. The following chart summarizes the data coercion that takes place when you use the various types of variables and parameters as output from the four input path types. The cells indicate the value stored in the variable or parameter based on the input value. The shaded cells indicate combinations that are not possible. See "Examples of Data Coercion Using Variables and Parameters as Output" for examples.


I n p u t
T y p e
Logical Float Integer Symbolic Text
Data Path
false when Data-value
< 0.5
; true when Data- value 0.5

Floating point
Data-value

Data-value rounded to the nearest integer
Symbolic Data-value
(a quantity gives an error)

Textual Data- value
Inference Path
true or false (unknown is ignored)
Belief-value
Discrete integer Belief- value (0 and 1 only, rounded to nearest)
Symbolic Status-value (.true, .false, or unknown)
Textual symbolic Status-value (".TRUE," ".FALSE," or "UNKNOWN")
Control Path

Adds 1.0 to Last-recorded- value
Adds 1 to Last-recorded- value


Examples of Data Coercion Using Variables and Parameters as Output

The following figure shows a Numeric Entry Point connected to a logical variable. The figure shows the Type-in override dialog for the Numeric Entry Point and the table for the logical variable.


The next figure shows a Belief Entry Point connected to a float variable. The figure shows the T/F/U override dialog for the Belief Entry Point and the table for the float variable.


| Prev | Next | Start of Chapter | End of Chapter | Contents | Index | (9 out of 12)

Copyright © 1996, Gensym Corporation, Inc.