addDurationConstraint - Add duration constraint to interaction - MATLAB (original) (raw)
Main Content
Add duration constraint to interaction
Since R2025a
Syntax
Description
[durationConstraint](#mw%5F4a108847-34e5-4d49-bc8a-293517373bfb) = addDurationConstraint([start](#mw%5F0d8ab60f-3307-4991-b520-8980580c1efb), [end](#mw%5F567355bb-11a6-4129-a7e3-10b524916802), [expression](#mw%5F79e09190-49ac-49d3-acfa-abbc40c304c6))
adds a duration constraint between the start occurrence specified bystart
and the end occurrence specified by end
with the expression specified by expression
.
Examples
Create a sequence diagram programmatically to describe the scenario of a pedestrian crossing the street at an intersection with traffic lights.
To learn more about sequence diagrams, see Author Sequence Diagrams Interactively.
Open Traffic Light Example
Load the TLExample
architecture model.
model = systemcomposer.openModel('TLExample');
Create a new sequence diagram named 'InhibitCopy
'.
diagram = model.addInteraction('InhibitCopy');
Add Lifelines
Add a lifeline for each component in the architecture.
sourceLifeline = diagram.addLifeline('TLExample/source'); pollerLifeline = diagram.addLifeline('TLExample/poller'); switchLifeline = diagram.addLifeline('TLExample/switch'); lampLifeline = diagram.addLifeline('TLExample/lampController'); controllerLifeline = diagram.addLifeline('TLExample/controller');
Get the root fragment and root operand of the interaction.
rootFragment = diagram.RootFragment; rootOperand = rootFragment.Operands(1);
Add Messages and Fragments
Add two messages to the root operand.
sourceToPollerMsg = rootOperand.addMessage(sourceLifeline, "switchout", pollerLifeline, "sw", "rising(sw-1){sw==1}"); pollerToSwitchMsg = rootOperand.addMessage(pollerLifeline, "switchEvent", switchLifeline, "switchEvent", "switchEvent{switchEvent==1}");
Add an alternative fragment to the root operand.
altFrag = rootOperand.addFragment('Alt');
Specify the guard expressions for each operand of the alternative fragment.
op1 = altFrag.Operands(1); op1.Guard = "switch/inhibit==0"; op2 = altFrag.addOperand("switch/inhibit==1");
Add two messages to the first operand of the alternative fragment.
switchToLampControllerMsg1 = op1.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==1}"); switchToControllerMsg = op1.addMessage(switchLifeline, "switchPush", controllerLifeline, "pedRequest", "pedRequest");
Add a message to the second operand of the alternative fragment.
switchToLampControllerMsg2 = op2.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==2}");
Add Duration Constraints
Add a duration constraint between the two messages in the first operand of the alternative fragment.
startEvent = switchToLampControllerMsg1.End; endEvent = switchToControllerMsg.End; expression = "t > 12msec"; durationConstraint = diagram.addDurationConstraint(startEvent, endEvent, expression);
Open Sequence Diagram
Open the newly created sequence diagram.
Input Arguments
Expression defining duration constraint, specified as a string.
An expression of a duration constraint contains:
- A keyword to represent the duration observation. Use:
t
orduration
. - A relational operator. Use:
>
,<
,>=
, or<=
. - A time value.
- A unit of time. Use:
sec
,msec
, orusec
.
Example: duration < 10sec
Example: 1 >= t > 3msec
Output Arguments
Version History
Introduced in R2025a
See Also
Tools
Functions
- openViews | sim | addInteraction | getInteraction | getInteractions | open | addLifeline | addFragment | addOperand | addMessage | addAnnotation | findLifeline | findElement | move | move | move | destroy | next | current | reset
Objects
- systemcomposer.arch.Model | systemcomposer.interaction.Interaction | systemcomposer.interaction.Iterator | systemcomposer.interaction.Lifeline | systemcomposer.interaction.MessageEvent | systemcomposer.interaction.FormalGate | systemcomposer.interaction.Message | systemcomposer.interaction.Fragment | systemcomposer.interaction.Operand | systemcomposer.interaction.DurationConstraint | systemcomposer.interaction.Annotation