1

我正在尝试制作一个需要使用 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))))

对不起,这些都是非常基本的条件和操作。但是我无法做到。

非常感谢您的帮助。

4

2 回答 2

0

在 RHS 中不需要使用 AND,两个断言都会被执行

=>
(assert (parent-of (parent ?mother) (child ?child))) 
(assert (parent-of (parent ?father) (child ?child)))
于 2013-11-05T12:25:51.373 回答
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> 
于 2013-11-05T15:27:03.310 回答