Esempio n. 1
0
  private IntegerVariable getOrCreateVariable(Attribute attribute) {
    String attributeName = attribute.getName();
    String featureId = attribute.getFeature().getId();
    String identifier = attributeValue;

    String[] parts = new String[] {identifier, featureId, attributeName};

    String attributeId = concatenate(parts, attributeDelimiter);

    IntegerVariable integerVariable = nodeVariables.get(attributeId);
    if (integerVariable == null) {
      integerVariable = createAttributeValueVariable(attribute, attributeId);
      nodeVariables.put(attributeId, integerVariable);
    }
    return integerVariable;
  }
Esempio n. 2
0
  private void transformAttribute(Attribute attribute) {
    // 0: attribute is disabled if feature is disabled
    // 1: attribute is enabled if feature is selected
    IntegerVariable featureVariable = getOrCreateVariable(attribute.getFeature());

    Constraint memberConstraint = getMemberConstraint(attribute);

    // if feature is enabled, then attribute value must be in bounds
    Constraint featureEnabled = Choco.eq(featureVariable, 1);
    Constraint checkAttribute = Choco.implies(featureEnabled, memberConstraint);
    getModel().addConstraint(checkAttribute);

    IntegerVariable attributeVariable = getOrCreateVariable(attribute);

    Constraint featureDisabled = Choco.eq(featureVariable, 0);
    Constraint attrDisabled = Choco.eq(attributeVariable, attributeDisabled);

    Constraint disabledAttr = Choco.ifOnlyIf(featureDisabled, attrDisabled);
    getModel().addConstraint(disabledAttr);
  }