private IntegerVariable getVariableForAttributeOperand(AttributeOperand operand) { IntegerVariable variable = null; if (operand instanceof AttributeReference) { AttributeReference attRef = (AttributeReference) operand; Attribute attribute = attRef.getAttribute(); variable = getOrCreateVariable(attribute); } else if (operand instanceof AttributeValue) { AttributeValue value = (AttributeValue) operand; int valueInt = value.getInt(); String valueName = value.getName(); if (valueName != null && valueName.length() > 0) { AttributeOperand other = getOtherOperand(operand); if (other instanceof AttributeReference) { AttributeReference attRef = (AttributeReference) other; Domain domain = attRef.getAttribute().getDomain(); if (domain instanceof DiscreteDomain) { DiscreteDomain discreteDomain = (DiscreteDomain) domain; EList<DomainValue> values = discreteDomain.getValues(); for (DomainValue domainValue : values) { String name = domainValue.getName(); if (valueName.equals(name)) { valueInt = domainValue.getInt(); break; } } } else if (domain instanceof NumericalDomain) { valueInt = Integer.decode(valueName); } } } variable = Choco.constant(valueInt); } return variable; }
private Constraint getMemberConstraint(Attribute attribute) { Constraint memberConstraint = null; IntegerVariable attributeValueVariable = getOrCreateVariable(attribute); // if attribute value is set, then the according attribute value must be // set if (FeatureModelHelper.isAttributeValueSet(attribute)) { int value = FeatureModelHelper.getAttributeValue(attribute); memberConstraint = Choco.eq(value, attributeValueVariable); } else { // check domain values Domain domain = attribute.getDomain(); if (domain instanceof NumericalDomain) { NumericalDomain numericalDomain = (NumericalDomain) domain; // value of attribute must be in one of the intervals. int[] values = getNumericalValues(numericalDomain, attribute); memberConstraint = Choco.member(attributeValueVariable, values); } else if (domain instanceof DiscreteDomain) { DiscreteDomain discreteDomain = (DiscreteDomain) domain; int[] domainValues = discreteDomainValues.get(discreteDomain.getId()); memberConstraint = Choco.member(attributeValueVariable, domainValues); } } return memberConstraint; }
private int[] initDomainValues(DiscreteDomain domain) { EList<DomainValue> values = domain.getValues(); int[] valueArray = new int[values.size()]; Iterator<DomainValue> iterator = values.iterator(); for (int i = 0; i < valueArray.length; i++) { valueArray[i] = iterator.next().getInt(); } return valueArray; }
private int[] getOrCreateDomainValues(DiscreteDomain domain) { String id = domain.getId(); int[] values = discreteDomainValues.get(id); if (values == null) { values = initDomainValues(domain); discreteDomainValues.put(id, values); } return values; }