Question

I am trying to make a family tree program where I need to use the AND/OR operation. But somehow I am unable to do it. I am using 6.3 CLIPS WIN. Here is what I am doing.

(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))))

I am sorry, these are very basic conditions and operations. However I am unable to do it.

Much appreciate your help.

No correct solution

OTHER TIPS

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> 

There is no need to use AND in RHS, both asserts will be executed

=>
(assert (parent-of (parent ?mother) (child ?child))) 
(assert (parent-of (parent ?father) (child ?child)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top