Nikil,
  What I said about the missing map entries still holds true but listen to Wolfgang. Since you are concerned with efficiency, using eval() and a map is a very inefficient approach.
     Scott

Wolfgang Laun [3/19/2009 9:09 AM] wrote:
It appears that you want to reason about travel bookings or some such thing.

You are thinking of the various attributes as individual (abstract) things that
have a designation (such as "Adult Fare") and a value, with the intent to
handle this with a set of facts, each of which has these two fields. While
this "property list" view of data may have its merits, it complicates the writing
of rules in system like Drools.

Moreover, keeping this data in a map is fine from the Java point of view, but it
leads to complications while processing it in DRL rules. (To say nothing
about the poor performance due to eval all over the place.) I'm not sure
about the relation between your Java class RuleAttributes and the
HashMap instance hmAttriList, but even if the latter were an instance
of the former (so it is a subclass of HashMap), it is questionable what
the $a.Values["..."] returns - most likely not an Integer, and this is
confirmed by the compiler's error message.

Try to view a Booking as a Java Bean with attributes
int numberOfAdults
int numberOfChildren
int childFare
int adultFare
boolean rejected
and any other attribute of a booking you might want to put there.

Create an instance of this bean and add it to Working Memory.

A rule could now be written as

rule "adt_chld_fare"
no-loop true
when
    $b: Booking( $af : adultFare, childFare > ($af - 1500) )
then
    modify( $b ){ setRejected( true ); }
end

There are many possible variations on this. Here is just one idea:

You might not want to have the rejection being stored in the Booking bean,
so you could, perhaps assert an instance of another suitably composed Bean
class Rejection
    Booking booking
    String    reason

Much of the design depends on what and how you need to get the results
of rule firing back to the application, so I won't continue.

-W
On Thu, Mar 19, 2009 at 7:52 AM, Nikhil_dev <k.nikhil@verchaska.com> wrote:

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@14a0fe1]
]
Error Message : org.mvel.CompileException: could not perform numeric
operation on non-numeric types: left-type=null; right-type=java.lang.Integer




_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users