2

From what I understand in "matching" step several rules might get "enabled" because their conditions are satisfied by the facts in WM. However I thought in conflict resolution step only one of the rules in agenda will be fired.

Now I have a program in which 2 rules are enabled into agenda and in run step both get fired! Isn't it supposed that only one rule be fired?

CLIPS> (defrule testrule1 (declare (salience 1)) 
(testfact1) (testfact2) => (printout t "testrule1 firing." crlf))
CLIPS> (defrule testrule2 
(testfact1) => (printout t "testrule2 firing." crlf))
CLIPS> (assert (testfact1) (testfact2))
==> f-1     (testfact1)
==> Activation 0      testrule2: f-1
==> f-2     (testfact2)
==> Activation 1      testrule1: f-1,f-2
<Fact-2>
CLIPS> (agenda)
1      testrule1: f-1,f-2
0      testrule2: f-1
For a total of 2 activations.
CLIPS> (run)
FIRE    1 testrule1: f-1,f-2
testrule1 firing.
FIRE    2 testrule2: f-1
testrule2 firing.
CLIPS> 
wmac
  • 1,023
  • 1
  • 16
  • 34

1 Answers1

3

Conflict resolution does not prevent both rules from firing - it just determines which is fired first. If you only want one of the two rules to fire, then you should either retract testfact1 in the RHS of the selected rule or remove the other rule from the agenda by some other means (e.g., using a control fact).

bogatron
  • 18,639
  • 6
  • 53
  • 47
  • Giarratano's book (one of the major in the field) mentions in several places that the selection process (i.e. Conf. Res.) will select only one rule. So it means it will select one at a time, and then next one until no activation remains on the agenda? Am I right? – wmac Nov 07 '14 at 18:57
  • Yes, that is correct. It selects the rule on the agenda to be fired *next*. But that doesn't prevent other rules on the agenda from subsequently firing unless the fired rule does something to take them off of the agenda. A point to note is that not all rules on the agenda are guaranteed to fire - the rule that is currently selected can change which rules are on the agenda (e.g., by retracting facts or changing the current module). – bogatron Nov 07 '14 at 19:34