I am working on an activity diagram that contains several actions, each with a tagged value called i: int . This activity diagram has a context block named "context" with a value variable sum: int = 0 .
I want to update the "sum" during the simulation, such that
sum = sum + i
For example, after simulating this diagram, sum should become 5 (i_action1 = 2 and i_action2 = 3)
Could someone provide guidance on how to model this? Specifically, how can I retrive the value of i in a clear and effective way? I tried with opaque action, with groovy code
sum = sum + ALH.getTagValue(this, “i”);
But it doesn't work, because "this" is the script, not my action. I tried also with this.getOwner() and this.getCaller() and self, but no luck.
Any examples or best practices would be greatly appreciated!
Thank you!
The following python script works with my version of the simulation engine:
def getTagValueOfCurrentAction(tagName):
namedElement = ALH.getCaller()
taggedValues = namedElement.getTaggedValue()
for v in taggedValues:
if v.getTagDefinition().getName() == tagName:
return v.getValue()[0]
print (getTagValueOfCurrentAction("i"))
I think the reason why the helper doesn't work, is that no runtime object is created for an opaque action.
PS: You probably have a good reason for using a stereotype attribute (on language level) to calculate a block attribute (on user model level). If not, you could replace them with value pins. I think it would be much easier to use them in the script.