Abhay,<br><br>Do you need a list?<br><br>You can assign RAM to COMPUTERS with this:-<br><br><span style="font-family: courier new,monospace;">when</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $c : Computer( $type : type )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $r : RAM( compatibleWith == $type )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">then</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $c.addRAM( $r );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">end</span><br style="font-family: courier new,monospace;">
<br>This would add all RAM (in Working Memory) compatible with COMPUTER to computer.<br><br>You could use a list of RAM as a Fact in WM and change your rule to use that:-<br><br><span style="font-family: courier new,monospace;">when</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $l : MyList( )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $c : Computer( $type : type )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $r : RAM( compatibleWith == $type ) from $l</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">then</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $c.addRAM( $r );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">end</span><br style="font-family: courier new,monospace;"><br>Or you can define a rule to construct the list too:-<br><br><span style="font-family: courier new,monospace;">when</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $l : MyList( $t : typeRAM )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> RAM( $c : $t )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">then</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> $l.add( $r )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">end</span><br><br>I assume you'd need to differentiate different lists for different types; so I have shown use of "MyList" which could subclass ArrayList and have a "Type of RAM" attribute. Drools doesn't "do" generics.<br>
<br>With kind regards,<br><br>Mike<br><br><div class="gmail_quote">2011/5/9 Abhay B. Chaware <span dir="ltr"><<a href="mailto:Abhay.Chaware@kpitcummins.com">Abhay.Chaware@kpitcummins.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size: 12pt;"> </span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Wendy, </span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Thanks for helping me out so far. </span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">I have another question. What if I have
all my “RAM” objects inserted into working memory. How
should I write my rule’s “when” portion to get a collection
of all the RAM objects matching type “DDR” ? In other words,
can I get collection of facts assigned to a variable and use it in the
“then” part ?</span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Thanks</span></font></p><div><div></div><div class="h5">
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Abhay</span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">==================================</span></font></p>
<p class="MsoNormal"><b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma; font-weight: bold;">From:</span></font></b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;">
<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b><span style="font-weight: bold;">On
Behalf Of </span></b>Wendy Mungovan<br>
<b><span style="font-weight: bold;">Sent:</span></b> Friday, May 06, 2011 5:47 PM<br>
<b><span style="font-weight: bold;">To:</span></b> Rules Users List<br>
<b><span style="font-weight: bold;">Subject:</span></b> Re: [rules-users] Basic
rules question</span></font></p>
<p class="MsoNormal"><font color="black" face="Arial" size="3"><span style="font-size: 12pt; font-family: Arial; color: black;"> </span></font></p>
<p class="MsoNormal"><font color="black" face="Arial" size="3"><span style="font-size: 12pt; font-family: Arial; color: black;"> </span></font></p>
<p class="MsoNormal"><font color="black" face="Arial" size="3"><span style="font-size: 12pt; font-family: Arial; color: black;">Q2:<br>
So the rule would be something like:<br>
<br>
rule "RAM type"<br>
when<br>
$product: Product(type == "laptop");<br>
then<br>
//you are looking for the best way to set valid RAM
types in the then part of the rule?<br>
$product.setRamType("DDR");<br>
//or<br>
$product.setValidRamOptions( getValidRamOptions("DDR"));<br>
end<br>
<br>
where getValidRamOptions would be a custom function included through 'import
function' so you can then load the choices from some where else. Or if
RamOptions were an object in memory you could have a rule like:<br>
<br>
rule "RAM type"<br>
when<br>
$product: Product(type == "laptop");<br>
$ramOptions: RAMOptions(type == "DDR");<br>
<br>
then<br>
$product.setValidRamOptions( $ramOptions.getList());<br>
end<br>
<br>
<br>
<br>
<br>
Wendy</span></font></p>
<p class="MsoNormal"><font color="black" face="Arial" size="3"><span style="font-size: 12pt; font-family: Arial; color: black;"> </span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">==================================</span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;"> </span></font></p>
<div>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Regards,</span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: navy;"> </span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Abhay Chaware</span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial" size="1"><span style="font-size: 7.5pt; font-family: Arial; color: navy;">Sr. Designer | KPIT Cummins Infosystems Ltd
| Board: +91 020 6652 5000 | Extn: 2989 | <a href="mailto:abhay.chaware@kpitcummins.com" target="_blank">abhay.chaware@kpitcummins.com</a>
|<a href="http://www.kpitcummins.com" target="_blank">www.kpitcummins.com</a> </span></font><font color="navy"><span style="color: navy;"></span></font></p>
<p class="MsoNormal"><font color="green" face="Webdings" size="5"><span style="font-size: 18pt; font-family: Webdings; color: green;">P</span></font><font color="black" face="Webdings" size="2"><span style="font-size: 11pt; font-family: Webdings; color: black;"> </span></font><font color="green" face="Tahoma" size="1"><span style="font-size: 7.5pt; font-family: Tahoma; color: green;">Please consider the environment before printing this e-mail</span></font></p>
</div>
<div>
<div class="MsoNormal" style="text-align: center;" align="center"><font face="Times New Roman" size="3"><span style="font-size: 12pt;">
<hr size="2" width="100%" align="center">
</span></font></div>
<p class="MsoNormal"><b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma; font-weight: bold;">From:</span></font></b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;">
<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b><span style="font-weight: bold;">On
Behalf Of </span></b>Wendy Mungovan<br>
<b><span style="font-weight: bold;">Sent:</span></b> Friday, May 06, 2011 5:47 PM<br>
<b><span style="font-weight: bold;">To:</span></b> Rules Users List<br>
<b><span style="font-weight: bold;">Subject:</span></b> Re: [rules-users] Basic
rules question</span></font></p>
</div>
<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size: 12pt;"> </span></font></p>
<div>
<p class="MsoNormal"><font face="Arial" size="3"><span style="font-size: 12pt; font-family: Arial;">Abhay,<br>
Q1: I think that this will depend on how many different products
you have. If there is a small number it is more straight forward to have
a rule for each one (so the 2nd option). This allows all you logic to be
in one place. If there are a large number of products and writing a rule
for each one is intractable you probably would want to look into some
generalizations of the rules. Is that helpful?<br>
<br>
Q2: I'm not quite sure what you are getting at in Q2. Are you
trying to write validation rules or rules that are modifying the facts?</span></font></p>
<div>
<p class="MsoNormal"><font face="Arial" size="3"><span style="font-size: 12pt; font-family: Arial;"> </span></font></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom: 12pt;"><font face="Arial" size="3"><span style="font-size: 12pt; font-family: Arial;">Wendy</span></font></p>
<div>
<div class="MsoNormal" style="text-align: center;" align="center"><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;">
<hr size="1" width="100%" align="center">
</span></font></div>
<p class="MsoNormal" style="margin-bottom: 12pt;"><b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma; font-weight: bold;">From:</span></font></b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;"> Abhay B.
Chaware <<a href="mailto:Abhay.Chaware@kpitcummins.com" target="_blank">Abhay.Chaware@kpitcummins.com</a>><br>
<b><span style="font-weight: bold;">To:</span></b> "<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>"
<<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>><br>
<b><span style="font-weight: bold;">Sent:</span></b> Fri, May 6, 2011 4:59:46 AM<br>
<b><span style="font-weight: bold;">Subject:</span></b> [rules-users] Basic rules
question</span></font></p>
<div>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Hi </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">I am a newbie to rule based applications and trying to get
the concept of rules. I have couple of questions about rules to start with, not
specifically about Drools though.</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Q1 - Should rules be data/model specific or can/should they
be generic or both</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">==========================================================</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">e.g. </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">If selected product “TYPE” is
“laptop”, then category “RAM” should have all
“DDR” type items compatible ( selecting items matching certain
property )</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">OR</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">If selected product is “IBM T42”, then category
“RAM” should have “512MB DDR” , “1024MB
DDR”, “2048MB DDR” compatible. ( assigning individual
items in rules )</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">OR</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Combination of both</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Q2 – How should be the data modeled in above case</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">==========================================================</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">e.g. </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">in product master, each item ( e.g. T40, T42 ) should have a
“TYPE” ( e.g. desktop or laptop ) , all items in category
“RAM” should have a “TYPE” ( e.g. DDR ) and then
control the assignment of RAM options to the PRODUCT through Rule using
“DDR” type ?</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">OR</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">in product master, each item ( e.g. T40, T42 ) should have a
“TYPE” ( e.g. desktop or laptop ) , all items in category
“RAM” should have a “compatibleProduct” column (
e.g. desktop or laptop ) and control the assignment of RAM to PRODUCT through
“dynamic” rules by selecting all the RAMs by passing the
“TYPE” of the product to the database handler.</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Am I making my point clear ?</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Thanks</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Abhay</span></font></p>
</div>
<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size: 12pt;"><br clear="all">
This message contains information that may be privileged or confidential and is
the property of the KPIT Cummins Infosystems Ltd. It is intended only for the
person to whom it is addressed. If you are not the intended recipient, you are
not authorized to read, print, retain copy, disseminate, distribute, or use
this message or any part thereof. If you receive this message in error, please
notify the sender immediately and delete all copies of this message. KPIT
Cummins Infosystems Ltd. does not accept any liability for virus infected
mails. </span></font></p>
</div>
</div>
</div>
</div></div></div><div><div></div><div class="h5">
<br clear="all"> This message contains information that may be privileged or confidential and is the property of the KPIT Cummins Infosystems Ltd. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. KPIT Cummins Infosystems Ltd. does not accept any liability for virus infected mails.
</div></div></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>