When G2 invokes a rule, G2 creates a task called a rule invocation. Each rule invocation is a copy of the information in the invoked rule.
Truth-threshold attribute of the Inference Engine Parameters system table. Prioritizing Rules
Every rule has a priority that determines how G2 schedules rule invocations for that rule. By default, the scheduler executes rules at a priority of 6.
To override the default priority for executing a rule:
Specify a value for the Rule-priority attribute of the rule.
Scheduling tasks by priority becomes important in the unusual case when G2 is working at maximum capacity. G2 can postpone the execution of the lowest priority tasks until the next G2 clock tick. Therefore, you should use priorities to identify what tasks can safely be postponed if necessary.
Each time G2 completes a task, G2 starts executing the next highest task in the task list for the current G2 clock tick. If a task with priority 1 comes in while G2 is performing a priority 2 task, then after the priority 2 task completes, G2 starts executing the priority 1 task.
At each G2 clock tick, G2 begins performing the tasks that the scheduler has associated with that clock tick. For a given clock tick, G2 begins performing tasks with a higher priority before those with a lower priority. However, G2 must suspend some tasks, or put them into a waiting state, before they can complete. This means that a task with a high priority that has already begun, and that must be suspended for some reason, might not complete before another task with a lower priority begins and completes.
One example of this is the activity of evaluating the antecedent of a rule that can backward chain to other rules. Evaluating the antecedent of a rule might require invoking another rule that concludes a value for a variable or that causes data seeking.
For example, if rule
R1 is declared to have a Rule-priority of 3, and rule R2 is declared to have a Rule-priority of 5, and both rule R1 and R2 backward chain to rule R3 that declares a Rule-priority of 8, then G2 creates and invokes a rule invocation for rule R3 that has the priority 3. If G2 cancels the rule invocation for rule
R1 for any reason, G2 does not reschedule rule R3 with a Rule-priority of 5; rule R3 retains its Rule-priority setting of 3.
focus or invoke action.
To set the timeout interval for a rule:
Specify a time interval for the Timeout-for-rule-completion attribute of the rule.
Timeout-for-inference-completion attribute in the Inference Engine Parameters system table. G2 uses the latter attribute as the timeout interval for rules whose Timeout-for-rule-completion attribute contains the value use default. Depending on the nature of the values that your rules and procedures manipulate, setting long time intervals for the completion of your rules can lead to inconsistencies in your KB's knowledge.
For instance, if the values of variables are periodically unavailable to your rules, you should create
whenever rules that respond to the event expression does not receive a value. A variable does not receive a value when its validity interval has expired, as declared in its Validity-interval attribute.
G2 executes each rule invocation in several stages, as follows:
Timeout-for-rule-completion attribute of the rule, G2 performs the appropriate time-out processing. See Evaluating the Antecedent.
in order phrase, then G2 performs the actions in the consequent sequentially.
in order phrase, then G2 executes the actions in the consequent in parallel.
Timeout-for-rule-completion time interval, G2 performs the appropriate time-out processing.
Timeout-for-rule-completion attribute setting, G2 performs time-out processing. This means G2 makes one final attempt to evaluate the complete antecedent:
in order is present. If the phrase is not present, G2 first attempts to evaluate all the expressions in all the actions in the consequent. After G2 successfully evaluates all expressions in the consequent, G2 schedules all actions to be performed in parallel, in other words, within the same transaction scope. For information about the scope of a transaction, see Understanding Transactions and Transaction Scopes.
Evaluating all the expressions in the consequent might require G2 to suspend this rule invocation, so that G2 can perform data seeking to obtain values.
Time-Out Processing
If G2 cannot evaluate all the expressions in the consequent within the declared Timeout-for-rule-completion time interval, G2 performs time-out processing. This means that G2 makes a final attempt to evaluate all the expressions in the consequent as follows:
This means that each action begins executing with the same context of information. For example, if the expressions in any two consequent actions refer to the same item or value, G2 evaluates those expressions by starting with the same set of items or values.
Example 1: The following rule includes two actions that increment the variable X:
unconditionally
conclude that X = X + 1 and
conclude that X = X + 1
Example 2: The two actions in the next rule increment the variable
X by differing amounts:
unconditionally
conclude that X = X + 1 and
conclude that X = X + 3
conclude actions start with the same source value for X, when the rule completes successfully, the value of X will be incremented by 3. this is because, among actions that execute in parallel and that update the same value, the action specified last in the rule determines the new value after the rule completes. Example 3: The consequent actions in this rule refer to the variable that gives the value of the
Minimum-temperature of tank-1:
if the temperature-measured of tank-1
then conclude that
the minimum-temperature of tank-1 = min (the temperature of tank-1,
the minimum-temperature of tank-1)
and conclude that the global-minimum-temperature of tank-monitor
= min (the minimum-temperature of tank-1, the minimum-temperature of
tank-monitor)
Minimum-temperature of tank-1 for each conclude action. If the purpose of the
Global-minimum-temperature of tank-monitor is to store the minimum temperature ever recorded for any tank monitor in the KB, then this rule concludes the value of the Global-minimum-temperature of tank-monitor incorrectly. This is because the second conclude action uses a value for the Minimum-temperature of tank-1 that does not include the calculation performed in the first conclude action. Therefore, this rule should be rewritten by using sequential execution (described below).Also, because G2 executes consequent actions within one transaction scope, after the actions start executing, G2 allows no other KB processing to take place until all the consequent actions finish executing.
in order is present. If it is present, G2 prepares to perform the actions in the consequent in sequence. G2 evaluates the expression in the first action in the consequent, then executes the action, and so on for every action in the consequent. When performing the actions in the consequent of a rule sequentially, G2 executes each action within its own transaction scope, as described in One Transaction Scope Per Consequent Action.
If executing any consequent action depends upon obtaining a new current value for any variable, G2 suspends this rule invocation and sets a wake-up flag on each variable without a current value that is referenced in that action.
Time-Out Processing
If G2 cannot perform all consequent actions in sequence within the declared Timeout-for-rule-completion time interval, G2 performs time-out processing. For instance, if a rule invocation is suspended because an action contains an expression that refers to a variable, and the action has been waiting for a new current value for that variable, G2 wakes up the rule and performs time-out processing, as follows:
inform actions without having the values of all variables; G2 displays expired current values for variables with asterisks.
For example, G2 performs these consequent actions sequentially:
for any demonstration-window DW
if the subworkspace of DW exists
then in order
change the arrow-region icon-color of DW to yellow and
start populate-demonstration-frame ( the initial-item-count
of DW )
Initial-item-count attribute of a demonstration window is given by an integer variable. Because each consequent action in this rule takes place within its own transaction scope, this rule cannot prevent other KB processing from taking place between the completion of the
change action and the completion of the start action. In this case, if the variable that gives the value of the
Initial-item-count of the demonstration window requires a new current value, G2 might be required to suspend this rule invocation while backward chaining or other data seeking takes place. This means that G2 cannot prevent other KB processing from changing the color of the demonstration-window's arrow-region to a color other than yellow while the
start action is suspended. Depending on the activity that the populate-demonstration-window procedure performs, this possibility might leave some of the current KB's knowledge in an inconsistent state.