Global Constraints

The global constraints encapsulate the global composition rules for the features in a feature model. This page describes in detail how global constraints can be expressed within XFeature and how compliance with them can be checked.

Composition Rules

A complete model of a product family consists of the list of all the features that may appear in applications instantiated from the family, together with a list of the composition rules that define the legal combinations of features that may appear in an application.

Two types of composition rules can be distinguished.

  • Local composition rules express constraints on the combinations of sub-features that are children of the same feature. A local composition rule might, for instance, express a constraint that a certain feature can only have one sub-feature or that it can only have one sub-feature selected out of two possible options.
  • Global composition rules express constraints on relationships between non-contiguous features in different parts of the feature diagram. A typical example of such rules are so-called require-exclude relationships (expressing the condition that the presence of a certain feature is incompatible with, or requires, the presence of another feature in a different part of the feature diagram).

Local Constraints

At first sight, the approach sketched in the previous section cannot accommodate global composition rules. It uses XML documents to express both the family and the application models and it automatically derives an XML schema from the family model. The relationship of instantiation between the family model and the application model is then expressed by saying that the XML document representing the application model must be validated by this XML schema. This approach has the virtue of simplicity but is limited by the expressive power of an XML Schema which allows only comparatively simple composition rules to be expressed. In practice, it is only local composition rules that can be easily expressed.

Global Constraints

The use of an XML-language to express the application model, however, opens the way to more sophisticated approaches to expressing global composition rules. Arguably, the most obvious and the most flexible way to do so is to encode the general constraints as XSL programs that are run on the XML-based model of the application and produce an outcome of either constraint satisfied or constraint not satisfied. Such an approach is powerful but has the drawback that it requires the family designer to be proficient in XSL.

In order to avoid this drawback while still exploiting the power of XSL to express general feature composition constraints, an alternative approach has been selected where the global composition constraints are expressed in a dedicated language and a compiler is then provided to translate the constraint model expressed in this language into an XSL program that checks compliance with the constraints at application model level.

For consistency with the overall XML-based approach, the language to express the global constraints is an XML-based language defined with XML Schema and the compiler for the constraint model is an XSL program. The following terminology is used in the rest of this document:

  • The Global Constraint Meta-Model is the XML Schema that defines the XML-based language used to express the global constraints.
  • The Global Constraint Compiler is the XSL program that reads the global constraints model (expressed as an XML document validated by the Constraint Meta-Model XML Schema) and transforms it into an XSL program that checks whether a certain feature model complies with certain global constraints.

Global Constraints Meta-Model

XFeature contains a global constraint meta-model encoded as an XML Schema that defines an XML-based language to define global constraints. The file src/general_files/GlobalConstraintsMetaModel.xsd contains the formal language definition.

Users define a global constraint model as an XML document that must be validated by the global constraint meta-model. This constraint model expresses the global constraints that apply to a particular feature model. The XFeature tool uses the global constraint model compiler to process the constraint model and to generate the global constraint checker.


Figure 1: GlobalCompositionConstraintsFrameworkFeatureDiagram

The global constraint meta-model allows four types of global constraints to be expressed:

  • Requires Constraints: constraints whereby the presence of a certain feature A in the feature model requires a second feature B to be present (i.e. A situation where A is present but B is missing represents a violation of the global constraints). RequiresConstraint feature is understood as follows: There is a feature Feature in the framework model that requires one or more RequiredFeatures to be toggled on.
  • Exclude Constraints: constraints whereby a certain set of features are mutually incompatible (i.e. if any two or more feature from the set of incompatible features are present, then the global constraint is violated). ExcludeConstraint defines a set of two or more Feature elements that are mutually exclusive each other.
  • Custom Constraints: arbitrary constraints expressed as XPath expressions. The Element node represents either a toggle feature in the target framework feature diagram (its presence) or feature value. Each Element has its Name (by which is referenced in CustomCondition) and its Value that uniquely identifies the feature (or its value) using XPath syntax. The CustomCondition is expressed as a logical expression above elements or arithmetic expressions some operands of which some are elements.
  • Conditional Constraints: constraints of the form: if (some feature-related condition holds) then (some feature-related constraint must hold). This type of constraints is a special form of the more general "custom constraint". It is provided as a separate type of constraint for convenience and because experience shows that it is often found in practice.

It is expected that most users will only need the first three types of constraints.

Global Constraints Compiler and Global Constraints Checker

The XFeature tool uses the global constraint model compiler to process the constraint model and to generate the global constraint checker. The global constraint checker is an XSL program that can be run on the target feature model to verify that it satisfies its global constraints.

The global constraint compiler is not a single file. Rather it is a set of XSL programs that work together to transform the global constraints defined for some particular family to XSL program. Implementation of the global constraint model compiler is fairly complex and involves about a dozen of files. The whole pocess is illustrated in the following figure and explained below.


Figure 2: GlobalConsraintCheckerGeneration

The above figure illustrates how global constraints compiler is implemented within the XFeature tool. Once user finished definition of the family feature model MyFamily.xfm along with global constraints of the family MyFamily.xgc the global constraint checker can be generated in the following steps (see the left half of the above figure).

  1. Family feature model MyFamily.xfm is processed by an XSL program *XfmNamesTranaslator.xsl. This XSL program is specific to an XFeature configuration. In the above figure IcsrXfmNamesTranaslator.xsl is used suggesting that ICSR configuration was used to desing the MyFamily.xfm family model. This *XfmNamesTranaslator.xsl XSL program assigns an XPath expression to each node in the family feature model. The assigned XPath is such that it will point to its node in application feature models that belong to the family defined in MyFamily.xfm. The output of the transformation is saved in temporary file gcValueTmp.xfm.
  2. Global constraint definition file MyFamily.xgc is processed by XgcNamesTransaltor.xsl XSL program that takes gcValueTmp.xfm as a parameter and generates temporary file gcValueTmp.xgc. The input and output files are almost identical, the only difference is that the XPath expression used in MyFamily.xgc to identify features are replaced by the XPath expression assigned to the respective nodes by configuration specific *XfmNamesTranaslator.xsl script in the previous step.
  3. ClobaConstriantsCompiler.xsl takes the modified global constraints definition gcValueTmp.xgc and generates global constraint checker which is a XSL program names MyFamilyApp.xgcc in the figure. The name of the file is user defined and it is the same as the application meta model file name (except the extension, of course).

The global constraint checker is then used by XFeature when application feature model is being validated. The validation of global constraints is done in two steps.

  1. First, the names of features of the application feature model MyApplication.xfm are translated to be the same as in family feature model and global constraint definition. This is done by generic xfmReomveUniquenames.xsl script which is delivered with XFeature and is configuration neutral. The trasnforamtion results in temporary file gcValueAppTmp.xfm.
  2. Second, the generated gcValueAppTmp.xfm is processed by global constraint checker MyFamilyApp.xgcc. The XSL program logs all constraint checks to a text file and ends silently if all checks pass. In case of global constraint violation it immediately reports the error and quits the execution.

There is a demonstration that presents how the global constraint framework is used withing the XFeature tool in the user manual. Note that the user is not required to understand the implementation detail described in this section in order to use global constraint in his/her feature models. All it takes is to locate the *XfmNamesTranaslator.xsl file in the folder corresponding to the current XFeature configuration.