Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL]Guard condition at target element in matched rule
[ATL]Guard condition at target element in matched rule [message #800642] Fri, 17 February 2012 10:01 Go to next message
MinhTu TonThat is currently offline MinhTu TonThatFriend
Messages: 38
Registered: February 2012
Member
Hi all,
I am facing a problem when realizing a transformation to a model without the certainty of the existence of its elements. For example, in this following rule, I am not sure about the existence of the elements elem1, elem2, ... in the MMB!B model, so I need to perform some kinds of guard conditions to make sure the rule is not going to raise an error about the existence of elem1, elem2, ...
rule Transform
from i : MMA!A
to o : MMB!B
(
elem <- i.elem,
elem1 <- i.elem1 (guard condition 1),
elem2 <- i.elem2 (guard condition 2),
...
)

Untill now, after reading the ATL manual and the discussions on this forum, I found one solution. The Transformation rule can be separated in to many rules corresponding to each guard condition as follow:
rule Transform0
from i : MMA!A (not guard condition 1 and not guard condition 2)
to o : MMB!B
(
elem <- i.elem
)

rule Transform1 extends Transform0
from i : MMA!A (guard condition 1 and not guard condition 2)
to o : MMB!B
(
elem1 <- i.elem1
)

rule Transform2 extends Transform0
from i : MMA!A (not guard condition 1 and guard condition 2)
to o : MMB!B
(
elem2 <- i.elem2
)

rule Transform3 extends Transform0
from i : MMA!A (guard condition 1 and guard condition 2)
to o : MMB!B
(
elem1 <- i.elem1,
elem2 <- i.elem2
)

With 2 "uncertain" attributes in the target model, we have got already 4 additional rules, how about 3, 4 or more attributes?
I thought also about putting the guard conditions in the imperative section of ATL rules but it turned out that we cannot mix matched rules in imperative code. For instance, writing
rule Transform
from i : MMA!A
to o : MMB!B
(
elem <- i.elem
)
do
[
if (guard condition 1)
o.elem1 <- i.elem1;
...
}

will not give the attended results because the rule to transform from one elem to another elem is a matched one!

I wonder if anyone has got the same problem? Your help will be well appreciated!

[Updated on: Fri, 17 February 2012 10:05]

Report message to a moderator

Re: [ATL]Guard condition at target element in matched rule [message #800984 is a reply to message #800642] Fri, 17 February 2012 19:31 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 147
Registered: July 2009
Senior Member
On 17/02/12 11:01, Capi Tali wrote:
> Hi all,
> I am facing a problem when realizing a transformation to a model without the
> certainty of the existence of its elements. For example, in this following
> rule, I am not sure about the existence of the elements elem1, elem2, ... in
> the MMB!B model, so I perform some guard condition to make sure the rule is
> not going to raise an error about the existence of elem1, elem2, ...
> rule Transform
> from i : MMA!A
> to o : MMB!B
> (
> elem <- i.elem,
> elem1 <- i.elem1 (guard condition 1),
> elem2 <- i.elem2 (guard condition 2),
> ..
> )

Is this what you need:

rule Transform {
from i : MMA!A
to o : MMB!B (
elem <- i.elem,
elem1 <- if (guard condition 1) then i.elem1 else OclUndefined endif,
elem2 <- if (guard condition 2) then i.elem2 else OclUndefined endif,
..
elemColl <- if (guard condition 2) then i.elemColl else Sequence{} endif,
)
}

Dennis
Re: [ATL]Guard condition at target element in matched rule [message #801069 is a reply to message #800984] Fri, 17 February 2012 21:59 Go to previous message
MinhTu TonThat is currently offline MinhTu TonThatFriend
Messages: 38
Registered: February 2012
Member
Hi Dennis,
Your solution works perfectly. Many thanks for your consideration Wink.
Previous Topic:ATL too slow when transforming
Next Topic:[ATL] Transform to unknown target element
Goto Forum:
  


Current Time: Thu Apr 25 07:52:47 GMT 2024

Powered by FUDForum. Page generated in 0.03281 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top