Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to write a complex cost function where index i is expressed by a function

    Posted 04/25/19 07:14 PM

    Originally posted by: NaomiLearnCplex


    Hello there,

    Below is the coding for a binary integer minimization problem. My cost function cij is the sum of decision variables xij from i to i+9. The last 9 rows exceed the range of i. I want to express the row index as a function of i. The row index is represented as 1 plus the remainder of i divided by the number of rows (ns), where i iterates from i to i+9. (Detailed formuation is shown in below picture) By doing this, I can form a closed row sum loop by connecting the last row to the first row. However, I don't know how to write my cost function using CPLEX.

    What I did is to write 

    dexpr int c[i in shift, j in comb ] = x [ i] [ j ] +x [ i+1] [ j ] +x [ i+2] [ j ] +x [ i+3] [ j ] +x [ i+4] [ j ] +x [ i+5] [ j ] +x [ i+6] [ j ] +x [ i+7] [ j ] +x [ i+8] [ j ] +x [ i+9] [ j]

    ;

    But definitely, this expression has a range problem.

     

    Anyone could help? Many thanks in advance!

    int nc=...; 
    int ns=...; 
    
    
    range comb=1..nc; 
    range shift=1..ns; 
    
    //define decision variables
    dvar boolean x[shift][comb];
    
    //define parameters 
    int CombSF[comb]=...;
    dexpr int c[i in shift, j in comb]= x[i][j]+x[i+1][j]+x[i+2][j]+x[i+3][j]+x[i+4][j]+x[i+5][j]+x[i+6][j]+x[i+7][j]+x[i+8][j]+x[i+9][j];
    int dl[shift]=...;
    int du[shift]=...;
    
    //define objective function
    minimize sum(i in shift, j in comb)c[i][j]*x[i][j];
    
    //define constraints
    subject to 
    { 
    Con01:
    forall(i in shift)
      dl[i]<=sum(j in comb)x[i][j]<=du[i];
    
    Con02:
    forall(j in comb)
      sum(i in shift)x[i][j]==CombSF[j];
    }

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to write a complex cost function where index i is expressed by a function

    Posted 04/26/19 02:22 AM

    Hi,

    have you tried to turn

    dexpr int c[i in shift, j in comb]=
    x[i][j]+x[i+1][j]+x[i+2][j]+x[i+3][j]+x[i+4][j]+x[i+5][j]+x[i+6][j]+x[i+7][j]+x[i+8][j]+x[i+9][j];
     

    into

    dexpr int c[i in shift, j in comb]=
    sum(k in 0..9:i+k<=ns) x[i+k][j];

    in order not to have the out of range ?

     

    int nc=10;
    int ns=30;
    range comb=1..nc;
    range shift=1..ns;

    //define decision variables
    dvar boolean x[shift][comb];

    //define parameters
    int CombSF[i in comb]=rand(10);
    dexpr int c[i in shift, j in comb]=
    //x[i][j]+x[i+1][j]+x[i+2][j]+x[i+3][j]+x[i+4][j]+x[i+5][j]+x[i+6][j]+x[i+7][j]+x[i+8][j]+x[i+9][j];
    sum(k in 0..9:i+k<=ns) x[i+k][j];

    int dl[i in shift]=rand(10);
    int du[i in shift]=rand(10)+20;

    //define objective function
    minimize sum(i in shift, j in comb)c[i][j]*x[i][j];

    //define constraints
    subject to
    {
    Con01a:
    forall(i in shift)
    dl[i]<=sum(j in comb)x[i][j];

    Con01b:
    forall(i in shift)
    sum(j in comb)x[i][j]<=du[i];

    Con02:
    forall(j in comb)
    sum(i in shift)x[i][j]==CombSF[j];
    }

     

    works better.

     

    regards

     

    https://www.linkedin.com/pulse/low-barrier-entry-optimization-through-cplex-alex-fleischer/

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to write a complex cost function where index i is expressed by a function

    Posted 04/26/19 01:23 PM

    Originally posted by: NaomiLearnCplex


    Thank you. I modified a bit to meet my needs and it works!

    dexpr int c[i in shift, j in comb]= sum (k in 0..4)x[1+(i+k-1)%ns][j];

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer