Author Topic: Conditional Looping in SysML Activity Diagrams  (Read 477 times)

Miguel

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Conditional Looping in SysML Activity Diagrams
« on: July 09, 2020, 10:19:01 am »
Hi folks,

This is more of a SysML question than and EA-specific, but hoping to get some insight/suggestions.

I'm trying to figure out how to represent control logic, like a while loop in a SysML Activity Diagram.  In my case, I have a behavior I want to model in an Activity Diagram that looks at a collection of things that are candidates for some change.  There may be from zero to several items that have to change. 

I don't know how to handle that.  I do understand about IF-THEN-ELSE Decision nodes.  I just don't know how to do conditional looping in order to operate on a set of items from 0 to many. 

Sequence Diagrams have this ability, but in this case, an AD is more appropriate, because I'm not calling out to some other component/service, so there is no 'interaction'.  So, like I mentioned, I'm trying to do this as an Activity Diagram.

Here's an attempt to boil down the construct:



I think that in the above, the "get all..." action will produce a collection of one or more FOOs, which will be consumed one at a time by the "Do something..." action.  But two things that I don't know how to do:

1- how do I handle there not being any FOOs that matched the criteria?  I'd like to wind up at the "No FOOs..." SendSignal action.  I can't figure out how to get there.

2- if one or more FOOs are found, I believe that the above will "Do something..." to them one at a time, but how do I know when I am at the end of the set so that I can go on to the "At Least One..." SendSignal action, and just as importantly, how do I only get there once?

In a nutshell, at the end of the activity, I only want to send one signal; one of the two listed.

Thanks for the help...
Miguel


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7296
  • Karma: +84/-12
    • View Profile
Re: Conditional Looping in SysML Activity Diagrams
« Reply #1 on: July 09, 2020, 03:31:34 pm »
What you are looking for is an ExpansionRegion.

Quote
An ExpansionRegion is a StructuredActivityNode that executes its content multiple times corresponding to elements of
input collection(s).

Effectively, you create the region with any inputs and outputs involved and the contents of that region will be performed for each set of inputs.
Eve

support@sparxsystems.com

Miguel

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Conditional Looping in SysML Activity Diagrams
« Reply #2 on: July 10, 2020, 08:19:44 am »
Eve, thank you, that helped point me in the right direction.  Expansion Regions seem to be a little more advanced concept; it's not discussed in any of my three SysML books.

But it did lead to some EA-specific questions:

Here is a diagram on the EA site describing Expansion Regions:



And some text from EA: "An Expansion Region surrounds a process to be imposed multiple times on the incoming data, once for every element in the input collection." (highlights mine).

What I can't figure out how to do in EA is to add the "incoming data" (and the outgoing counterpart):



Nothing in the toolbox or properties gets me there.  In the expansion region properties there is an "input element" and "output element", but I'm not able to select a type (block) defined elsewhere in the model, so I'm unsure what that would even be used for.  So... how do I get the items circled in red, above, onto my diagram's Expansion Region.

Also, how would I specify that I'm sending in an Array, Bag, Set.  Are these types in SysML?  They don't seem to be.  Do I just say obj[0..*]?  Or do I have to define a "SetofObject" type?



Finally, just a note for completeness.  Once you got me on the path of looking for Expansion Region, I did also find that there is a special item called Loop Node, that is a type of Structured Activity.  That might work for what I'm trying to do, though I do like the Expansion Region, if I can figure out how to use it in EA.

Couple of EA links:
https://sparxsystems.com/enterprise_architect_user_guide/14.0/model_domains/expansionregion.html
https://sparxsystems.com/enterprise_architect_user_guide/14.0/model_domains/loop_and_conditional_nodes2.html



Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7296
  • Karma: +84/-12
    • View Profile
Re: Conditional Looping in SysML Activity Diagrams
« Reply #3 on: July 10, 2020, 09:17:54 am »
Yes, it's not a construct I've seen used frequently. I did check though and it is one of the UML constructs that are directly imported to SysML. I misread it, the list it appears in is the UML types excluded from SysML not included. I still think it's the clearest way to express what is going on.

The ExpansionNode, drawn as 3 joined boxes, is available in the context menu for your Region. It's also available on our UML (but not SysML) Activity toolbox.

As for how to display the type on those nodes, that requires going into my first disagreement with that diagram... It doesn't make any sense to describe a type as an array in an Activity diagram. You will have the type of all relevant object nodes set as the type of the array, then set a multiplicity on the node. So in that diagram all Pins and Expansion nodes should be showing the same type, whatever is stored in the array.

My second disagreement with that diagram is that it needs Pins on the inner actions. Being inside an expansion region doesn't have that.

If you want to look into the LoopNode, it's available when you drop a 'Structured Activity' from the toolbox. My tip is that it's even more complex, and will probably obscure that you are processing multiple items in a collection.
« Last Edit: July 10, 2020, 10:18:02 am by Eve »
Eve

support@sparxsystems.com

Miguel

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Conditional Looping in SysML Activity Diagrams
« Reply #4 on: July 10, 2020, 10:14:52 am »
Great!  Thank you, Eve.  I'm going to work on this, probably over the weekend and will plan on providing some thoughts as a first-timer using the Expansion Region.

Just one thing I want to confirm...

As for how to display the type on those nodes, that requires going into my first disagreement with that diagram... It doesn't make any sense to describe a type as an array in an Activity diagram. You will have the type of all relevant object nodes set as the type of the array, then set a multiplicity on the node. So in that diagram all Pins and Expansion nodes should be showing the same type, whatever is stored in the array.

I think what you mean is that the output pin of my prior action will be MyObject[0..*] and the input to the Expansion Node of the Expansion Region should also be MyObject[0..*], right?  Type and multiplicity match and the [0..*] indicates the same concept as an Array/Set/Bag, but without defining a special type to contain it... yeah?

Thanks,
Miguel

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7296
  • Karma: +84/-12
    • View Profile
Re: Conditional Looping in SysML Activity Diagrams
« Reply #5 on: July 10, 2020, 10:20:18 am »
I'm afraid I'm not sure how the multiplicity is handled on the expansion nodes. The examples I've seen it's not specified. I think that would mean that each occurrence of the region will take one object from the node.
Eve

support@sparxsystems.com

KThiel

  • EA Novice
  • *
  • Posts: 8
  • Karma: +2/-0
    • View Profile
    • Strypes
Re: Conditional Looping in SysML Activity Diagrams
« Reply #6 on: July 11, 2020, 12:22:39 am »
Hi Miquel,

Isn't it possible to also use a control flow, run both your activities in parallel and with creating loops in each parallel path with decision nodes and merges?
And with the control flow you can activate the send signals.

Kind regards,

Koen van Thiel
Kind regards,

Koen van Thiel
System integrator

e:    koen.van.thiel@strypes.nl   
w:    www.strypes.nl