[great-users] understanding rules behaviour in GReAT

Achim Gädke Achim.Gaedke at vuw.ac.nz
Tue Feb 1 22:06:11 CST 2011


On 01/02/11 21:32, Daniel Balasubramanian wrote:
> Could you please give the following details:
>
> -The code inside the guard.
> -The packets that are being passed in to this rule?
>
> Also, I'm not sure I understand what's happening; you say:
>
> "Inserting this pattern into a case block behaves as expected."
>
> Does it behave unexpectedly if you use a regular block as opposed to a case block?
Hi great-users and Daniel!

While creating a bigger transformation project I came across some 
behaviour which I did not expect.

I've created a test transformation to contain three tests for simple 
comparison. This is this rule which I want to test:

The meta-model is kept very simple, a container, which can contain 
containers and items. Items have a switch to be "ignored".

Thus the guard code is: return (!Item.IgnoreThis());
The Attribute Mapping code in this rule is:
cout<<"executing AttributeMapping on "<<Item.name()<<endl;

The input model contains a container with ItemA (IgnoreThis=False), 
ItemB (IgnoreThis=True) and a SubContainer.
All necessary mga files are attached.

Test 1 (upper branch):
To observe the output packets I've connected another rule which writes 
for each Item a line on the console.
This is done by the AttributeMapping code:
cout<<"After pattern rule: found Item "<<Item.name()<<endl;

I generate code, compile and execute the transformation in the cmd window.

Observed:
The relevant output reads like this:
> executing AttributeMapping on ItemA
> After pattern rule: found Item ItemA
> After pattern rule: found Item ItemB
The attribute mapping is executed once for ItemA, the guard becomes true.
But ItemA and ItemB are forwarded to the output and received by my 
observer rule.
The SubContainer is not observed, because it is not an Item (see Test 3).

Expected:
Considering the pseudo code for a rule in the technical manual (section 
3.4):
> Function Name : ExecuteRule
> Inputs : 1. Rule rule (rule to execute)
>              2. List of Packets inputs
> Outputs : 1. List of Packets outputs
> outputs = ExecuteRule(rule, inputs)
> {
>         List of Packets matches
>         List of Packets outputs
>         for each input in inputs
>                 { matches = PatternMatcher(rule, input)
>                 for each match in matches
>                         { if match doesn't satisfy guard
>                                 matches.Remove(match)
>                         }
>                 for each match in matches
>                         { Effector(rule, match)
>                            outputs.Add(match)
>                         }
>                 }
>         return outputs
> }
The guard prevents forwarding, so Only ItemA should be forwarded. ItemB 
should be prevented by the guard.
The AttributeMapping is executed correctly only for ItemA.

Test 2 (middle branch):
Is similar to 1, but using this pattern&guard inside a Case in a Test Block.
There is no AttributeMapping inside a case structure.

Observed:
This output belongs to the middle branch:
> After test block: found Item ItemA
Only ItemA is forwarded.

Expected:
As observed, ItemB is not forwarded.

Test 3 (lower branch):
The last test focuses on the filtering effect of the itself pattern. So 
I remove the Guard and the Attribute mapping. The rule's  InputPort is 
fed with the SubContainer. In addition to this I change the rule, which 
receives the output packages, such that it expects Containers.

Observed:
Output created by the lower branch.
> After pattern rule found container:SubContainer
So that pattern forwards the SubContainer, which is a Container Model 
and not an Item.
This behaviour could not be observed in the debugger. A breakpoint to 
the start of the receiver rule is not hit.

Expected:
The pattern has an Item bound to the input and output, so only Items 
should propagate through the rule.

---------------------------------------------------------

The relevant software versions are:

GME 10.11.24
GReAT 1.7.5
UDM 3.2.7
Windows Vista Ultimate
Visual Studio 2008

Cheers, Achim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://list.isis.vanderbilt.edu/pipermail/great-users/attachments/20110202/6d4a6cc6/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 13356 bytes
Desc: not available
Url : http://list.isis.vanderbilt.edu/pipermail/great-users/attachments/20110202/6d4a6cc6/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MyContainer.mga
Type: application/octet-stream
Size: 1411 bytes
Desc: not available
Url : http://list.isis.vanderbilt.edu/pipermail/great-users/attachments/20110202/6d4a6cc6/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SimpleMetaModel.mga
Type: application/octet-stream
Size: 4876 bytes
Desc: not available
Url : http://list.isis.vanderbilt.edu/pipermail/great-users/attachments/20110202/6d4a6cc6/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SelectItems.mga
Type: application/octet-stream
Size: 29522 bytes
Desc: not available
Url : http://list.isis.vanderbilt.edu/pipermail/great-users/attachments/20110202/6d4a6cc6/attachment-0002.obj 


More information about the great-users mailing list