Setdefault Rule
Unlike the require rule, the setdefault rule applies a default configuration status and uses a triggering mechanism to control when the solver attempts to satisfy the rule. The setdefault rule can include an optional explanation message.
The setdefault has this syntax, similar to the require rule.
1setdefault(condition, expression, message);The setdefault rule evaluates the condition.
- If the condition was never true or is false on initial evaluation, the solver doesn't attempt to satisfy the expression and doesn't show a message, regardless of whether any part of the condition is changed
- If the condition was previously true and changes to false, the solver reverts any configuration state changes, such as product selections or quantity adjustments, that were applied when the condition was true. The configuration returns to the state it would be in without the setdefault rule.
- If the condition is true, the solver performs one of these actions.
- If any part of the condition is changed or the parent component is new, the solver attempts to satisfy the expression. If the solver can't satisfy the expression, an explanation message is shown (if included).
- If no part of the condition is changed, the solver evaluates the expression without attempting to satisfy it. If the expression evaluates to false, an explanation message is shown (if included).
The key difference between the setdefault rule and the require rule is that the setdefault rule attempts to satisfy the expression only when a condition is changed. If no condition is changed, the setdefault rule performs a passive evaluation. The require rule always attempts to satisfy the expression when the condition is true.
In this scenario, we use the requiredKW attribute (the user's power requirement) as the condition and the Accessories relation as the target for the recommended cardinality.
1type Accessory;
2type GeneratorSet {
3int requiredKW = [101..10000];
4relation Accessories : Accessory[1..99];
5/**
6* @Title High Power Accessory Recommendation
7* The setdefault constraint specifies that 2 accessory units are
8* recommended when the required power capacity is greater than 2000 kW.
9*/
10setdefault(
11requiredKW > 2000,
12Accessories[Accessory] == 2,
13"2 specialized accessory kits are recommended for power levels above 2000 kW"
14);
15}