1
votes

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> 
1

1 Answers

3
votes

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).