Originally posted by: Wendy717
I'd like to implement the following constraint with Cplex12.6:
sum(z) X_ijz <= M * Y_ij , where X_ijz is a numVar and Y_ij is a boolVar indicator
When I directly implement the constraint, there is no problem. But when I tried to use the logical constraint ifThen, it seems the constraint set are not included into the model. Below is the copied code of the ifThen implementation. Is there any wrong with the constraint building?
for(int i=0; i<numCamp; i++){
Camp cmp = _allCamps.get(i);
for(int j=0; j<cmp.getNumTruck(); j++){
IloIntVar[] dvs = _volume.get(cmp).get(j);
IloIntExpr varSum = _cplex.intExpr();
for(int z=0; z<numZn; z++){
varSum = _cplex.sum(varSum, dvs[z]);
}
IloConstraint sumGe1Constr = _cplex.ge(varSum, 1.0);
IloConstraint sum0Constr = _cplex.le(varSum, 0.8);
IloConstraint eq1Constr = _cplex.eq(_occupation.get(cmp)[j], 1);
IloConstraint eq0Constr = _cplex.eq(_occupation.get(cmp)[j], 0);
_cplex.ifThen(sumGe1Constr, eq1Constr);
_cplex.ifThen(sum0Constr, eq0Constr);
}
}
}
#CPLEXOptimizers#DecisionOptimization