RETRACT - RE: [rules-users] Shadow fact problem? - truth maintenance issue?

Anstis, Michael (M.) manstis1 at ford.com
Tue Mar 20 06:43:32 EDT 2007


Sorry to all - I've traced the issue down to me. Because the new
Attribute was logically asserted and it's very assertion caused "rule
3a" not to be true the Attribute was being correctly revoked. Using
rules sure makes your brain twist and turn!

As far as I can tell the problem with "contains" is still correct (i.e.
not working properly).

-----Original Message-----
From: Anstis, Michael (M.) 
Sent: 20 March 2007 09:49
To: 'Rules Users List'
Subject: RE: [rules-users] Shadow fact problem? - truth maintenance
issue?

Re-posted without the attachment (224kb).

If you require it I can send direct (or the original message is waiting
to be moderated)

-----Original Message-----
From: Anstis, Michael (M.) 
Sent: 20 March 2007 09:40
To: 'Rules Users List'
Subject: RE: [rules-users] Shadow fact problem? - truth maintenance
issue?

Hi (Edson?),

I came across another problem (verified with trunk) which I think
relates to truth maintenance:-

** Rules (only ones in rulebase)

rule "Test 3a"
salience 2000
when
	$m : Machine ( )
	not (exists $a : Attribute ( name == "TEST4", parent == $m ) ) 
then
	System.out.println("DEBUG---> [salience 2000] Attribute 'TEST4'
not found");
	System.out.println("DEBUG---> [salience 2000] Attribute 'TEST4'
added");
	Attribute a = new Attribute("TEST4", 999);
	$m.addAttribute(a);
	assertLogical(a);
end

rule "Test 3b"
salience 1999
when
	$m : Machine ( )
	not (exists $a : Attribute ( name == "TEST4", parent == $m ) ) 
then
	System.out.println("DEBUG---> [salience 1999] Attribute 'TEST4'
(still) not found - woot");
end

rule "Test 3c"
salience 1998
when
	$m : Machine ( )
	exists $a : Attribute ( name == "TEST4", parent == $m )
then
	System.out.println("DEBUG---> [salience 1998] Attribute 'TEST4'
found - double woot");
End

This causes the execution of rule "Test 3a" to be constantly activated
as illustrated with the attached log: Activations for "Rule 3a" are
created, which asserts a new object causing cancellation of activation
of "Rule 3b" and activation of "Rule 3c" (great!). However something
somewhere is causing the newly asserted object to be retracted causing
the reversal of the above leading to continued execution of "Rule 3a".

With kind regards,

Mike
 

-----Original Message-----
From: Anstis, Michael (M.) 
Sent: 19 March 2007 16:52
To: 'Rules Users List'
Subject: RE: [rules-users] Shadow fact problem?

Hi Edson,

I've tested branch in SVN but have to report that the following does not
work as expected:-

** Java

Machine mt1=new Machine();
mt1.setDescription("Test Machine");
Attribute at1=new Attribute("TEST1", 5);
Attribute at2=new Attribute("TEST2", 25);
mt1.addAttribute(at1);	// <-- A machine contains an ArrayList of
Attributes
mt1.addAttribute(at2);	// <-- A machine contains an ArrayList of
Attributes
wm.assertObject(mt1);
wm.assertObject(at1);
wm.assertObject(at2);

** Rules

rule "Test 1a" 		// <-- Works OK
when
	$m : Machine ( description == "Test Machine" )
then
	System.out.println("DEBUG---> Adding new Attribute(\"TEST3\") to
Machine");
	Attribute a = new Attribute("TEST3", 100);
	$m.addAttribute(a);
	assertLogical(a);
end

rule "Test 1b"		// <-- Does not activate
when
	$a : Attribute ( name == "TEST3" )
	$m : Machine ( attributesList contains $a )
then
	System.out.println("DEBUG---> Found machine with new
Attribute");
End

The following rule does however work which suggests a problem with
"contains"(?):-

rule "Test 1c"		// <-- Does activate
when
	$m : Machine ( description == "Test Machine" )
	$a1 : Attribute ( name == "TEST1", parent == $m )
	$a2 : Attribute ( name == "TEST2", parent == $m )
	$a3 : Attribute ( name == "TEST3", parent == $m )
then
	System.out.println("DEBUG---> " + $m.toString());
	System.out.println("DEBUG---> " + $a1.toString());
	System.out.println("DEBUG---> " + $a2.toString());
end

Also, the following type of syntax appears problematic:-

rule "Test 2"
when
	$m : Machine ( description == "Test Machine" )
	$a1 : Attribute ( name == "TEST1", parent == $m )
	$a2 : Attribute ( name == "TEST2", parent == $m )
then
	System.out.println("DEBUG---> " + $m.toString());
	System.out.println("DEBUG---> " + $a1.toString());
	System.out.println("DEBUG---> " + $a2.toString());
End

This particular example works OK (all facts asserted outside of rules)
however this (real life) example does not:-

rule "Material - Lock Pressure Modifier"
salience 849
when
	MaterialEntry ( $m : material )
	$a1 : Attribute ( name == Constants.ATTRIBUTES_PROCESS_TOTAL_XY,
$txy : number )
	$a2 : Attribute ( name ==
Constants.ATTRIBUTES_MATERIAL_LOCK_PRESSURE, $mlp : number, parent == $m
)
then
	Attribute a = new
Attribute(Constants.ATTRIBUTES_MATERIAL_LOCK_PRESSURE_MODIFIER, m);
	assertLogical(a);
	$m.addAttribute(a);
end

rule "Material - Clamping Force"
salience 848
when
	MaterialEntry ( $m : material )
	$a1 : Attribute( name == Constants.ATTRIBUTES_PROCESS_TOTAL_XY,
$txy : number )						// <-- Same as
above
	$a2 : Attribute( name ==
Constants.ATTRIBUTES_MATERIAL_LOCK_PRESSURE, $mlp : number, parent == $m
)			// <-- Same as above
//(a)	$a3 : Attribute( name ==
Constants.ATTRIBUTES_MATERIAL_LOCK_PRESSURE_MODIFIER, $lpm : number,
parent == $m )	// <-- Asserted above
//(b)	$a3 : Attribute( name ==
Constants.ATTRIBUTES_MATERIAL_LOCK_PRESSURE_MODIFIER, $lpm : number )
then
	System.out.println("DEBUG--->" + $a2.getParent());
	System.out.println("DEBUG--->" + $a3.getParent());
end 

If line "//(a)" is used the rule does not fire; if rule "//(b)" is used
instead (i.e. the RHS does not check the "parent" property) the rule
triggers. However the two debug lines show "$a2.getParent()" and
"$a3.getParent()" point to the same object - one "parent == $m" worked
the other (asserted by a rule) does not appear to work. 

Thanks,

Mike

-----Original Message-----
From: Anstis, Michael (M.) 
Sent: 15 March 2007 12:34
To: 'Rules Users List'
Subject: RE: [rules-users] Shadow fact problem?

Hi Edson,

Don't worry Edson - you have enough to do to excuse missing a question.

I don't want to put the check into the consequence - oh no, but as given
by my examples the rule "A" never fires when its in the LHS. I wanted to
check my understanding that rule "A" should work the same as rule "B"
with the difference being that the condition is handled by the RETE
network and not some hacky code in the RHS. I am planning on checking
both in trunk tonight - unfortunately family matters mean I can't spend
too much time on the computer in the evenings and I was only able to
play with Maven last night.

Cheers,

Mike
 

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
Sent: 15 March 2007 12:08
To: Rules Users List
Subject: Re: [rules-users] Shadow fact problem?


   Michael,

   Sorry, I missed your previous message... why are you moving the check

into the consequence? As you already realized, that is not  a good 
solution...
   Did you tried your original rule in trunk? Bug is still there?

    []s
    Edson

Anstis, Michael (M.) wrote:

>Sorry to push Edson,
>
>The performance degradation from having the "parental check" in the RHS
>versus the LHS is (expectedly) terrific. We have thousands of
>"attributes" relating to different parent objects and having the rule
>activate for every combination is causing performance problems. Moving
>the RHS into a LHS "eval" would be no better either.
>
>On a different matter, I have successfully installed the source with
>Maven (thanks Mark) and can debug trunk in Eclipse at home!
>
>With kind regards,
>
>Mike
>
>-----Original Message-----
>From: Anstis, Michael (M.) 
>Sent: 14 March 2007 12:28
>To: 'Rules Users List'
>Subject: RE: [rules-users] Shadow fact problem?
>
>OK, Edson, I will try to check it out (I'm having problems accessing
>subversion from work so will try from home).
>
>Whilst trying to implement a workaround though I may have discovered
>another problem (which might have been fixed too):-
>
>rule "A"
>when
>	MaterialEntry ( $m : material )
>	$a2 : Attribute( name ==
>Constants.ATTRIBUTES_MATERIAL_LOCK_PRESSURE, $mlp : number, parent ==
$m
>)
>	$a3 : Attribute( name ==
>Constants.ATTRIBUTES_MATERIAL_LOCK_PRESSURE_MODIFIER, $lpm : number,
>parent == $m )
>then
>	System.out.println("Rule A"); //<-- Never fires
>end
>
>rule "B"
>when
>	MaterialEntry ( $m : material )
>	$a2 : Attribute( name ==
>Constants.ATTRIBUTES_MATERIAL_LOCK_PRESSURE, $mlp : number )
>	$a3 : Attribute( name ==
>Constants.ATTRIBUTES_MATERIAL_LOCK_PRESSURE_MODIFIER, $lpm : number )
>Then
>	if($a2.getParent() == $m && $a3.getParent() == $m) {
>		System.out.println("Rule B"); //<-- Fires
>	}
>end
>
>If the check for "parent" being equal across $m, $a2 and $a3 is in the
>LHS the rule doesn't activate. However if check is in the RHS the rule
>is OK.
>
>Any thoughts or views (Edson)?
>
>Thanks,
>
>Mike 
>
>-----Original Message-----
>From: rules-users-bounces at lists.jboss.org
>[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Edson Tirelli
>Sent: 13 March 2007 22:57
>To: Rules Users List
>Subject: Re: [rules-users] Shadow fact problem?
>
>
>   Mike,
>
>   Yes, that is a "shadow fact unwanted side-effect" (nice name for a 
>bug hm? :) ), but I remember fixing something similar as part of
another
>
>ticket I was working on. Is it possible for you to verify if the
problem
>
>is happening in trunk?
>   If it is still hapenning, let me know and I will fix it.
>
>   Thank you,
>       Edson
>
>Anstis, Michael (M.) wrote:
>
>  
>
>>Hi,
>>
>>I am running 3.1-M1 and have (by way of example) two simple rules; A 
>>and B as follows:-
>>
>>      *rule* "A"
>>      *when*
>>              $a1 : Attribute ( name == Constants.ATTRIBUTES_A, $pa :
>>      number )
>>              $a2 : Attribute ( name == Constants.ATTRIBUTES_B, $nc :
>>      number )
>>              $p : Process ( attributesList* contains* $a1,
>>      attributesList* contains* $a2 )
>>      *then*
>>             * double* txy = doSomeMaths($pa, $nc, $p);
>>              Attribute a =* new* Attribute(Constants.ATTRIBUTES_C,
>>    
>>
>txy);
>  
>
>>              $p.addAttribute(a);
>>             * assertLogical*(a);
>>             * modify*($p);
>>              System.out.println("Rule 'A' fired");
>>      *end*
>>                             
>>      *rule* "B"
>>      *when*
>>              $a1 : Attribute ( name == Constants.ATTRIBUTES_C, $txy :
>>      number)
>>              $p : Process( attributesList* contains* $a1 )    
>>                              // <-- Line causing rule not to activate
>>
>>      *then*
>>             * double* m = doSomeMoreMaths($txy, $p);
>>              System.out.println("Rule 'B' fired");
>>      *end*
>>
>>Process exposes an ArrayList of Attribute objects (each having a 
>>name\value pair).
>>
>>When the content of the ArrayList held by Process is added to (Rule 
>>'A') the next rule (Rule 'B') is not being activated.
>>
>>Can anybody provide any insight into how best a workaround can be 
>>engineered?
>>
>>With kind regards,
>>
>>Mike
>>
>>----------------------------------------------------------------------
-
>>    
>>
>-
>  
>
>>_______________________________________________
>>rules-users mailing list
>>rules-users at lists.jboss.org
>>https://lists.jboss.org/mailman/listinfo/rules-users
>> 
>>
>>    
>>
>
>
>  
>


-- 
 Edson Tirelli
 Software Engineer - JBoss Rules Core Developer
 Office: +55 11 3124-6000
 Mobile: +55 11 9218-4151
 JBoss, a division of Red Hat @ www.jboss.com


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




More information about the rules-users mailing list