Re: [rules-users] Firing a rule if at least its two conditions are satified
I had to do something like this. The way I did it is by prividing a method in my object in working memory that takes multiple Boolean conditions and loops through them and return true if at least N of the conditions were true. So, this funtions will take N and a list of all conditions. Then it returns true or false. So, your eval will look like this: eval(obj.atLeastNTrue(n, conditionA, conditionB, conditionC, etc)) Sent from my iPhone On Jun 3, 2010, at 7:03 AM, skasab2s wrote: > > Hello, > > we are using Drools in our company. We have a rule with three > conditions in > this format: > > when > Condition A > Condition B > Condition C > then > execute Action 1 > > Now we have a situation, in which the rule should fire if AT LEAST > two of > the three conditions are satisfied. Do you know how to implement > this? Any > ideas or hints? > > Many thanks and regards! > > skasab2s. > > > > > -- > View this message in context: > http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-least-its-two-conditions-are-satified-tp867432p867432.html > Sent from the Drools - User 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] Firing a rule if at least its two conditions are satified
By the "solutions given" I didn't mean to tell mine was good, apparently it's not, I was talking about the other ones. -Message d'origine- De : rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] De la part de PAYET, Manuel Envoyé : jeudi 3 juin 2010 15:33 À : Rules Users List Objet : Re: [rules-users] Firing a rule if at least its two conditions are satified The solutions given are useable anyway, Thanks for this information GreG -Message d'origine- De : rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] De la part de Greg Barton Envoyé : jeudi 3 juin 2010 15:29 À : Rules Users List Objet : Re: [rules-users] Firing a rule if at least its two conditions are satified This will not work. Rules will not predictably react to changes in global variables. Use an object in working memory. GreG On Jun 3, 2010, at 7:15, "PAYET, Manuel" wrote: If I were you, I'd use something like Global java.lang.Integer cnt; Rule "before everything" Salience 10 When Eval(true) Then Cnt=0 End Rule "condition A" When condition A Then cnt=cnt+1; End Rule "condition B" When condition B Then cnt=cnt+1; End Rule "condition C" When condition B Then cnt=cnt+1; End Rule "action 1, after everything" Salience -10 When eval(cnt>=2) Then execute action 1 End Of course, if you change the fact, you'll probably have to think about things like lock-on-active to increment only one time the cnt variable -Message d'origine- De : rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] De la part de skasab2s Envoyé : jeudi 3 juin 2010 14:04 À : rules-users@lists.jboss.org Objet : [rules-users] Firing a rule if at least its two conditions are satified Hello, we are using Drools in our company. We have a rule with three conditions in this format: when Condition A Condition B Condition C then execute Action 1 Now we have a situation, in which the rule should fire if AT LEAST two of the three conditions are satisfied. Do you know how to implement this? Any ideas or hints? Many thanks and regards! skasab2s. -- View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-least-its-two-conditions-are-satified-tp867432p867432.html Sent from the Drools - User 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 contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ 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 This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Firing a rule if at least its two conditions are satified
The solutions given are useable anyway, Thanks for this information GreG -Message d'origine- De : rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] De la part de Greg Barton Envoyé : jeudi 3 juin 2010 15:29 À : Rules Users List Objet : Re: [rules-users] Firing a rule if at least its two conditions are satified This will not work. Rules will not predictably react to changes in global variables. Use an object in working memory. GreG On Jun 3, 2010, at 7:15, "PAYET, Manuel" wrote: If I were you, I'd use something like Global java.lang.Integer cnt; Rule "before everything" Salience 10 When Eval(true) Then Cnt=0 End Rule "condition A" When condition A Then cnt=cnt+1; End Rule "condition B" When condition B Then cnt=cnt+1; End Rule "condition C" When condition B Then cnt=cnt+1; End Rule "action 1, after everything" Salience -10 When eval(cnt>=2) Then execute action 1 End Of course, if you change the fact, you'll probably have to think about things like lock-on-active to increment only one time the cnt variable -Message d'origine- De : rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] De la part de skasab2s Envoyé : jeudi 3 juin 2010 14:04 À : rules-users@lists.jboss.org Objet : [rules-users] Firing a rule if at least its two conditions are satified Hello, we are using Drools in our company. We have a rule with three conditions in this format: when Condition A Condition B Condition C then execute Action 1 Now we have a situation, in which the rule should fire if AT LEAST two of the three conditions are satisfied. Do you know how to implement this? Any ideas or hints? Many thanks and regards! skasab2s. -- View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-least-its-two-conditions-are-satified-tp867432p867432.html Sent from the Drools - User 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 contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ 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 This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Firing a rule if at least its two conditions are satified
This will not work. Rules will not predictably react to changes in global variables. Use an object in working memory. GreG On Jun 3, 2010, at 7:15, "PAYET, Manuel" wrote: If I were you, I'd use something like Global java.lang.Integer cnt; Rule "before everything" Salience 10 When Eval(true) Then Cnt=0 End Rule "condition A" When condition A Then cnt=cnt+1; End Rule "condition B" When condition B Then cnt=cnt+1; End Rule "condition C" When condition B Then cnt=cnt+1; End Rule "action 1, after everything" Salience -10 When eval(cnt>=2) Then execute action 1 End Of course, if you change the fact, you'll probably have to think about things like lock-on-active to increment only one time the cnt variable -Message d'origine- De : rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] De la part de skasab2s Envoyé : jeudi 3 juin 2010 14:04 À : rules-users@lists.jboss.org Objet : [rules-users] Firing a rule if at least its two conditions are satified Hello, we are using Drools in our company. We have a rule with three conditions in this format: when Condition A Condition B Condition C then execute Action 1 Now we have a situation, in which the rule should fire if AT LEAST two of the three conditions are satisfied. Do you know how to implement this? Any ideas or hints? Many thanks and regards! skasab2s. -- View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-least-its-two-conditions-are-satified-tp867432p867432.html Sent from the Drools - User 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 contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ 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] Firing a rule if at least its two conditions are satified
Yes, you're right Tihomir Surdilovic your solution is way more elegant than mine. And to skasab2s: you should use a function to avoid copy and paste three time the same then clause De : rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] De la part de Tihomir Surdilovic Envoyé : jeudi 3 juin 2010 14:40 À : rules-users@lists.jboss.org Objet : Re: [rules-users] Firing a rule if at least its two conditions are satified IMO you can just use activation groups and not have to deal with incrementing, something like: rule first activation-group "myactgrp" when Condition A Condition B then ... end rule second activation-group "myactgrp" when Condition A Condition C then ... end rule third activation-group "myactgrp" when Condition B Condition C then ... end When one of these rules fire it will cancel the activation of all other rules in the same activation group. You can also then add salience to control rule priority. On 6/3/10 8:15 AM, PAYET, Manuel wrote: If I were you, I'd use something like Global java.lang.Integer cnt; Rule "before everything" Salience 10 When Eval(true) Then Cnt=0 End Rule "condition A" When condition A Then cnt=cnt+1; End Rule "condition B" When condition B Then cnt=cnt+1; End Rule "condition C" When condition B Then cnt=cnt+1; End Rule "action 1, after everything" Salience -10 When eval(cnt>=2) Then execute action 1 End Of course, if you change the fact, you'll probably have to think about things like lock-on-active to increment only one time the cnt variable -Message d'origine- De : rules-users-boun...@lists.jboss.org<mailto:rules-users-boun...@lists.jboss.org> [mailto:rules-users-boun...@lists.jboss.org] De la part de skasab2s Envoyé : jeudi 3 juin 2010 14:04 À : rules-users@lists.jboss.org<mailto:rules-users@lists.jboss.org> Objet : [rules-users] Firing a rule if at least its two conditions are satified Hello, we are using Drools in our company. We have a rule with three conditions in this format: when Condition A Condition B Condition C then execute Action 1 Now we have a situation, in which the rule should fire if AT LEAST two of the three conditions are satisfied. Do you know how to implement this? Any ideas or hints? Many thanks and regards! skasab2s. -- View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-least-its-two-conditions-are-satified-tp867432p867432.html Sent from the Drools - User mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org<mailto:rules-users@lists.jboss.org> https://lists.jboss.org/mailman/listinfo/rules-users This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ rules-users mailing list rules-users@lists.jboss.org<mailto:rules-users@lists.jboss.org> https://lists.jboss.org/mailman/listinfo/rules-users This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Firing a rule if at least its two conditions are satified
A better approach is probably to split up the conditions from action. Each condition would be a separate rule which would use insertLogically to insert a new object. Then have another rule which accumulates and counts how many of these objects exist in the working memory. If the count is >= 2 then perform the action. Thomas From: rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Tihomir Surdilovic Sent: 03 June 2010 13:40 To: rules-users@lists.jboss.org Subject: Re: [rules-users] Firing a rule if at least its two conditions are satified IMO you can just use activation groups and not have to deal with incrementing, something like: rule first activation-group "myactgrp" when Condition A Condition B then ... end rule second activation-group "myactgrp" when Condition A Condition C then ... end rule third activation-group "myactgrp" when Condition B Condition C then ... end When one of these rules fire it will cancel the activation of all other rules in the same activation group. You can also then add salience to control rule priority. On 6/3/10 8:15 AM, PAYET, Manuel wrote: If I were you, I'd use something like Global java.lang.Integer cnt; Rule "before everything" Salience 10 When Eval(true) Then Cnt=0 End Rule "condition A" When condition A Then cnt=cnt+1; End Rule "condition B" When condition B Then cnt=cnt+1; End Rule "condition C" When condition B Then cnt=cnt+1; End Rule "action 1, after everything" Salience -10 When eval(cnt>=2) Then execute action 1 End Of course, if you change the fact, you'll probably have to think about things like lock-on-active to increment only one time the cnt variable -Message d'origine- De : rules-users-boun...@lists.jboss.org<mailto:rules-users-boun...@lists.jboss.org> [mailto:rules-users-boun...@lists.jboss.org] De la part de skasab2s Envoyé : jeudi 3 juin 2010 14:04 À : rules-users@lists.jboss.org<mailto:rules-users@lists.jboss.org> Objet : [rules-users] Firing a rule if at least its two conditions are satified Hello, we are using Drools in our company. We have a rule with three conditions in this format: when Condition A Condition B Condition C then execute Action 1 Now we have a situation, in which the rule should fire if AT LEAST two of the three conditions are satisfied. Do you know how to implement this? Any ideas or hints? Many thanks and regards! skasab2s. -- View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-least-its-two-conditions-are-satified-tp867432p867432.html Sent from the Drools - User mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org<mailto:rules-users@lists.jboss.org> https://lists.jboss.org/mailman/listinfo/rules-users This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ rules-users mailing list rules-users@lists.jboss.org<mailto: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] Firing a rule if at least its two conditions are satified
IMO you can just use activation groups and not have to deal with incrementing, something like: rule first activation-group "myactgrp" when Condition A Condition B then ... end rule second activation-group "myactgrp" when Condition A Condition C then ... end rule third activation-group "myactgrp" when Condition B Condition C then ... end When one of these rules fire it will cancel the activation of all other rules in the same activation group. You can also then add salience to control rule priority. On 6/3/10 8:15 AM, PAYET, Manuel wrote: If I were you, I'd use something like Global java.lang.Integer cnt; Rule "before everything" Salience 10 When Eval(true) Then Cnt=0 End Rule "condition A" When condition A Then cnt=cnt+1; End Rule "condition B" When condition B Then cnt=cnt+1; End Rule "condition C" When condition B Then cnt=cnt+1; End Rule "action 1, after everything" Salience -10 When eval(cnt>=2) Then execute action 1 End Of course, if you change the fact, you'll probably have to think about things like lock-on-active to increment only one time the cnt variable -Message d'origine- De : rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] De la part de skasab2s Envoyé : jeudi 3 juin 2010 14:04 À : rules-users@lists.jboss.org Objet : [rules-users] Firing a rule if at least its two conditions are satified Hello, we are using Drools in our company. We have a rule with three conditions in this format: when Condition A Condition B Condition C then execute Action 1 Now we have a situation, in which the rule should fire if AT LEAST two of the three conditions are satisfied. Do you know how to implement this? Any ideas or hints? Many thanks and regards! skasab2s. -- View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-least-its-two-conditions-are-satified-tp867432p867432.html Sent from the Drools - User 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 contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ 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] Firing a rule if at least its two conditions are satified
If I were you, I'd use something like Global java.lang.Integer cnt; Rule "before everything" Salience 10 When Eval(true) Then Cnt=0 End Rule "condition A" When condition A Then cnt=cnt+1; End Rule "condition B" When condition B Then cnt=cnt+1; End Rule "condition C" When condition B Then cnt=cnt+1; End Rule "action 1, after everything" Salience -10 When eval(cnt>=2) Then execute action 1 End Of course, if you change the fact, you'll probably have to think about things like lock-on-active to increment only one time the cnt variable -Message d'origine- De : rules-users-boun...@lists.jboss.org [mailto:rules-users-boun...@lists.jboss.org] De la part de skasab2s Envoyé : jeudi 3 juin 2010 14:04 À : rules-users@lists.jboss.org Objet : [rules-users] Firing a rule if at least its two conditions are satified Hello, we are using Drools in our company. We have a rule with three conditions in this format: when Condition A Condition B Condition C then execute Action 1 Now we have a situation, in which the rule should fire if AT LEAST two of the three conditions are satisfied. Do you know how to implement this? Any ideas or hints? Many thanks and regards! skasab2s. -- View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-least-its-two-conditions-are-satified-tp867432p867432.html Sent from the Drools - User 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 contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Firing a rule if at least its two conditions are satified
Hello, we are using Drools in our company. We have a rule with three conditions in this format: when Condition A Condition B Condition C then execute Action 1 Now we have a situation, in which the rule should fire if AT LEAST two of the three conditions are satisfied. Do you know how to implement this? Any ideas or hints? Many thanks and regards! skasab2s. -- View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Firing-a-rule-if-at-least-its-two-conditions-are-satified-tp867432p867432.html Sent from the Drools - User mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users