[rules-users] Runing Rules in Two Phases ( using AgendaFilters ) with inference
Wolfgang Laun
wolfgang.laun at gmail.com
Mon Aug 12 04:26:35 EDT 2013
Use agenda groups, not agenda filters. The latter will fire your rules
as "blanks" whereas agenda groups are just the thing for letting rules
fire in controlled stages.
-W
On 12/08/2013, viraj <mayuraviraj at gmail.com> wrote:
> Hi all,
>
> I have a system which i'm running to learn drools. In this system I have
> two
> sets of rules. First one is eligible rules and other set is selection rules
> which depend on eligible rules. So the system first evaluate eligible rules
> and then add those results to facts in-order to use in selection rules.
> System is working fine in this way. Now I want to run this with two
> phases.
> i.e without using fireAllRules() , I need to run eligible rules ( which are
> in rule package "rule.eligible" ) using AgendaFilter and then later run the
> selection rules which are in "rule.selection" package. The problem is even
> though eligible rules activate selection rules , in second phase selection
> rules won't run. I checked rule execution with KnowledgeRuntimeLogger. This
> shows eligible rules correctly activate selection rules but later when i
> run
> selection rules only , those activated rules do not get executed. I really
> want to rule this in two phases since in some scenarios, I only need
> eligible objects. Is there a another way to achieve this kind of work ?
>
> Ex : Eligible Rule
> package rule.eligible
> rule "Eligible Rule 1 - 4 "
> no-loop true
> when
> $evaluationResults : EvaluationResults( valids not contains "4" );
> UserProfile( userState == UserState.TEST , status == 1 )
> then
> modify( $evaluationResults ) { addIntoEvaluated( 4 + "" ) } ;
> end
>
>
> Ex : Selection Rule
> package rule.selection
> rule "Selection Rule - 3"
> no-loop true
> when
> $evaluationResults : EvaluationResults( validMap not contains "3" ,
> valids contains "4" )
> then
> modify( $evaluationResults ){ addIntoEvaluatedMap("3", "21","23")}
> end;
>
> I'm executing rules in following way.
> To run eligible rules.
> statefulKnowledgeSession.fireAllRules(DroolsHelper.getActivatedRulesFromRuleStartWith("Eligible
> Rule"));
>
> To run selection rules.
> statefulKnowledgeSession.fireAllRules(DroolsHelper.getActivatedRulesFromRuleStartWith("Selection
> Rule"));
>
> Method DroolsHelper.getActivatedRulesFromRuleStartWith
> public static AgendaFilter getActivatedRulesFromRuleStartWith(final
> String startWith) {
> AgendaFilter filter = new AgendaFilter() {
> public boolean accept(Activation activation) {
> if (activation.getRule().getName().startsWith(startWith)) {
> return true;
> }
> return false;
> }
> };
> return filter;
> }
>
> Thanks in advance
>
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Runing-Rules-in-Two-Phases-using-AgendaFilters-with-inference-tp4025458.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list