2016-08-01 35 views
1

Mit einer Datei test.clp auslöst passend:CLIPS: Modify-Instanz nicht Muster

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

ich laden Sie die Datei und:

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> 

Die Agenda zeigt keine aktive Regel. Ich würde erwarten, dass die Änderung (modify-instance) für den Wert 8 die Mustererkennung auslöst und die Regel "over-threshold" für den Lauf ausgewählt und in die Agenda aufgenommen wird. Was vermisse ich?

Antwort

1

Aus dem Bereich 5.4.1.7, Pattern-Matching mit Objektmuster des Grund Programming Guide:

Wenn eine Instanz erstellt oder gelöscht wird, werden alle Muster für das Objekt aktualisiert. Wenn jedoch ein Steckplatz geändert wird, sind nur die Muster betroffen, die explizit auf diesem Steckplatz übereinstimmen.

So die Regeln ändern explizit die Schlitze Sie Pattern-Matching wollen übereinstimmen auszulösen:

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