Yes, that is the correct behavior and checking of equality will not help on that. If you want facts to match only in one way but not the reverse, you need to have some kind of "ordering" between them and must add a constraint to your rules to avoid that. Note that this is not a rules engine issue, but a model design issue.
    Example of how to solve that is:

* if your facts have an attribute with an ID/code/whatever that may be ordered, you can do:

when
    MyFact( $id : id )
    MyFact( id > $id )
then
   ...
end

   So the ">" constraint will prevent facts matching both ways.
   If you don't have such attribute, you can use system id, but that is ugly, and you probably could find a better modeling for your facts. Anyway, it would be like:

when
   $f1 : MyFact()
   $f2 : MyFact()
   eval( System.identityHashCode( $f1 ) > System.identityHashCode( $f2 ) )
then
  ...
end
 
   Again, the above works, but is damn ugly... :)

   []s
   Edson



2007/5/20, Sikkandar Nawabjan <Sikkandar.Nawabjan@ustri.com>:
Edson,
am getting the following output
[ b, a ]
[ a, b ]
only the order of the output is different. so if i check a equal to b according to the cross product law the then part execute 2 times?
thats y i check the reference in the then part.
 
how to use eval to  variable comparison of objects in a single line

Thanks and  regs,
Basha
 
 
 
 
 
 
 

 
 
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Message: 3
Date: Sat, 19 May 2007 09:53:29 -0300
From: "Edson Tirelli" <tirelli@post.com>
Subject: Re: [rules-users] [rule-users]how to create object properties
        in      single stmnt
To: "Rules Users List" <rules-users@lists.jboss.org>
Message-ID:
        <e6dd5ba30705190553p1f5f794ct91ad250fb1ad3753@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

    Sikkandar,

    In 3.0.6, if you have 2 strings in the working memory ("a" and "b" ) and
you write:

rule "cross product"
when
    $s1: String()
    $s2: String()
then
    System.out.println("[ "+$s1+", "+$s2+" ]");
end

   The result MUST be:

[ a, b ]
[ b, a ]

   If it is not that, then we have a bug, but our integration tests that
test this specific situation are working fine. Plz let us know if it is
different for you.
   In 4.0, the result must be:

[ a, b ]
[ b, a ]
[ a, a ]
[ b, b ]

   So a fact (by default) may match multiple simultaneous patterns.

   Regarding your second question, comparing properties of the same object
is also something we added for 4.0. In 3.0.x you need eval() too.

   []s
   Edson

2007/5/19, Sikkandar Nawabjan <Sikkandar.Nawabjan@ustri.com>:
>
> Hi ,
> The very reason i used to compare two object reference is that i got then
> executed multiple time when i do duplicate check between object properties.
> so i beleive the pattern match happen more than a time
> for example
>  when
>      $obj1:object($code:code,$stdate:startdate);
>      $obj2:object(code==$code,startdate=$stdate);
>  then
> if(obj1!=obj2)
>      System.out.println("Fired");
>
> My questions are
>
> 1) In 3.0.6 is there any other way to avoid this multiple check other than
> using eval(which affects performance i beleive). i can't use this operator
> in 3.0.6
>
> 2) related to this i have one more query. how to check properties within
> the object itself
>
> for example i want to do
>  when
>      $obj1:object($code:code,$stdate:startdate,$enddate:enddate > $stdate,
> reasoncode == $code);
>  then
>      System.out.println("Fired");
> i beleive the above throws error in 3.0.6 (nullpointer related to alpha
> node)
>
> Earlier reply is highly appreciated
>
> Thanks and Regs,
> Bassha
>
>

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




--
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com