Here's what's happening: First of all, the rule Use-edge is, of course,
the one that initiates the backwards-chaining. As written, it matches
any edge fact, so the fact created to request backwards-chaining is
generic.

The rule need-edge is the one that satisfies requests for edges. It is
also fairly generic, in that it responds to any need-edge request --
i.e., it's need-edge fact has no explicit slot matching. As the manual
says, "The rule compiler rewrites rules like this... : it adds a
negated match for the [edge] pattern itself to the rule's LHS."
Because the need-edge pattern is generic, this negated pattern is
generic, too. So the rewritten rule looks like this:

 (defrule need-edge
        (need-edge)
        (people ?name)
        (not (edge))
 =>
        (assert (edge (name ?name) (valueA 0) (valueB 1)))
 )

Now you see that as soon as one edge fact is asserted, any pending
activations are removed and the rule won't fire again. 

So, what do you do? You want the backwards-chaining requests to be
specific, and the need-edge rule to use this specificity. If you
rewrite these two rules as follows, you'll see that your system works
as expected:


(defrule Use-edge
        (people ?name)
        (edge (name ?name) (valueA ?A) (valueB ?B))
=>
        (printout t "we now have an edge named " ?name crlf)
)

(defrule need-edge
        (need-edge (name ?name))
=>
        (assert (edge (name ?name) (valueA 0) (valueB 1)))
)


Note that the rewritten LHS of need-edge now looks like


(defrule need-edge
        (need-edge (name ?name))
        (not (edge (name ?name)))
=> ...

which is exactly what you want.



I think Mark Guadagna wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> 
> Here is a scenario regarding backward-chaining that I don't understand.
> Perhaps someone can explain the results. Essentially, I don't 
> understand why several rules activated in backward-chaining are deactivated
> if only one fires. The sample below illustrates my mis-understanding.
> 
> Please help me understand what I need to do to get all rules activated
> during backward chaining to fire.
> 
> -Mark
> 
> ;; -------------------------- cut here ----------------------
> 
> ;;I have some deftemplate like the following:
> ;;
> (deftemplate edge
>       (slot name)
>       (slot valueA)
>       (slot valueB)
> )
> 
> ;; I establish that I want to backward-chain over edge templates.
> (do-backward-chaining edge)
> 
> ;; I have some rule which requires the use of edge templates.
> (defrule Use-edge
>       (edge (name ?name) (valueA ?A) (valueB ?B))
> =>
>       (printout t "we now have an edge named " ?name crlf)
> )
> 
> ;; And a rule to create edge templates from the need for edge. Note this
> rule
> ;; requires people facts.
> (defrule need-edge
>       (need-edge)
>       (people ?name)
> =>
>       (assert (edge (name ?name) (valueA 0) (valueB 1)))
> )
> 
> ;; reset to seed the backward-chaining
> (reset)
> 
> ;;and then add some facts about people.
> (assert (people mark))
> (assert (people chris))
> (assert (people jeff))
> 
> 
> ;; -------------------------- cut here ----------------------
> 
> ;; When I run load this I see my people facts, and the need-edge fact.
> Jess> (facts)
> f-0   (initial-fact)
> f-1   (need-edge (name nil) (valueA nil) (valueB nil))
> f-2   (people mark)
> f-3   (people chris)
> f-4   (people jeff)
> For a total of 5 facts.
> 
> 
> ;; I also see activations of need-edge as I suspect. 
> ;; And what I want is for all three rules to fire. But, they don't.
> Jess> (agenda)
> [Activation: need-edge  f-1,, f-4 ; time=9 ; salience=0] 
> [Activation: need-edge  f-1,, f-3 ; time=8 ; salience=0] 
> [Activation: need-edge  f-1,, f-2 ; time=7 ; salience=0] 
> For a total of 3 activations. 
> 
> 
> ;; When I run, only one need-edge rule fires, and the others are
> deactivated. 
> ;; WHY? shouldn't they all fire. 
> Jess> (run)
> we now have an edge named jeff
> 2 
> 
> 
> ;; I want to end up with an edge fact for all 3 people. But, I only get the
> one for Jeff.
> Jess> (facts)
> f-0   (initial-fact)
> f-1   (need-edge (name nil) (valueA nil) (valueB nil))
> f-2   (people mark)
> f-3   (people chris)
> f-4   (people jeff)
> f-5   (edge (name jeff) (valueA 0) (valueB 1))
> For a total of 6 facts.
> Jess> 
> 
> I want facts like this, but am not getting them:
> 
> f-5   (edge (name jeff) (valueA 0) (valueB 1))
> f-6   (edge (name mark) (valueA 0) (valueB 1))
> f-7   (edge (name chris) (valueA 0) (valueB 1))
> 
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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]
> ---------------------------------------------------------------------
> 



---------------------------------------------------------
Ernest Friedman-Hill  
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9012                  [EMAIL PROTECTED]
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550

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