next up previous

5.3 CONFLICT RESOLUTION STRATEGIES

The agenda is the list of all rules which have their conditions satisfied (and have not yet been executed). Each module has its own agenda. The agenda acts similar to a stack (the top rule on the agenda is the first one to be executed). When a rule is newly activated, itís placement on the agenda is based (in order) on the following factors:

a) Newly activated rules are placed above all rules of lower salience and below all rules of higher salience.

b) Among rules of equal salience, the current conflict resolution strategy is used to determine the placement among the other rules of equal salience.

c) If a rule is activated (along with several other rules) by the same assertion or retraction of a fact, and steps a and b are unable to specify an ordering, then the rule is arbitrarily (not randomly) ordered in relation to the other rules with which it was activated. Note, in this respect, the order in which rules are defined has an arbitrary effect on conflict resolution (which is highly dependent upon the current underlying implementation of rules). Do not depend upon this arbitrary ordering for the proper execution of your rules.

CLIPS provides seven conflict resolution strategies: depth, breadth, simplicity, complexity, lex, mea, and random. The default strategy is depth. The current strategy can be set by using the setstrategy command (which will reorder the agenda based upon the new strategy).

5.3.1 Depth Strategy

Newly activated rules are placed above all rules of the same salience. For example, given that facta activates rule1 and rule2 and factb activates rule3 and rule4, then if facta is asserted before factb, rule3 and rule4 will be above rule1 and rule2 on the agenda. However, the position of rule1 relative to rule2 and rule3 relative to rule4 will be arbitrary.

5.3.2 Breadth Strategy

Newly activated rules are placed below all rules of the same salience. For example, given that facta activates rule1 and rule2 and factb activates rule3 and rule4, then if facta is asserted before factb, rule1 and rule2 will be above rule3 and rule4 on the agenda. However, the position of rule1 relative to rule2 and rule3 relative to rule4 will be arbitrary.

5.3.3 Simplicity Strategy

Among rules of the same salience, newly activated rules are placed above all activations of rules with equal or higher specificity. The specificity of a rule is determined by the number of comparisons that must be performed on the LHS of the rule. Each comparison to a constant or previously bound variable adds one to the specificity. Each function call made on the LHS of a rule as part of the :, =, or test conditional element adds one to the specificity. The boolean functions and, or, and not do not add to the specificity of a rule, but their arguments do. Function calls made within a function call do not add to the specificity of a rule. For example, the following rule

(defrule example
   (item ?x ?y ?x)
   (test (and (numberp ?x) (> ?x (+ 10 ?y)) (< ?x 100)))
   =>)

has a specificity of 5. The comparison to the constant item, the comparison of ?x to its previous binding, and the calls to the numberp, <, and > functions each add one to the specificity for a total of 5. The calls to the and and + functions do not add to the specificity of the rule.

5.3.4 Complexity Strategy

Among rules of the same salience, newly activated rules are placed above all activations of rules with equal or lower specificity.

5.3.5 LEX Strategy

5.3.6 MEA Strategy



next up previous