2016-08-01 59 views
1

有一個文件test.clp:CLIPS:修改實例不會觸發模式匹配

(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會觸發模式匹配,並選擇規則「超過閾值」運行並放入議程。我錯過了什麼?

回答

1

從部分5.4.1.7,模式匹配與對象的模式,基本編程指南:

當創建或刪除一個實例,該對象適用於所有 模式更新。但是,當插槽更改時,只有那些在該插槽上顯式匹配的模式纔會受到影響。

所以修改規則來明確匹配要觸發模式匹配的插槽:

(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))