No, since "2" is in the WM, the condition of r3 is true and the action
part of r3 should be executed again.
Sorry, probably I had to mention that we start the engine with "1" in
the working memory.
Let me give two simpler examples.
We have rules:
R1 = If A then insert(B)
R2 = If A then insert(C)
R3 = If B and C then retract (C)
And let's assume we have A in the working memory
Then set of states in the WM is as follows:
0 -- A (initial state)
1 -- A, B (R1 is executed)
2 -- A, B, C (R2 is executed)
3 -- A, B (R3 is executed)
4 -- the process stops, even if A and B are in the WM and R2 can be
executed.
But if rules are as follows:
R1 = If A then insert(B)
R2 = If not C and A then insert(C)
R3 = If B and C then retract (C)
And we have A in the WM,h
1 -- A, B (R1 is executed)
2 -- A, B, C (R2 is executed)
3 -- A, B (R3 is executed)
4 -- A, B, C (R2 is executed again! The process does not stop and runs
in a loop)
So, in both examples there is fact A, which forces R2 to fire, but in
one case it does and in the other it does not and I do not understand
why.
/Sergey
------------------------------------------------------------------------
*From:* Mark Proctor [mailto:[EMAIL PROTECTED]
*Sent:* Monday, October 01, 2007 6:37 PM
*To:* lukichev
*Cc:* 'Adrian Giurca'
*Subject:* Re: JBoss rules execution algorithm
If you don't have the 'not' how will r3 know to re-insert 4? Without
the 'not' in r3 it is just:
*rule* "r3"
*when*
$num1:Integer(intValue == 2)
*then*
*insert*(*new* Integer(4));
*end
*There is nothing that would cause this rule to re-match when 4 is
retracted.
lukichev wrote:
Dear Mark, thank you for your answer,
I understand that insertion and retractions cause the triggering of r3
on and off. What is not clear to me why when there is no negation in
r3 the behavior is different?
We have r3 (when intVal == 2 then insert(4)) and since "2" is in the
working memory, the condition of r3 is always true. When "4" is
retracted by r4, it should be asserted again by r3, but it does not
happen.
I understand that the engine probably use a mechanism, which prevents
the same rule to fire (in our case r3) on the same facts twice, but
why it does not work when negation to r3 is added?
/Sergey
------------------------------------------------------------------------
*From:* Mark Proctor [mailto:[EMAIL PROTECTED]
*Sent:* Monday, October 01, 2007 6:03 PM
*To:* lukichev
*Cc:* [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>;
'Adrian Giurca'
*Subject:* Re: JBoss rules execution algorithm
For the case when r2 has the 'not'. When 4 doesn't exist r3 is true,
when r3 fires it asserts 4, thus r3 can no longer be true, however r4
retracts the 4 and 2 still exists, thus enabling r3 to match again
which causes the recursion - basically the insertion and retracting of
4 is toggling r3 on and off. Best thing to do is always use the audit
log so you can visualise what's going on.
Mark
lukichev wrote:
Dear Mark,
I have a question concerning rule execution algorithm in JBoss 4.0.1.
There are 2 rule sets, one runs in a circle and another one stops.
The first one, which stops:
*rule* "r1"
*when*
$num1:Integer(intValue == 1)
*then*
*insert*(*new* Integer(2));
*end*
*rule* "r2"
*when*
$num1:Integer(intValue == 2)
*then*
*insert*(*new* Integer(3));
*end*
*rule* "r3"
*when*
$num1:Integer(intValue == 2)
*then*
*insert*(*new* Integer(4));
*end*
*rule* "r4"
*when*
$num1:Integer(intValue == 3)
$num2:Integer(intValue == 4)
*then*
*retract*($num2);
*end*
* *
The second one, which runs in a circle, is different from the one
above by the additional condition in r3:
*not* $num2:Integer(intValue == 4)
I would expect the same behavior of these two rule sets, but it is
different. Could you, please, comment, why this is so?
Sincerely,
Sergey Lukichev
Research Assistant, REWERSE I1, rule modeling and markup