Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially
It seems to me that you should write this as a plain old if/then/else/if... in Java (or any other language). Or is there something else in the way Drools evaluates rules over facts in working memory that makes it highly desirable to use rules? This has been asked before, and more often than not there was a way to avoid a way of establishing the sequence of RHS execution by salience or whatever. So, if you do need rules, you can assign decreasing salience values to all your rules. To terminate, either call the engine's halt() method, or retract the fact(s) triggering the rules. But note that all conditions will be evaluated before the first RHS is executed. To aoid this: see the 1st sentence. -W On 26 September 2011 06:54, Saurabh Pandey meet.saurabhpan...@gmail.comwrote: In drools rules, all the LHS ie when conditions are executed at the start, then all there subsequent rhs ie then part executes, In my project i want to run it as a simple if-else i.e When ... Then do. When ... Then do.. if this when is false then only go to the next when, and if its true then execute its then and then move ahead to the other when. i tried agenda-group, activation-group but these are not working for me. Can some one plz help me! -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all-lhs-execute-before-all-the-rhs-i-want-to-run-sequentially-tp3368215p3368215.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] Drools all lhs execute before all the rhs, i want to run sequentially
Thanks for ur suggestion! I just wanted to keep the business logic in separate drools layer. -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all-lhs-execute-before-all-the-rhs-i-want-to-run-sequentially-tp3368215p3368412.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] Drools all lhs execute before all the rhs, i want to run sequentially
@Nguy I tried salience but it just orders the execution of when part, but still all when execute before the then parts -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all-lhs-execute-before-all-the-rhs-i-want-to-run-sequentially-tp3368215p3368415.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] Drools all lhs execute before all the rhs, i want to run sequentially
take a simple scenario: when condition1 condition2 then ... Does the condition2 gets executed even if the condition1 is false, normally it should not because the conditions in the when are actually combined with an AND. Has anywhen tried this?? -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all-lhs-execute-before-all-the-rhs-i-want-to-run-sequentially-tp3368215p3368464.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] Drools all lhs execute before all the rhs, i want to run sequentially
This isn't an if statement evaluated left to right with an between each part. Drools uses the rete algorithm to make execution more efficient. Put very simply (and probably inaccurately) Rete creates an evaluation tree where inputs are put in the top and activations come out the end. In this case the tree would have: One node that evaluated condition1, this node outputs a list of all the facts that matches it. A node for condition 2 which outputs a list all the facts that match that condition. A node for the rule, this takes the outputs of the other two nodes and produces an activation for each pair of items (assuming condition 1 and 2 aren't related). If you had another rule with condition1 and condition3 then they would both share the first node greatly improving efficiency and re-evaluation time. Thomas -Original Message- From: rules-users-boun...@lists.jboss.org [mailto:rules-users- boun...@lists.jboss.org] On Behalf Of Saurabh Pandey Sent: 26 September 2011 08:15 To: rules-users@lists.jboss.org Subject: Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially take a simple scenario: when condition1 condition2 then ... Does the condition2 gets executed even if the condition1 is false, normally it should not because the conditions in the when are actually combined with an AND. Has anywhen tried this?? -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all- lhs-execute-before-all-the-rhs-i-want-to-run-sequentially- tp3368215p3368464.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 ** This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmas...@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary. NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00 ** ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially
You missed the second part of the instructions - once a rule has matched you need to make sure the other rules don't match. This can be achieved in multiple ways: Call the engines halt method - just stop evaluation. Retract the facts - then nothing else can match it. Update the facts to stop the condition from being matched - eg add a processed field and make the rules match only if processed is false. Insert a new fact and modify your rules to only run if that fact doesn't exist - eg add not YourResultObject() to the when's and insert(new YourResultObject()); to the thens. Thomas -Original Message- From: rules-users-boun...@lists.jboss.org [mailto:rules-users- boun...@lists.jboss.org] On Behalf Of Saurabh Pandey Sent: 26 September 2011 07:49 To: rules-users@lists.jboss.org Subject: Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially @Nguy I tried salience but it just orders the execution of when part, but still all when execute before the then parts -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all- lhs-execute-before-all-the-rhs-i-want-to-run-sequentially- tp3368215p3368415.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 ** This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmas...@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary. NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00 ** ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially
these are my rules: rule Rule 03 salience 10 when $info : RuleRunner() eval(RuleRunner.check()) eval(RuleRunner.setIt()) then System.out.println(3**); $info.printResult(1); end rule Rule 04 salience 8 when $info : RuleRunner() eval(RuleRunner.check()) then System.out.println(4**); $info.printResult(2); end these are my java methods: static boolean cvar = true; public void printResult(int i){ System.out.println(i); } public static boolean check(){ System.out.println(check**); return cvar; } public static boolean setIt(){ cvar = false; return true; } this is how i am invoking the rules: KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newFileResource(rule03.drl), ResourceType.DRL ); if ( kbuilder.hasErrors() ) { System.err.println( kbuilder.getErrors().toString() ); } KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() ); StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession(); ksession.execute(new RuleRunner()); This is the output: check** 3** 1 4** 2 Why is check printing only once though its called 2 times in 2 rules, and when cvar is false then also 2nd rule's then part is executing? Is it that static methods of same name are called once and there result is stored and used in all rules?? -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all-lhs-execute-before-all-the-rhs-i-want-to-run-sequentially-tp3368215p3368864.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] Drools all lhs execute before all the rhs, i want to run sequentially
Have you read the expert guide? http://docs.jboss.org/drools/release/5.2.0.Final/drools-expert-docs/html_single/index.html - At least up to the end of chapter 4. Why are you using static fields and methods? You are changing the value of objects in the when condition which is really really really bad and it's no wonder nothing is working like you are expecting. The fact that you are using eval's is a good indication that your code is written wrong, for simple rules you never need to use it. Thomas -Original Message- From: rules-users-boun...@lists.jboss.org [mailto:rules-users- boun...@lists.jboss.org] On Behalf Of Saurabh Pandey Sent: 26 September 2011 11:22 To: rules-users@lists.jboss.org Subject: Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially these are my rules: rule Rule 03 salience 10 when $info : RuleRunner() eval(RuleRunner.check()) eval(RuleRunner.setIt()) then System.out.println(3**); $info.printResult(1); end rule Rule 04 salience 8 when $info : RuleRunner() eval(RuleRunner.check()) then System.out.println(4**); $info.printResult(2); end these are my java methods: static boolean cvar = true; public void printResult(int i){ System.out.println(i); } public static boolean check(){ System.out.println(check**); return cvar; } public static boolean setIt(){ cvar = false; return true; } this is how i am invoking the rules: KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newFileResource(rule03.drl), ResourceType.DRL ); if ( kbuilder.hasErrors() ) { System.err.println( kbuilder.getErrors().toString() ); } KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() ); StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession(); ksession.execute(new RuleRunner()); This is the output: check** 3** 1 4** 2 Why is check printing only once though its called 2 times in 2 rules, and when cvar is false then also 2nd rule's then part is executing? Is it that static methods of same name are called once and there result is stored and used in all rules?? -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all- lhs-execute-before-all-the-rhs-i-want-to-run-sequentially- tp3368215p3368864.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 ** This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmas...@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary. NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00 ** ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially
@thomas thanks for your comments I am new to drools, can u plz give me an alternative to the above code. -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all-lhs-execute-before-all-the-rhs-i-want-to-run-sequentially-tp3368215p3368917.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] Drools all lhs execute before all the rhs, i want to run sequentially
Saurabh Pandey wrote: @Nguy I tried salience but it just orders the execution of when part, but still all when execute before the then parts Hi, it seems to me that you are using the wrong tool to solve your problem. Drools is a rule-based execution engine (among other things) not a glorified if-then-else-if executor. I'd suggest you consult the Drools manual (site is off at the moment). At the beggining there is a nice section about when you could benefit from a Drools-like approach or not. If you still think that Drools is best suited for your needs, you need to rethink your approach. I would not suggest using salience as this could be mistaked as a way to force procedural logic on a system(Drools) that is inherently not so. -Stathis -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all-lhs-execute-before-all-the-rhs-i-want-to-run-sequentially-tp3368215p3368415.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] Drools all lhs execute before all the rhs, i want to run sequentially
As I said, try reading the expert doc, there's some examples in there which you can base your code on. Once you've done that or if you have any questions about the samples/what the documentation means then post them and we'd be pleased to help, but the first step is to structure your code correctly using objects that follow the bean conventions and rules structured correctly with conditions against objects and appropriate modify statements. Thomas -Original Message- From: rules-users-boun...@lists.jboss.org [mailto:rules-users- boun...@lists.jboss.org] On Behalf Of Saurabh Pandey Sent: 26 September 2011 11:51 To: rules-users@lists.jboss.org Subject: Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially @thomas thanks for your comments I am new to drools, can u plz give me an alternative to the above code. -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all- lhs-execute-before-all-the-rhs-i-want-to-run-sequentially- tp3368215p3368917.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 ** This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmas...@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary. NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00 ** ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially
Hi, If you have a lot of rules like it you might be able to use the jBPM (what what the Drools Flow) to help with this. Otherwise plan old java might be easier... Wendy From: Swindells, Thomas tswinde...@nds.com To: Rules Users List rules-users@lists.jboss.org Sent: Monday, September 26, 2011 6:53 AM Subject: Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially As I said, try reading the expert doc, there's some examples in there which you can base your code on. Once you've done that or if you have any questions about the samples/what the documentation means then post them and we'd be pleased to help, but the first step is to structure your code correctly using objects that follow the bean conventions and rules structured correctly with conditions against objects and appropriate modify statements. Thomas -Original Message- From: rules-users-boun...@lists.jboss.org [mailto:rules-users- boun...@lists.jboss.org] On Behalf Of Saurabh Pandey Sent: 26 September 2011 11:51 To: rules-users@lists.jboss.org Subject: Re: [rules-users] Drools all lhs execute before all the rhs, i want to run sequentially @thomas thanks for your comments I am new to drools, can u plz give me an alternative to the above code. -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all- lhs-execute-before-all-the-rhs-i-want-to-run-sequentially- tp3368215p3368917.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 ** This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmas...@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary. NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00 ** ___ 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] Drools all lhs execute before all the rhs, i want to run sequentially
In drools rules, all the LHS ie when conditions are executed at the start, then all there subsequent rhs ie then part executes, In my project i want to run it as a simple if-else i.e When ... Then do. When ... Then do.. if this when is false then only go to the next when, and if its true then execute its then and then move ahead to the other when. i tried agenda-group, activation-group but these are not working for me. Can some one plz help me! -- View this message in context: http://drools.46999.n3.nabble.com/Drools-all-lhs-execute-before-all-the-rhs-i-want-to-run-sequentially-tp3368215p3368215.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