Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  how to create a boolean expression

    Posted 07/19/13 12:26 PM

    Originally posted by: Hosssein


    Hi,

    In my CP model, W is the set of variables.

    could you please tell me how I can create the following expression?

    (W[1]==1) && (W[2]==1) .... && (W[n]==1)

    Note that I dont know the value of n beforehand, So I need to create it in a loop like below:

    for (int i=1; i<=n ; i++){

         Expression := Expression && (W[i]==1)

    }
    I could not do this by IloNumExpr. Could you please tell me what I have to do ?

    Thanks in advance for your help.


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: how to create a boolean expression

    Posted 07/19/13 12:55 PM

    Originally posted by: rdumeur


    Dear Hussein,

    the && operator is only defined on constraints. If you want to use it within an expression you need to do something like:

    #include <ilcp/cp.h>

    IloInt someValue(IloInt x);

    int main() {
      IloEnv        env;
      IloModel        model(env);
      IloInt        n(10);
      IloIntVarArray    vars(env, n, 0, 10);
      IloConstraint       c;
      for(IloInt i(0); i < 10; ++i) {
        IloConstraint    test(vars[i] == someValue(i));
        if(i  == 0)
          e = test;
        else
          e = e && test; // compose constraints with &&
      }
      // do whatever you want with e

      // to use constraint e as an expression you can  do (e == <boolean value>).

    }
     

    I hope this helps.

    Cheers,

     

       Renaud


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: how to create a boolean expression

    Posted 07/19/13 04:48 PM

    Originally posted by: Hosssein


    Thank you so much ;))))


    #CPOptimizer
    #DecisionOptimization