Sorry - I didn&#39;t have the time earlier to fully parse the more complex rule. The problem you&#39;re having is that the engine reevaluates the conditions on each working memory change, and since, as you noticed, the list has changed, the rule fires again. The no-loop attribute prevents a rule from reactivating itself &quot;with the current set of facts&quot;. You do not have the same set of facts, and so no-loop is not applicable in your case.<div>
<br></div><div>It looks to me like you want to insert the results of the Dfs.search() operation as a fact or list of facts, and then include a pattern in your condition that prevents the rule from firing if these results exist in working memory. You would then have another rule or set of rules that process the results, retracting them as they go. Once all the results from one firing of the accumulate rule have been processed and retracted, then the accumulate rule would be free to fire again on the next set of data.</div>
<div><br></div><div>(An aside: since Dfs.search() returns a Map, you&#39;ll probably want to create your own implementation since a rule with a pattern on Map() would evaluate true for any map that happens to be in working memory. However, a rule that&#39;s looking for DfsSearchResults would only match in your particular case. Another (perhaps better) option is to use traits to have your Map &quot;don&quot; a trait that your other rules can then reason on. Traits are still an experiment feature but I&#39;ve played with them and they are very cool.)</div>
<div><br></div><div>Before I ramble too much further, here is a very pseudocoded version of what I&#39;m talking about. I&#39;m going to assume that Dfs.search() returns something called DfsSearchResults; whether that type is an implementation of Map or a trait is semi-irrelevant.</div>
<div><br></div><div>We&#39;re also going to assume a new type called DfsSearchResult:</div><div><br></div><div>declare DfsSearchResult</div><div>  assignment : <span style>PlanifEventAssignment</span></div><div><span style>  employee : </span><span style>EmployeeValue</span></div>
<div><span style>end</span></div><div><br></div><div>So your accumulate rule would be:</div><div><br></div><div>rule &quot;close-shift&quot;</div><div> when</div><div>  not DfsSearchResult( ) // Keeps this rule from activating again until all results of the previous firing are processed</div>
<div>  $shift : Shift( )</div><div>  $assignments : ... // this condition stays the same</div><div>  $availables : ... // this condition stays the same too</div><div>  $results : DfsSearchResults( size &gt; 0 ) from Dfs.search( $assignments, $availables )</div>
<div><font color="#222222" face="arial, sans-serif"> then</font></div><div><font color="#222222" face="arial, sans-serif">  for ( DfsSearchResult dsr : $results ) { // the magic of pseudocode is it doesn&#39;t compile and we don&#39;t care!</font></div>
<div><font color="#222222" face="arial, sans-serif">   </font><span style>PlanifEventAssignment assignment = ...</span></div><div><span style>   </span><span style>EmployeeValue employee = ...</span></div><div><font color="#222222" face="arial, sans-serif">   insert( new DfsSearchResult( assignment, employee ) );</font></div>
<div><font color="#222222" face="arial, sans-serif">  }</font></div><div><font color="#222222" face="arial, sans-serif">end</font></div><div><font color="#222222" face="arial, sans-serif"><br></font></div><div><font color="#222222" face="arial, sans-serif">And now you&#39;ll have a processing rule:</font></div>
<div><font color="#222222" face="arial, sans-serif"><br></font></div><div><font color="#222222" face="arial, sans-serif">rule &quot;update-assignment&quot;</font></div><div><font color="#222222" face="arial, sans-serif"> when</font></div>
<div><font color="#222222" face="arial, sans-serif">  $dsr : DfsSearchResult( $a : assignment, $e : employee )</font></div><div><font color="#222222" face="arial, sans-serif"> then</font></div><div><font color="#222222" face="arial, sans-serif">  modify($a) { setClose(true); setEmployee($e); }</font></div>
<div><font color="#222222" face="arial, sans-serif">  retract($dsr);</font></div><div><font color="#222222" face="arial, sans-serif">end</font></div><div><font color="#222222" face="arial, sans-serif"><br></font></div><div>
<font color="#222222" face="arial, sans-serif"><br></font></div><div><font color="#222222" face="arial, sans-serif">I think that will get you as least in the right direction. </font><span style="color:rgb(34,34,34);font-family:arial,sans-serif">I hope this helps.</span></div>
<div><font color="#222222" face="arial, sans-serif"><br></font></div><div><font color="#222222" face="arial, sans-serif">Mike</font></div><div><font color="#222222" face="arial, sans-serif"><br></font></div><div><div>P.S. Now that I think about it, I&#39;d like to amend the guideline I wrote in my last email: &quot;No looping in the consequence unless it is to decompose a collection of data into simple facts that are much easier to reason over... or if I have another really good reason.&quot;</div>
<div><br><div><div><br><div class="gmail_quote">2012/3/13 Patrik Dufresne <span dir="ltr">&lt;<a href="mailto:ikus060@gmail.com" target="_blank">ikus060@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Mike,<div><br></div><div>I see your point, it&#39;s very valid for the snippet rule, but can&#39;t be apply to the real one since I need to run a function using eval().</div>

<div><span><font color="#888888"><br clear="all">Patrik Dufresne</font></span><div><div><br>
<br><br><div class="gmail_quote">On Tue, Mar 13, 2012 at 4:45 PM, Mike Melton <span dir="ltr">&lt;<a href="mailto:mike.melton@gmail.com" target="_blank">mike.melton@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">


Let the rule engine do what it does best. You are fighting against the optimizations of the engine by trying to control the flow. You can rewrite your rule as<div><br></div><div>rule &quot;my-rule&quot;</div><div> when</div>



<div>  $entity : Entity( closed == false )</div><div> then</div><div>  modify($entity) { setClosed(true); }</div><div>end</div><div><br></div><div>The rule will fire (once) for each Entity which matches the condition. I haven&#39;t taken the time to apply the same exercise to your more complex rule, but a general rule you should abide by is &quot;No looping in the consequence unless I have a really good reason.&quot;</div>



<div><br></div><div>Mike</div><div><br></div><div><br><div class="gmail_quote">2012/3/13 Patrik Dufresne <span dir="ltr">&lt;<a href="mailto:ikus060@gmail.com" target="_blank">ikus060@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div><div>
Hi,<div><br></div><div>I have some trouble to figure out how to stop / start the propagation of updates within a Then block.</div><div>Here is a snippet to represent the problem I have.</div><div><br></div><div>rule &quot;my-rule&quot;</div>




<div>    when</div><div>        $objects : List()</div><div>                from accumulate( $entity : Entity(closed==false), collectList($entity) )<br></div><div>    then<br></div><div>        for(Object obj : $objects) {</div>




<div>            ((Entity) obj).setClosed(true);<br></div><div>            update(obj);<br></div><div>        }</div><div>end</div><div><br></div><div>When this rule&#39;s consequence is called first, the first enity in the list is &#39;update&#39;, but then update if propagated to immediately causing the rule to be evaluated with all the entities minus the updated one. So I&#39;m wondering if there is a transaction like operation allowing me to update all the entities in the list and then fire the rules.</div>




<div><br></div><div>According to the documentation no-loop should have help me for this.</div><div><br></div><div>Here is the original rules</div><div><div>rule &quot;close-shift&quot;</div><div><span style="white-space:pre-wrap">        </span>salience -1</div>




<div><span style="white-space:pre-wrap">        </span>when</div><div><span style="white-space:pre-wrap">                </span>$shift : Shift( )</div><div><span style="white-space:pre-wrap">                </span>$assignments : List( size &gt; 0 )</div>
<div><span style="white-space:pre-wrap">                                </span>from accumulate (</div><div><span style="white-space:pre-wrap">                                        </span>$assignment : PlanifEventAssignment( </div><div><span style="white-space:pre-wrap">                                                </span>close == false, </div>




<div><span style="white-space:pre-wrap">                                                </span>shift == $shift ),</div><div><span style="white-space:pre-wrap">                                        </span>collectList($assignment) )</div><div><span style="white-space:pre-wrap">                </span>$availables : List( size &gt;= $assignments.size )</div>




<div><span style="white-space:pre-wrap">                                </span>from accumulate ( ( and</div><div><span style="white-space:pre-wrap">                                        </span>ShiftAssignment(</div><div><span style="white-space:pre-wrap">                                                </span>shift == $shift,</div>




<div><span style="white-space:pre-wrap">                                                </span>$employee : employee)</div><div><span style="white-space:pre-wrap">                                        </span>$available : EmployeeAvailable (</div><div><span style="white-space:pre-wrap">                                                </span>employee == $employee,</div>




<div><span style="white-space:pre-wrap">                                                </span>assignment.shift == $shift) ),</div><div><span style="white-space:pre-wrap">                                        </span>collectList($available) )</div><div><span style="white-space:pre-wrap">                </span>eval( Dfs.search($assignments, $availables) != null )</div>




<div><span style="white-space:pre-wrap">        </span>then</div><div><span style="white-space:pre-wrap">                </span>// Recalculate the result.</div><div><span style="white-space:pre-wrap">                </span>Map table = Dfs.search($assignments, $availables);</div>




<div><span style="white-space:pre-wrap">                </span>for(Object entry : table.entrySet()) {</div><div><span style="white-space:pre-wrap">                        </span>PlanifEventAssignment assignment = (PlanifEventAssignment)((Entry)entry).getKey();</div>




<div><span style="white-space:pre-wrap">                        </span>EmployeeValue employee = (EmployeeValue)((Entry)entry).getValue();</div><div><span style="white-space:pre-wrap">                        </span>assignment.setClose(true);</div>
<div><span style="white-space:pre-wrap">                        </span>assignment.setEmployee(employee);</div><div><span style="white-space:pre-wrap">                        </span>update(assignment);</div><div><span style="white-space:pre-wrap">                </span>}</div>




<div>end</div></div><span><font color="#888888"><div><br></div><div><br></div><div>Patrik Dufresne<br>
</div>
</font></span><br></div></div>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></blockquote></div><br></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></blockquote></div><br></div></div>
</div></div>