Lesson 14: Multiplicity & Cardinality: The Power of Brackets [ ]
Multiplicity & Cardinality: The Power of Brackets [ ]
In SysML v1, multiplicities were represented either visually on association ends or textually inside block compartments as property strings.
SysML v2 makes that cardinality part of the textual declaration. A model can state that a truck has at least four wheels, between two and four doors, an optional sunroof, and any number of cargo boxes.
That makes the design intent readable where the feature is defined. It also gives a specialized model a clear rule for how it may narrow a general model's allowed counts.
The Concept: How Many?
In SysML v2, every Feature (Part, Port, Attribute, Item) has a multiplicity. It constrains the allowable cardinality of that feature.
- Exact Count:
[4]means exactly 4. - Range:
[2..4]means between 2 and 4 inclusive. - Optional:
[0..1]means it might not exist. - Unlimited:
[*](shorthand) or[0..*](explicit lower bound) means zero to infinity.
The Code: Designing a Modular Truck
Let's build a truck where we define exactly how many wheels, doors, and trailers it can have. Crucially, we will define a generic truck first, then specialize it into a specific configuration.
package AutomotiveDesign {
part def Truck {
// 1. Range [Min..Max] or [Min..*]
// A generic truck has at least 4 wheels.
// We define a wide range here so subclasses can narrow it.
part wheels[4..*] : Wheel;
// 2. Range [2..4]
// It can have 2, 3, or 4 doors, depending on configuration.
part doors[2..4] : Door;
// 3. Optional [0..1]
// The Sunroof is optional. 0 means it doesn't exist; 1 means it does.
part sunroof[0..1] : Sunroof;
// 4. Unlimited [*]
// We can carry any number of cargo boxes.
// We can also add keywords like 'ordered' or 'nonunique'.
part cargo[*] ordered : CargoBox;
// 5. Trailers (Optional Component)
part trailers[0..1] : Trailer;
}
// 6. Redefining Multiplicity in a Subclass
part def HeavyHauler :> Truck {
// We redefine wheels to lock the count to exactly 18.
// This is valid because 18 is within the parent's range of [4..*].
part :>> wheels[18];
}
}Deep Dive: Under the Hood of the Brackets
Default Multiplicity
When a multiplicity is omitted from a text declaration, a default multiplicity range is determined:
Does the usage subset or redefine a parent?
│
┌────────────────┴────────────────┐
YES NO
│ │
Inherits parent multiplicity Is it an Attribute, Port,
or Item (including Part) usage?
│
┌─────────────┴─────────────┐
YES NO
│ │
Is it owned by a Defaults to [0..*]
Classifier (not a package)?
│
┌─────────────┴─────────────┐
YES NO
│ │
Does it lack explicit Defaults to [0..*]
subsetting or redefinition?
│
┌─────────────┴─────────────┐
YES NO
│ │
Defaults to [1..1] Defaults to [0..*]This means that - for attribute, item, part, and port usages owned by a definition or usage, the usual implicit multiplicity is [1..1] when there is no explicit multiplicity, subsetting, or redefinition. In other situations, the effective default can be [0..*]. And if your feature subsets or redefines an existing feature, it automatically inherits the multiplicity of that parent feature. The practical lesson is to write brackets whenever the count is meaningful to the design, especially for ranges, optionality, and redefinitions.
Expression-Based (Parametric) Multiplicities
Multiplicity bounds do not have to be hardcoded integers. SysML v2 allows the lower and upper bounds of a multiplicity range to be parameterized by expressions (such as attributes or calculations) defined within the same context.
This is incredibly useful for modeling physical systems where the number of sub-components scales dynamically based on structural parameters:
package BatterySystemArchitecture {
private import ISQ::*;
private import ScalarValues::*;
part def BatteryCell;
part def SmartBattery {
// Parametric multiplier attribute
attribute expectedModuleCount : Integer;
// The upper bound is bound to the value of an attribute
part cellModules[0..expectedModuleCount] : BatteryCell;
}
}Multiplicity on Successions & Control Flows
Multiplicities can also be applied directly to Succession Ends to constrain behavioral execution loops and model conditional branching.
In this pattern, a multiplicity on a succession end limits how many times the target performance can occur relative to the source performance:
package CameraControl {
action def Focus;
action def Shoot;
part def DSLR_Camera {
action focus[*] : Focus;
action shoot[*] : Shoot;
// Succession Multiplicity Constraint:
// on focus means focus MUST perform first.
// [0..1] on shoot means shooting is optional and occurs at most once per focus performance.
succession shootingSequence
first focus then [0..1] shoot;
}
}Collection Semantics: Uniqueness vs. Ordering
When a feature has a multiplicity greater than 1, it represents a collection of references. You can append keywords to explicitly declare the algebraic structure of this collection:
unique(Default): The collection cannot contain duplicate object references.nonunique: Duplicate references are permitted (e.g., repeating the same sensor reading value).unordered(Default): Elements have no chronological or index-based order.ordered: Elements form a sequence indexed from 1 to the cardinality of the collection.
V1 vs. V2 Multiplicity Cheat Sheet
| Concept | SysML v1 | SysML v2 |
|---|---|---|
| Multiplicity notation | Represented on association ends or written in block compartments as [min..max]. | Integrated into the feature declaration in square brackets: wheels[4..*] : Wheel. |
| Ordered collection | {ordered} property modifier. | ordered keyword. |
| Optional feature | 0..1 multiplicity. | [0..1] multiplicity with normative brackets. |
| Omitted multiplicity | Normatively defaults to 1..1 on properties. | [1..1] for qualifying structural usages; otherwise defaults to [0..*] (or inherits from parent). |
Next Lesson
We will look at Attributes & The ISQ Library. We've been using Real and Integer, but real engineering requires physics. We will learn how to use ISQ::Mass and ISQ::Power to make our models physically aware.