0

I need to know which rules and facts were fired in which inference step.

I used watch rules to print out which rules have fired. But I cannot figure out how to output at which steps the rules have fired.

Can anyone help?

Inyoung Kim 김인영
  • 1,434
  • 1
  • 17
  • 38
  • Not sure what you are trying to achieve. Could you elaborate further? What you mean with "at which steps the rules have fired"? – noxdafox Mar 16 '22 at 08:44
  • @noxdafox To my understanding, expert systems infer iteratively. Step1 [Rule Matching+Conflict Resolution+New Conclusions], Repeat this with new conclusions (this is step2)... repeat until no new conclusions. So in CLIPS, I couldn't figure out for some concluded facts at which steps they have been concluded – Inyoung Kim 김인영 Mar 17 '22 at 08:07

1 Answers1

1

From section 2.5.1 of the Basic Programming Guide

The actions of applicable rules are executed when the CLIPS inference engine is instructed to begin execution of applicable rules. If more than one rule is applicable, the inference engine uses a conflict resolution strategy to select which rule should have its actions executed. The actions of the selected rule are executed (which may affect the list of applicable rules) and then the inference engine selects another rule and executes its actions. This process continues until no applicable rules remain.

Or more succinctly:

  1. Pick a rule to fire.
  2. Execute the actions of that rule.
  3. Repeat.

Pattern matching and conflict resolution (the maintenance of the rules on the agenda) occur as facts are being asserted and retracted in the actions of the rule, so step 1 is really just select the rule at the top of the agenda. There is no gap between when an assert/retract action is processed and the fact is finally asserted/retracted. You can observe this by watching facts and activations:

         CLIPS (6.4 2/9/21)
CLIPS> 
(defrule start
   =>
   (assert (a) (b)))
CLIPS> 
(defrule have-a
   (a)
   =>
   (assert (d)))
CLIPS> 
(defrule have-b
   (b)
   =>
   (assert (e)))
CLIPS> (watch rules)
CLIPS> (watch facts)
CLIPS> (watch activations)
CLIPS> (run)
FIRE    1 start: *
==> f-1     (a)
==> Activation 0      have-a: f-1
==> f-2     (b)
==> Activation 0      have-b: f-2
FIRE    2 have-b: f-2
==> f-3     (e)
FIRE    3 have-a: f-1
==> f-4     (d)
CLIPS> 
Gary Riley
  • 10,130
  • 2
  • 19
  • 34