我有以下CLIPS脚本。我正在尝试获取p1, p2, p3
的值
如果未知get-p2-2
并且已知p2
,则应激活最后一个规则p3
。
(defrule main
(initial-fact)
=>
(assert(fact (read))) ; user enters 1
(assert(p1 unknown))
(assert(p2 unknown))
(assert(p3 unknown))
)
;;;=====================================================
(defrule get-p1
(fact 1)
(p1 unknown)
=>
(printout t"p1 known"crlf)
(assert (p1 known)))
;;;======================================================
(defrule get-p2
(fact 1)
(p1 known)
(p2 unknown)
=>
(printout t "p2 known"crlf)
(assert (p2 known))
(assert (fact 2)))
;;;======================================================
(defrule get-p3
(fact 2)
(p3 unknown)
=>
(printout t"p3 known"crlf)
(assert (p3 known)))
;;;======================================================
(defrule get-p2-2
(fact 2)
(p2 unknown)
(p3 known)
=>
(printout t "p2 known"crlf)
(assert (p2 known)))
但是p2
在规则get-p2
中是已知的。
因此,规则get-p2-2
应该永远不会被激活。但是它确实被激活了,我得到了输出
p1 known
p2 known
p3 known
p2 known ; this should not be here
为什么激活get-p2-2
?
答案 0 :(得分:1)
您不会撤回任何未知的事实,因此p1,p2和p3都是已知的,也未知,因此可以激活get-p2-2。
CLIPS> (reset)
CLIPS> (run)
1
p1 known
p2 known
p3 known
p2 known
CLIPS> (facts)
f-0 (initial-fact)
f-1 (fact 1)
f-2 (p1 unknown)
f-3 (p2 unknown)
f-4 (p3 unknown)
f-5 (p1 known)
f-6 (p2 known)
f-7 (fact 2)
f-8 (p3 known)
For a total of 9 facts.
CLIPS>
撤消get-p1,get-p2和get-p3中的未知事实,您将获得所需的结果。
(defrule get-p1
(fact 1)
?f <- (p1 unknown)
=>
(retract ?f)
(printout t "p1 known" crlf)
(assert (p1 known)))