[rules-users] Questions about logically justified objects

Mark Proctor mproctor at codehaus.org
Sun Jan 13 14:53:49 EST 2008


Geoffrey De Smet wrote:
> Let's say I have 2 rooms:
>  - Room A with penalty 10
>  - Room B with penalty 5
> Both are inserted into the WM and never change.
> Let's say I have 1 exam:
>  - Exam X which starts out assigned to Room A.
> It's inserted into the WM, but it will change when rules are fired.
>
> Let's say I have this rule:
>
> rule "roomPenalty"
>   when
>     $exam : Exam();
>   then
>     Object cause = $exam;
>     int weight = $exam.getRoom().getPenalty();
>     insertLogical(new Penalty(cause, weight);
> end
>
> After my first fireAllRules, there is 1 logical asserted Penalty(10).
>
> Next, I switch Exam X to Room B (instead of Room A) and I fire all Rules.
> The _same_ rule applies on the _same_ fact and a logical asserted 
> Penalty(5) is inserted.
>
> How do I enable the following different use cases?
>
> 1) Keep Penalty(10), discard Penalty(5)
This  works if they the same hashcode/equals result
> 2) Remove Penalty(10), add Penalty(5)
You will  have to do  this manually, match Penalty in the  "when" side 
and retract it on t he right  side before logically asserting something 
else.
> 3) Keep Penalty(10), add Penalty(5)
This works if  they  each have adifferent hashcode/equals
>
> What happens if:
> 1) Penalty's equals/hashcode only uses "cause"?
then 1) happens
> 2) Penalty's equals/hashcode uses both "cause" and "weight"?
then 3) happens




More information about the rules-users mailing list