2016-08-01 5 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에 대한 값의 변경 (인스턴스 수정)이 패턴 일치를 트리거하고 "임계 값 초과"규칙이 실행 및 의제에 선택 될 것으로 기대합니다. 내가 뭘 놓치고 있니? 기본 프로그래밍 가이드의 섹션 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)) 
:

그래서 명시 적으로 패턴 매칭을 트리거 할 슬롯을 일치하도록 규칙을 수정