2016-08-01 3 views
1

パターンマッチングをトリガしません:クリップ:修正・インスタンスは、ファイル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の値の変更(インスタンスの変更)がパターンマッチングをトリガーし、 "above-threshold"ルールが実行のために選択され、アジェンダに置かれると期待します。私は何が欠けていますか?セクション5.4.1.7、基本的なプログラミングガイドのオブジェクトパターンとのパターンマッチングから

答えて

1

インスタンスが作成または削除された場合、オブジェクト に適用されるすべてのパターンが更新されます。ただし、スロットが変更された場合、そのスロットで明示的に一致するパターンのうち、 のパターンのみが影響を受けます。

ので、明示的にパターンマッチングをトリガしたいスロットを一致させるためにルールを変更:

(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)) 
関連する問題