public IntegerVariable[] generateRandomDurations(final int n) { final IntegerVariable[] durations = new IntegerVariable[n]; final int gap = horizon / n; int max = gap + horizon % n; for (int i = 0; i < n - 1; i++) { final int v = RANDOM.nextInt(max) + 1; max += gap - v; durations[i] = Choco.constant(v); } durations[n - 1] = Choco.constant(max); return durations; }
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; }