Proxy Variables with Constraints on Types and Relationships
Use proxy variables to reference the variables of related types, including parent, root, and sibling types.
The supported proxy variables include:
- Cardinality
- Parent
- this.quantity
Cardinality is a fundamental concept in Constraint Modeling Language (CML), controlling the quantity of product instances allowed in a defined relationship. It’s crucial for ensuring product structure validity and optimizing performance.
The cardinality proxy variable refers to the cardinality of a relationship, that is, the quantity of instances of the same type in a relationship. The first parameter is the type name. The second, optional parameter is the port name. This variable differs from the this.quantity proxy variable, which refers to the quantity of the current instance.
Use this format:
Each parameter value can be a string or a string variable. If you don’t specify the relation name, the engine searches all ports to find the type.
The cardinality bounds are defined within the relation declaration with square brackets, formatted as [minimum..maximum].
These examples illustrate how cardinality is defined and managed in the Generator Set model, focusing on standard definition, conditional enforcement, and reading the quantity.
See Message Rule.
This example shows how the Generator Set uses different cardinality ranges to define fixed requirements, optional components, and minimum quantities for necessary components.
Key Concepts:
- Syntax: Cardinality is specified immediately after the component type in the relation declaration.
- Best Practice: Specifying the smallest required range, such as [1..1] or [0..5], ensures the constraint engine tests fewer combinations, which prevents performance degradation.
Cardinality can be dynamically enforced based on attributes of the parent product using the require() constraint keyword. For more information, see Require Rule.
This pattern (require(condition, relation[type] == N, ...)) allows the CML model to enforce a precise fixed number of child components when a quantity threshold or attribute condition is met on the parent.
The cardinality() keyword is a proxy variable used to refer to the size of a relationship. The count() keyword is an aggregate function that counts matching components or attribute conditions within a relation. Both can be used to read quantities for validation or aggregation rules.
Both cardinality() and count() can be used to determine the total quantity of items in a relationship. In this scenario, they return the same value because the count() condition covers all possible active instances.
Cardinality is a proxy variable representing the headcount or size of the relation, whereas count is a function used to evaluate specific attribute conditions or filters within those instances.
For more information, see Message Rule.
Instance Quantity is the quantity of a child product per instance of the parent product. It differs from the end quantity, which is the total quantity of the child product across all parent instances. For example, if a customer orders 3 generator sets and each set requires 2 alternators, the instance quantity is 2, the quantity per bundle. The end quantity of alternators is 6.
The constraint engine calculates instance quantity when the constraint model CML meets all of these conditions.
- Instance Quantity Access (
orgHasInstanceQtyAccess) is turned on. To turn on Instance Quantity Access, go to Revenue Settings and turn on the Instance Quantity Access setting. - The child product’s
ProductRelatedComponentrecord hasQuantityScalingMethod__cset to Proportional. - The child product’s end quantity divides evenly by the parent product’s quantity.
The constraint engine divides the child’s end quantity by the parent’s quantity to derive the instance quantity.
In the Generator Set configuration, instanceQty is assigned the value of this.quantity. Quantities for MainAlternator and TemperatureSensor are returned as instance quantities of GeneratorSet.
The require rule validates against instanceQty values, confirming the per-set configuration is correct regardless of how many sets the customer orders.
The parent() proxy variable is used to turn on components at any level of the product hierarchy (child, grandchild, and so on) to access the attributes (variables) defined by their ancestor types. This mechanism facilitates the flow of configuration data and calculated values from the top of the bundle down to its components.
The parent() keyword functions as a proxy variable used to reference attributes residing in the immediate parent or any ancestor type in the configuration model.
| Variable Name | Syntax | Purpose |
|---|---|---|
parent() | parent(<ancestor variable name>, <level>) | Retrieves the value of an attribute from a parent or ancestor type. |
- Targeting Ancestors: The first parameter is the name of the attribute in the ancestor type that you want to reference.
- Level Parameter: The second parameter (
<level>) is optional and specifies how many levels up the hierarchy the engine searches. If omitted, it typically references the immediate parent. The level index for theparent()function effectively starts from 0 (implicit) for the immediate parent. - Level 0 (Default): When you use
parent(attributeName), the engine references the attribute in the immediate parent. - Level n: When you specify
parent(attributeName, 1), the engine reaches one level beyond the immediate parent, to the grandparent. - Data Flow:
parent()makes sure that the data flows unidirectionally, where the child reads attributes calculated or defined by the parent, which helps to prevent complex circular dependencies. - Single Inheritance: CML follows a single inheritance model, where a type can only extend one other type at a time.
- Same Variable Name: In CML, using the same variable name between a parent bundle and its child accessories is a standard architectural pattern for cascading values down a product hierarchy. This allows a child component to automatically inherit or synchronize its properties with the parent type, ensuring configuration consistency.
In this example, the standardsAndCompliance selection made at the bundle level is passed down to every accessory within that bundle.
The parent() proxy variable is essential for cascading configuration data and constraints down the product hierarchy, so that child components reference attributes defined by their ancestors.
This example uses attributes found on the GeneratorSet type (the parent) and demonstrates how related components (like TemperatureSensor) access those values using the parent() proxy variable. Here’s the hierarchy context.
| Parent Type | Relation Name | Child Type | Cardinality | Key Attribute Usage |
|---|---|---|---|---|
Root GeneratorSet | TemperatureSensors | TemperatureSensor | [0..5] | Defines primary inputs (requiredKW) and a derived attribute (ULComplianceEnforced) based on the standardsAndCompliance selection. |
Child TemperatureSensor (Instance within GeneratorSet relation) | Not Applicable | Not Applicable | Not Applicable | Uses the parent() proxy variable to reference the requiredKW attribute from its ancestor (GeneratorSet). A constraint ensures the component’s capacity (maxOperatingKW) meets the requirement inherited from the parent. |
Grandchild StatorTemperatureSensor (Subtype of TemperatureSensor) | Not Applicable | Not Applicable | Not Applicable | Inherits functionality from TemperatureSensor. Uses parent() to retrieve the calculated ULComplianceEnforced boolean from the GeneratorSet. Enforces a conditional installation rule using the Implication Operator (->). |
- Direct Reference (Immediate Parent): In the
TemperatureSensortype,int parentRequiredKW = parent(requiredKW);accesses therequiredKWattribute defined in the immediately superior type, which isGeneratorSet. - Unidirectional Data Flow: The
parent()proxy variable is critical for enabling unidirectional data flow, where calculated or defined values in the parent are read by children to enforce constraints. The engine makes sure that parent aggregation and calculation are complete before theparent()function executes in the child component.
this.quantity is a proxy variable used specifically to access the quantity of the current instance (the specific product line item) within a configuration.
- Scope: It refers only to the quantity of the specific instance in which it’s used. It’s used at the component level to determine the quantity of that item selected by the user or set by the constraint engine.
- Calculation Rule: The
this.quantityproxy variable can be used only within a calculation rule. - Distinction from
cardinality():this.quantitydiffers from thecardinality()proxy variable, which refers to the total number of instances of a specific type within a relationship and includes the quantity of other instances of the same type. - Read-Only/Validation: When accessing quantity in CML, attributes like
this.quantity, or external equivalents likelineItemQuantityorItemEndQuantity, are treated as read only and should be used only in calculation or evaluation rules. It isn’t recommended to use it to drive component creation, which should be done via cardinality.
In the Generator Set configuration, a component like the NaturalGasReformer uses this.quantity to define a local attribute representing how many units were selected, which is used for internal calculations (like total capacity or total weight contribution).