Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Min Max Problem in CPLEX Studio IDE

  • 1.  Min Max Problem in CPLEX Studio IDE

    Posted Mon February 05, 2018 10:02 AM

    Originally posted by: Bahman


    Hi Everyone,

    Considering the following codes written in Cplex Studio IDE, I would ask you please advise me how I can write a min max function

     

    tuple s {

      int i;

      int j;

    }

    {s} S=...;

    {string} G=...;

    {int} k=asSet(1..3);

    {int} T=asSet(1..6);

    float P=...;

    float d[K][G]=...;

     

    dvar boolean Z[S][K][T];

    dexpr float PE[<i,j> in S][g in G]=sum (k in K, t in T) Z[<i,j>][K][T]*d[k][g]*P;

    .............................................................................................................................

     

    Now I would like to write two different codes with the following two objectives (for all <i,j> in S, k in K, t in T and g in G):

    1) Minimize the maximum PE[<i,j>][g];

    2) Minimize the maximum PE[<i,j>][g] - minimum PE[<i,j>][g]

     

    I would appreciate your reply!

     

    Regards
    Bahman


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Min Max Problem in CPLEX Studio IDE



  • 3.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Mon February 05, 2018 10:31 AM

    Originally posted by: Bahman


    Dear Alex,

    I appreciate your prompt reply! I would ask you if it matters if I make use of maxl or minl instead of max and min functions, respectively?

    Regards,
    Bahman


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Mon February 05, 2018 10:37 AM

    Hi

    It does not matter:

    range r=1..5;
    dvar int x[i in r] in r;

    //minimize max(i in r) x[i];
    minimize maxl(x[1],x[2],x[3],x[4],x[5]);
    subject to
    {

    }

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Mon February 05, 2018 10:38 AM

    Originally posted by: Bahman


    Dear Alex,

    I got the difference! Thank you!

     

    Regards
    Bahman


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Mon February 05, 2018 10:24 AM

    In your case you can model this directly without using OPL's min() or max() function:

    1. You can use an auxiliary variable PEmax and a constraint PEmax >= PE[<i,j>][g]. Then minimizing PEmax gives the desired result.
    2. Similarly to the previous case, use auxiliary variable PEdist and constraint PEdist >= PE[<i1,j1>][g1] - PE[<i2,j2>][g2] for all combinations of i, j, g. Then again, minimizing PEmax gives the desired result.

    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Mon February 05, 2018 10:36 AM

    Originally posted by: Bahman


    Dear Daniel, 

    I have written the following constraint but I am not sure if it works well:

     

       forall(<i,j,l> in S, <p,s,t> in S: <i,j,l> !=<p,s,t>, g in G)
          Ct1:
            max (<i,j,l> in S) PE[<i,j,l>][g] - min (<p,s,t> in S) PE[<p,s,t>][g] <= 0.50*sum(<e,r,t> in S) PE<e,r,t>][g];

    Regards,
    Bahman


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Wed September 25, 2019 08:01 AM

    Originally posted by: NALK


    Dear Daniel and ALEX, 

    Is there any specific OPL syntax  to find the minimum of the smallest positive number in an array (non-zero ))??  for example  (  A[j]={2,3,4,0,1})  

    Thanks in advance,

     

    Kind Regards,

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Wed September 25, 2019 09:44 AM

    Hi

    {int}  A={2,3,4,0,1};

    int minNonZeroPos=min(i in A:i>=1) i;
    execute
    {
    writeln(minNonZeroPos);
    }

    gives

    1

    but please open new threads for new topics

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Thu September 26, 2019 03:00 AM

    Originally posted by: NALK


    Thank you Alex  , Thats good but it is still valid for such for such  expression  Min (i in 1..5 ) A_i*X_i         such that       A_i=[2,3,4,0,1]  and   X_i=[1,0,1,0,0.5]       X is a decisiion variable 

     

    Thanks a lot, 


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Thu September 26, 2019 03:58 AM

    Hi

    then you may write

    range r=1..5;

    int  A[r]=[2,3,4,0,1];
    float v[r]=[1,0,1,0,0.5] ;

    dvar float X[r];
    dvar float E[r];
    dvar float res;

    subject to
    {
    forall(i in r) X[i]==v[i];

    forall(i in r) (A[i]*X[i]>=0.001) => (E[i]==A[i]*X[i]);
    forall(i in r) (A[i]*X[i]<=0.001) => (E[i]==maxint);

    res==min (i in 1..5 ) (E[i]) ;
    }

    execute
    {
    writeln(res);
    }

     

    which gives 0.5

     

    But again please open new threads for new topics

    regards

     

    https://www.linkedin.com/pulse/how-opl-alex-fleischer/


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Min Max Problem in CPLEX Studio IDE

    Posted Thu September 26, 2019 08:01 AM

    Originally posted by: NALK


    Thanks a lot Alex  ,


    #CPLEXOptimizers
    #DecisionOptimization