Main Content

addConstraint

Add constraint to variant configuration data object

    Description

    Note

    This function requires Variant Manager for Simulink®.

    addConstraint(varConfigData,constraintName) adds a constraint with the name constraintName to a Simulink.VariantConfigurationData object varConfigData.

    You can use constraints to check if all the variant configurations present in varConfigData 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.

    example

    addConstraint(___,condition) adds a constraint using the input arguments in previous syntax and also sets the condition expression to condition.

    addConstraint(___,description) adds a constraint along with a description of the constraint.

    Examples

    collapse all

    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

    collapse all

    Variant configuration data to which you want to add a new constraint, specified as a Simulink.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

    expand all