Hello,

 

Me again and no it is not spamming, and I’m still drools newbie ;-)

 

I was facing a problem of infinite loop with one of my rule, I have solved it but I’m wondering if my solution is not too costful on a performance point of view.

So my question is really on the most efficient way of solving the infinite loop problem I’m gonna expose you right now.

 

First of all, a few words the problem I want to solve with Drools :

My company is a bank where traders are making deals on markets, these deals must be classified in book, this is what we call “booking process”.

Booking is done according to booking criteria : which trader has made the deal ? on which product ? etc …

A booking rule defines a set of criteria and the target book where the deal will classified.

 

The guilty rule’s job was to fill DealMatchingBookingRules with the booking rules applicable on a deal, (DealMatchingBookingRules references a unique deal).  

I have put below a corrected version by commenting the update($dealMatchingBookingRules) instruction of the RHS.

 

With update uncommented, the problem occurred when 2 booking rule were matching the same deal in here’s my understanding of the problem

Facts inserted in the session :

-         dmbr1 (instance of DealMatchingBookingRule) referencing a deal

-         br1 and br2 matching the deal referenced in dmr1

Results :

  1. rule is activated with (dmbr1, br1), dmbr1 is updated
  2. rule is activated with (dmbr1, br2), dmbr1 is updated - (dmbr1, br1) does not activate the rule because of no-loop rule attribute
  3. rule is activated AGAIN with (dmbr1, br1), dmbr1 is updated : back to step 1
  4. rule is activated AGAIN with (dmbr1, br2), dmbr1 is updated : back to step 2
  5. infinite loop on step1 & step 2

 

I have fixed the problem by removing the call to update, but for the next steps of my process (not shown here) Drools need to aware of the modified DealMatchingBookingRules. I thus have written a rule which only update all DealMatchingBookingRules.

 

Is there a better way to solve this infinite loop ?

Feel free to make comments, I’m really open to any suggestion/enhancement.   

 

Regards,

 

Joël Costigliola

 

 

rule "Find matching level 1 booking rules by deal"

  salience 10

  no-loop

  ruleflow-group "Find level 1 matching booking rules by deal group"

 

  when

    $dealMatchingBookingRules : DealMatchingBookingRules($dealModel : deal, $dealProductRelatedIndexes : dealProductRelatedIndexes)

    $bookingRule : BTExecutionBookingRuleModel (

      priority == 1

      // when a criterion is not set, it is considered as satisfied.

      && (traderCriterion == null || $dealModel.trader == traderCriterion)

      && (portfolioCriterion == null || $dealModel.portfolio == portfolioCriterion)

      // when a product type criterion is set to unknown, it is considered as satisfied whatever deal product type is.

      && (productTypeStringCriterion == null || productTypeCriterion == ProductType.Unknown 

          || $dealModel.product.productType == productTypeCriterion) 

      && (listedIndexCriterion == null || $dealProductRelatedIndexes.relatedIndexes contains listedIndexCriterion)

    )

  then

    $dealMatchingBookingRules.addMatchingBookingRule($bookingRule);

    // update($dealMatchingBookingRules) : COMMENTED BECAUSE WAS CAUSING INFINITE LOOP !

end

 

// Does the job of update($dealMatchingBookingRules) but without INFINITE LOOP.

rule "Refresh facts in level 1 booking rule process"

  salience 5

  no-loop

  ruleflow-group "Refresh facts in level 1 booking rule process group"

 

  when

    $dealMatchingBookingRules : DealMatchingBookingRules()

  then

    update($dealMatchingBookingRules);

end

 

 

 


 
Ce courriel et toutes les pièces jointes sont confidentiels et peuvent être couverts par un privilège ou une protection légale. Il est établi à l’attention exclusive de ses destinataires. Toute utilisation de ce courriel non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse préalable. Toutes opinions exprimées dans ce courriel ne sauraient nécessairement refléter celle de Natixis, de ses filiales. Elles sont aussi susceptibles de modification sans notification préalable. Si vous recevez ce courriel par erreur, merci de le détruire et d’en avertir immédiatement l’expéditeur. L’Internet ne permettant pas d’assurer l’intégrité de ce courriel, Natixis décline toute responsabilité s’il a été altéré, déformé ou falsifié et chaque destinataire qui utilise ce mode de communication est supposé en accepter les risques.
 
This email and any attachment are confidential and may be legally privileged or otherwise protected from disclosure. It is intended only for the stated addressee(s) and access to it by any other person(s) is unauthorised. Any use, dissemination or disclosure not in accordance with its purpose, either in whole or in part, is prohibited without our prior formal approval. Any opinion expressed in this email may not necessarily reflect the opinion of Natixis, its affiliates. It may also be subject to change without prior notice. If you are not an addressee, you must not disclose, copy, circulate or in any other way use or rely on the information contained in this email. If you have received it in error, please inform us immediately and delete all copies. The Internet can not guarantee the integrity of this email therefore Natixis shall not be liable for the email if altered, changed or falsified and anyone who communicates with us by e-mail is taken to accept these risks.