On Tuesday 15 May 2007 11:22:49 am Skeptic 2000 wrote:
> What I should do to avoid this situation in which two instances of Y
> will be created.
>

As you know, your version:

(defrule sum-X
    ?x1 <- (X (a ?a1)) 
    ?x2 <- (X (a ?a2)) 
    (not (test (eq ?x1 ?x2))) ...

will match when ?x1 and ?x2 are not the same, but it will match two different 
ways for any two facts (first, second, or second, first). If you want it to 
match just once for a pair of facts, then you need to pick one of these two 
possibilities. Ordering the fact ids works well:

(defrule sum-X
    ?x1 <- (X (a ?a1)) 
    ?x2 <- (X (a ?a2)) 
    (test (> ?x1 ?x2)) ...

So this will be activated just once for each pair of facts.

> If what I try to do is not clear, please say so.
> Thanks.
>
> CLP file :
>
> (deftemplate X (slot a))
>
> (deftemplate Y   (slot s))
>
> (defrule sum-X    ?x1 <- (X (a ?a1))    ?x2 <- (X (a ?a2))    (not (test
> (eq ?x1 ?x2)))=>    (assert (Y (s (+ ?a1 ?a2))))    (printout t "y asserted
> " ?a1 " " ?a2 crlf))
>
> (reset)
>
> (assert (X (a 3)))(assert (X (a 5)))
>
> (run)
>
> Result :
>
> Jess, the Rule Engine for the Java Platform
> Copyright (C) 2006 Sandia Corporation
> Jess Version 7.0p1 12/21/2006
>
>
> y asserted 5 3
> y asserted 3 5
> _________________________________________________________________
> Soyez parmi les premiers à essayer Windows Live Mail.
> http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-49
>11fb2b2e6d



-- 
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550                 http://www.jessrules.com

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