Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to count in a desicion variable?

    Posted 04/08/14 03:51 AM

    Originally posted by: appleme


     Hi,all.

    tuple  JUP
      {   int index;
        string p;
        string u;      
      } ; 
     
     {JUP} jup=...;

     
      dvar int+ jupz[jup] in 0..1;

    I want to get the count from  jupz where  jup.p="T" and jupz[jup]==1 ,How to realize?I found there is no count function to do this.

    Could you help me

    Thanks.

     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: How to count in a desicion variable?

    Posted 04/08/14 09:09 AM

    Originally posted by: ChrisBr


    Hello,

    You could try this:
      c == count(all(j in jup : j.p=="T") jupz[j], 1);

    I suggest you have a look at the documentation
    IDE and OPL > Optimization Programming Language (OPL) > Language Quick Reference > OPL functions > count

    I hope this helps,

    Chris.
     


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: How to count in a desicion variable?

    Posted 04/08/14 10:08 PM

    Originally posted by: appleme


    Thanks for your help.

    I tested,It works well.


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: How to count in a desicion variable?

    Posted 04/08/14 10:16 PM

    Originally posted by: appleme


     I found a question.

    c == count(all(j in jup : j.p=="T") jupz[j], 1);

    this line is a constraint,It is not a equation.

    could this function "count(all(j in jup : j.p=="T") jupz[j], 1)" set to a int variable or as condition in if ? 

    I found

    if(count(all(j in jup : j.p=="T") jupz[j], 1)<=5) or c=count(all(j in jup : j.p=="T") jupz[j], 1);

    it doesn't work.


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: How to count in a desicion variable?

    Posted 04/10/14 07:43 AM

    Originally posted by: ChrisBr


    Hello,

    Since the result of "count(...)" depends on decision variables, it is not possible to set it to an int as long as the values of the concerned decision variables are not known. But this is possible after the resolution when the decision variables are fixed.

    You can set it to a "dexpr int" or define a "dvar int" and constrain it to be equal to the result of "count(...)".

    To sum up, all the following statements are allowed:

    dexpr int c1 = count(all(j in jup : j.p=="T") jupz[j], 1);
    dvar int c2 in 0..card(jup);
    subject to {
      c2 == count(all(j in jup : j.p=="T") jupz[j], 1);
    }
    int c3 = count(all(j in jup : j.p=="T") jupz[j], 1);
    

    About your second question: it is mentioned in documentation that
            Conditions in if-else statements must be ground; that is, they must not contain decision variables.

    So you cannot write:

     if(count(all(j in jup : j.p=="T") jupz[j], 1)<=5) ...
    


    But you can use implications of constraints instead, for example:

    ((count(all(j in jup : j.p=="T") jupz[j], 1)) <=5) => (...);
    

    or conditional expression, for example:

      k == (((count(all(j in jup : j.p=="T") jupz[j], 1)) <=5) ? 1000 : -1);
    


    I hope this clarifies,

    Chris.
     


    #DecisionOptimization
    #OPLusingCPOptimizer