<br>&nbsp;&nbsp; &nbsp; This is what in Portuguese we call a &quot;tempest in a glass of water&quot;... :)<br><br>&nbsp;&nbsp;&nbsp;&nbsp; In fact, the problem is simple once you think about how write a constraint to give you the largest Price. Using the &quot;not&quot; CE will help you on this matter:
<br><br>rule &quot;Price Product rule using price length&quot;<br> &nbsp; &nbsp;when<br> &nbsp; &nbsp; &nbsp; &nbsp;$s : Product ( $productLength : length &gt; 0)<br> &nbsp; &nbsp; &nbsp; &nbsp;$price : Price( $priceLength : length &lt;= $productLength )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not Price( length &gt; $priceLength, length &lt;= $productLength )
<br> &nbsp; &nbsp;then<br> &nbsp; &nbsp; &nbsp; &nbsp;$s.setAmount($s.getAmount() + $price.getAmount());<br> &nbsp; &nbsp; &nbsp; &nbsp;$s.setLength($s.getLength() - $priceLength.intValue());<br> &nbsp; &nbsp; &nbsp; &nbsp;modify($s);<br>end<br><br>&nbsp;&nbsp; So the above rule is saying: match a Product with a Price, in a way that does NOT exist another Price whose length is greater than the matched Price, but still less or equal to the Product length. In other words, match a Product with the Price with the greatest length but still less or equal to the Product length.
<br><br>&nbsp;&nbsp; Hope it helps.<br><br>&nbsp;&nbsp; Regards,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edson<br><br><div><span class="gmail_quote">2007/5/11, Mark Proctor &lt;<a href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Interesting problem, you want dyanmic prioritisation based upon the<br>value of a field. We have no declarative sugar for this, but it might<br>make a nice use case. We could allow someone to specify an expression<br>that determine a value of priority.
<br>&nbsp;&nbsp;&nbsp;&nbsp;salience = ($price.length);<br><br>That would allow for some interesting situations. Its unlikely this will<br>make 4.0 - but the solution interests me enough that if I get bored, I<br>might just do it ;)<br><br>Until that time I think you&#39;ll have to use some combination of a
<br>command/semaphore object and additional rules.<br><br>Mark<br><br>Maxime wrote:<br>&gt; Hello,<br>&gt;<br>&gt; I&#39;m trying to find how to manage priority within a rule.&nbsp;&nbsp;Let me<br>&gt; explain the problem. I&#39;ll try to be as clear as possible but bear with
<br>&gt; me since I am new to rules.<br>&gt; We have two objects, the Product is the object I&#39;m trying to price and<br>&gt; the object Price is the one that knows all the prices. Both products<br>&gt; and prices have fields amount and length.&nbsp;&nbsp;Product amount is
<br>&gt; initialized to 0 and prices are going to determine the product amount<br>&gt; depending on its length.<br>&gt;<br>&gt; Let&#39;s see an example :<br>&gt;<br>&gt; Product : P -&gt; length = 5, amount = 0<br>&gt; Price : P1&nbsp;&nbsp;-&gt; length = 1, amount = 50
<br>&gt; Price : P2&nbsp;&nbsp;-&gt; length = 3, amount = 100<br>&gt;<br>&gt; With this configuration, after asserting the 3 objects to the WM, the<br>&gt; amount field of Product P should have a value of 200 ( 1*100 + 2*50)<br>&gt; because the price with the greatest length should be favored over the
<br>&gt; other ones.<br>&gt;<br>&gt; Here is the rule I made :<br>&gt;<br>&gt; rule &quot;Price Product rule using price length&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;when<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$s : Product (length &gt; 0)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$price : Price($length: length)
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;then<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$s.setAmount($s.getAmount() + $price.getAmount());<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$s.setLength($s.getLength() - $length.intValue());<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modify($s);<br>&gt; end<br>&gt;<br>&gt; This is obviously wrong because it always takes the first asserted
<br>&gt; price object.&nbsp;&nbsp;I don&#39;t know how to make a rule which would take the<br>&gt; amount of the price object with the greatest length in priority.<br>&gt;<br>&gt; Any help would be very much appreciated.<br>&gt;<br>
&gt; Cheers,<br>&gt;<br>&gt; Max<br>&gt;<br>&gt; _______________________________________________<br>&gt; rules-users mailing list<br>&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>&gt; 
<a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>&gt;<br><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">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><br>-- <br>&nbsp;&nbsp;Edson Tirelli
<br>&nbsp;&nbsp;Software Engineer - JBoss Rules Core Developer<br>&nbsp;&nbsp;Office: +55 11 3529-6000<br>&nbsp;&nbsp;Mobile: +55 11 9287-5646<br>&nbsp;&nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>