【问题标题】:clips - same slot in pattern and action剪辑 - 模式和动作中的相同插槽
【发布时间】:2021-06-21 18:56:47
【问题描述】:

当我们定义 rule 时,我们可以在patternaction 区域(assert 所在的位置)中拥有相同的槽 名称吗?我用下面的代码举例:

(deftemplate b1
    (slot s1) 
    (slot s2))

(deftemplate b2
    (slot s1) 
    (slot s2)) 

(deftemplate b3
    (slot r1)
    (slot r2))

(deftemplate b4
    (slot r1)
    (slot r2))

; Facts
(deffacts F 
    (b1 (s1 2)(s2 5))
    (b2 (s1 7)(s2 9)))


; Rules
(defrule R1 
    (b1 (s1 ?x1)(s2 ?y1))
    (b2 (s1 ?x2)(s2 ?y2))
=>
    (assert (b4(r1 (* ?x1 ?x2))(r2 (* ?y1 ?y2))))

    (printout t)    
)

(defrule R2 
    (b2 (s1 ?x1)(s2 ?y1))
    (b3 (r1 ?x2)(r2 ?y2))
=>
    (assert (b3(r1 (* ?x1 ?x2))(r2 (* ?y1 ?y2))))

    (printout s)
)

我描述的情况位于代码的R2规则中。当我运行程序时,我看到只有规则R1 被执行。是因为这条线吗?

    (b3 (r1 ?x2)(r2 ?y2))
=>
    (assert (b3(r1 (* ?x1 ?x2))(r2 (* ?y1 ?y2))))

因为我们已经使用了两次 r1,就像我之前说的那样。

【问题讨论】:

    标签: rules clips


    【解决方案1】:

    仅当 b2 和 b3 事实都存在时,规则 R2 才会执行。仅当规则由不同的 b3 事实激活时,才会从规则 R2 的动作中断言 b3 事实。在规则的条件和操作中使用相同的槽不会阻止该规则的激活。

    【讨论】:

      猜你喜欢
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      • 2017-10-20
      • 2020-04-29
      • 1970-01-01
      相关资源
      最近更新 更多