Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  need help about IloNumExpr

    Posted 02/20/12 09:03 PM

    Originally posted by: orange2005


    Dear all,

    I have a difficulty for coding a constraint.
    I have IloNumExpr A, IloNumVarArray x, and IloBoolVarArray y.

    I want to code the below constraint:

    if y[i][j]==1 then A+=x[i][j].

    anyone knows how to code it in Cplex with c++?

    Thanks in advance!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: need help about IloNumExpr

    Posted 02/20/12 10:09 PM

    Originally posted by: RafaelMartinelli


    Notice that += is not a constraint.
    What do you want to do with the expression A?
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: need help about IloNumExpr

    Posted 02/20/12 10:22 PM

    Originally posted by: orange2005


    the final constraint is
    model.add(A<=1)
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: need help about IloNumExpr

    Posted 02/21/12 02:32 AM

    Originally posted by: SystemAdmin


    Do I understand correctly that you want to state this:
    if y[i][j]==1
      then A + x[i][j] <= 1
      else A <= 1
    

    where x and y are variables.
    It should be possible to formulate that using IloIfThen.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: need help about IloNumExpr

    Posted 02/21/12 02:44 AM

    Originally posted by: orange2005


    Hi, Daniel,

    I want
    for (i=0; i<I; i++)
    {
    for (j=0; j<J; j++)
    {
    if (y[i][j]==1)
    A+=x[i][j];
    }
    }
    model.add(A<=1);

    It seems that I cannot use IloIfThen(env,(y[i][j]==1),(A+=x[i][j]));

    Could you please help me out?

    Thank you!
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: need help about IloNumExpr

    Posted 02/21/12 02:48 AM

    Originally posted by: SystemAdmin


    Is y a parameter or a variable?
    What is the range of +x+? Is it a boolean variable? Is it non-negative?
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: need help about IloNumExpr

    Posted 02/21/12 02:52 AM

    Originally posted by: orange2005


    y is Bool variable
    x is real number variable, its range is 0,1
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: need help about IloNumExpr

    Posted 02/21/12 03:07 AM

    Originally posted by: SystemAdmin


    I can think of different ways to implement that.
    First:
    model.add(A <= 1); // This must always be satisfied.
    model.add(IloIfThen(env, y[i][j] == 1, A + x[i][j] <= 1)); // More restrictive if y[i][j] == 1
    

    Second (using a helper variable):
    IloNumVar b(env, 0, 1, "b");
    model.add(A <= b);
    model.add(IloIfThen(env, y[i][j] == 1, b <= 1 - x[i][j]));
    

    Third (turning your problem into a QCP):
    model.add(A + y[i][j] * x[i][j] <= 1);
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: need help about IloNumExpr

    Posted 02/21/12 10:14 AM

    Originally posted by: orange2005


    Thanks a lot!
    #CPLEXOptimizers
    #DecisionOptimization