Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  min() and max() in empty sets

    Posted 02/03/12 10:07 AM

    Originally posted by: SystemAdmin


    Hi everybody, I'm having some problems understanding how min() and max() operators work with empty set. Let's consider max(), since min() behaves symmetrically. As it is reported in the documentation, max() over an empty set should return -infinity. Consider this simple example:

    
    using CPLEX;   range R = 1..3;   
    
    int a[i in R] = i; dvar 
    
    int x[R] in R; dvar 
    
    int y in R;   maximize sum(i in R)(x[i]) + y; subject to 
    { y == maxl(1, max(i in 0..-1) a[i]); 
    }
    


    It's easy to see that, since y is bound to 1 (because the max in that empty set is -infinity), the optimal objective function has value 3 + 3 + 3 + 1 = 10. This example works as intended.
    Let's now consider this other example which is very similar:

    
    using CPLEX;   range R = 1..3;   
    
    int a[i in R] = i; dvar 
    
    int x[R] in R; dvar 
    
    int y in R;   maximize sum(i in R)(x[i]) + y; subject to 
    { y == maxl(1, max(i in 0..-1) x[i]); 
    }
    


    The only thing that changed is that the max() operator is maximizing the variable x instead that the constant a. When CPLEX has finished solving this, the Problem Browser says that x and y have "No value" (I'm pretty sure that this means that the problem is unfeasible), while it seems clear to me that it should behave the same way as the previous one, with the objective function once again having value of 3 + 3 + 3 + 1 = 10.

    What am I missing? How do max() and min() work with empty set while maximizing or minimizing variables?

    Regards,
    Stefano
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: min() and max() in empty sets

    Posted 02/04/12 04:37 AM
    Hi,

    maybe you could try to use the CP engine:

    using CP;
     
    range R = 1..3;
     
    int a[i in R] = i;
    dvar int x[R] in R;
    dvar int y in R;
     
    maximize
            sum(i in R)(x[i]) + y;
    subject to {
            y == maxl(1, max(i in 0..-1) x[i]);
    }
    


    will give you a result.

    Regards

    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: min() and max() in empty sets

    Posted 02/06/12 08:55 AM

    Originally posted by: SystemAdmin


    Thank you for your answer, indeed your example works as expected. So you confirm that the CPLEX engine is not able to handle max/min of decision expressions (dexpr) over empty sets? This could have an impact on the way one has to model its problem, because as far as I understood (I am still a beginner here) CP and CPLEX are optimized for different things.

    Regards,
    Stefano
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: min() and max() in empty sets

    Posted 02/07/12 01:53 PM
    Hi,

    what you wrote should word but does not.
    A workaround is to protect the max/min.

    using CPLEX;
     
    range R = 1..3;
     
    {int} s={};
     
    int a[i in R] = i;
    dvar int x[R] in R;
    dvar int y in R;
     
    maximize
            sum(i in R)(x[i]) + y;
    subject to {
      if (card(s)==0)
       y==1;
       else
            y == max(i in s) x[i];
    }
    


    Could that help you?

    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: min() and max() in empty sets

    Posted 02/08/12 07:39 AM

    Originally posted by: SystemAdmin


    Thank you, in a general way it could, but mine was just a minimal example to underline the problem. My real issue is a bit different for a couple of reasons:

    1) The set in which I'm finding the maximum is built at runtime by a condition of its tuple elements:

    max(a in A : a.property == 1) x[a];
    


    Unfortunately, a syntax like this does not work:
    if(card(a in A : a.property == 1) > 0)
    


    2) I would like to have a compact "one line expression" to assign its value to a dexpr for efficiency reasons. I don't know (and don't think) that this is possible when your variable is "decided" by an if statement. Let's say my case would really resemble this one:

    dvar int x[A];
    dexpr int y = sum(a in A : a.property == 1) x[a];
    


    where in the set A you could also not have any a s.t. a.property == 1 (or any other kind of expressions over elements of A).
    Any ideas?

    Regards,
    Stefano
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: min() and max() in empty sets

    Posted 02/04/12 04:49 AM
    PS:

    If you want to use CPLEX, then you can rewrite into:

    range R = 1..3;
     
    int a[i in R] = i;
    dvar int x[R] in R;
     
    dexpr int y2=maxl(1, max(i in 0..-1) a[i]);
    dvar int y in R;
     
    maximize
            sum(i in R)(x[i]) + y;
    subject to {
      y==y2;        
    }
    


    Regards

    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: min() and max() in empty sets

    Posted 02/04/12 05:07 AM
    Hi

    forget my previous mail but keep my first one

    regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: min() and max() in empty sets

    Posted 02/08/12 02:22 PM
    Hi

    let me suggest a syntax example

    using CPLEX;
     
    range R = 1..3;
     
    {int} s={};
     
    tuple t
    {
     int property; 
    }  
     
    {t} A={<0>};
     
    dvar int x[A] in R;
     
     
     
    dexpr int y = sum(a in A : a.property == 1) x[a];
     
    {t} subsetOfAWithProp1={a |a in A : a.property == 1};
    int AisEmpty=(card(subsetOfAWithProp1) > 0)?0:1; 
     
     
    maximize
            sum(i in A)(x[i]) + y;
    subject to {
      
      if (AisEmpty==1)
      {
        ct:y<=10;
      }    
            
    }
    


    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: min() and max() in empty sets

    Posted 02/09/12 10:30 AM

    Originally posted by: SystemAdmin


    Thank you so much! I swear I tried the one-line-if syntax, but I didn't recall it was working. Still, too bad you have to implement such a workaround for CPLEX.

    Regards,
    Stefano
    #DecisionOptimization
    #OPLusingCPLEXOptimizer