Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Why ifThen constraint is not added into Cplex model?

    Posted 11/05/14 03:26 AM

    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


  • 2.  Re: Why ifThen constraint is not added into Cplex model?

    Posted 11/10/14 02:33 AM

    Your constraints are added because IloCplex.ifThen() only creates a constraint. It does not add it to the CPLEX instance. You need to call IloCplex.add() as well:

    _cplex.add(_cplex.ifThen(sumGe1Constr, eq1Constr));
    _cplex.add(_cplex.ifThen(sum0Constr, eq0Constr));

    Are your dvs[z] variables all integer or binary variables? If not then I think your two formulations are not equivalent.

    In

    sum(z) X_ijz <= M * Y_ij

    Y_ij will be non-zero as soon as any of the X_ijz are non-zero. However, in your reformulation

    sum(z) X_ijz >= 1  =>  Y_ij == 1

    Y_ij will only be forced to 1 if the left-hand side is larger than 1.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Why ifThen constraint is not added into Cplex model?

    Posted 11/11/14 10:54 AM

    Originally posted by: Wendy717


    Thank you, Daniel.

    Indeed, dvs[z] are all binaries. So your answer solved my problem.


    #CPLEXOptimizers
    #DecisionOptimization