Hi,

I'm actually evaluating Jess and have a problem with backward chaining.

Here is what I want to solve: I want to "calculate" in a backward chaining
manner the ancestors of an individual.

My facts are something like

        (Parent P P1)
        (Parent P1 P11)
        (Parent P11 P111)

and so, I would like to get the ancestors of P11. Thus, after executing my
rules, I would like to get those new facts :

        (Ancestor P P11)
        (Ancestor P1 P11)

Thanks for your help.
Claude.

Here is my complete code :

; =====================================
;       file name : testbw.txt
; =====================================
(do-backward-chaining Ancestor)

(defrule print-ancestor-P11
  (Ancestor ?x P11)
  =>
  (printout t "Done." crlf)
)

(defrule create-ancestor1
  (need-Ancestor $?)
  (Parent ?x ?y)
  =>
  (printout t "1-Calculating ancestor of " ?y crlf)
  (assert(Ancestor ?x ?y))
)

(defrule create-ancestor2
  (need-Ancestor $?)
  (Ancestor ?x ?y)
  (Parent ?y ?z)
  =>
  (printout t "2-Calculating ancestor of " ?z crlf)
  (assert(Ancestor ?x ?z))
)

(reset)
(assert (Parent P P1))
(assert (Parent P1 P11))
(assert (Parent P11 P111))
(run)

; =====================================


Here is the trace of the execution :

Jess> (batch mydata/testbw.txt)
1-Calculating ancestor of P111
1 Jess> (facts)
f-0   (initial-fact)
f-1   (need-Ancestor nil P11)
f-2   (need-Ancestor nil nil)
f-3   (Parent P P1)
f-4   (Parent P1 P11)
f-5   (Parent P11 P111)
f-6   (Ancestor P11 P111)
For a total of 7 facts.
Jess>


---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to