Drools rules dependency and looping scenario

417 views
Skip to first unread message

barfa...@gmail.com

unread,
Sep 1, 2021, 6:04:52 AM9/1/21
to Drools Usage

Hi All,

We are migrating rules from Abinitio BRE to Drools. There are multiple set of rules and each set have more than 50 rules. These rules are interdependent. There are looping scenario like rule1 is dependent on rule2 and rule2 is on rule3 and rule3 is on rule1 like this.

 We choose “None” hit policy and used Salience to manage dependency. Also used “Lock-on-Active”  But still, we are facing looping scenario and sometimes rules not getting fired even condition is satisfied.

 We are looking for suggestions, like how to avoid looping and manage dependency. 

Thanks,

Anil

Davi Sáránszky Mesquita

unread,
Sep 1, 2021, 10:01:31 AM9/1/21
to drools...@googlegroups.com
Hi,

I tested every type os cenarios of execution flow on Drools. All that will work-a-like "latch control".

1) Making a Salience tree. Will work. But results in a complicated control over numerous rules.
2) Execution Flow, Agenda Group, Activation Group. This needs to tried before you proceed.

I will show 2 cases that connect the rules themselves.

1) Scenario: Rule "B" depends on Rule "A".

declare rule_a
end

rule "A"
when
not rule_a()
then
rule_a obj = new rule_a();
insert(obj);
end

declare rule_b
end

rule "B"
when
rule_a()
not rule_b()
then
rule_b obj = new rule_b();
insert(obj);
end

2) Scenario: Rule "1461" will check if another Rule entered before its execution.

Note: Every "insert" will loop the RETE execution.

declare rule_1461
entered : Boolean
end

declare init_1461
end

rule "Rule init 'Rule' 1461"
salience 1000
when
not rule_1461()
not init_1461()

rule_<sub>()

then
init_1461 obj = new init_1461();
insert(obj);
end

rule "Ending Rule 'Rule' 1461"
salience -1000
when
not rule_1461()
init_1461()
then
rule_1461 regra = new rule_1461();
regra.setEntered(false);
insert(regra);
end

rule "Rule 1461"
when
not rule_1461()
init_1461()

rule_<sub>( entered = true )

<another conditions>

then
rule_1461 regra = new rule_1461();
regra.setEntered(true);
insert(regra);
end




Davi




--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/21a70019-09b2-4e0f-a89e-45e721af44c1n%40googlegroups.com.

barfa...@gmail.com

unread,
Sep 2, 2021, 2:12:53 AM9/2/21
to Drools Usage
Thanks Davi,

That is a good example, but in our case, we are using GDST(sorry I forgot to mention in my previous message). 

Here is example
   Let say we have Employees object and there are two rules. (I know this is not correct way, but to explain the problem I have create these two rules. We are using in and not in conditions, which create similar scenario).

First rule : based on salary calculate tax, Since its Salience is higher so this rule will execute first. 
Second rule : it is dependent on first rule, Now from second rule only one condition should fire. But for Tax=7000 all three row will trigger. 

Dependent_rule_example.PNG
 
We have used "None" hit policy, so that we can use "Salience" to maintain dependency. 
( None hit policy property is to fire all matching cases of rule. Where as Resolved and First hit will fire only one case from above).

We are looking for solution to avoid trigger multiple scenario and second to avoid looping. Sometime this create loop also. 

Thanks,
Anil

Davi Sáránszky Mesquita

unread,
Sep 2, 2021, 9:12:24 AM9/2/21
to drools...@googlegroups.com
Oh... well, i dont know how to use drools Workbench pretty well. I used drools expert (binaries/kogito).
I observed that exist the source code!
And, if you see my examples. You will need to create a bunch of data objects... that will be cumbersome.
I dont know the best way to proceed. And now i am still curious

image.png



Davi




Reply all
Reply to author
Forward
0 new messages