2016-07-28 6 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、それはあまりにも火をdid'tので、何か問題がなければならない、または多分別の方法があります。

答えて

0

あなたのルールの中で(および)を使用しないでください。

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

そして、あなたはさらに2つの括弧を書かれている、あなたの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

ありがとうございます! –

関連する問題