Decision Optimization

Decision Optimization

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


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

choose max value from a set

  • 1.  choose max value from a set

    Posted 11/25/14 05:22 PM

    Originally posted by: stathis_d


    Hello, 

    i'm wondering if someone can help with the following. In one of my constraints i want to force the value 1 for a binary variable s[j], when :  variable x[j]=1 and, parameter  grade[j] (of the x[j]=1) has the highest value.

    I use conditional constraint for this one but i can't find a way to somehow force cplex to choose the highest value from the remaining set.  I try to introduce a new parameter m=max[j in Locations]grade[j] but always choose the highest from all the values of grade[j]. So, I'm wondering if there is any other way to force the highest value from a set of prices, thanks in advance! 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: choose max value from a set

    Posted 11/26/14 03:26 AM

    Hi,

    could

    range r =1..10;

     

    dvar boolean x[r];

     

    int grade[i in r]=i;

     

    int maxgrade=max(i in r) grade[i];

    int imaxgrade=first({i | i in r:grade[i]==maxgrade});

     

    subject to

    {

    x[imaxgrade]==1;

    }

    help ?

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: choose max value from a set

    Posted 11/26/14 07:45 AM

    Originally posted by: stathis_d


    Hi Alex, 

    thanks for your answer. I have tried couple of stuff  but doesn't seem to work. Using the: 

    int maxgrade=max(i in r) grade[i]; 

    it always choose the highest from the whole list.  What i am trying  to do is firstly to check if distance is between 1.5 and 2 so then x[j]=1 and from those x[j]=1 to choose only the one that has the highest grade[j].   

    I am wondering also in the syntax that you indicate what is the use of first? Does it choose the first element or the max from the set of maxgrade? 

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: choose max value from a set

    Posted 11/26/14 09:32 AM

    Hi

    range r =1..10;

     

    int x[i in r]=i mod 2;

     

    int grade[i in r]=i;

     

    int maxgrade=max(i in r:x[i]==1) grade[i];

    int imaxgrade=first({i | i in r:grade[i]==maxgrade});

     

    execute

    {

    writeln(imaxgrade) ;

    }

    will pick the biggest among the ones such as x[j]==1

    I use first to pick the first one if the set is not a singleton

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer