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 :
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