剪辑中不合逻辑的不匹配

Illogical unmatch in clips

我对 Clips 中的规则匹配有疑问,特别是我不明白为什么这条规则没有激活!。 我有一个名为 REASONING 的模块,我在其中用这个 deftemplate 定义了一个事实 (deftemplate planning (slot value (allowed-values start stop)))。 我第一次关注这个模块时,我用这个规则断言这个事实

(defrule start-reasoning
 (declare (salience 90))
 (not (planning))
 =>
 (assert (planning (value start)))
)

接下来,这个事实将永远不会收回,只会修改它的位置。 在我定义 planning 的同一个模块中,我有另一个规则,它从开始到停止改变了值。

(defrule plan-done
    (declare (salience 60))
    ?<-(planning(value start)
    =>
    (modify ?p (value stop))
)

这是此模块激活的最后一条规则。之后剪辑执行弹出焦点。现在轮到再次关注这个模块时,我发现 <code>(planning (value stop))

f-4839  (explore-memory (pos-r 2) (pos-c 5) (direction west)(action turnleft)
(param1 nil) (param2 nil) (param3 nil) (open-depth 0) (ident 0))
f-4843  (planning (value stop))
f-4845  (exec (step 0)(action turnleft)(param1 nil)(param2 nil) (param3 nil))
f-5029  (exec (step 1)(action turnright)(param1 nil)(param2 nil)(param3 nil))

所以我希望必须激活下面写的规则,但它没有发生! 再次更改槽值的条件是它在模块 PLAN_MANAGER 内,因此我不能在 REASONING 内激活任何其他规则,直到 Clips 不执行 focus on PLAN_MANAGER.

(defrule go-to-plan-manager
  (declare (salience 90))
  (planning (value stop))
  =>
  (focus PLAN_MANAGER)
) 

奇怪的是,如果我调用匹配函数,我会得到这个输出。

>(matches go-to-plan-manager)
Matches for Pattern 1
f-4843
Activations
None

任何人都可以帮助我理解为什么 CLIPS 没有列入议程 go-to-plan-manager?我哪里错了?

鉴于缺乏可重现的示例来证明其他情况,最可能的解释是 go-to-plan-manager 在焦点最初弹出之前的某个时间点执行。重新关注模块只会更改从中提取激活的议程,但不会重新激活之前已执行的规则。

我可以根据您包含的代码片段创建的最简单的示例表明您的 go-to-plan-manager 规则将在 plan-done 规则之后立即执行,除非有其他规则的显着性为 90或更高,在 go-to-plan-manager 规则可以执行之前弹出焦点。

CLIPS> (deftemplate planning (slot value (allowed-values start stop)))
CLIPS> 
(defrule start-reasoning
 (declare (salience 90))
 (not (planning))
 =>
 (assert (planning (value start))))
CLIPS> 
(defrule plan-done
    (declare (salience 60))
    ?p<-(planning(value start))
    =>
    (modify ?p (value stop)))
CLIPS> 
(defrule go-to-plan-manager
  (declare (salience 90))
  (planning (value stop))
  =>
  (printout t "go-to-plan-manager executed" crlf))
CLIPS> (reset)
CLIPS> (watch rules)
CLIPS> (run)
FIRE    1 start-reasoning: *
FIRE    2 plan-done: f-1
FIRE    3 go-to-plan-manager: f-2
go-to-plan-manager executed
CLIPS> (matches go-to-plan-manager)
Matches for Pattern 1
f-2
Activations
 None
(1 0 0)
CLIPS>