Business-Centric CML Examples
These Constraint Modeling Language (CML) structures implement quantity aggregation and resolve calculation dependencies.
This CML example shows how to model bundle rollups by separating aggregation from validation, ensuring correct calculation order, solver stability, and business-rule consistency
In example 1, the GeneratorSet type contains the totalItemPowerKW variable that is assigned with the totalPowerKW. The model specifies a relationship based on the product classification (modelClassification). This relationship includes aggregation using the sum() function that calculates the totalPowerKW from the products selected in the modelClassification during bundle configuration. The model contains a message for displaying the totalItemPowerKW with the modelClassification.totalPowerKW on the Product Configuration.
As a result, the engine calculates the totalPowerKW of user selected products in the modelClassification and assigns this value to the totalItemPowerKW. The system displays both values in the information message on the Product Configuration.
This pattern breaks unsolvable loops by enforcing unidirectional data flow (Parent dictates Child quantity based on Child aggregates).
In example 2, the relationship includes aggregation using the total() function that calculates the sumOfChildPower from the selected products in the voltageclassification. The GeneratorSet type contains the totalDistributionValue with the explicit domain ([0.00..1000.00]). The model contains two constraints with corresponding @sequence annotation to enforce the logical order for calculation of the calcTotalDistribution (using child products data) and defining the quantity for the voltageclassification child items.
This advanced pattern uses the @(groupBy=attribute) annotation to create virtual components (RegionGroup) for aggregation, referencing the source data relation in the parent type (SubscriptionOrder.licenses) using the sourceContextNode annotation.
In example 3, the licenses relationship that is brought as an external source by @(sourceContextNode="SubscriptionOrder.licenses"), includes an aggregation using the sum() function that calculates the groupTotalUsers from the selected products in the RegionalLicense. The RegionGroup type contains the groupTotalUsers variable that serves the aggregation. The SubscriptionOrder type contains the aggregate metric totalUsers which is calculated by summing all groupTotalUsers. The model contains one core constraint on RegionGroup to enforce that groupTotalUsers equals the sum of all userCount from its member licenses.