Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

If-Else statements using decision variables

  • 1.  If-Else statements using decision variables

    Posted 11/14/08 08:43 AM

    Originally posted by: SystemAdmin


    [ph mooraa said:]

    Hi All,

    I have following definitions of decision variables -

    typedef IloArray<IloBoolVarArray> BoolVarMatrix;
    typedef IloArray<BoolVarMatrix> BoolVar3Matrix;
    BoolVar3Matrix sched(env1,4);
    IloBoolVarArray t(env1,T);

    how can I write logical statement which involve these decision variables? for example,

    for(IloInt z=0;z<T;z++) {<br />                        for(IloInt h=0;h<4;h++) {<br />                                for(IloInt r=0;r<4;r++) {<br />                                        if(sched[h][r][z]==1 || t[z]==1)    //line 100  (if any element of sched is 1, I want t[z] to be 1
                                                    t[z] = 1;                                  //line 101
                                            else                                                  //line 102 
                                                    t[z]=0;
                                    }
                            }
                    }

    I get errors like -
    100: error: could not convert `operator||(((const IloConstraint&)((const IloConstraint*)((IloConstraint*)(&operator==(((const IloNumExprArg&)((const IloNumExprArg*)((IloNumExprArg*)(+(+(+(&sched)->IloArray<X>::operator[] [with X = main()::BoolVarMatrix](h))->IloArray<X>::operator[] [with X = IloBoolVarArray](r))->IloBoolVarArray::operator[](z))))), 1.0e+0))))), ((const IloConstraint&)((const IloConstraint*)((IloConstraint*)(&operator==(((const IloNumExprArg&)((const IloNumExprArg*)((IloNumExprArg*)(+(&t)->IloBoolVarArray::operator[](z))))), 1.0e+0))))))' to `bool'
    101: error: invalid conversion from `int' to `IloNumVarI*'
    101: error: initializing argument 1 of `IloBoolVar::IloBoolVar(IloNumVarI*)'

    I tried using IloExpr but it didn't work. Both sched and t arrays are decision variables.

    Any help will be really useful.

    Thanks, phm


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: If-Else statements using decision variables

    Posted 11/14/08 07:38 PM

    Originally posted by: SystemAdmin


    [prubin said:]

    Logical constraints have to be converted to algebraic constraints in an integer program.  (This is a generic statement, not specific to CPLEX.)  I don't understand your if-else (specifically, why you have t[z] == 1 in the antecedent), so I'll demonstrate a slight modification.  If you want to say "if sched[h][r][z] is 1 for any h and r, then t[z] is 1, else t[z] is 0", you can write it as

    t[z] <= sum_h sum_r sched[h][r][z]<br />16*t[z] >= sum_h sum_r sched[h][r][z]

    You'll need to replace the double sum with an IloExpr computed by summing sched[h][r][z] over h and r.  The 16 is because there are 16 terms in that sum, given the dimensions you specified in the for statements; if those dimensions might differ, you'll need to replace 16 with the computed number of terms in the double summation.  It's left to the reader as an exercise to confirm that t[z] = 1 iff at least one sched[h][r][z] is 1.

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization