Re: [rules-users] [Drools4]: Filter executed rules by *.drl file
Thanks for your answers. The context fact thing would work, but it is really polluting the rules and makes a lot of unnecessary constraint checks. Furthermore the extends is not implemented in Drools 4 or I am blind (maybe it would be a good idea to switch to drools 5 anyway...). So I think I will go with the one drl per rulebase solution. @manstis: Could you explain why you think the control fact solution is better? -- View this message in context: http://drools.46999.n3.nabble.com/Drools4-Filter-executed-rules-by-drl-file-tp3182568p3184864.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] [Drools4]: Filter executed rules by *.drl file
It was just a feeling, but Vincent's words from (presumably) experience gives the individual rulebase option more credence. On 20 July 2011 09:29, magendo robert.heisenb...@yahoo.com wrote: Thanks for your answers. The context fact thing would work, but it is really polluting the rules and makes a lot of unnecessary constraint checks. Furthermore the extends is not implemented in Drools 4 or I am blind (maybe it would be a good idea to switch to drools 5 anyway...). So I think I will go with the one drl per rulebase solution. @manstis: Could you explain why you think the control fact solution is better? -- View this message in context: http://drools.46999.n3.nabble.com/Drools4-Filter-executed-rules-by-drl-file-tp3182568p3184864.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ 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
Re: [rules-users] [Drools4]: Filter executed rules by *.drl file
Control facts could be a good solution if a execution (of rules) can use some multiple DRL, and if you are using a lot of facts. For example, if you want to do DRL1 and then DRL5 (because of some logic) on the same facts, in that order, you can add control rules to your KB that set/update the Context fact according to some conditions. Note that you can do the same with multiple KB, but then you have to re-insert the objects from one session to another (but it is not so complex, nor so costly). But for the number of DRL you have, I really think that cutting them in KB will be better. Moreover you can implement a big chief controller, that stores the KB in a map, lazily complied when needed. This way, you may not have the whole 300 KB in memory ... And you can even distribute the KB in distributed Agents, and implement the big chief controller with drools (with fusion?) to store some logic about launching the suitable KB according to the event you get, or chain KB, or whatever you can imagine. - Mail original - De: Michael Anstis michael.ans...@gmail.com À: Rules Users List rules-users@lists.jboss.org Envoyé: Mercredi 20 Juillet 2011 11:32:12 Objet: Re: [rules-users] [Drools4]: Filter executed rules by *.drl file It was just a feeling, but Vincent's words from (presumably) experience gives the individual rulebase option more credence. On 20 July 2011 09:29, magendo robert.heisenb...@yahoo.com wrote: Thanks for your answers. The context fact thing would work, but it is really polluting the rules and makes a lot of unnecessary constraint checks. Furthermore the extends is not implemented in Drools 4 or I am blind (maybe it would be a good idea to switch to drools 5 anyway...). So I think I will go with the one drl per rulebase solution. @manstis: Could you explain why you think the control fact solution is better? -- View this message in context: http://drools.46999.n3.nabble.com/Drools4-Filter-executed-rules-by-drl-file-tp3182568p3184864.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ 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
[rules-users] [Drools4]: Filter executed rules by *.drl file
Before I start do explain my problem I should say that I have already searched through the older posts and found similiar problems but not exactly the following one: My Application has multiple RuleFiles (*.drl each with its own package) which can be dynamically added/removed. Based on a context (lets say String foo = bar) only the rulepackage which fits to bar should be executed. Usually that isnt a problem, because drools just executes the rules with the fitting facts. But in this case all the rules in the rulepackages check the same type of facts. Currently I am using an AgendaFilter (if rulepackage == xyz { accept = true}) to achieve this goal, but firstly it doesnt effect inserting of facts (LHS of every rule is executed) and secondly I have read that it should only be used for unit testing, since it couples java code with rule behavior. While reading older posts I have found two possible solutions that could work: 1. Using a contextObject which has foo and is checked in the first rule of each rulepackage. This first rule and the remaining rules in the rulepackage have the same agenda group. So if the first rule doesnt fit, the other rules wont be executed, either (does this really work? ;)). 2. Putting every rulepackge in its own rulebase. Then I would check the context in java and execute the fitting rulebase. Let's say I have about 300 *.drl files. Which solution would be better? Maybe there is a better solution 3) of which I didnt think yet. Then dont hesitate and tell it to me :) Thanks in advance for any help. -- View this message in context: http://drools.46999.n3.nabble.com/Drools4-Filter-executed-rules-by-drl-file-tp3182568p3182568.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] [Drools4]: Filter executed rules by *.drl file
magendo wrote: 1. Using a contextObject which has foo and is checked in the first rule of each rulepackage. This first rule and the remaining rules in the rulepackage have the same agenda group. So if the first rule doesnt fit, the other rules wont be executed, either (does this really work? ;)). Well, that doesnt even seem to work. Here are 2 examples I tried out: rule one auto-focus agenda-group foobar when foo != bar then drools.getWorkingMemory().clearAgendaGroup(foobar); end rule all the other rules agend-group foobar when some conditions then some consequences end This way the some conditions part is still executed in the lhs of all the other rules, altough I cleared the agendagroup foobar (I guess that happens because the rhs is only executed after fireallrules()). There must be a way to affect the lhs of the other rules before fireallrules() is executed?! Btw. my LHS is quite expensive thats why I dont wont to execute it 100 times when only the right one is needed. -- View this message in context: http://drools.46999.n3.nabble.com/Drools4-Filter-executed-rules-by-drl-file-tp3182568p3182842.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] [Drools4]: Filter executed rules by *.drl file
In your scenario, I believe the best (better) approach would be to use a control fact (first in your RHS). Your context can become a Fact itself:- rule one when Foo( value == bar ) ...other patterns then ...do your thang end rule two when Foo( value == bar ) ...other patterns then ...do your other thang end On 19 July 2011 16:25, magendo robert.heisenb...@yahoo.com wrote: magendo wrote: 1. Using a contextObject which has foo and is checked in the first rule of each rulepackage. This first rule and the remaining rules in the rulepackage have the same agenda group. So if the first rule doesnt fit, the other rules wont be executed, either (does this really work? ;)). Well, that doesnt even seem to work. Here are 2 examples I tried out: rule one auto-focus agenda-group foobar when foo != bar then drools.getWorkingMemory().clearAgendaGroup(foobar); end rule all the other rules agend-group foobar when some conditions then some consequences end This way the some conditions part is still executed in the lhs of all the other rules, altough I cleared the agendagroup foobar (I guess that happens because the rhs is only executed after fireallrules()). There must be a way to affect the lhs of the other rules before fireallrules() is executed?! Btw. my LHS is quite expensive thats why I dont wont to execute it 100 times when only the right one is needed. -- View this message in context: http://drools.46999.n3.nabble.com/Drools4-Filter-executed-rules-by-drl-file-tp3182568p3182842.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ 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
Re: [rules-users] [Drools4]: Filter executed rules by *.drl file
In my opinion, for 300 drl files, the better is to use a specific KB for each DRL (or some KAgent). This way you don't have to pollute your rules with control facts (and you can eventually re-use some part of DRL files into multiple context KB), and the RETE is tightened to the strict minimum (no eval of useless constraints). Moreover, I am not sure if drools compiler can really handle some removal or addition of rules dynamically in a existing KB without having to recompile all rules (so keeping up-to-date a big KB can be costly). If you (still) want to use your solution 1 (ie control facts), you can also use rule inheritance (which make a rule inherit the conditions of another parent rule, and the parent rule will contain the check on the control fact) : rule context-rule enabled false // this rule won't fire by itself when Context(task = bar) then // not used anyway end rule X extends context-rule when // specific conditions then // fired when specific conditions AND context-rule's conditions are met end ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users