我如何找出某些规则在哪一步触发?

How can I find out at which step some rules have fired?

我需要知道在哪个推理步骤中触发了哪些规则和事实。

我使用 watch rules 打印出触发了哪些规则。但是我不知道如何输出规则触发的步骤。

有人可以帮忙吗?

摘自《基本编程指南》第 2.5.1 节

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.

或更简洁:

  1. 选择要触发的规则。
  2. 执行该规则的操作。
  3. 重复。

模式匹配和冲突解决(维护议程上的规则)发生在规则行动中声明和撤回事实时,因此第 1 步实际上只是 select 处的规则议程的首要任务。处理 assert/retract 动作与最终 asserted/retracted 之间没有间隔。您可以通过观察事实和激活来观察这一点:

         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>