[rules-users] Identify Rule on Attributes

Nikhil_dev k.nikhil at verchaska.com
Thu Mar 19 02:52:04 EDT 2009


i have combined all the rules into a single RuleBase,
below is the content of drl file,

package com.vtech.ruleengine.module.rulemanagermodule
import com.vtech.ruleengine.module.rulemanagermodule.RuleAttributes;
import java.util.Map;

rule  "adt_chld_fare"
dialect "mvel"
when 
        $a : RuleAttributes() 
        eval ($a.Values["Adult Fare"]> ($a.Values["Child Fare"]+ 1500 ) ) 
then 
         ($a.Values["AcceptRejectFilter"]='Reject')
end


rule  "DEMO_RULE"
dialect "mvel"
when 
        $a : RuleAttributes() 
        eval ($a.Values["Adult Fare"]> 8000 ) 
then 
         ($a.Values["Nett Payable"]= ($a.Values["Adult Fare"]* 0.80 ) ) 
end


rule  "Compare_date_1"
dialect "mvel"
when 
        $a : RuleAttributes() 
        eval ('12-Jan-2009'>='15-Jan-2008') 
then 
         ($a.Values["Adult Fare"]= 5000 ) 
end


rule  "Rule_20090106_1"
dialect "mvel"
when 
        $a : RuleAttributes() 
        eval ( ($a.Values["No Of Adults"]< 10 ) && ($a.Values["No Of
Adults"]> 5 ) ) 
then 
         ($a.Values["Adult Fare"]= ($a.Values["Adult Fare"]+ -50 ) ) 
end


rule  "Rule_20090107_Markup"
dialect "mvel"
when 
        $a : RuleAttributes() 
        eval ($a.Values["markupPerc"]>= 0 ) 
then 
         ($a.Values["markupAmount"]=
($a.Values["buyingAmount"]*$a.Values["markupPerc"]) ) 
end


rule  "Sample_Rule"
dialect "mvel"
when 
        $a : RuleAttributes() 
        eval ($a.Values["Sector"]< 0 ) 
then 
         ($a.Values["Via"]= ($a.Values["Via1"]+ 1250 ) ) 
end

i am passing following hashmap containing,
hmAttriList.put("Adult Fare", 8000);
hmAttriList.put("Child Fare", 80);
hmAttriList.put("Gross Fare", 0);
hmAttriList.put("Published Fare", 0);

while executing it i am getting following error message
SEVERE [global]
org.mvel.CompileException: could not perform numeric operation on
non-numeric types: left-type=null; right-type=java.lang.Integer
        at
org.mvel.math.IEEEFloatingPointMath.doOperationNonNumeric(IEEEFloatingPointMath.java:149)
        at
org.mvel.math.IEEEFloatingPointMath._doOperations(IEEEFloatingPointMath.java:102)
        at
org.mvel.math.IEEEFloatingPointMath.doOperation(IEEEFloatingPointMath.java:43)
        at org.mvel.util.ParseTools.doOperations(ParseTools.java:810)
        at
org.mvel.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:21)
        at org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java:45)
        at
org.mvel.ast.Substatement.getReducedValueAccelerated(Substatement.java:24)
.............
..............
==>[ActivationCreated(0): rule=adt_chld_fare;
tuple=[fid:1:1:com.vtech.ruleengine.module.rulemanagermodule.RuleAttributes at 14a0fe1]
]
Error Message : org.mvel.CompileException: could not perform numeric
operation on non-numeric types: left-type=null; right-type=java.lang.Integer






Wolfgang Laun-2 wrote:
> 
> On Mon, Mar 16, 2009 at 6:24 AM, Nikhil_dev <k.nikhil at verchaska.com>
> wrote:
> 
>>
>> As you guys have suggested to combine all the rule base into one then for
>> example(one which i have already mentioned)
>> i will combine Rule1 , rule 2 and rule3 into 1 rule base then, when i
>> pass
>> the variables to the rulebase who will i come to know which rules were
>> executed.
>>
> 
> Knowing (as you say) about the execution of rules may be used by the
> system you build in several ways. In any case, the right hand side of a
> rule (after the "when" keyword) is the place to program the actions
> that preserve the knowledge that this rule has fired. If nothing is done
> on the right hand side, then the effect of the execution of a rule is
> indeed lost.
> 
> The most important ways of making use of the firing of a rule are:
> 
> (1) To assert a (new) fact into the Working Memory. This is done if
> one expects these new facts to combine with each other or the original
> facts in more rule firings.
> 
> (2) To modify an existing fact that has been found (matched) by
> the rule. This may, in turn, fire other rules.
> 
> (3) To make use of some application service to inform the user
> of your system that the system has concluded a result. A very
> simple way would be to print a message on the terminal; a more
> sophisticated way might be to send a message; etc.
> 
> Certainly any combination of these basic techniques is to be
> considered as well.
> 
> You have, so far, shown us examples of very simple rules; it is
> not clear to me what the purpose of this system will ultimately be.
> Therefore, I cannot advise you about what is best in your case.
> 
> 
>> things i would like to know if i am going to execute this idea, the
>> number
>> of rules that i will using say around 100000, is it advisable to include
>> all
>> of them in to 1 rulebase!!!
>> will there be any performance issues.
>>
> 
> Performance is not only a question of the number of rules; it is also
> a question of the quality of the conditions, the number of patterns and
> the number of facts that are asserted.
> 
> 100000 rules is certainly a big number. Memory consumption will
> be high. Loading facts and firing depends on the way patterns are
> written, and how many facts you'll have in a session. But for me
> the main point is how you'll manage to produce this many rules.
> Even if you manage to think up, write and test one rule per minute
> then this would take 1666 hours or about 10 months of work!
> Moreover, you'll have to make sure that this set of rules is consistent
> in their combination, e.g., that it doesn't miss a combination of facts
> that it should react upon.
> 
> To build a good rule based system isn't easier than building any other
> complex software system; perhaps it is even more difficult. There are
> some good books around that describe the designs that might be applied
> with such systems; some of them are referenced on this page:
> http://www.jboss.org/drools/documentation.html
> 
> -W
> 
> 
>>
>>
>>
>> Anstis, Michael (M.) wrote:
>> >
>> > Furthermore a rulebase can contain rules from many resources (e.g.
>> > DRL's).
>> >
>> > So I guess the cause of your pain is why do you need multiple
>> > rulebases!??!
>> >
>> > -----Original Message-----
>> > From: rules-users-bounces at lists.jboss.org
>> > [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Scott Reed
>> > Sent: 13 March 2009 14:41
>> > To: Rules Users List
>> > Subject: Re: [rules-users] Identify Rule on Attributes
>> >
>> > A RuleBase can contain many rules, not just one. Generally we take all
>> > the rules we need for an application and we assemble them into one
>> > rulebase, so we don't have to figure out which rulebase to use. Does
>> > that help?
>> >
>> > Nikhil_dev [3/13/2009 8:16 AM] wrote:
>> >> Perfect this is the situation but the only difference is the last
>> > part,
>> >>
>> >> Rulebase for all the 3 Rules are stored in memory.
>> >>
>> >> Now i have is attributes(implemented as bean class), but the issue is
>> > i dont
>> >> know which Rulebase to use out of the three which is present in the
>> > memory,
>> >> fetching them one by one and executing it individually is possible but
>> > a
>> >> long procedure which i want to avoid.(executing 3 Rule is ok what if i
>> > have
>> >> 100000 rules it will be very slow process)
>> >>
>> > _______________________________________________
>> > rules-users mailing list
>> > rules-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>> > _______________________________________________
>> > rules-users mailing list
>> > rules-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>> >
>>
>>
>> -----
>> Regards,
>> :working:Nikhil
>> --
>> View this message in context:
>> http://www.nabble.com/Identify-Rule-on-Attributes-tp22471473p22532090.html
>> Sent from the drools - user mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 


-----
Regards,
:working:Nikhil
-- 
View this message in context: http://www.nabble.com/Identify-Rule-on-Attributes-tp22471473p22594579.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list