Sorry - I didn't have the time earlier to fully parse the more complex rule. The problem you'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 "with the current set of facts". You do not have the same set of facts, and so no-loop is not applicable in your case.
Hi Mike,I see your point, it's very valid for the snippet rule, but can't be apply to the real one since I need to run a function using eval().
Patrik Dufresne
On Tue, Mar 13, 2012 at 4:45 PM, Mike Melton <mike.melton@gmail.com> wrote: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 asrule "my-rule"when$entity : Entity( closed == false )thenmodify($entity) { setClosed(true); }endThe rule will fire (once) for each Entity which matches the condition. I haven't taken the time to apply the same exercise to your more complex rule, but a general rule you should abide by is "No looping in the consequence unless I have a really good reason."Mike2012/3/13 Patrik Dufresne <ikus060@gmail.com>_______________________________________________Hi,I have some trouble to figure out how to stop / start the propagation of updates within a Then block.Here is a snippet to represent the problem I have.rule "my-rule"when$objects : List()from accumulate( $entity : Entity(closed==false), collectList($entity) )thenfor(Object obj : $objects) {((Entity) obj).setClosed(true);update(obj);}endWhen this rule's consequence is called first, the first enity in the list is 'update', but then update if propagated to immediately causing the rule to be evaluated with all the entities minus the updated one. So I'm wondering if there is a transaction like operation allowing me to update all the entities in the list and then fire the rules.According to the documentation no-loop should have help me for this.Here is the original rulesrule "close-shift"salience -1when$shift : Shift( )$assignments : List( size > 0 )from accumulate ($assignment : PlanifEventAssignment(close == false,shift == $shift ),collectList($assignment) )$availables : List( size >= $assignments.size )from accumulate ( ( andShiftAssignment(shift == $shift,$employee : employee)$available : EmployeeAvailable (employee == $employee,assignment.shift == $shift) ),collectList($available) )eval( Dfs.search($assignments, $availables) != null )then// Recalculate the result.Map table = Dfs.search($assignments, $availables);for(Object entry : table.entrySet()) {PlanifEventAssignment assignment = (PlanifEventAssignment)((Entry)entry).getKey();EmployeeValue employee = (EmployeeValue)((Entry)entry).getValue();assignment.setClose(true);assignment.setEmployee(employee);update(assignment);}endPatrik Dufresne
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users