(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))
)
最后,它也没有发射,所以一定有问题,或者可能还有其他方法。
答案 0 :(得分:0)
请勿在规则中使用(defrule myrule
(s (time 1803))
(f1 (start ?s1))
(f2 (start ?s2))
(f3 (start ?s3))
=> ...)
,不需要。
(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
)
看看你的合成器,你又写了两个括号))
{{1}}
再见
答案 1 :(得分: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>