private Constraint createAttributeConstraint(AttributeConstraint attributeConstraint) { Constraint result = null; Constraint constraint = null; AttributeOperand leftOperand = attributeConstraint.getLeftOperand(); IntegerVariable leftOperandVariable = getVariableForAttributeOperand(leftOperand); AttributeOperand rightOperand = attributeConstraint.getRightOperand(); IntegerVariable rightOperandVariable = getVariableForAttributeOperand(rightOperand); Relop operator = attributeConstraint.getOperator(); switch (operator) { case EQUAL: constraint = Choco.eq(leftOperandVariable, rightOperandVariable); break; case GREATER_THAN: constraint = Choco.gt(leftOperandVariable, rightOperandVariable); break; case GREATER_THAN_OR_EQUAL: constraint = Choco.geq(leftOperandVariable, rightOperandVariable); break; case LESS_THAN: constraint = Choco.lt(leftOperandVariable, rightOperandVariable); break; case LESS_THAN_OR_EQUAL: constraint = Choco.leq(leftOperandVariable, rightOperandVariable); break; case UNEQUAL: constraint = Choco.neq(leftOperandVariable, rightOperandVariable); break; default: break; } IntegerVariable leftFeatureVariable = getFeatureVariableForOperand(leftOperand); IntegerVariable rightFeatureVariable = getFeatureVariableForOperand(rightOperand); // if both are features and both are selected, then the attribute constraint must be evaluated if (leftFeatureVariable != null && rightFeatureVariable != null) { Constraint leftFeatureSelected = Choco.eq(leftFeatureVariable, 1); Constraint rightFeatureSelected = Choco.eq(rightFeatureVariable, 1); Constraint and = Choco.and(leftFeatureSelected, rightFeatureSelected); result = Choco.implies(and, constraint); } else { // if one of the two operand is a constant,the constraint will be evaluated if the host // feature is selected if (leftFeatureVariable != null) { result = getFeatureAttributeValueConstraint(leftFeatureVariable, constraint); } else if (rightFeatureVariable != null) { result = getFeatureAttributeValueConstraint(rightFeatureVariable, constraint); } } return result; }
private AttributeOperand getOtherOperand(AttributeOperand operand) { AttributeOperand other = null; EObject container = operand.eContainer(); if (container instanceof AttributeConstraint) { AttributeConstraint attConstraint = (AttributeConstraint) container; AttributeOperand leftOperand = attConstraint.getLeftOperand(); AttributeOperand rightOperand = attConstraint.getRightOperand(); if (EcoreUtil.equals(operand, leftOperand)) { other = rightOperand; } else { other = leftOperand; } } return other; }