[rules-users] Runing Rules in Two Phases ( using AgendaFilters ) with inference

viraj mayuraviraj at gmail.com
Mon Aug 12 04:02:20 EDT 2013


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.


More information about the rules-users mailing list