To prevent performance degradation or unexpected behaviors when the constraint engine executes CML code, follow these practices when writing code.
-
Relationship Cardinality: Specify the Smallest Range Required
Specify the smallest required cardinality for a variable so the constraint engine tests fewer combinations of values and performs better.
-
Decimals and Doubles: Consider the Impact of Scale on Performance
Scale is the number of digits that follow the decimal point in a decimal or double. Consider its impact on performance before using decimals and doubles in expressions.
-
Variable Domains: Keep Domains as Small as Possible
A variable domain is the set of all possible values that the variable can take. Keep domains as small as possible to reduce the combinations that the constraint engine tests.
-
Calculating Values: Put Calculations Inside of Constraints
To calculate a value, put the calculation inside of a constraint instead of in an inline expression.
-
Relationships: Combine Relationships to Reduce Performance Impact
Creating multiple relationships on a type can impact performance. When possible, combine relationships to improve performance.
-
Sequence: Use the Sequence Variable Annotation to Specify the Order of Execution
Use the sequence variable annotation to specify the order in which the constraint engine sets values for a constraint model’s attributes and relationships.
-
Sequence and Configurable
Using the configurable property with the sequence variable affects how the solver handles attributes and whether it overrides user input.
-
Automatically Add a Product: Define as a Separate Constraint
To automatically add a product and also set attributes on the product, define these procedures as separate constraints.
-
Configurator API: Include the Attribute Developer Name When Creating or Updating Attributes
When a constraint model is active, include the attribute developer name in Product Configurator API requests that create or update a product attribute.
-
Access Quantity in CML: Cardinality and Attribute Constraints
There are two ways to access quantity in CML. Use cardinality constraints and attribute constraints correctly for best performance.
-
Pricing Fields Not Supported in CML
Pricing fields, such as ListPrice and NetUnitPrice, aren’t supported in CML and shouldn’t be used in constraint models.
-
Configure Child or Grandchild Products Based on Parent Product
Use the parent keyword to configure child and grandchild products dynamically based on the parent product.
-
PCG Group Relations: Follow Order in Constraints
Order the Product Component Group (PCG) group relations in the way they appear in the constraints.
-
Relations Without PCG: Follow Order in Constraints
Order of relations matters for constraint evaluation. Specify the relations used in the left side of the constraints first.
-
Relation Aggregates: Stabilize Preferences Using Staged Variables
To improve solver stability and prevent backtracking, stage relation aggregates through local variables and state anchors instead of referencing them directly in preferences.
-
Virtual Quote Root: Model Cross-Bundle Logic Using a Shared Transaction Parent
For transaction-level rules that span products that have no parent-child relationship, use a virtual quote as a transaction root pattern.
-
Dependent Logic: Use Configurable Variable Annotation to Prevent Premature Default Assignment
Use the configurable variable annotation on a target attribute to prevent the engine from assigning a default value before your calculation and preference rules execute.
-
Consolidate Multiple Default Configurations
Apply dynamic, overridable default quantities to a single component based on multiple states of a driving attribute, using one derived variable and a single setdefault rule.