On 1 June 2011 16:55, Simon Chen <span dir="ltr">&lt;<a href="mailto:simonchennj@gmail.com">simonchennj@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
<br>
I have the following problem.<br>
<br>
Let&#39;s say, I have a class Number3(), with three fields a, b, and c.<br>
<br>
I have the following rule:<br>
<br>
rule &quot;test3&quot;<br>
    when<br>
        Number3($a: a, $b: b)<br>
        $minvalue: Number()<br>
            from accumulate(Number3(a == $a, b == $b, $c: c), min($c))<br>
    then<br>
        System.out.println($a + &quot; &quot; + $b + &quot; &quot; + $minvalue);<br>
end<br>
<br>
<br>
Say, I have four objects (1,2,3), (1,2,4), (1,3,4), (1,3,5).<br>
<br>
The result shows four lines:<br>
1 3 4.0<br>
1 3 4.0<br>
1 2 3.0<br>
1 2 3.0<br>
<br>
But I want the output to be:<br>
1 3 4.0<br>
1 2 3.0<br>
<br>
meaning that for each unique pair of a and b, I want the rule to fire only once.<br>
<br></blockquote><div><br>In this particular case you might try<br><br>rule &quot;test3&quot;<br>
    when<br>      Number3($a: a, $b: b, $c)<br>
       not Number3( a == $a, b == $b, c &lt; $c )<br>
    then<br>
        System.out.println($a + &quot; &quot; + $b + &quot; &quot; + $c);<br>
end<br><br>Event this will fail, if there are two identical (w.r.t. a, b and c) Number3 objects.<br><br>For the general case, you must have some way of picking a single Number3 with some a/b-combination.<br><br>Alternatively, insert possibly multiple triplets &lt;a,b,min(c)&gt; and harvest one from each group, using additional rules.<br>
<br>Or use an additional fact containing &lt;a,b(,c)&gt; to indicate that you have computed the minimum. But then you must get rid of these auxiliaries.<br><br>-W<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Is this doable?<br>
<br>
Thanks.<br>
-Simon<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>
</blockquote></div><br>