我是CLIPS的新手,我无法弄清楚为什么我的代码无法运行。实际上我没有得到任何错误,但是当我按下运行时,事实并没有改变,而且目标永远都找不到。该项目是我们有2瓶。瓶子A容量为3,B容量为2.目标是A有0,B有1.我们可以用这些规则来做:fillA,fillB,emptyA,emptyB,moveAB,moveBA。 以下是我的代码。有人可以帮忙吗?谢谢!
(deffacts problem
(name A cap 3 water 0)
(name B cap 2 water 0)
)
(defrule goal
(declare (salience 100))
(name A water 0)
(name B water 1)
=>
(printout t "FOUND" crlf)
(halt)
)
(defrule start
(initial-fact)
=>
(set-strategy random)
)
(defrule emptyA
?x<-(name A water ?w)
=>
(retract ?x)
(assert (name A water 0))
)
(defrule emptyB
?x<-(name B water ?w)
=>
(retract ?x)
(assert (name B water 0))
)
(defrule fillA
?x<-(name A water ?w)
=>
(retract ?x)
(assert (name A water 3))
)
(defrule fillB
?x<-(name B water ?w)
=>
(retract ?x)
(assert (name B water 2))
)
(defrule moveAB
?x<-(name A water ?w)
?y<-(name B water ?water)
(test (not (< ?w 0)))
(test (not (> ?water 2)))
=>
(retract ?x ?y)
(assert (name B water ?w))
(assert (name A water ?water))
)
(defrule moveBA
?x<-(name A water ?w)
?y<-(name B water ?water)
(test (not (> ?w 3)))
(test (not (< ?water 0)))
=>
(retract ?x ?y)
(assert (name A water ?water))
(assert (name B water ?w))
)
答案 0 :(得分:1)
所有事实模式都将名称事实与三个字段相匹配。你的名字事实有五个字段。需要完全匹配。例如,而不是以下模式:
(name B water ?w)
您应该使用:
(name B cap ? water ?w)
或:
(name B cap ?c water ?w)
或者,使用deftemplate事实,以便您只能指定模式中感兴趣的插槽:
(deftemplate bottle
(slot name)
(slot cap)
(slot water (default 0)))
(deffacts problem
(bottle (name A) (cap 3))
(bottle (name B) (cap 2)))
(defrule fillA
?x <- (bottle (name A ) (water ?w))
=>
(modify ?x (water 3)))