2016-08-01 1 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> 

Программа не показывает никакого активного правила. Я ожидаю, что изменение (modify-instance) для значения до 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)) 
Смежные вопросы