If you have *either*
   Fact1( $m : month, $s1 : score )
   Fact2( month == $m, $s2 : score )

   Fact1( $m : month, $s1 : score )
   Fact2( month == $m, $s2 : score )
   Fact3( month == $m, score == $1 + $2 )

then you can easily write two rules that (a) detect the
first case and progress to the second one (without insertLogical),
and (b) detect an aberration from the second one and fix the
score sum.


On 4 August 2010 12:28, Stephen Mcgruer <s0840449@sms.ed.ac.uk> wrote:

We have the following situation: Fact1 and Fact2 both have a 'score'
property. They also both have a 'month' property. When a Fact1 and a
Fact2 have the same month (at most there will only be one such pairing
for each month), a Fact3 is created with a score made from adding the
two base Facts scores:

rule "ExampleRule"
       dialect "mvel"
            Fact1( fact1Month : month, fact1Score : score > 0)
            Fact2( month == fact1Month, fact2Score : score > 0)
            Fact3 fact3 = new Fact3();
            fact3.setScore( fact1Score + fact2Score);

Our problem is that if fact1Score or fact2Score is now changed, a new
Fact3 with a new score is created, *but* the old Fact3 is of course
not removed - the conditions in its when still hold true as well (the
new score is still above 0).

Can anyone think of a way to make sure that if either fact1Score or
fact2Score is changed, then the old fact3 is removed from memory?

The only way we could at all think to do this is to add a timestamp to
fact3, and to have another rule that retracts old fact3s if there is
one with a newer timestamp and the same month... but it seems horribly


The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

rules-users mailing list