2016-07-28 46 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))) 
) 

我想,也許RHS不會順序運行。但我該怎麼做呢? 後來我改變了我的方法是這樣的:爲什麼我的規則不能開火?如何做到這一點?

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

和finaly,但我以前不火了,所以一定有什麼不對勁,也許還有另一種途徑。

回答

0

不要在規則中使用(和),這是不需要的。

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

,看看你的synthax,你已經寫了兩個括號))

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

再見

0

有在你的代碼很多語法錯誤。更正的代碼是:

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

謝謝,它的工作原理! –

相關問題