CLIPS:修改实例不触发模式匹配 [英] CLIPS: modify-instance does not trigger pattern matching

查看:74
本文介绍了CLIPS:修改实例不触发模式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个文件 test.clp:

Having a file test.clp:

(defclass TestClass (is-a USER)
    (role concrete)
    (pattern-match reactive)
    (slot value)
    (slot threshold))


(definstances TestObjects 
    (Test of TestClass
    (value 0)
    (threshold 3)))

(defrule above-threshold
    ?test <- (object (is-a TestClass))
    (test (> (send ?test get-value) (send ?test get-threshold)))
    =>
    (printout t "*** Above threshold!! ***" crlf)
    (refresh below-threshold))

(defrule below-threshold
    ?test <- (object (is-a TestClass))
    (test (> (send ?test get-value) (send ?test get-threshold)))
    =>
    (printout t "*** Back to normal ***" crlf)
    (refresh above-threshold))

我加载文件并:

CLIPS> (reset)
CLIPS> (agenda)
0      below-threshold: [Test]
For a total of 1 activation.
CLIPS> (run) 
*** Back to normal ***
CLIPS> (modify-instance [Test] (value 8))
TRUE
CLIPS> (agenda)
CLIPS> 

议程没有显示任何活动规则.我希望将值(修改实例)更改为 8 会触发模式匹配,并且会选择规则高于阈值"来运行并放入议程.我错过了什么?

The agenda does not show any active rule. I would expect the change (modify-instance) for value to 8 would trigger pattern matching and rule "above-threshold" would be selected for running and put in the agenda. What am I missing?

推荐答案

来自《基本编程指南》的第 5.4.1.7 节,与对象模式的模式匹配:

From section 5.4.1.7, Pattern-Matching with Object Patterns, of the Basic Programming Guide:

创建或删除实例时,所有模式适用于该对象已更新.但是,当插槽更改时,只有那些在该插槽上明确匹配的模式会受到影响.

When an instance is created or deleted, all patterns applicable to that object are updated. However, when a slot is changed, only those patterns that explicitly match on that slot are affected.

因此修改规则以明确匹配您要触发模式匹配的插槽:

So modify the rules to explicitly match the slots you want to trigger pattern matching:

(defrule above-threshold
    ?test <- (object (is-a TestClass)
                     (value ?value)
                     (threshold ?threshold))
    (test (> ?value ?threshold))
    =>
    (printout t "*** Above threshold!! ***" crlf)
    (refresh below-threshold))

(defrule below-threshold
    ?test <- (object (is-a TestClass)
                     (value ?value)
                     (threshold ?threshold))
    (test (< ?value ?threshold))
    =>
    (printout t "*** Back to normal ***" crlf)
    (refresh above-threshold))

这篇关于CLIPS:修改实例不触发模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆