Originally posted by: SystemAdmin
Sorry, my fault. I didn't remember that semi-continuous variables must not have negative bounds (from the docs):
A semi-continuous variable is a variable that by default can take the value 0 (zero) or any value between its semi-continuous lower bound (sclb) and its upper bound (ub). The semi-continuous lower bound (sclb) must be finite. The upper bound (ub) need not be finite. The semi-continuous lower bound (sclb) must be greater than or equal to 0 (zero). An attempt to use a negative value for the semi-continuous lower bound (sclb) will result in that bound being treated as 0 (zero).
So instead of using X, X1 and X2 as described before you should use
-
X1 is 0 or in 3,10
-
X2 is 0 or in 3,10
-
X = X1 - X2
-
X1 <= 10*b
-
-X2 >= -10*(1-b)
This should do the trick. I changed your code accordingly and no longer get the error:
import ilog.cplex.*;
import ilog.concert.*;
public class Semi {
public static void main(String[] args) {
try {
int noOfVar = 10;
int noOfRev = 5;
IloCplex model = new IloCplex();
IloNumVar X[] = model.numVarArray(noOfVar, -11, 11);
IloSemiContVar X1[] = model.semiContVarArray(noOfVar, 3, 11, IloNumVarType.Float);
IloSemiContVar X2[] = model.semiContVarArray(noOfVar, 3, 11, IloNumVarType.Float);
IloNumVar E[] = model.numVarArray(noOfRev, -100, 100);
IloNumVar E_abs[] = model.numVarArray(noOfRev, 0, 100);
IloNumVar b[]=model.boolVarArray(noOfVar);
for (int i = 0; i < E.length; ++i) {
model.addLe(model.prod(1.0, E[i]), E_abs[i]);
model.addLe(model.prod(-1.0, E[i]), E_abs[i]);
}
for (int i = 0; i < X.length; ++i) {
model.addEq(model.diff(X1[i], X2[i]), X[i]);
model.addLe(X1[i],model.prod(10, b[i]));
model.addGe(model.prod(-1., X2[i]),model.prod(-10, model.sum(1, model.prod(-1, b[i]))));
}
IloNumExpr exprn1 = model.scalProd(X, X);
IloNumExpr exprn2 = model.sum(E_abs);
model.addMinimize(model.sum(model.prod(0.7, exprn1),
model.prod(0.3, exprn2)));
model.solve();
} catch (IloException e) {
System.err.println("IloException: " + e);
}
}
}
#CPLEXOptimizers#DecisionOptimization