I want to find out the minimum of two variables in the LHS (Left Hand Side) of a drools rule. For example:
$variable1 : // Some value generation lines
$variable2 : // Some value generation lines
// This doesn't work
$minimumOfVariable1And2 : min($variable1,$variable2)
So how will the minimum be found out, is the question. Thanks.
One way:
when
FactA($a : a, ...)
FactB($b : b, ...)
FactC(c < Math.min($a, $b), ...)
then
...
Another way:
when
FactA($a : a, ...)
FactB($b : b, ...)
then
int c = Math.min($a, $b);
...
Now, when it becomes interesting is when FactA and FactB are the same type:
when
Assignment($a : a, ...)
Assignment(a < $a, ...)
// $a this the minimum
then
...
because if 2 assignments have the same a, this rule will match twice (once for A1-A2 and once for A2-A1).