Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Collecting all instances and calculating the values
Collecting all instances and calculating the values [message #1852727] Thu, 02 June 2022 09:40 Go to next message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Dear all,

I have a metamodel (in attachments) which has a self-reference relation. I can create a topology such as A->B A->C B->E B->F C ->G G->H. Each Period element has a duration. I should calculate each duration with respect to root A. For example, at first, I start with A, take the duration value, sum that value with C's duration, then G, then H and for each step, I should update this duration element. H should have the total sum of durations. In ATL transformation how can I reach this topology? Which methods should I use? Should I begin from the eContainer to reach these elements?


Thank you so much.

Best regards.
  • Attachment: dd.png
    (Size: 11.00KB, Downloaded 79 times)
Re: Collecting all instances and calculating the values [message #1852801 is a reply to message #1852727] Sat, 04 June 2022 13:49 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

You can navigate both ways in the case of a containment reference - downwards and upwards - so it's up to you. What's more problematic is how to go about updating the same attributes that you're trying to read:

  1. You can write a copy transformation, where you can always access the original duration values, because you're writing the new duration values to new model elements.
  2. You can write a refining mode transformation, where you somehow phase the transformation to first calculate - and temporarily store - every new duration values, and to then assign those values.



Cheers,
Dennis
Re: Collecting all instances and calculating the values [message #1852868 is a reply to message #1852801] Wed, 08 June 2022 23:01 Go to previous messageGo to next message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Hi Dennis,

Thank you so much for your answer,

I tried something like this;

helper context PIM!Period def: calculatePeriod(pimm: PIM!Period) : Integer =

if (pimm.Period>0)
then
pimm.hasSelfGenNode->iterate(it; per: Integer = 0 | per+it.Period )
else
0
endif;

I need to access the current element and its relations of hasSelfGenNode and by iterating those elements I would like to update the period.

Update: I need to reach the leaf elements of the topology, but transformation takes them random or according to the creation of those elements. Is it possible to order them somehow?

Best regards.

[Updated on: Thu, 09 June 2022 09:28]

Report message to a moderator

Re: Collecting all instances and calculating the values [message #1853127 is a reply to message #1852868] Sun, 19 June 2022 17:51 Go to previous messageGo to next message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Hi Dennis,

I should copy the instances before the transformation is triggered. How can I achieve this?

Thank you.

Best regards.
Re: Collecting all instances and calculating the values [message #1853284 is a reply to message #1853127] Sun, 26 June 2022 08:09 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

Your requirements are becoming a bit too specific without having a concrete (zipped-up) Eclipse project to look at:
Quote:
I need to access the current element and its relations of hasSelfGenNode and by iterating those elements I would like to update the period.

OK.
Quote:
I need to reach the leaf elements of the topology, but transformation takes them random or according to the creation of those elements. Is it possible to order them somehow?

The transformation iterates the EMF model in the order that EMF provides: that is usually the order in which the elements are stored in the XMI file. Depending on where in the code you need these elements in order, you can either or not do it. I need specific code to give you an answer.
Quote:
I should copy the instances before the transformation is triggered. How can I achieve this?

Copying instances IS a transformation. The obvious answer is to write (or generate) another transformation that copies your instances, but that means you have to deal with explicitly correlating which instance copy correlates with which source instance. Is that what you want?


Cheers,
Dennis
Re: Collecting all instances and calculating the values [message #1853285 is a reply to message #1853284] Sun, 26 June 2022 09:09 Go to previous messageGo to next message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Hi Dennis,

Thank you so much for your help and time.

I managed to gather all instances using the " helper def: instances: PIM!DataInstance = PIM!DataInstance.allInstances()->asSequence(); " This holds all platform-independent elements and I think two things: I can traverse back, but as A->B->C are connected using reference relation, is it possible have something like eContainerReferences() etc? I can find the elements that refers to an element (i, e finding the element B, using the element A., then by traversing back i can sum all Period values until I reach the end.

or

I can approach it as linked list logic like in C language. I have implemented a helper context like this;

helper context OclAny def: addPath(ins:PIM!DataInstance) : PIM!DataInstance =
thisModule.instances->iterate(it; travel: PIM!DataInstance = thisModule.instances->first()
|

if (ins.refGetValue('Name').debug('ins')=it.refGetValue('hasSelfGenNode').first().debug('it')) then
thisModule.items->append((travel)).debug('**match**')
else
thisModule.items
endif);

I should implement this recursively, I am able to from the point C to B, then I should go from B to A until it ends by summing the 'Period' values. Once the recursion is completed it will update the Period value of the target.

I used all instances to create the copy of the source model, I think the ordering problem can be solved by approaching the link list method. I think I still need help with the recursion.



There is also another question that can be easily solved I think https://www.eclipse.org/forums/index.php/t/1111067/, I am trying to adapt my transformation to EMFTVM, interestingly I could increment the counter value in VM-specific engine, but imperative part doesn't update the counter value in EMFVTM engine.



Re: Collecting all instances and calculating the values [message #1853462 is a reply to message #1853285] Sun, 03 July 2022 09:01 Go to previous message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Hi,

Considering the above metamodel, i try to gather every child node recursively. I managed to access the chield elements and store the return values of the recursive calls, but it then returns Sequence{} to the do{} block. I think I should stop the iteration somehow. The code is as follows.



 helper context OclAny def: StoreItems(kk:PIM!DataInstance, str:Sequence(PIM!DataInstance)):Sequence(OclAny) =
 let fakeVar : Sequence(OclAny) = str in str->append(kk);


helper context OclAny def: getHasGen(chield:PIM!DataInstance,curr:PIM!DataInstance) : Sequence(PIM!DataInstance) =
	if chield.hasSelfGenNode.size()>0 and chield.hasSelfGenNode->includes(curr) then self.getName(chield.hasSelfGenNode->at(chield.hasSelfGenNode->indexOf(curr))).debug('Chield Match') else 'None' endif;



helper context OclAny def: addPath(current_instance:PIM!DataInstance,str:Sequence(PIM!DataInstance)) : Sequence(PIM!DataInstance) =
	let store : Sequence (PIM!DataInstance) = str.debug('CALLED  LET') in
	thisModule.instances->iterate(it; travel: PIM!DataInstance = thisModule.instances->first().debug('\n\n-----Entry-------\n ')
		|
												
	if (current_instance.Name.debug('\n Gelen 1 \n '.concat(current_instance.Name.concat('\n**')))=(it.getHasGen(it,current_instance).debug('Owns '.concat(it.getName(it)+'-> '))))   then
   
	  		store->append(store->StoreItems(it,store))->addPath(it,store).debug('str 2')->append(it).debug('Should Return * '+store.toString().concat('**'))--debug('Additions'.concat(it.getName(it)))->addPath(it)
			
		else
			store.debug('ELSE STORE')	   
	endif);

While printing debug message which is "store->append(store->StoreItems(it,store))->addPath(it,store).debug('str 2')->append(it).debug", it shows the parent and grandparent node.
However, inside the do block, it returns an empty Sequence{}. Moreover, the store value somehow gets also empty at the 'else store.debug('ELSE STORE')'. I also tried to store the values inside a global variable, but it did not work. All i need to do is have the store values returned to the do part.

do{
(pim.addPath(pim,pim.returnItems())).debug('Add');
}




UPDATE

helper context OclAny def: getHasGenSel(curr:PIM!DataInstance) : Sequence(PIM!DataInstance) =
thisModule.instances->select(p | p.getChield(p)->includes(curr));


helper context OclAny def: addPathSel(current_instance:OclAny) : Sequence(PIM!DataInstance) =
	if current_instance<>OclUndefined then
	let var : Sequence(OclAny) = Sequence{} in var.union(var.getHasGenSel(current_instance)).debug('Ret value')
	else
		OclUndefined
	endif;




I simplified the code a little bit. Yet, the problem is that 'var' value still returns an empty Sequence and I should reach lastly added item, then give that item as parameter to the addPathSel to create recursion. Eventually, the latest sequence should return all the path from leaf to root. But i could not understand why var value is always empty.


Best regards.

[Updated on: Sun, 03 July 2022 14:36]

Report message to a moderator

Previous Topic:Accessing referring elements?
Next Topic:[ATL] Library in EMFTVM launch config?
Goto Forum:
  


Current Time: Thu Apr 18 05:11:52 GMT 2024

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

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

Back to the top