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

Comparing Variables and Parameters

You use variables and parameters in your knowledge base (KB) to represent changing data and as a means of maintaining a history of important values. Within a KB, variables and parameters can exist as autonomous objects, to hold the attribute values of user-defined objects, or as superior classes of your own user-defined variable and parameter classes.

Since all variables and parameters represent a value, you can refer to either in an expression as a value, rather than as an item. For example, this expression, referring to the quantitative variable Q1:

replaces the value of Q1 with 200, since G2 evaluates the variable as a value.

Within a KB, you can use variables and parameters to represent external values. For example, in a KB monitoring a nuclear power plant, variables could represent temperature readings. The reason for using variables or parameters to represent such knowledge is twofold. They:

For more about the interaction with rules, see Variables, Parameters, and Rules.

Parameter Features

In effect, a parameter is a simple variable. Parameters provide a storage space in memory for an inconstant data value that can be updated as often as necessary. In addition to storing a data value, a parameter has these capabilities:

History keeping permits the parameter to save its values over a specified period of time. Once historical data exists, you can display, evaluate, store, and retrieve its contents.

Forward chaining allows the parameter to trigger other events when it receives a value, by invoking rules that refer to it.

A parameter is guaranteed to have a value, and does not require data seeking to obtain one. Parameters supply reliable data sources that all parts of G2 can access.

Variable Features

In contrast, a variable can be thought of as a complex parameter. A variable also stores a data value, keeps history, and can cause forward chaining to rules. Additionally, a variable can:

A variable does not always have a value, and its value can expire.

All variables are capable of having two values concurrently: a value obtained through a data server, and a simulation value. You can save a history of one or both of those values.

The G2 Simulator, which can provide simulation values, is a superseded capability. For more information, see Appendix F, Superseded Practices.

Memory Considerations

As with all items, variables and parameters maintain their capabilities within their attributes, such as Last-recorded-value and Validity-interval.

The chaining capabilities of both items are an exception. Although you specify which chaining options to use in an attribute of a parameter or a variable, the capability is actually a behavioral aspect of the inference engine. As such, it does not severely impact the memory requirements of a parameter or variable.

Since variables have more capabilities than parameters, they require more memory. In addition, the History-keeping-spec attribute for both variables and parameters can require potentially large amounts of storage, depending on its value.

Summary of Variable and Parameter Differences

The following table summarizes the differences between parameters and variables:

Characteristic Variable Parameter
Always has a value


Can have a validity interval


Can receive values from a conclude action


Can receive values from a generic formula


Can receive values from an external data source


Can receive values from a specific formula


Can be referenced directly by a procedure


Can have a history


Has a data server


Must have an initial value


Can cause forward chaining


Can cause backward chaining or other data seeking


Can be the value of an object attribute


Consider these issues when deciding whether to use a variable or a parameter:

If the data value... Then choose a...
Requires a specific data server, such as G2 Gateway, for obtaining values outside of G2
Variable, since you cannot specify a data server in a parameter.
Is time dependent so that the item updates on a regular basis and can expire
Variable, since parameters do not support expiration times.
Requires a value at all times, and does not require a specific data server
Parameter, since a parameter is guaranteed to have a current value and does not have a data server.

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

Copyright © 1997 Gensym Corporation, Inc.