CLIPS 条件元素不匹配但激活规则
CLIPS conditional elements not matched but rule activated
我有以下 CLIPS 脚本。我正在尝试获取 p1, p2, p3
的值
如果 p2
未知且 p3
已知,则应激活最后一条规则 get-p2-2
。
(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
被激活?
您不撤销任何未知事实,因此 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)))
我有以下 CLIPS 脚本。我正在尝试获取 p1, p2, p3
的值
如果 p2
未知且 p3
已知,则应激活最后一条规则 get-p2-2
。
(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
被激活?
您不撤销任何未知事实,因此 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)))