addConstraint - Add constraint to variant configuration data object - MATLAB (original) (raw)
Main Content
Add constraint to variant configuration data object
Syntax
Description
Note
This function requires Variant Manager for Simulink®.
addConstraint([varConfigData](#mw%5Fdfdab400-3a3a-4104-bd1b-6b94ce18beb4),[constraintName](#mw%5F6574e7b4-23f7-4178-ac92-6c803c52ac59))
adds a constraint with the name constraintName
to a Simulink.VariantConfigurationData objectvarConfigData
.
You can use constraints to check if all the variant configurations present invarConfigData
satisfy certain conditions. The constraint must be specified as a valid Boolean condition expression. The expression can contain variant control variables used in the model hierarchy, names of variant configurations of referenced components in the hierarchy, or a combination of these (since R2025a). Simulink evaluates these constraints during variant configuration activation, model compilation, simulation, and code generation workflows.
addConstraint(___,[condition](#mw%5F6580c24a-96d2-4b2a-83f6-1642c63e0d59))
adds a constraint using the input arguments in previous syntax and also sets the condition expression to condition
.
addConstraint(___,[description](#mw%5Fd53b79e9-cfd1-432d-a8b7-2639b7555083))
adds a constraint along with a description of the constraint.
Examples
Add a new constraint to the variant configuration data object associated with a top-level model. Define the condition using variant control variables used in the model hierarchy.
modelName="slexVariantManagement"; open_system(modelName); vcd = Simulink.VariantManager.getConfigurationData("slexVariantManagement"); addConstraint(vcd,"ControllerPlantConstraint",... "~((Ctrl == ControllerType.Linear) && (PlantLoc == PlantLocation.External))",... "Linear controller must not have an external plant")
Get the variant configuration data object for a referenced component in the model hierarchy.
open_system("slexVariantManagementExternalPlantMdlRef"); subvcd = Simulink.VariantManager.getConfigurationData("slexVariantManagementExternalPlantMdlRef");
Add another constraint to the top-level model using names of configurations defined for the referenced component.
addConstraint(vcd,"ExternalPantFidelityConstraint", ... "(isConfigActive(subvcd,""LowFid"") || isConfigActive(subvcd,""HighFid""))");
Input Arguments
Variant configuration data to which you want to add a new constraint, specified as aSimulink.VariantConfigurationData
object.
Name of the constraint, specified as a character vector or string scalar.
Example: "LinInternal"
Data Types: char
| string
Boolean condition expression that is defined in terms of variant control variables and referenced component configurations, specified as a character vector or string scalar. The expression must evaluate to true
to satisfy the constraint.
Example: "~((Ctrl==ControllerType.Linear) && (PlantLoc==PlantLocation.External))"
Data Types: char
| string
Description of the constraint, specified as a character vector or string scalar.
Example: "Linear controller must not have an external plant"
Data Types: char
| string
Limitations
- Variant Manager constraints are evaluated based on the values of variant control variables defined in the base workspace or data dictionaries linked to the model for which the constraint is defined.
Version History
Introduced in R2013b
You can use the isConfigActive function in the condition
argument to specify the constraint condition using referenced component configuration names.