2016-07-28 4 views
-1
(defrule myrule 
(and 
    (s (time 1803)) 
    (f1 (start ?s1)) 
    (f2 (start ?s2)) 
    (f3 (start ?s3)) 
) 
=> 
if(< ?s1 7) 
    then 
    (bind ?s1 (+ ?s1 24)) 
if(< ?s2 7) 
    then 
    (bind ?s2 (+ ?s2 24)) 
if(< ?s3 7) 
    then 
    (bind ?s3 (+ ?s3 24)) 
if(or (> ?s1 ?s2) (> ?s2 ?s3)(> ?s1 ?s3)) 
    then 
    (assert 0015))) 
) 

ich denke, vielleicht die RHS nicht sequentiell laufen. Aber wie soll ich es machen? dann änderte ich meine Art und Weise wie folgt aus:Warum kann meine Regel nicht feuern? wie man es macht?

(deffunction time-24 (?w1) 
    (if(< ?w1 7) 
    then 
    (bind ?w1 (+ ?w1 24)) 
    ) 

    ) 

(defrule myrule 
(and 
    (s (time 1803)) 
    (f1 (start ?s1)) 
    (f2 (start ?s2)) 
    (f3 (start ?s3)) 
    (time-24 ?s1) 
    (time-24 ?s2) 
    (time-24 ?s3) 
) 
=> 
(if(or (> ?s1 ?s2) (> ?s2 ?s3)(> ?s1 ?s3)) 
    then 
    (assert 0015)) 
) 

und finaly, es did't Feuer zu, so muss es etwas falsch sein, oder vielleicht gibt es eine andere Art und Weise.

Antwort

0

Verwenden Sie nicht (und) innerhalb Ihrer Regel, es ist nicht erforderlich.

(defrule myrule 
    (s (time 1803)) 
    (f1 (start ?s1)) 
    (f2 (start ?s2)) 
    (f3 (start ?s3)) 
=> ...) 

und Blick auf Ihre Synthax, haben Sie zwei weitere Klammern geschrieben))

(defrule myrule (and 
     (s (time 1803)) 
     (f1 (start ?s1)) 
     (f2 (start ?s2)) 
     (f3 (start ?s3))) 
    => if(< ?s1 7) 
     then 
     (bind ?s1 (+ ?s1 24)) if(< ?s2 7) 
     then 
     (bind ?s2 (+ ?s2 24)) if(< ?s3 7) 
     then 
     (bind ?s3 (+ ?s3 24)) if(or (> ?s1 ?s2) (> ?s2 ?s3)(> ?s1 ?s3)) 
     then 
     (assert 0015) )) ;remove these 2 parenthesis 
    ) 

Bye

0

Es gibt zahlreiche Syntaxfehler in Ihrem Code. Korrigierter Code ist:

CLIPS> (deftemplate s (slot time)) 
CLIPS> (deftemplate f1 (slot start)) 
CLIPS> (deftemplate f2 (slot start)) 
CLIPS> (deftemplate f3 (slot start)) 
CLIPS> 
(deffacts start 
    (s (time 1803)) 
    (f1 (start 9)) 
    (f2 (start 8)) 
    (f3 (start 4))) 
CLIPS> 
(deffunction time-24 (?w1) 
    (if (< ?w1 7) 
    then 
    (return (+ ?w1 24)) 
    else 
    (return ?w1))) 
CLIPS> 
(defrule myrule 
    (and (s (time 1803)) 
     (f1 (start ?s1)) 
     (f2 (start ?s2)) 
     (f3 (start ?s3))) 
    => 
    (bind ?s1 (time-24 ?s1)) 
    (bind ?s2 (time-24 ?s2)) 
    (bind ?s3 (time-24 ?s3)) 
    (if (or (> ?s1 ?s2) 
      (> ?s2 ?s3) 
      (> ?s1 ?s3)) 
    then 
    (assert (F0015)))) 
CLIPS> (reset) 
CLIPS> (agenda) 
0  myrule: f-1,f-2,f-3,f-4 
For a total of 1 activation. 
CLIPS> (run) 
CLIPS> (facts) 
f-0  (initial-fact) 
f-1  (s (time 1803)) 
f-2  (f1 (start 9)) 
f-3  (f2 (start 8)) 
f-4  (f3 (start 4)) 
f-5  (F0015) 
For a total of 6 facts. 
CLIPS> 
+0

danke, es funktioniert! –

Verwandte Themen