On 1 June 2011 16:55, Simon Chen <simonchennj@gmail.com> wrote:
Hi all,

I have the following problem.

Let's say, I have a class Number3(), with three fields a, b, and c.

I have the following rule:

rule "test3"
   when
       Number3($a: a, $b: b)
       $minvalue: Number()
           from accumulate(Number3(a == $a, b == $b, $c: c), min($c))
   then
       System.out.println($a + " " + $b + " " + $minvalue);
end


Say, I have four objects (1,2,3), (1,2,4), (1,3,4), (1,3,5).

The result shows four lines:
1 3 4.0
1 3 4.0
1 2 3.0
1 2 3.0

But I want the output to be:
1 3 4.0
1 2 3.0

meaning that for each unique pair of a and b, I want the rule to fire only once.


In this particular case you might try

rule "test3"
   when
      Number3($a: a, $b: b, $c)
      not Number3( a == $a, b == $b, c < $c )
   then
       System.out.println($a + " " + $b + " " + $c);
end

Event this will fail, if there are two identical (w.r.t. a, b and c) Number3 objects.

For the general case, you must have some way of picking a single Number3 with some a/b-combination.

Alternatively, insert possibly multiple triplets <a,b,min(c)> and harvest one from each group, using additional rules.

Or use an additional fact containing <a,b(,c)> to indicate that you have computed the minimum. But then you must get rid of these auxiliaries.

-W
 
Is this doable?

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