<div dir="ltr"><div><div>Thanks a lot for your explanations. <br><br></div>I think a good rule of thumb for a Drools beginner like myself is to use a modify{} whenever I modify a fact in the working memory and use @PropertyReactive and @watch to tweak performance. <br>
<br></div>Thanks again. <br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 16, 2014 at 12:05 AM, Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The basic rule is this: If modify is called on a fact it causes<br>
reevaluation of all LHSs where facts of that type are used.<br>
<br>
You may omit modify if the change does not have any effect on the<br>
logic, and you may omit it if this particular change should be hidden<br>
from the engine. (There's the use case of collecting facts A in a<br>
Collection property of fact B with a rule combining a (new) A with a<br>
B: clearly, modify of B would cause the rule to fire over and over<br>
again, which might be prevented using no-loop - but other occurrences<br>
of B might be reevaluated, too.)<br>
<br>
A more selective reaction to modification is possible using the<br>
"property reactive" feature - see the docs.<br>
<div class="HOEnZb"><div class="h5"><br>
-W<br>
<br>
<br>
<br>
On 15/06/2014, Poissy.B <<a href="mailto:poissy.b@gmail.com">poissy.b@gmail.com</a>> wrote:<br>
> Thanks Wolfgang. Actually I kind of figured out how to fix it but am not<br>
> sure why it is fixed.<br>
><br>
> First to explain the context, this erratic rule belongs to a rule<br>
> flow-group B that is executed right after another group (A).<br>
><br>
> There is actually a rule in A that modifies $mainProcess, more<br>
> specifically, it adds the actual ItemAwareElements that should be returned<br>
> by the methods getGivenResources and getReceivedResources. However I did<br>
> not enclose that in a "modify" statement. My point was that it is useless<br>
> to let the WM know as that modification has no influence on group A rules.<br>
> And I was thinking that it does not even matter for group B rules as I am<br>
> playing with fact's internal properties and not the fact per se.<br>
> (specifically: a HashSet having Set values).<br>
><br>
> I guess I was wrong assuming all this. So my question is:<br>
> - Do we need to use the modify statement whenever the state of an object<br>
> from the working memory is changed? (even if the part of the state that<br>
> changed is not relevant to the reasoner)<br>
> - In other words, can we sometimes avoid the modify when manipulating facts<br>
> to prevent the rules from being re-evaluated uselessly?<br>
><br>
> Thanks!<br>
><br>
><br>
> On Sun, Jun 15, 2014 at 3:59 PM, Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>><br>
> wrote:<br>
><br>
>> OK, it's a bug all right. 5.4.0 had some problems. It might be worth<br>
>> trying a later 5.x version.<br>
>> -W<br>
>><br>
>> On 15/06/2014, Poissy.B <<a href="mailto:poissy.b@gmail.com">poissy.b@gmail.com</a>> wrote:<br>
>> > Yes it does fire if I comment either of them, and I get the exact same<br>
>> > response.<br>
>> ><br>
>> > I am using Drools 5.4.0.Final runtime.<br>
>> ><br>
>> > Actually Products is the name property of an object of type<br>
>> > DataObjectReference (wich implements ItemAwareElementAdapter). The<br>
>> > point<br>
>> of<br>
>> > providing the output was just to show you that the<br>
>> > List<ItemAwareElementAdapter> returned by both getGivenResources() and<br>
>> > getReceivedResources() is indeed not empty so the "exists" constraint<br>
>> > should have been matched.<br>
>> ><br>
>> > Thanks!<br>
>> ><br>
>> ><br>
>> > On Sun, Jun 15, 2014 at 2:06 PM, Wolfgang Laun<br>
>> > <<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>><br>
>> > wrote:<br>
>> ><br>
>> >> See inline.<br>
>> >><br>
>> >> On 15/06/2014, Poissy.B <<a href="mailto:poissy.b@gmail.com">poissy.b@gmail.com</a>> wrote:<br>
>> >> > Hello,<br>
>> >> ><br>
>> >> > I am a little bit confused as I don't get what I am doing wrong.<br>
>> >> > Here<br>
>> >> > is<br>
>> >> my<br>
>> >> > rule:<br>
>> >> ><br>
>> >> > **************************<br>
>> >> > rule "Exchange Pattern"<br>
>> >> > when<br>
>> >> > $p2: ProcessAdapter()<br>
>> >> > $mainProcess: ProcessAdapter( isMainProcess(), this!=$p2)<br>
>> >> > MessageFlowAdapter ( fromProcess == $mainProcess,<br>
>> >> > toProcess==$p2)<br>
>> >> > MessageFlowAdapter ( fromProcess == $p2,<br>
>> >> > toProcess==$mainProcess)<br>
>> >> > exists ItemAwareElementAdapter( ) from<br>
>> >> > $mainProcess.getReceivedResources($p2)<br>
>> >> > exists ItemAwareElementAdapter( ) from<br>
>> >> > $mainProcess.getGivenResources($p2)<br>
>> >> > then<br>
>> >> > System.out.println("** FOUND EXCHANGE PATTERN betwwen<br>
>> >> > "+$mainProcess.getParticipant().getName()+" AND<br>
>> >> > "+$p2.getParticipant().getName());<br>
>> >> > System.out.println("Given:<br>
>> >> ><br>
>> >><br>
>> "+$mainProcess.getGivenResources($p2)+$mainProcess.getGivenResources($p2).size());<br>
>> >> > System.out.println("Received:<br>
>> >> ><br>
>> >><br>
>> "+$mainProcess.getReceivedResources($p2)+$mainProcess.getReceivedResources($p2).size());<br>
>> >> > System.out.println("Intersection:<br>
>> >> ><br>
>> >><br>
>> "+$mainProcess.intersectGivenAndReceivedResourcesWithProcess($p2)+$mainProcess.intersectGivenAndReceivedResourcesWithProcess($p2).size());<br>
>> >> > end<br>
>> >> > **************************<br>
>> >> ><br>
>> >> > This rule is never fired, although I know it should.<br>
>> >> ><br>
>> >> > When I comment out the ONE OF the two "exists" constraints, I get<br>
>> >> > this<br>
>> >> > output:<br>
>> >><br>
>> >> Does the rule fire when you comment out either "exists" conditional<br>
>> >> element,<br>
>> >> i.e., it doesn't matter which one is removed?<br>
>> >><br>
>> >> Which Drools version are you using?<br>
>> >><br>
>> >> -W<br>
>> >><br>
>> >> ><br>
>> >> > **************************<br>
>> >> > ** FOUND EXCHANGE PATTERN betwwen Amazon AND Ship.Comp.<br>
>> >> > Given: [Products (ID:DataObjectReference_2)]1<br>
>> >> > Received: [Products (ID:DataObjectRefeference_GEN7)]1<br>
>> >> > Intersection: [Products (ID:DataObject_2)]1<br>
>> >> > **************************<br>
>> >><br>
>> >> I can't say that a display of fact type "Products" is clearly<br>
>> >> indicating<br>
>> >> the<br>
>> >> presence of an ItemAwareElementAdapter. That said, the rule shouldn't<br>
>> >> fire even with a single "exists", so I assume this is an interface<br>
>> >> implemented<br>
>> >> by Products.<br>
>> >><br>
>> >> ><br>
>> >> > >From the output you can see that the rule should have been fired<br>
>> >> > with<br>
>> >> the<br>
>> >> > two "exists" constrains as both conditions are met, but it doesn't.<br>
>> >> > I am kind of new to Drools so I may be doing an horrible mistake but<br>
>> >> google<br>
>> >> > haven't been my friend so far. Any help will be very appreciated!<br>
>> >> ><br>
>> >> > Thanks.<br>
>> >> > Anis<br>
>> >> ><br>
>> >> _______________________________________________<br>
>> >> rules-users mailing list<br>
>> >> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
>> >> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>> >><br>
>> ><br>
>> _______________________________________________<br>
>> rules-users mailing list<br>
>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
>><br>
><br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br></div>