blob: e5af6eee10b392e7152016706e54a7e0db90559b [file] [log] [blame]
-----------------------------------------------------------------------
-- Copyright (C) 2015-2016 --
-- University of Firenze, Italy --
-- --
-- All rights reserved. This program and the accompanying materials --
-- are made available under the terms of the Eclipse Public License --
-- v1.0 which accompanies this distribution, and is available at --
-- http://www.eclipse.org/legal/epl-v20.html --
-- --
-- Contributors: --
-- Leonardo Montecchi lmontecchi@unifi.it --
-----------------------------------------------------------------------
-- @path PNML=/org.chess.statebased/metamodels/placeTransition.ecore
query PNML2DEEM_query = PNML!PetriNet.allInstances()->
collect(x | x.toString());
-- collect(x | x.toString().writeTo('GasDetectionProject/model'));
helper context PNML!PetriNet def: toString():String =
'<NDFile-\'1.2\'>\n\n'+
'NET:"'+self.id.clean()+'",2000,2000;\n'+
'COLORS:White,Black,Black,Black,Black,Black;\n'
+'\n'+
PNML!Variable.allInstances()->iterate(i; acc:String=''| acc + i.toString())
+'\n'+
PNML!Study.allInstances()->iterate(i; acc:String=''| acc + i.toString())
+'\n'+
PNML!Place.allInstances()->iterate(i; acc:String=''| acc + i.toString())
+'\n'+
PNML!GSPNTransition.allInstances()->iterate(i; acc:String=''| acc + i.toString())
+'\n'+
PNML!GSPNArc.allInstances()->iterate(i; acc:String=''| acc + i.toString())
+'\n'+
PNML!Measure.allInstances()->iterate(i; acc:String=''| acc + i.toString() + '\n')
+'\n'
;
helper context PNML!Place def: toString(): String =
if self.nodegraphics.oclIsUndefined() then
'PLACE:"'+self.id.clean()+'",1500,1500,'+self.initialMarking.text+',0;\n'
else
'PLACE:"'+self.id.clean()+'",'+ self.nodegraphics.position.x+','+self.nodegraphics.position.x+','+self.initialMarking.text+',0;\n'
endif;
helper context PNML!GSPNImmediateTransition def: toString(): String =
-- 'TRANS:"'+self.Name+'",1500,1500,V,Immediate,'+self.Priority+',0,\'\', \'\',\n'+
if(self.nodegraphics.oclIsUndefined()) then
'TRANS:"'+self.id.clean()+'",1500,1500,V,Immediate,'
else
'TRANS:"'+self.id.clean()+'",'+self.nodegraphics.position.x+','+self.nodegraphics.position.y+',V,Immediate,'
endif+
self.Priority+
',1,'+
'\''+
if(self.Guard.oclIsUndefined()) then '' else self.Guard.toString() endif+
'\''+
', \''+self.Weight+'\',\n'+
' (\n'+
self.Weight +
'\n' +
' );\n';
helper context PNML!GSPNTimedTransition def: toString(): String =
if(self.nodegraphics.oclIsUndefined()) then
'TRANS:"'+self.id.clean()+'",1500,1500,V,Timed,1,'
else
'TRANS:"'+self.id.clean()+'",'+self.nodegraphics.position.x+','+self.nodegraphics.position.y+',V,Timed,1,'
endif+
self.Distribution.getCode()+
',\''+
if(self.Guard.oclIsUndefined()) then '' else self.Guard.toString() endif
+'\', \''+self.Distribution.paramSequence()->first()+'\',\n'+
'(\n'+' '+
'1.000000e+00' +
self.Distribution.paramSequence().subSequence(2, self.Distribution.paramSequence().size())->iterate(
i; acc : String = '' |
acc + ',\n' +
' '+'\''+i.toString()+'\''
)+
'\n);\n';
helper context PNML!Distribution def: getCode(): String =
if self.oclIsTypeOf(PNML!Deterministic) then
'0'
else if self.oclIsTypeOf(PNML!Exponential) then
'1'
else if self.oclIsTypeOf(PNML!Gaussian) then
'11'
else if self.oclIsTypeOf(PNML!Uniform) then
'13'
else if self.oclIsTypeOf(PNML!Gamma) then
'3'
else --if self=#Weibull then
'14'
endif endif endif endif endif;
helper context PNML!Distribution def: paramSequence(): Sequence(Real) =
if self.oclIsTypeOf(PNML!Deterministic) then
Sequence{self.Value}
else if self.oclIsTypeOf(PNML!Exponential) then
Sequence{self.Rate}
else if self.oclIsTypeOf(PNML!Gaussian) then
Sequence{self.Mean, self.Variance}
else if self.oclIsTypeOf(PNML!Uniform) then
Sequence{self.Lower, self.Upper}
else if self.oclIsTypeOf(PNML!Gamma) then
Sequence{self.Alpha, self.Beta}
else --if self=#Weibull then
Sequence{self.Alpha, self.Beta}
endif endif endif endif endif;
helper context PNML!GSPNArc def: toString(): String =
if self.source.oclIsKindOf(PNML!Place) then
--Input Arc / Inhibitor Arc
if self.type = #inhibitor then
--Inhibitor Arc
'OARC:"'+self.source.id.clean()+'","'+self.target.id.clean()+'",1,2,\''
else
--Input Arc
'IARC:"'+self.source.id.clean()+'","'+self.target.id.clean()+'",1,0,\''
endif
+if(self.MultiplicityFunction.oclIsUndefined()) then '' else self.MultiplicityFunction.toString() endif
+'\',\n ('+
if self.source.nodegraphics.oclIsUndefined() then
'1500,1500'
else
self.source.nodegraphics.position.x.toString()+','+self.source.nodegraphics.position.y.toString()
endif
+','+
if(self.target.nodegraphics.oclIsUndefined()) then
'1500,1500'
else
self.target.nodegraphics.position.x.toString() + ',' + self.target.nodegraphics.position.y.toString()
endif
+'),1;\n'
else
--Output Arc
'OARC:"'+self.target.id.clean()+'","'+self.source.id.clean()+'",1,1,\''+
if(self.MultiplicityFunction.oclIsUndefined()) then '' else self.MultiplicityFunction.toString() endif
+'\',\n'+
' ('+
if self.target.nodegraphics.oclIsUndefined() then
'1500,1500'
else
self.target.nodegraphics.position.x.toString()+','+self.target.nodegraphics.position.y.toString()
endif
+','+
if(self.source.nodegraphics.oclIsUndefined()) then
'1500,1500'
else
self.source.nodegraphics.position.x.toString() + ',' + self.source.nodegraphics.position.y.toString()
endif
+'),1;\n'
endif;
helper context PNML!ValueExpression def: toString(): String = self.value.toString();
helper context PNML!OpAnd def: toString(): String = '(' + self.expression1.toString() + ')AND(' + self.expression2.toString()+')';
helper context PNML!OpOr def: toString(): String = '(' + self.expression1.toString() + ')OR(' + self.expression2.toString()+')';
helper context PNML!OpNot def: toString(): String = 'NOT(' + self.expression.toString() + ')';
helper context PNML!OpSum def: toString(): String = self.expression1.toString() + '+' + self.expression2.toString();
helper context PNML!OpGreater def: toString(): String = self.expression1.toString() + '>' + self.expression2.toString();
helper context PNML!OpEqual def: toString(): String = self.expression1.toString() + '=' + self.expression2.toString();
helper context PNML!OpTrue def: toString(): String = 'TRUE';
helper context PNML!OpFalse def: toString(): String = 'FALSE';
helper context PNML!IfThenElse def: toString(): String =
'IF('+self.condition.toString()+')THEN('+self.ifTrue.toString()+')ELSE('+self.ifFalse.toString()+')';
helper context PNML!MarkingExpression def: toString(): String = 'MARK('+self.place.id.clean()+')';
helper context PNML!Study def: toString(): String =
'STUDY:"'+self.name+'"'+
self.vars.asOrderedSet()->iterate(
i; acc:String=''| acc + ',1,"{'+
i.toString() +
'}",0'
)
+';\n';
helper context PNML!VariableValues def: toString(): String =
self.values.asOrderedSet().first().toString()+
self.values.asOrderedSet().subOrderedSet(2, self.values.size()) ->iterate(
i; acc:String=''| acc + ',' + i.toString()
)
;
helper context PNML!Variable def: toString(): String =
'VARIABLE:"'+self.name+'","Real";\n';
helper context PNML!Measure def:toString(): String =
'RES_FUNC:"'+self.name+'",\''+self.rewardFunction.toString()+'\','+self.evaluationType.toString()+';';
helper context PNML!InstantOfTime def:toString(): String = '0';
helper context PNML!IntervalOfTime def:toString(): String = '1';
helper context PNML!IntervalOfTimeAveraged def:toString(): String = '2';
--Fix to make DEEM happy (it does not like dots in element names)
--Any dot is replace by a double underscore (to distinguish from single underscore)
helper context String def:clean(): String = self.regexReplaceAll('\\.', '__');