Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Many to one transformation
Many to one transformation [message #959330] Fri, 26 October 2012 16:31 Go to next message
Tomás Ruiz-López is currently offline Tomás Ruiz-López
Messages: 12
Registered: October 2012
Location: Dallas
Junior Member
I am trying to specify a tranformation where many instances in the source model have to be combined into a single instance in the target model. Each of these instances add new attributes or relationships to the target element. However, what I'm getting is that several instances are created in the target model, each one of them with the same name. I have set the attribute "name" to "unique = true" and "ID = true" in the ecore file, but the problem still remains.

Any clue about how to avoid this duplicated instances? Is it possible to determine if an instance has already been created in a target model, and if so, do not create it?

I hope to be clear. Any help would be appreciated.
Re: Many to one transformation [message #961769 is a reply to message #959330] Sun, 28 October 2012 15:33 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis Wagelaar
Messages: 165
Registered: September 2012
Senior Member

Op 26/10/12 20:32, Tomás Ruiz-López schreef:
> I am trying to specify a tranformation where many instances in the source
> model have to be combined into a single instance in the target model. Each of
> these instances add new attributes or relationships to the target element.
> However, what I'm getting is that several instances are created in the target
> model, each one of them with the same name. I have set the attribute "name" to
> "unique = true" and "ID = true" in the ecore file, but the problem still remains.

There's nothing you can - or should - do in the metamodel definition.

>
> Any clue about how to avoid this duplicated instances? Is it possible to
> determine if an instance has already been created in a target model, and if
> so, do not create it?
>
> I hope to be clear. Any help would be appreciated.

ATL is a source-driven transformation language, which means that x occurrences
of a source pattern will always create exactly x occurrences of a
corresponding target pattern (*).

The trick is to *not* prevent the creation of multiple instances in your
transformation. You'll have an intermediate model with duplicate instances in
it. You can then create a second transformation, based on a copy
transformation, which merges the duplicate elements in your intermediate model
into a single element in the final model.

A similar problem was addressed in the TTC 2011 Live Contest
(http://planet-research20.org/ttc2011/index.php?option=com_content&view=article&id=161&Itemid=204),
where multiple behavioural specifications had to be merged into a single program.

Cheers,
Dennis

(*) Exceptions are lazy rules and called rule, which can create *more* than x
occurrences of the target pattern. Unique lazy rules were invented to reduce
that number back to x.


Cheers,
Dennis
Re: Many to one transformation [message #961778 is a reply to message #959330] Sun, 28 October 2012 15:43 Go to previous messageGo to next message
Tomás Ruiz-López is currently offline Tomás Ruiz-López
Messages: 12
Registered: October 2012
Location: Dallas
Junior Member
Thanks Dennis. I guess you refer to running the second transformation in refining mode, don't you? I somehow managed to get this done without this second run, by making use of the thisModule.resolveTemp operation. I don't know if this can be generalized or just worked on my case, but if I find a possible generalization, I will post it.

Thanks again
Re: Many to one transformation [message #962340 is a reply to message #961778] Mon, 29 October 2012 02:15 Go to previous messageGo to next message
Tomás Ruiz-López is currently offline Tomás Ruiz-López
Messages: 12
Registered: October 2012
Location: Dallas
Junior Member
Dennis, I've tried to apply a refining transformation to the target model, something just like:

module TM2TM;

create OUT: TM refining IN: TM;


But the duplicates are still present. How could you merge duplicates?
Re: Many to one transformation [message #963162 is a reply to message #962340] Mon, 29 October 2012 16:08 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis Wagelaar
Messages: 165
Registered: September 2012
Senior Member

Op 29/10/12 03:15, Tomás Ruiz-López schreef:
> Dennis, I've tried to apply a refining transformation to the target model,
> something just like:
>
>
> module TM2TM;
>
> create OUT: TM refining IN: TM;
>
>
> But the duplicates are still present. How could you merge duplicates?

Double-checked, and indeed I did not mention refining mode: that's because
refining mode still copies all elements, which is not what you want. You
should use an explicit copy transformation, in which you use a filter
condition to copy only the first instance of your duplicated elements.

Please refer to ATLCopy.atl and Superimpose.atl at
http://soft.vub.ac.be/viewvc/atl-superimposition-semantics/

Superimpose.atl defines a custom "inElements" helper attribute that is used in
ATLCopy.atl and Superimpose.atl to filter which elements should be copied. In
this case, ATL rules and helpers from two modules are merged into one. Only
rule/helper with a given name/signature should be copied.

These example transformations are further explained in the following paper,
section 5: http://soft.vub.ac.be/Publications/2009/vub-soft-tr-09-10.pdf

Cheers,
Dennis


Cheers,
Dennis
Re: Many to one transformation [message #966023 is a reply to message #963162] Wed, 31 October 2012 17:43 Go to previous messageGo to next message
Tomás Ruiz-López is currently offline Tomás Ruiz-López
Messages: 12
Registered: October 2012
Location: Dallas
Junior Member
Oh, I see what you mean. I'll take a look at it. Nevertheless, going back to my first concern, it is not exactly what I was looking for. I want merging of multiple instances into a new one.

For instance, consider instances A1 and A2. Both are mapped to instance B. However, A1 sets one property of B, and A2 sets another one. What I'm obtaining is:

A1 -> B(p1)
A2 -> B(p2)

i.e., two instances of B, with the same key identifier, but with different properties. I would like to have B(p1, p2), either from A1 and A2, or from B(p1) and B(p2). Is that possible?
Re: Many to one transformation [message #967077 is a reply to message #966023] Thu, 01 November 2012 13:21 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis Wagelaar
Messages: 165
Registered: September 2012
Senior Member

Op 31/10/12 18:43, Tomás Ruiz-López schreef:
> Oh, I see what you mean. I'll take a look at it. Nevertheless, going back to
> my first concern, it is not exactly what I was looking for. I want merging of
> multiple instances into a new one.
>
> For instance, consider instances A1 and A2. Both are mapped to instance B.
> However, A1 sets one property of B, and A2 sets another one. What I'm
> obtaining is:
>
> A1 -> B(p1)
> A2 -> B(p2)
>
> i.e., two instances of B, with the same key identifier, but with different
> properties. I would like to have B(p1, p2), either from A1 and A2, or from
> B(p1) and B(p2). Is that possible?

Yes, you can have multiple input elements in a rule:

rule AtoB {
from a1 : IN!A1, a2 : IN!A2 (a1.something = a2.something)
to b : B (
p1 <- a1.p1,
p2 <- a2.p2)
}

Caveat: implicit tracing does not work for rules with multiple input elements.
You have to use thisModule.resolveTemp() on a Tuple{'a1' -> ..., 'a2' -> ...}
to get to the 'b' element from another rule.

Of course, this assumes there will always be both an A1 and an A2 instance
available. It will also generate one B for each combination of A1 and A2 for
which the filter condition holds (a1.something = a2.something).

Dennis


Cheers,
Dennis
Re: Many to one transformation [message #967135 is a reply to message #967077] Thu, 01 November 2012 14:24 Go to previous messageGo to next message
Tomás Ruiz-López is currently offline Tomás Ruiz-López
Messages: 12
Registered: October 2012
Location: Dallas
Junior Member
Thanks Dennis, I really appreciate your help. One last concern: I assume this works with a fixed number of input parameters, but in some cases, I may need to combine an arbitrary number of Ai instances into a single B instance. In that case, the input parameter would be a Collection of A elements matching a certain condition, and the output a B element. However, I don't find a way to match a collection of elements in the "from" part of the rule... is that even possible?
Re: Many to one transformation [message #967284 is a reply to message #967135] Thu, 01 November 2012 16:44 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis Wagelaar
Messages: 165
Registered: September 2012
Senior Member

Op 01-11-12 15:24, Tomás Ruiz-López schreef:
> Thanks Dennis, I really appreciate your help. One last concern: I assume this
> works with a fixed number of input parameters, but in some cases, I may need
> to combine an arbitrary number of Ai instances into a single B instance. In
> that case, the input parameter would be a Collection of A elements matching a
> certain condition, and the output a B element. However, I don't find a way to
> match a collection of elements in the "from" part of the rule... is that even
> possible?

No, that's not possible. It is possible to navigate the input model using OCL,
however:

rule AtoB {
from a1 : IN!A1
using {
otherAs : Sequence(IN!AbstractA) = IN!AbstractA.allInstances()->select(...);
a2s : Sequence(IN!A2) = otherAs->select(a|a.oclIsKindOf(IN!A2));
...
}
to b : B (
p1 <- a1.p1,
p2 <- if a2s->notEmpty() then a2s->first().p2 else OclUndefined endif),
...
}

Again: this assumes there's always at least an A1 instance present.

If you always want to generate exactly one B, you can also use an endpoint
rule (has no from part and always triggers).

Dennis


Cheers,
Dennis
Re: Many to one transformation [message #967303 is a reply to message #967284] Thu, 01 November 2012 17:05 Go to previous message
Tomás Ruiz-López is currently offline Tomás Ruiz-López
Messages: 12
Registered: October 2012
Location: Dallas
Junior Member
Thank you. I didn't know about endpoint rules. I guess with this explanation everything is mucho clearer to me.
Previous Topic:Iterate through an array and conditional check
Next Topic:how to write for logic
Goto Forum:
  


Current Time: Wed Oct 01 22:28:31 GMT 2014

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

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