<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Nikil,<br>
&nbsp; 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.<br>
&nbsp;&nbsp;&nbsp;&nbsp; Scott<br>
<br>
Wolfgang Laun [3/19/2009 9:09 AM] wrote:
<blockquote
 cite="mid:17de7ee80903190609r10bb372bh3746e818ff97db83@mail.gmail.com"
 type="cite">It appears that you want to reason about travel bookings
or some such thing.<br>
  <br>
You are thinking of the various attributes as individual (abstract)
things that<br>
have a designation (such as "Adult Fare") and a value, with the intent
to<br>
handle this with a set of facts, each of which has these two fields.
While<br>
this "property list" view of data may have its merits, it complicates
the writing<br>
of rules in system like Drools.<br>
  <br>
Moreover, keeping this data in a map is fine from the Java point of
view, but it<br>
leads to complications while processing it in DRL rules. (To say nothing<br>
about the poor performance due to eval all over the place.) I'm not sure<br>
about the relation between your Java class RuleAttributes and the<br>
HashMap instance hmAttriList, but even if the latter were an instance<br>
of the former (so it is a subclass of HashMap), it is questionable what<br>
the $a.Values["..."] returns - most likely not an Integer, and this is<br>
confirmed by the compiler's error message.<br>
  <br>
Try to view a Booking as a Java Bean with attributes<br>
int numberOfAdults<br>
int numberOfChildren<br>
int childFare<br>
int adultFare<br>
boolean rejected<br>
and any other attribute of a booking you might want to put there.<br>
  <br>
Create an instance of this bean and add it to Working Memory.<br>
  <br>
A rule could now be written as<br>
  <br>
rule "adt_chld_fare"<br>
no-loop true<br>
when<br>
&nbsp;&nbsp;&nbsp; $b: Booking( $af : adultFare, childFare &gt; ($af - 1500) )<br>
then<br>
&nbsp;&nbsp;&nbsp; modify( $b ){ setRejected( true ); }<br>
end<br>
  <br>
There are many possible variations on this. Here is just one idea:<br>
  <br>
You might not want to have the rejection being stored in the Booking
bean,<br>
so you could, perhaps assert an instance of another suitably composed
Bean<br>
class Rejection<br>
&nbsp;&nbsp;&nbsp; Booking booking<br>
&nbsp;&nbsp;&nbsp; String&nbsp;&nbsp;&nbsp; reason<br>
  <br>
Much of the design depends on what and how you need to get the results<br>
of rule firing back to the application, so I won't continue.<br>
  <br>
-W<br>
  <div class="gmail_quote">On Thu, Mar 19, 2009 at 7:52 AM, Nikhil_dev <span
 dir="ltr">&lt;<a moz-do-not-send="true"
 href="mailto:k.nikhil@verchaska.com" target="_blank">k.nikhil@verchaska.com</a>&gt;</span>
wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
i have combined all the rules into a single RuleBase,<br>
below is the content of drl file,<br>
    <br>
package com.vtech.ruleengine.module.rulemanagermodule<br>
import com.vtech.ruleengine.module.rulemanagermodule.RuleAttributes;<br>
import java.util.Map;<br>
    <br>
rule &nbsp;"adt_chld_fare"<br>
dialect "mvel"<br>
when<br>
&nbsp; &nbsp; &nbsp; &nbsp;$a : RuleAttributes()<br>
&nbsp; &nbsp; &nbsp; &nbsp;eval ($a.Values["Adult Fare"]&gt; ($a.Values["Child Fare"]+ 1500
) )<br>
then<br>
&nbsp; &nbsp; &nbsp; &nbsp; ($a.Values["AcceptRejectFilter"]='Reject')<br>
end<br>
    <br>
    <br>
rule &nbsp;"DEMO_RULE"<br>
dialect "mvel"<br>
when<br>
&nbsp; &nbsp; &nbsp; &nbsp;$a : RuleAttributes()<br>
&nbsp; &nbsp; &nbsp; &nbsp;eval ($a.Values["Adult Fare"]&gt; 8000 )<br>
then<br>
&nbsp; &nbsp; &nbsp; &nbsp; ($a.Values["Nett Payable"]= ($a.Values["Adult Fare"]* 0.80 ) )<br>
end<br>
    <br>
    <br>
rule &nbsp;"Compare_date_1"<br>
dialect "mvel"<br>
when<br>
&nbsp; &nbsp; &nbsp; &nbsp;$a : RuleAttributes()<br>
&nbsp; &nbsp; &nbsp; &nbsp;eval ('12-Jan-2009'&gt;='15-Jan-2008')<br>
then<br>
&nbsp; &nbsp; &nbsp; &nbsp; ($a.Values["Adult Fare"]= 5000 )<br>
end<br>
    <br>
    <br>
rule &nbsp;"Rule_20090106_1"<br>
dialect "mvel"<br>
when<br>
&nbsp; &nbsp; &nbsp; &nbsp;$a : RuleAttributes()<br>
&nbsp; &nbsp; &nbsp; &nbsp;eval ( ($a.Values["No Of Adults"]&lt; 10 ) &amp;&amp;
($a.Values["No Of<br>
Adults"]&gt; 5 ) )<br>
then<br>
&nbsp; &nbsp; &nbsp; &nbsp; ($a.Values["Adult Fare"]= ($a.Values["Adult Fare"]+ -50 ) )<br>
end<br>
    <br>
    <br>
rule &nbsp;"Rule_20090107_Markup"<br>
dialect "mvel"<br>
when<br>
&nbsp; &nbsp; &nbsp; &nbsp;$a : RuleAttributes()<br>
&nbsp; &nbsp; &nbsp; &nbsp;eval ($a.Values["markupPerc"]&gt;= 0 )<br>
then<br>
&nbsp; &nbsp; &nbsp; &nbsp; ($a.Values["markupAmount"]=<br>
($a.Values["buyingAmount"]*$a.Values["markupPerc"]) )<br>
end<br>
    <br>
    <br>
rule &nbsp;"Sample_Rule"<br>
dialect "mvel"<br>
when<br>
&nbsp; &nbsp; &nbsp; &nbsp;$a : RuleAttributes()<br>
&nbsp; &nbsp; &nbsp; &nbsp;eval ($a.Values["Sector"]&lt; 0 )<br>
then<br>
&nbsp; &nbsp; &nbsp; &nbsp; ($a.Values["Via"]= ($a.Values["Via1"]+ 1250 ) )<br>
end<br>
    <br>
i am passing following hashmap containing,<br>
hmAttriList.put("Adult Fare", 8000);<br>
hmAttriList.put("Child Fare", 80);<br>
hmAttriList.put("Gross Fare", 0);<br>
hmAttriList.put("Published Fare", 0);<br>
    <br>
while executing it i am getting following error message<br>
SEVERE [global]<br>
org.mvel.CompileException: could not perform numeric operation on<br>
non-numeric types: left-type=null; right-type=java.lang.Integer<br>
&nbsp; &nbsp; &nbsp; &nbsp;at<br>
org.mvel.math.IEEEFloatingPointMath.doOperationNonNumeric(IEEEFloatingPointMath.java:149)<br>
&nbsp; &nbsp; &nbsp; &nbsp;at<br>
org.mvel.math.IEEEFloatingPointMath._doOperations(IEEEFloatingPointMath.java:102)<br>
&nbsp; &nbsp; &nbsp; &nbsp;at<br>
org.mvel.math.IEEEFloatingPointMath.doOperation(IEEEFloatingPointMath.java:43)<br>
&nbsp; &nbsp; &nbsp; &nbsp;at org.mvel.util.ParseTools.doOperations(ParseTools.java:810)<br>
&nbsp; &nbsp; &nbsp; &nbsp;at<br>
org.mvel.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:21)<br>
&nbsp; &nbsp; &nbsp; &nbsp;at
org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java:45)<br>
&nbsp; &nbsp; &nbsp; &nbsp;at<br>
org.mvel.ast.Substatement.getReducedValueAccelerated(Substatement.java:24)<br>
.............<br>
..............<br>
==&gt;[ActivationCreated(0): rule=adt_chld_fare;<br>
tuple=[fid:1:1:com.vtech.ruleengine.module.rulemanagermodule.RuleAttributes@14a0fe1]<br>
]<br>
Error Message : org.mvel.CompileException: could not perform numeric<br>
operation on non-numeric types: left-type=null;
right-type=java.lang.Integer<br>
    <br>
    <br>
  </blockquote>
  </div>
  <br>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
  </pre>
</blockquote>
</body>
</html>