According to the spec the selection must find the most experienced,
with age as a tie breaker.
A single rule is sufficient:
$p: Person( $xp: experience, $age: age )
not Person( experience > $xp || experience == $xp && age > $age )
Although you can write even more complex constraints, it might not be
convenient. An evaluation function like the following could be
considered
(as long as long is sufficient):
long rating( int a, int b, int c ){
return ((long)a*AMAX + b)*BMAX + c;
}
Or, using accumulate, the best can be found by coding
init/action/result explicitly (or implement this as a custom
accumulate function);
$best: Person() from
accumulate ( $p: Person( $e: experience, $a: age ),
init( Person best = null; int ex = -1; ),
action( if( $e > ex || $e == ex && $a > best.getAge()
){
best = $p; ex = $e; } ),
result( best ) )
-W
On 12/06/2012, Davide Sottara <dsotty(a)gmail.com> wrote:
-- You have several options.. one is the more declarative:
$best : Person( $xp : experience )
not Person( experience > $xp )
-- Another option is to accumulate and find the highest level of
experience:
accumulate( Person( $xp : experience ), $max : max ( $xp ) )
then you can match against that, either directly or inserting that value as
a fact:
$best : Person( $exp : exp >= $max )
-- which leads to a possible solution for the multi-criteria case, creating
score facts:
when
$p : Person( $xp : experience, $a: age )
then
insert( new Score( $p, /* an appropriate function of your xp and age */ )
);
end
at this point, the previous options apply to the score facts directly.
-- Of course there are other variations and possibilities
Davide
btw, are you assuming that no other Person will be insert after the best
has
been chosen, right?
--
View this message in context:
http://drools.46999.n3.nabble.com/Solving-Conflict-Resolution-on-values-o...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users