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