[rules-users] Salience not working

Edson Tirelli tirelli at post.com
Wed May 14 11:36:16 EDT 2008


   Oh, ok, now it makes sense.

   So, yes, it seems the behavior is correct. Remember that LHS is only
evaluated at assert time or when a modify()/update() on a given fact is
called.
   So, at assert time, your eval() will evaluate to true and activate the
rule. You never call modify()/update on the AirTravelPolicyData, and so,
your condition is never re-evaluated. That is why you are getting your
"strange behavior".
   BTW, what is probably making you even more confused is the fact that you
are using nested objects. Try first understanding the use of flat object
models. When you understand that, you can play with nested models and will
not have this kind of problem.

   Hope it helps,
      Edson


2008/5/14 sridhar123 <sridhar.peddinti at sabre.com>:

>
> I changed variable names in the last minute to make more sense, the actual
> eval statement is as following:
>
>
>
>       eval(((Boolean) $discard).booleanValue() == false)
>
>
>
> I do have $discard bound in my rule, you still think above statement throw
> compilation error. I don't get any compilation errors. However at run time
> it is not getting the right value (well.. what I think is a right value J )
>
>
>
> -sridhar
>
>
>
> sridhar123 wrote:
> >
> >
> > Here is my drl file: It seems LHS of all rules executed first
> irrespective
> > of salience or focus. What am i doing wrong? Appreciate your help.
> >
> > rule "Eval Window"
> >     salience 10
> >     agenda-group "Eval Window"
> > //    activation-group "Eval Window"
> >     auto-focus true
> >       when
> >       $data : AirTravelPolicyData($reqDep :
> fareRequest.requestedDeparture,
> >               $reqRet : fareRequest.requestedReturn,
> >               $itr : itinerary,
> >               $evalWindow : policySettings.evaluationWindow,
> >               $depart : departureFlight.departure,
> >               $retrn : returnFlight.departure
> >               )
> >
> >           eval ((DateUtil.subtractHours((Date)$reqDep,
> > ((Integer)$evalWindow).intValue()))
> >
>                     .before((Date)$depart))
> >        then
> > // modify block sets $itr.discardable to true
> >      modify($itr) {
> >       setAsDiscardable()
> >      }
> > //     update ($data);
> >      drools.setFocus("Eval carrier");
> > end
> >
> >
> > rule "Eval carrier"
> >  salience 5
> >  agenda-group "Eval carrier"
> > // activation-group "Eval carrier"
> >       when
> >       $data : AirTravelPolicyData($prefCarrier :
> > policySettings.preferredCarrier,
> >               $carrier : departureFlight.carrier,
> >                       $discard :  itinerary.discarded
> >               )
> > //   Eval Window rule changed discarded flag to true so this condition
> > should fail but it dose not ???
> >           eval(((Boolean)$itr).booleanValue() == false)
> >      then
> >       // But.. when i print out the discard flag here it show as true..
> In that
> > case how eval condiation is passed?
> >         System.out.println("*********Current Itr in Eval carrier: " +
> > $discard );
> >
> > end
> >
> >
> >
> >
> > Edson Tirelli-3 wrote:
> >>
> >>   This is wrong:
> >>
> >> $data : MyFact( $anotherObj )
> >>
> >>    Is the parser accepting it without any error???? If so, it is a bug.
> >>    I can't even imagine what is the parsing result for such expression.
> >>
> >>    This is also wrong:
> >>
> >>   eval ($anotherObj.isDiscard() == true)
> >>
> >>    There is no previous binding for "$anotherObj". Only possible
> scenario
> >> is
> >> you defined it as a global.
> >>    So, whatever you are doing and seeing, I have no idea how you can
> >> execute
> >> rules.
> >>
> >>    Can you show us the whole DRL file you are using? Can you show the
> >> snippet of code you are using to execute it?
> >>
> >>    []s
> >>    Edson
> >>
> >>
> >>
> >>
> >>
> >> 2008/5/13 sridhar123 <sridhar.peddinti at sabre.com>:
> >>
> >>>
> >>> It still dosen't work as desired. Here is my code:
> >>>
> >>>      rule A
> >>> Salience 10
> >>> when
> >>>  $data : MyFact( $anotherObj )
> >>> then
> >>>   modify(  $anotherObj ) {
> >>>      setDiscard(true)
> >>>   }
> >>>
> >>> rule B
> >>> Salience 5
> >>> when
> >>>  eval ($anotherObj.isDiscard() == true)
> >>> then
> >>>  ...
> >>>
> >>> It seems, all When conditions are executed first irrespective of "then"
> >>>
> >>> I also tried with agenda group and having default focus on Rule A and
> in
> >>> Then section setting focus to Rule B - still the condition doesnt
> match.
> >>> When i inspect fact - after Rule A is executed, i see my flag is set to
> >>> true
> >>> - but not visible to Rule B.
> >>>
> >>> Do i need to write seperate drl files. Also, i am using eclipse 3.3 and
> >>> ruleflow seems buggy i can not add any rule flow groups. do i need to
> >>> use
> >>> 3.2. I am using Drools 4.0.4
> >>>
> >>> thank you
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> Alessandro Lazarotti wrote:
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> > rule A
> >>> >        Salience 10
> >>> >  when
> >>> >         $anotherObject: MyFact(discard != true)
> >>> >  then
> >>> >         modify($anotherObj){
> >>> >                  setDiscard(true)
> >>> >         }
> >>> >
> >>> >
> >>> > "Modify" update your fact in the current working memory.
> >>> >
> >>> >
> >>> >
> >>> > sridhar123 escreveu:
> >>> >
> >>> >
> >>> > It means, I can not fire all rules at once, I need to groups and
> >>> change
> >>> > focus in my java code?
> >>> >
> >>> > I couldn't find any docs or examples to properly use Salience - could
> >>> you
> >>> > please share an example (if you have one)
> >>> >
> >>> > thx
> >>> >
> >>> >
> >>> >
> >>> > Alessandro Lazarotti wrote:
> >>> >
> >>> >
> >>> >     You need upate() the fact $anotherObj in Working Memory.
> >>> >
> >>> > sridhar123 escreveu:
> >>> >
> >>> >
> >>> >       rule A
> >>> > Salience 10
> >>> > when
> >>> >  $data : MyFact( $anotherObj )
> >>> > then
> >>> >   $anotherObj.setDiscard(true)
> >>> >
> >>> > rule B
> >>> > Salience 5
> >>> > when
> >>> >   eval ($anotherObj.isDiscard() == true)
> >>> > then
> >>> >    ...
> >>> >
> >>> >
> >>> > I am trying to get Rule A executed before Rule B. So when condition
> in
> >>> > Rule
> >>> > B is valid. However i dont see "Saliene" has any effect. How else i
> >>> can
> >>> > do
> >>> > the above?
> >>> >
> >>> > thank you
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >     _______________________________________________
> >>> > rules-users mailing list
> >>> > rules-users at lists.jboss.org
> >>> > https://lists.jboss.org/mailman/listinfo/rules-users
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> >
> >>> > _______________________________________________
> >>> > rules-users mailing list
> >>> > rules-users at lists.jboss.org
> >>> > https://lists.jboss.org/mailman/listinfo/rules-users
> >>> >
> >>> >
> >>>
> >>> --
> >>> View this message in context:
> >>> http://www.nabble.com/Salience-not-working-tp17190028p17217969.html
> >>> Sent from the drools - user mailing list archive at Nabble.com.
> >>>
> >>> _______________________________________________
> >>> rules-users mailing list
> >>> rules-users at lists.jboss.org
> >>> https://lists.jboss.org/mailman/listinfo/rules-users
> >>>
> >>
> >>
> >>
> >> --
> >> Edson Tirelli
> >> JBoss Drools Core Development
> >> Office: +55 11 3529-6000
> >> Mobile: +55 11 9287-5646
> >> JBoss, a division of Red Hat @ www.jboss.com
> >>
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users at lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Salience-not-working-tp17190028p17232603.html
> Sent from the drools - user mailing list archive at Nabble.com.
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080514/a7d234d6/attachment.html 


More information about the rules-users mailing list