Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » Losing atributes after transformation
Losing atributes after transformation [message #654771] Thu, 17 February 2011 03:26 Go to next message
Oscar Andres Fajardo F. is currently offline Oscar Andres Fajardo F.Friend
Messages: 10
Registered: February 2011
Location: Colombia
Junior Member
Hi,
I'm having trouble finding out how to don't lose the attributes of my generated elements.
I'm new to QVT operational, I'm trying to remake a script I did in QVT relations with mediniQVT but I feel this is not so going good...
I'm no good programmer at all, and all I did in the code was using my imagination, hope I'm not doing huge mistakes...the thing is that some of the generated elements (operative units and products by now)are losing their names and other attributes and I don't understand why
Here's the code in QVTo:::


modeltype MAS uses 'http://MAS/1.0';
modeltype PNS uses 'http://PNS/1.0';

transformation MAS2PNS(in mas:MAS, out pns:PNS);

main()
{
mas.rootObjects()[MAS::MASModel] -> map MASmodel2PNSmodel();
}

mapping MAS::MASModel::MASmodel2PNSmodel() : PNS::PNSModel
{
result.Elements += self.Elements.map MASNE2PNSNE(result);
}

mapping MAS::MASNamedElement::MASNE2PNSNE(p: PNS::PNSModel)
disjuncts MASElement::MASElement2PNSElement//, MASRelation::MASRelations2PNSRelation
{
}
mapping MAS::MASElement::MASElement2PNSElement(p: PNS::PNSModel)
disjuncts MAS::Agent::Agent2PNSElement, MAS::Goal::Goal2PNSElements
{
}

/*
mapping MAS::MASRelation::MASRelations2PNSRelation(p: PNS::PNSModel)
{
self.map MASRelation2PNSRelation(p);
}

mapping MAS::MASRelation::MASRelation2PNSRelation(p: PNS::PNSModel): PNS::PNSRelation
{
result.name := self.name;
result.PNS := p;
}
*/
mapping MAS::Agent::Agent2PNSElement(p: PNS::PNSModel)
when{self.oclIsTypeOf(Agent)}
{
self.map Agent2RawMaterial(p);
}
mapping MAS::Agent::Agent2RawMaterial(p: PNS::PNSModel) : PNS::RawMaterial
when{self.oclIsTypeOf(Agent)}
{
result.name := self.name;
result.PNS := p;
result.price:= 1.0;
result.maxFlow := 10000.0;
}
abstract mapping MAS::Goal::Goal2PNSElements(p: PNS::PNSModel)
{
self.map Goal2IntermediateMaterial(p);
self.map Goal2OperationalUnit(p);
self.map Goal2Product(p);
}

mapping MAS::Goal::Goal2IntermediateMaterial(p: PNS::PNSModel) :PNS::IntermediateMaterial
{
result.name :=self.name;
result.PNS := p;
}

mapping MAS::Goal::Goal2OperationalUnit(p: PNS::PNSModel) : PNS::OperationalUnit
{
result.name = 'op_'+self.name;
result.PNS := p;
result.lowerBound = 10000.0;
result.upperBound = 10000.0;
}
mapping MAS::Goal::Goal2Product(p: PNS::PNSModel) : PNS::Product
{
result.name=self.name+'_oaf';
result.PNS := p;
result.price = 1.0;
result.reqFlow = 0.0;
result.maxFlow = 10000.0;
}

Plz help! °_°
*_*

If my original code helps, here it is...
/*
*
*/
transformation MAS2PNS(MAS:MAS,PNS:PNS)
{
top relation MASModel2PNSModel
{
checkonly domain MAS mm:MAS::MASModel
{};
enforce domain PNS pm:PNS::PNSModel
{};
}

top relation Agent2RawMaterial
{
en : String;

checkonly domain MAS a:MAS::Agent
{
MAS = mm : MAS::MASModel{},
name = en
};

enforce domain PNS rm:PNS::RawMaterial
{
--Creo el Raw Material
PNS =pm : PNS::PNSModel{},
name = en,
price = 1.0,
maxFlow = 10000.0
};

when
{
MASModel2PNSModel(mm,pm);
}
}

top relation Goal2PNSElements
{
gn:String;
checkonly domain MAS g:MAS::Goal
{
MAS = mm : MAS::MASModel{},
name = gn
};
enforce domain PNS pm : PNS::PNSModel
{
--Creo el Intermediate Material
Elements = im:PNS::IntermediateMaterial
{
PNS = pm,
name = gn
},
--Creo el Product
Elements = p:PNS::Product
{
PNS =pm : PNS::PNSModel{},
name=gn+'_oaf',
price = 1.0,
reqFlow = 0.0,
maxFlow = 10000.0
},
--Creo el Operational Unit
Elements = ou:PNS::OperationalUnit
{
PNS =pm : PNS::PNSModel{},
name = 'op_'+gn,
lowerBound = 10000.0,
upperBound = 10000.0
},
--Creo las relaciones que conectaran los Intermediate Materials con las Operational Units
Elements = rio:PNS::PNSRelation
{
PNS = pm,
name = gn+'_rel_opUnit'+gn,
source = im,
target = ou,
rate = 1.0
},
--Creo las relaciones que conectaran las Operational Units con los Products
Elements = rof:PNS::PNSRelation
{
PNS = pm,
name = 'opUnit_'+gn+'_rel_'+gn+'_oaf',
source = ou,
target = p,
rate = 1.0
}
};

when
{
MASModel2PNSModel(mm,pm);
}
}
}

Thank you very much!!!
Your help would be very appreciated...

PS: don't know how toattach files I will attach the plugins for the transformation as soon as I find out how this works...
(cant find the attach button xD )
Re: Losing atributes after transformation [message #654783 is a reply to message #654771] Thu, 17 February 2011 07:36 Go to previous messageGo to next message
Dennis HendriksFriend
Messages: 74
Registered: January 2010
Location: The Netherlands
Member
After a quick look, the first thing I saw (and this may be the whole
problem), is this mapping:

mapping MAS::Goal::Goal2OperationalUnit(p: PNS::PNSModel) : 
PNS::OperationalUnit
{
     result.name = 'op_'+self.name;
     result.PNS := p;
        result.lowerBound = 10000.0;
        result.upperBound = 10000.0;
}


You use '=', instead of ':=', meaning result.name is compared to
'op_'+self.name, instead of assigned. The same things happens for
lowerBound and upperBound.

One other thing, you may omit the 'result.' prefix here.

If you change all this, one would get (for this mapping):

mapping MAS::Goal::Goal2OperationalUnit(p: PNS::PNSModel) : 
PNS::OperationalUnit
{
     name := 'op_' + self.name;
     PNS := p;
     lowerBound := 10000.0;
     upperBound := 10000.0;
}


Hope this helps.

Dennis



Oscar Andres Fajardo F. wrote:
> Hi,
> I'm having trouble finding out how to don't lose the attributes of my
> generated elements.
> I'm new to QVT operational, I'm trying to remake a script I did in QVT
> relations with mediniQVT but I feel this is not so going good...
> I'm no good programmer at all, and all I did in the code was using my
> imagination, hope I'm not doing huge mistakes...the thing is that some
> of the generated elements (operative units and products by now)are
> losing their names and other attributes and I don't understand why
> Here's the code in QVTo:::
>
>
> modeltype MAS uses 'http://MAS/1.0';
> modeltype PNS uses 'http://PNS/1.0';
>
> transformation MAS2PNS(in mas:MAS, out pns:PNS);
>
> main() {
> mas.rootObjects()[MAS::MASModel] -> map MASmodel2PNSmodel();
> }
>
> mapping MAS::MASModel::MASmodel2PNSmodel() : PNS::PNSModel
> {
> result.Elements += self.Elements.map MASNE2PNSNE(result);
> }
>
> mapping MAS::MASNamedElement::MASNE2PNSNE(p: PNS::PNSModel)
> disjuncts MASElement::MASElement2PNSElement//,
> MASRelation::MASRelations2PNSRelation
> {
> }
> mapping MAS::MASElement::MASElement2PNSElement(p: PNS::PNSModel)
> disjuncts MAS::Agent::Agent2PNSElement, MAS::Goal::Goal2PNSElements
> {
> }
>
> /*
> mapping MAS::MASRelation::MASRelations2PNSRelation(p: PNS::PNSModel)
> {
> self.map MASRelation2PNSRelation(p);
> }
>
> mapping MAS::MASRelation::MASRelation2PNSRelation(p: PNS::PNSModel):
> PNS::PNSRelation
> {
> result.name := self.name;
> result.PNS := p;
> }
> */
> mapping MAS::Agent::Agent2PNSElement(p: PNS::PNSModel)
> when{self.oclIsTypeOf(Agent)}
> {
> self.map Agent2RawMaterial(p);
> }
> mapping MAS::Agent::Agent2RawMaterial(p: PNS::PNSModel) : PNS::RawMaterial
> when{self.oclIsTypeOf(Agent)}
> {
> result.name := self.name;
> result.PNS := p;
> result.price:= 1.0;
> result.maxFlow := 10000.0;
> }
> abstract mapping MAS::Goal::Goal2PNSElements(p: PNS::PNSModel)
> {
> self.map Goal2IntermediateMaterial(p);
> self.map Goal2OperationalUnit(p);
> self.map Goal2Product(p);
> }
>
> mapping MAS::Goal::Goal2IntermediateMaterial(p: PNS::PNSModel)
> :PNS::IntermediateMaterial
> {
> result.name :=self.name;
> result.PNS := p;
> }
>
> mapping MAS::Goal::Goal2OperationalUnit(p: PNS::PNSModel) :
> PNS::OperationalUnit
> {
> result.name = 'op_'+self.name;
> result.PNS := p;
> result.lowerBound = 10000.0;
> result.upperBound = 10000.0;
> }
> mapping MAS::Goal::Goal2Product(p: PNS::PNSModel) : PNS::Product
> {
> result.name=self.name+'_oaf';
> result.PNS := p;
> result.price = 1.0;
> result.reqFlow = 0.0;
> result.maxFlow = 10000.0;
> }
>
> Plz help! °_°
> *_*
>
> If my original code helps, here it is...
> /*
> * */ transformation MAS2PNS(MAS:MAS,PNS:PNS)
> {
> top relation MASModel2PNSModel
> {
> checkonly domain MAS mm:MAS::MASModel
> {};
> enforce domain PNS pm:PNS::PNSModel
> {};
> }
>
> top relation Agent2RawMaterial
> {
> en : String;
>
> checkonly domain MAS a:MAS::Agent
> {
> MAS = mm : MAS::MASModel{},
> name = en
> };
>
> enforce domain PNS rm:PNS::RawMaterial
> {
> --Creo el Raw Material
> PNS =pm : PNS::PNSModel{},
> name = en,
> price = 1.0,
> maxFlow = 10000.0
> };
>
> when
> {
> MASModel2PNSModel(mm,pm);
> }
> }
>
> top relation Goal2PNSElements
> {
> gn:String;
> checkonly domain MAS g:MAS::Goal
> {
> MAS = mm : MAS::MASModel{},
> name = gn
> };
> enforce domain PNS pm : PNS::PNSModel
> {
> --Creo el Intermediate Material
> Elements = im:PNS::IntermediateMaterial
> {
> PNS = pm,
> name = gn
> },
> --Creo el Product
> Elements = p:PNS::Product
> {
> PNS =pm : PNS::PNSModel{},
> name=gn+'_oaf',
> price = 1.0,
> reqFlow = 0.0,
> maxFlow = 10000.0
> },
> --Creo el Operational Unit
> Elements = ou:PNS::OperationalUnit
> {
> PNS =pm : PNS::PNSModel{},
> name = 'op_'+gn,
> lowerBound = 10000.0,
> upperBound = 10000.0
> },
> --Creo las relaciones que conectaran los Intermediate
> Materials con las Operational Units
> Elements = rio:PNS::PNSRelation
> {
> PNS = pm,
> name = gn+'_rel_opUnit'+gn,
> source = im,
> target = ou,
> rate = 1.0
> },
> --Creo las relaciones que conectaran las Operational
> Units con los Products
> Elements = rof:PNS::PNSRelation
> {
> PNS = pm,
> name = 'opUnit_'+gn+'_rel_'+gn+'_oaf',
> source = ou,
> target = p,
> rate = 1.0
> }
> };
>
> when
> {
> MASModel2PNSModel(mm,pm);
> }
> }
> }
>
> Thank you very much!!!
> Your help would be very appreciated...
>
> PS: don't know how toattach files I will attach the plugins for the
> transformation as soon as I find out how this works...
> (cant find the attach button xD )
Re: Losing atributes after transformation [message #655297 is a reply to message #654783] Sat, 19 February 2011 02:50 Go to previous messageGo to next message
Oscar Andres Fajardo F. is currently offline Oscar Andres Fajardo F.Friend
Messages: 10
Registered: February 2011
Location: Colombia
Junior Member
Thank you very much this totally helped me!!!
Got another question... Sorry Sad

If I execute the transformation repeatedly it doesnt replace the existing target model, instead places a "sibling" model...
Got any idea?
Red should replace Blue, instead it allocates right next to it... don't know why...at the end the code used right now.

Here's an example...

<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:PNS="http://PNS/1.0">
<PNS:PNSModel>
<Elements xsi:type="PNS:RawMaterial" name="a1" price="1.0" maxFlow="10000.0"/>
*
*
*
<Elements xsi:type="PNS:PNSRelation" rate="2.0" source="/0/@Elements.9" target="/0/@Elements.10"/>
</PNS:PNSModel>

<PNS:PNSModel>
<Elements xsi:type="PNS:RawMaterial" name="a1" price="1.0" maxFlow="10000.0"/>
<Elements xsi:type="PNS:RawMaterial" name="a2" price="1.0" maxFlow="10000.0"/>
*
*
*
<Elements xsi:type="PNS:PNSRelation" name="g2_rel_op_g2" rate="1.0" source="/1/@Elements.8" target="/1/@Elements.9"/>
<Elements xsi:type="PNS:PNSRelation" name="op_g2_rel_g2_oaf" rate="2.0" source="/1/@Elements.9" target="/1/@Elements.10"/>
</PNS:PNSModel>



modeltype MAS uses 'http://MAS/1.0';
modeltype PNS uses 'http://PNS/1.0';

transformation MAS2PNS(in mas:MAS, out pns:PNS);

main() 
{
	mas.rootObjects()[MAS::MASModel] -> map MASmodel2PNSmodel();
}

mapping MAS::MASModel::MASmodel2PNSmodel() : PNS::PNSModel
{
	result.Elements += self.Elements.map MASNE2PNSNE(result);
}

mapping MAS::MASNamedElement::MASNE2PNSNE(p: PNS::PNSModel)
disjuncts MASElement::MASElement2PNSElement//, MASRelation::MASRelations2PNSRelation
{
}

mapping MAS::MASElement::MASElement2PNSElement(p: PNS::PNSModel)
disjuncts MAS::Agent::Agent2PNSElement, MAS::Goal::Goal2PNSElements
{
}
/*
mapping MAS::MASRelation::MASRelations2PNSRelation(p: PNS::PNSModel)
{
	self.map MASRelation2PNSRelation(p);
}

mapping MAS::MASRelation::MASRelation2PNSRelation(p: PNS::PNSModel): PNS::PNSRelation
{
	result.name := self.name;
	result.PNS := p;
}
*/
mapping MAS::Agent::Agent2PNSElement(p: PNS::PNSModel)
when{self.oclIsTypeOf(Agent)}
{
	self.map Agent2RawMaterial(p);
}

mapping MAS::Agent::Agent2RawMaterial(p: PNS::PNSModel) : PNS::RawMaterial
when{self.oclIsTypeOf(Agent)}
{
	result.name := self.name;
	result.PNS := p;
	result.price:= 1.0;
	result.maxFlow := 10000.0;
}

abstract mapping MAS::Goal::Goal2PNSElements(p: PNS::PNSModel)
{
	var im : IntermediateMaterial;
	var ou : OperationalUnit;
	var pd: Product;
	
	im := self.map Goal2IntermediateMaterial(p);
	ou := self.map Goal2OperationalUnit(p);
	pd := self.map Goal2Product(p);
	map newRelation1(p,im,ou);
	map newRelation2(p,ou,pd);
}

mapping newRelation1(p: PNS::PNSModel, im:PNS::IntermediateMaterial,ou : PNS::OperationalUnit):PNS::PNSRelation
{
	result.PNS := p;
	result.name := im.name + '_rel_' + ou.name;
	result.source := im;
	result.target := ou;
	result.rate := 1.0;
}

mapping newRelation2(p: PNS::PNSModel, ou : PNS::OperationalUnit, pd : PNS::Product):PNS::PNSRelation
{
	result.PNS := p;
	result.name := ou.name + '_rel_'+pd.name;
	result.source := ou;
	result.target := pd;
	result.rate := 1.0;
}

mapping MAS::Goal::Goal2IntermediateMaterial(p: PNS::PNSModel) :PNS::IntermediateMaterial
{
	result.name :=self.name;
	result.PNS := p;
}

mapping MAS::Goal::Goal2OperationalUnit(p: PNS::PNSModel) : PNS::OperationalUnit
{
	result.name := 'op_'+self.name;
	result.PNS := p;
	result.lowerBound := 10000.0;
	result.upperBound := 10000.0;
}

mapping MAS::Goal::Goal2Product(p: PNS::PNSModel) : PNS::Product
{
	result.name := self.name+'_oaf';
	result.PNS := p;
	result.price := 1.0;
	result.reqFlow := 0.0;
	result.maxFlow := 10000.0;
}

Re: Losing atributes after transformation [message #655306 is a reply to message #655297] Sat, 19 February 2011 06:26 Go to previous message
Oscar Andres Fajardo F. is currently offline Oscar Andres Fajardo F.Friend
Messages: 10
Registered: February 2011
Location: Colombia
Junior Member
Seems it has somethig to do with: https://bugs.eclipse.org/bugs/show_bug.cgi?id=315007
Are there plans to correct this bug?
thank you
Previous Topic:problem with output SCA model file format
Next Topic:[ATL] Rule choose
Goto Forum:
  


Current Time: Fri Mar 29 04:42:44 GMT 2024

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

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

Back to the top