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:
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).
Newly activated rules are placed above all rules of the same salience. For example, given that fact- a activates rule- 1 and rule- 2 and fact- b activates rule- 3 and rule- 4, then if fact- a is asserted before fact- b, rule- 3 and rule- 4 will be above rule- 1 and rule- 2 on the agenda. However, the position of rule- 1 relative to rule- 2 and rule- 3 relative to rule- 4 will be arbitrary.
Newly activated rules are placed below all rules of the same salience. For example, given that fact- a activates rule- 1 and rule- 2 and fact- b activates rule- 3 and rule- 4, then if fact- a is asserted before fact- b, rule- 1 and rule- 2 will be above rule- 3 and rule- 4 on the agenda. However, the position of rule- 1 relative to rule- 2 and rule- 3 relative to rule- 4 will be arbitrary.
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.
Among rules of the same salience, newly activated rules are placed above all activations of rules with equal or lower specificity.
Among rules of the same salience, newly activated rules are placed using the OPS5 strategy of the same name. First the recency of the pattern entities that activated the rule is used to determine where to place the activation. Every fact and instance is marked internally with a "time tag" to indicate its relative recency with respect to every other fact and instance in the system. The pattern entities associated with each rule activation are sorted in descending order for determining placement. An activation with a more recent pattern entities is placed before activations with less recent pattern entities. To determine the placement order of two activations, compare the sorted time tags of the two activations one by one starting with the largest time tags. The comparison should continue until one activation's time tag is greater than the other activation's corresponding time tag. The activation with the greater time tag is placed before the other activation on the agenda.
If one activation has more pattern entities than the other activation and the compared time tags are all identical, then the activation with more time tags is placed before the other activation on the agenda. If two activations have the exact same recency, the activation with the higher specificity is placed above the activation with the lower specificity. Unlike OPS5, the not conditional elements in CLIPS have pseudo time tags which are used by the LEX conflict resolution strategy. The time tag of a not CE is always less than the time tag of a pattern entity, but greater than the time tag of a not CE that was instantiated after the not CE in question.
As an example, the following six activations have been listed in their LEX ordering (where the comma at the end of the activation indicates the presence of a not CE). Note that a fact's time tag is not necessarily the same as it's index (since instances are also assigned time tags), but if one fact's index is greater than another facts's index, then it's time tag is also greater. For this example, assume that the time tags and indices are the same.
rule-6: f-1,f-4
rule-5: f-1,f-2,f-3,
rule-1: f-1,f-2,f-3
rule-2: f-3,f-1
rule-4: f-1,f-2,
rule-3: f-2,f-1
Shown following are the same activations with the fact indices sorted as they would be by the LEX strategy for comparison.
rule-6: f-4,f-1
rule-5: f-3,f-2,f-1,
rule-1: f-3,f-2,f-1
rule-2: f-3,f-1
rule-4: f-2,f-1,
rule-3: f-2,f-1
Among rules of the same salience, newly activated rules are placed using the OPS5 strategy of the same name. First the time tag of the pattern entity associated with the first pattern is used to determine where to place the activation. An activation thats first pattern's time tag is greater than another activations first pattern's time tag is placed before the other activation on the agenda. If both activations have the same time tag associated with the first pattern, then the LEX strategy is used to determine placement of the activation. Again, as with the CLIPS LEX strategy, negated patterns have pseudo time tags.
As an example, the following six activations have been listed in their MEA ordering (where the comma at the end of the activation indicates the presence of a negated pattern).
rule-2: f-3,f-1
rule-3: f-2,f-1
rule-6: f-1,f-4
rule-5: f-1,f-2,f-3,
rule-1: f-1,f-2,f-3
rule-4: f-1,f-2,
Each activation is assigned a random number which is used to determine its placement among activations of equal salience. This random number is preserved when the strategy is changed so that the same ordering is reproduced when the random strategy is selected again (among activations that were on the agenda when the strategy was originally changed).