Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] [Solved] Calling a rule a fixed number of times
icon5.gif  [ATL] [Solved] Calling a rule a fixed number of times [message #808374] Mon, 27 February 2012 18:12 Go to next message
Algar fr is currently offline Algar frFriend
Messages: 19
Registered: December 2011
Junior Member
How to call an ATL rule a fixed number of times?
For instance 30 or 108.

Regards

[Updated on: Tue, 28 February 2012 13:39]

Report message to a moderator

Re: Calling a rule a fixed number of times [message #808397 is a reply to message #808374] Mon, 27 February 2012 18:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4153
Registered: July 2009
Senior Member
Hi

Perhaps the OCL index loop idiom will help

Sequence{1..38}->forAll(i : Integer| ...)

Regards

Ed Willink

On 27/02/2012 18:12, Missing name Mising name wrote:
> How to call a rule a fixed number of times?
> For instance 30 or 108.
>
> Regards
Re: Calling a rule a fixed number of times [message #808419 is a reply to message #808397] Mon, 27 February 2012 19:16 Go to previous messageGo to next message
Algar fr is currently offline Algar frFriend
Messages: 19
Registered: December 2011
Junior Member
Dear Edward,

Thank you for your answer.

How do you use that structure in a reference, so all the generated targets are assigned to the same source element ?

For instance, would this work? (I thought forAll returned a boolean value) :

t.contains38 <- Sequence{1..38}->forAll(i : Integer | thisModule.createOne())

What I want to have is t referencing the 38 elements.

Thank you very much again.
Best regards
Re: Calling a rule a fixed number of times [message #808801 is a reply to message #808419] Tue, 28 February 2012 06:42 Go to previous messageGo to next message
Algar fr is currently offline Algar frFriend
Messages: 19
Registered: December 2011
Junior Member
Dear Edward Willink,

I have tried your approach as follows:
t.contains3 <- (c -> forAll(i| thisModule.createOne())),

where c is defined as follows:
c : Sequence(Integer) = Sequence{1, 2, 3}

I have the following problem:
org.eclipse.m2m.atl.engine.emfvm.VMException: org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to java.lang.Boolean

I didn't manage to create a Sequence using the OCL index loop idiom that you mentioned as:
Sequence{1..38}

The '..' are not recognised, but I can create a Sequence of n elements recursively as well.

Do you know (or any one reading this thread Smile ) how to solve the problem related to the Boolean casting to create N number of target elements?

Thank you very much.
Best regards,
Re: Calling a rule a fixed number of times [message #808807 is a reply to message #808801] Tue, 28 February 2012 06:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4153
Registered: July 2009
Senior Member
Hi

I'm afraid that I cannot help you with ATL which I have never succeeded
in understanding. ATL uses its own OCL-like sub-language which appears
to fail to implement .. properly.

Regards

Ed Willink

On 28/02/2012 06:42, Missing name Mising name wrote:
> Dear Edward Willink,
>
> I have tried your approach as follows:
> t.contains3 <- (c -> forAll(i| thisModule.createOne())),
>
> where c is defined as follows:
> c : Sequence(Integer) = Sequence{1, 2, 3}
>
> I have the following problem:
> org.eclipse.m2m.atl.engine.emfvm.VMException:
> org.eclipse.emf.ecore.impl.DynamicEObjectImpl cannot be cast to
> java.lang.Boolean
>
> I didn't manage to create a Sequence using the OCL index loop idiom
> that you mentioned as:
> Sequence{1..38}
>
> The '..' are not recognised, but I can create a Sequence of n elements
> recursively as well.
>
> Do you know (or any one reading this thread :) ) how to solve the
> problem related to the Boolean casting to create N number of target
> elements?
>
> Thank you very much.
> Best regards,
>
Re: Calling a rule a fixed number of times [message #808813 is a reply to message #808807] Tue, 28 February 2012 06:59 Go to previous messageGo to next message
Algar fr is currently offline Algar frFriend
Messages: 19
Registered: December 2011
Junior Member
Thank you anyway Edward.

Does anyone know the answer?
How to create a fixed number of targets? (or how to call a rule a fixed number of times?)

Thank you very much,
Regards
Re: Calling a rule a fixed number of times [message #808855 is a reply to message #808813] Tue, 28 February 2012 08:17 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 523
Registered: July 2009
Senior Member
t.contains3 <- c->collect(e | thisModule.createOne())
Re: Calling a rule a fixed number of times [message #808885 is a reply to message #808855] Tue, 28 February 2012 08:55 Go to previous messageGo to next message
Algar fr is currently offline Algar frFriend
Messages: 19
Registered: December 2011
Junior Member
Thank you very much Sylvain!
I have tested it and it works great!

I am wondering how to apply this for a Sequence of a Sequence. The real problem was that I have a reference which is a container of N elements:

Original rule

rule SylvainTheRuler {
    from
        s : ...
    to
        t : ... (
            container <- s.refers -- it is a reference to a Sequence of objects
        )
}



If I apply your solution:

rule SylvainTheRuler {
    from
        s : ...
    using {
        c : Sequence (Integer) = Sequence{1,2,3};
    }
    to
        t : ... (
            container <- container <- c -> collect(e | thisModule.createOne(s.refers->first())),
        )
}	


It works really nice but only for the first element. How to do it for the whole Sequence s.refers?

PS: In fact, the length of c (the Sequence of integers) is different for each element of s.refers; the length is stored in each element of the sequence s.refers.

Thank you very much for your time and support,
Best regards
Re: Calling a rule a fixed number of times [message #808955 is a reply to message #808885] Tue, 28 February 2012 10:20 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 523
Registered: July 2009
Senior Member
        t : ... (
            container <- c -> collect(e | thisModule.createOne(s.refers->at(e))),
        )

but you could directly do :
        t : ... (
            container <- s.refers -> collect(e | thisModule.createOne(e)),
        )
Re: Calling a rule a fixed number of times [message #809105 is a reply to message #808955] Tue, 28 February 2012 13:39 Go to previous message
Algar fr is currently offline Algar frFriend
Messages: 19
Registered: December 2011
Junior Member
Thank you so much for your fast reply Sylvain.

It was not exactly what I meant in the problem, but I managed to solve it following the same philosophy of your solution.

Best regards and thank you very much.
Previous Topic:[qvto]failed to create object
Next Topic:[ATL]syntax source model
Goto Forum:
  


Current Time: Wed Nov 26 03:16:19 GMT 2014

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

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