if, initially, unconditionally, when, or whenever. This table shows which methods of invocation G2 supports for each kind of rule:
| Invocation Mechanism | if | initially | unconditionally | when | whenever |
|---|---|---|---|---|---|
|
Event detection
|
|
|
|
|
![]() |
|
Scanning
|
![]() |
|
![]() |
![]() |
|
|
Workspace activation
|
|
![]() |
|
|
|
|
Focusing on or invoking a rule category
|
![]() |
|
![]() |
![]() |
|
For a detailed description of how G2 invokes each kind of rule, see Invoking Rules.
This table shows whether each kind of rule can participate in backward chaining and forward chaining:
For information on how rules participate in backward and forward chaining, see Backward Chaining and Forward Chaining.
If Rules
An if rule specifies a condition, in the form of a truth-value expression, and one or more actions. if rule is:
[for {any | the} generic-reference-expression] ...
if truth-value-expression
then [in order]
action [and action] ...
if the level-in-gallons of tank-1 < empty-level-in-gallons of tank-1
then conclude that the status of tank-1 is empty
if rule is the most flexible kind of rule. An if rule can be invoked using forward and backward chaining, using scanning, and using the focus an invoke actions. An if rule can invoke other rules due to forward chaining and due to backward chaining. To make an
if rule behave like a when rule, edit its Options attribute to include the phrases not invocable via forward chaining and not invocable via backward chaining.
initially rule optionally specifies a condition, in the form of a truth-value expression, and one or more actions. G2 automatically invokes an
initially rule each time its parent KB workspace is activated. After an initially rule executes, G2 automatically disables it. A workspace is automatically activated when you start or restart the current KB. Also, the
activate action explicitly activates a subworkspace configured as an activatable subworkspace. For information about how and when workspaces are activated, see Activating and Deactivating Workspaces.
Tip: If you edit an initially rule after it has been invoked, G2 automatically enables the edited rule, if it otherwise valid to do so.
An initially rule can cause backward chaining and forward chaining to other rules. By default, an initially rule cannot be invoked using forward chaining or backward chaining. You can edit the Options attribute of an initially rule so that it can be invoked using backward chaining, but only from other initially rules. initially rule is:
initially
[for {any | the} generic-reference-expression [unconditionally] ] ...
[ { if truth-value-expression then} ]
[in order]
action [and action] ...
initially rules:
initially if: In this form, the antecedent of the rule can optionally specify one or more for expressions to create a generic rule, and must include a truth-value expression that specifies the condition under which G2 executes its consequent. You form this initially rule like an if rule, for example:
initially
for any demonstration-window DW
if the subworkspace of DW exists
then change the arrow-region icon-color of DW to yellow
initially unconditionally: In this form, the antecedent of the rule can include one or more for expressions and an unconditionally clause. The antecedent for this initially rule always evaluates to 1.0 true. You form this initially rule like an unconditionally rule, for example:
initially
for any valve V
unconditionally
conclude that the status of valve-1 is closed
initially with implied unconditionally: In this form, the antecedent of the rule cannot include a for expression. For example:
initially
inform the operator that
"Validation for [the name of the object O superior to this
workspace] is underway." and
focus on O
initially rules, G2 invokes those initially rules. G2 does not begin scanning other rules until the initially rules upon all newly activated workspaces complete or are suspended (due to backward chaining or data seeking). When the current KB starts, if no enabled workspace contains an initially rule, G2 begins scanning other types of rules immediately. For an activatable subworkspace that contains
initially rules, when G2 explicitly activates that subworkspace due to executing an activate action, G2 does not perform additional scanning of other rules until the initially rules on the newly activated subworkspace complete or are suspended (due to backward chaining or data seeking). If the newly activated workspace has no initially rules, G2 does not interrupt scanning other rules. When any workspace is activated, G2 invokes each
initially rule on the workspace at each rule's declared priority. When each initially rule has completed or is suspended (due to backward chaining or data seeking), G2 schedules scanned rules for the next G2 clock tick.
unconditionally rule specifies one or more actions to perform without a condition. G2 performs the consequent of an unconditionally rule each time the rule is invoked. For example, this unconditionally rule:
unconditionally
conclude that the status of tank-1 is empty
if rule:
if true
then conclude that the status of tank-1 is empty
unconditionally rule is:
[for {any | the} generic-reference-expression] ...
unconditionally
[in order]
action [and action] ...
if rule, an unconditionally rule can be invoked using backward chaining, using scanning, and using the focus or invoke actions. Since an unconditionally rule has no antecedent, it cannot be invoked using forward chaining.
when rule specifies a condition, in the form of a truth-value expression, and one or more actions. A
when rule is like an if rule that cannot be invoked using forward chaining or backward chaining. In this sense, a when rule is like an if rule that includes these phrases in its Options attribute: not invocable via forward chaining, not invocable via backward chaining. A
when rule can be invoked using scanning and using the focus or invoke actions.The syntax for a
when rule is:
[for {any | the} generic-reference-expression] ...
when truth-value-expression
then [in order]
action [and action] ...
when rule:
when the status of any pipe-valve PV1 is broken
then inform the operator that
"[ the name of PV1 ] is broken. Corrective action taken."
and
invoke repair rules for PV1
whenever refers to an event. G2 invokes a whenever rule each time the specific event occurs. The syntax for a whenever rule is:
[for {any | the} generic-reference-expression] ...
whenever event-expression [or event-expression] ...
[and when truth-value-expression]
[in order]
action [and action] ...
whenever any object O is moved by the user
then start align-workspace-objects ( the superior item of O )
whenever rule by using the reserved symbol or. This expression directs G2 to execute the consequent of the rule when any event specified in any of the event expressions in the antecedent occurs. For example:
whenever the level-status TS of any valve V receives a value
or TS fails to receive a value
then invoke heat-safety rules for V
when and specify a truth-value expression, which represents an additional condition that must be satisfied for G2 to perform the consequent of the rule. For example:
whenever the temperature-status TS of any valve V receives a value
and when TS is too-high
then invoke heat-safety rules for V
whenever rule to respond to events produced due to actions that use indirect referencing to affect an item or the value of an attribute. That is, if your KB's processing performs an action that affects an item or an attribute's value, and the action references that item or attribute in an indirect manner, then updating that item's knowledge or that attribute's value does not produce an event that is detectable using a whenever rule. Referencing an item or attribute by means of the
named by symbolic-expression expression, or referencing an item that is a member of a list or array, are examples of indirect referencing. G2 cannot invoke a
whenever rule by using scanning, forward chaining, or backward chaining. G2 ignores the Focal-objects, Focal-classes, and Categories attributes of a whenever rule. G2 does not execute a
whenever rule that refers to a variable in an expression that uses the named by or nearest to phrases.
whenever rule can contain. The general principles described previously in this section apply to all event expressions. The detectable events are:
whenever {variable | parameter | attribute} receives a value}
whenever variable fails to receive a value
whenever variable loses its value
whenever the miles-per-hour of any racing-car R loses its value
then start check-auto-speed (R)
whenever any instance of class is created
whenever any instance of tank T is created
then conclude that total-number-of-tanks = total-number-of-tanks + 1
and start initialize-tank (T)
create action is complete. To detect the creation of an item of any kind, specify ITEM itself as the item.
move action, or can fire in either case. Syntax:
whenever object is moved [by {the user | G2} ]
whenever item is enabled
whenever item is disabled
whenever any currency-exchange CE is disabled
then start exchange-tally (CE)
whenever {item | subworkspace} is activated
whenever {item | subworkspace} is deactivated
whenever the subworkspace of any shuttle S is activated
then conclude that the operational-status of S is active
whenever rules for detecting item deactivation is actually a G2 6.0 capability that is still under development. The capability has been included in G2 5.0 because many requests exist for it, but it does not have a standard interactive interface. Such a rule will not fire unless you set the rule's may-refer-to-inactive-items evaluation attribute to true.
To make a whenever rule for detecting item deactivation operative:
Create an action button to conclude the value of the rule's evaluation-attributes, using the following grammar:
conclude that the may-refer-to-inactive-items of the evaluation-attributes of myrule is true
evaluation-attributes of items are hidden attributes, which are not fully supported in G2 5.0. Do not use them in any way that is not specifically described in the G2 documentation or recommended by Gensym Customer Support.
whenever item {becomes | ceases to be} relation-name item
whenever item becomes related to item
whenever item ceases to be related to item
Two Items Become or Cease to Be Connected
See Detecting Connection and Disconnection Events for information about detecting connection events with whenever rules.