Constraints on Values¶
The constraints between elements of a product can be specified by defining behavioral blocks.
Each block behavior
defines constraint knowledge for one predefined structure.
Basic Constraints¶
The following definition shows a simple constraint stating that the values of the instances frontWheel
and rearWheel
must be equal.
behavior {
require frontWheel = rearWheel
}
In general, the constraint definition after the require
keyword can be a complex boolean expression composed by logical operators (||
and &&
).
The constraint can be extended by an explanation and a comment. Both extensions are optional.
behavior {
// This is a comment.
explanation "Front wheel and rear wheel must have the same value."
require frontWheel = rearWheel
}
Since the explanation text is available during the configuration process, it serves as a helpful guide for the user.
Comments are preceded by //
and are targeted to the developers of the knowledge base.
They are not accessible during the configuration process.
Conditioned Constraints¶
Constraints can have one or more conditions; multiple conditions are defined in separate lines.
behavior {
explanation "The color yellow is only possible for
front wheel size 18 or greater."
condition Color = Yellow
require frontWheel.size >= 18
}
The condition
keyword controls the activation of the constraint.
Here, only when the color is yellow, the size attribute of frontWheel has to have the value 18
.
The example illustrates that we can impose constraints not only on choice values, as previously done, but also on their corresponding attributes (see definition of type Wheel).
For instance, we specify that the numerical attribute size
must be at least 18 for bikes that are Yellow
.
Comparators and Logical Operators¶
Simple feature expressions allow for the comparators equal (=
) and not-equal (!=
).
For numerical fields, also the numerical comparators lower than (<
), lower equal (<=
), larger than (>
) and larger equal (>=
) can be used to build simple expressions.
Complex logical expressions can be composed using the boolean operators AND (&&
), OR (||
), and NOT (!
).
Combination Tables¶
Practical knowledge bases frequently aim to define the constraints between two or more feature elements. In these cases, the application of the behaviors introduced earlier can be extensive and complex to manage. A combinations table offers a concise syntax for a comprehensive constraint definition encompassing all values across two or more feature elements.
behavior {
explanation "Stands are mandatory for wheel sizes W14 and W16."
combinations (withStand rearWheel)
//===========================================================
allow (true (W14, W16))
allow (-*- (W18, W20, W22, W24, W26, W28))
}
The above combinations table describes valid combinations of the elements withStand
and rearWheel
.
Any combination, that does comply to some allow
-line in the table, is a valid combination for the product (according to this behavior).
Subsequently, any combination, that does not comply to some line in the table, is invalid.
A combinations table can have an arbitrary number of columns and the order of columns is also arbitrary.
In a cell, multiple values can be enumerated by using commas (,
), resulting in
a one-of (logical OR) semantics.
The wildcard sign -*-
matches any value of the corresponding feature element.
Opposed to the allow
keyword, the combination table also offers a forbid
keyword, that can be used to enumerate combinations that are explicitly forbidden.
behavior {
combinations ( Color rearWheel )
//==================================================
forbid ( Yellow (W14, W16) )
forbid ( Black W14 )
}
In this combination table, we forbid the color Yellow
for rear wheel choices W14
and W16
and additionally do not allow the color Black
for the rearWheel choice W14
.