我正在尝试制作一个家庭树程序,我需要使用AND / OR操作。但不知怎的,我无法做到。我正在使用6.3 CLIPS WIN。这就是我在做的事情。
(deftemplate father-of (slot father) (slot child))
(deftemplate mother-of (slot mother) (slot child))
(deftemplate parent-of (slot parent) (slot child))
(deffacts ........................................
(defrule parent-of ""
(or
(mother-of (mother ?mother) (child ?child))
(father-of (father ?father) (child ?child)))
=>
(and
(assert (parent-of (parent ?mother) (child ?child))
(assert (parent-of (parent ?father) (child ?child))))
对不起,这些都是非常基本的条件和操作。但是我无法做到。
非常感谢你的帮助。
答案 0 :(得分:0)
在RHS中不需要使用AND,两个断言都将被执行
=>
(assert (parent-of (parent ?mother) (child ?child)))
(assert (parent-of (parent ?father) (child ?child)))
答案 1 :(得分:0)
CLIPS> (deftemplate father-of (slot father) (slot child))
CLIPS> (deftemplate mother-of (slot mother) (slot child))
CLIPS> (deftemplate parent-of (slot parent) (slot child))
CLIPS>
(deffacts example
(mother-of (mother "Jane") (child "Billy"))
(father-of (father "Dave") (child "Billy")))
CLIPS>
(defrule parent-of ""
(or
(mother-of (mother ?parent) (child ?child))
(father-of (father ?parent) (child ?child)))
=>
(assert (parent-of (parent ?parent) (child ?child))))
CLIPS> (reset)
CLIPS> (facts)
f-0 (initial-fact)
f-1 (mother-of (mother "Jane") (child "Billy"))
f-2 (father-of (father "Dave") (child "Billy"))
For a total of 3 facts.
CLIPS> (watch rules)
CLIPS> (run)
FIRE 1 parent-of: f-2
FIRE 2 parent-of: f-1
CLIPS> (facts)
f-0 (initial-fact)
f-1 (mother-of (mother "Jane") (child "Billy"))
f-2 (father-of (father "Dave") (child "Billy"))
f-3 (parent-of (parent "Dave") (child "Billy"))
f-4 (parent-of (parent "Jane") (child "Billy"))
For a total of 5 facts.
CLIPS>