Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Using floor in IloVariables

    Posted 04/26/15 01:14 PM

    Originally posted by: Allexandre


    Hi,

    I'm implementing a linear programming where my objective function is:

    My code is:

      IloExpr spfo(env);
      for (int i = 0; i <= d.n; i++){
        if (i != 0) {
          spfo -= sp.pi_[(i-1)] * sp.y[i-1];
          sprintf(name,"y[%d]",i);
          sp.y[i-1].setName(name);      
        }
        for (int j = 1; j <= (d.n+1); j++){   
          if(i != j){                             
            if (!((i == 0) && (j == d.n+1))){     
              spfo += d.c[i][j] * sp.x[(d.n+1)*(i) + (j-1)];
              sprintf(name,"x[%d][%d]",i,j);
              sp.x[(d.n+1)*(i) + (j-1)].setName(name);
              sprintf(name,"f[%d][%d]",i,j);
              sp.f[(d.n+1)*(i) + (j-1)].setName(name);
            }
          }
        }
      }
      
      
      //int L = CPXXgetnumrows(cpx.envmp, cpx.lpmp) - (d.n + 1);
      for (int l = d.n+1; l <= (d.n + 1 + d.n); l++){
        sp.beta_[l-(d.n + 1)] = pi[l];    
        IloExpr spfoaux(env);
        for (int i = 1; i <= d.n; i++) spfoaux += sp.ul_[i-1]*sp.y[i-1];
        spfo -= sp.beta_[l-(d.n + 1)]*floor(double(spfoaux));
      }
      
      
      spfo -= sp.pi0_;      // -pi_0
      sp.fo = IloAdd(sp.mod, IloMinimize(env, spfo));
      spfo.end();
    

    My variables are: sp.x, sp.y and sp.f

    sp.beta_, sp.pi_ and sp.pi0_ are parameters whose stores the values from the constraints of my master problem.

    sp.ul_ also are a parameter.

    d stores some data about my problem, like the number of nodes, demands, etc.

    but it returns an error saying that it cannot convert IloExpr or IloVar (if I put the floor in my variable y_i) in double. 

     

    There is any way to do this (apply floor in my objetctive function)?


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Using floor in IloVariables

    Posted 04/26/15 04:16 PM

    You can introduce an auxiliary IntVar (I'll call it z), constraint z <= spfoaux, and subtract sp.beta_[l-(d.n + 1)]*z in spfo.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Using floor in IloVariables

    Posted 04/26/15 05:15 PM

    Originally posted by: Allexandre


    Hi PaulRubin,

    It's a good idea, using spfoaux as a upper bound. It would work when that sum gives me an exactly integer. But how can I define that z assumes exactly the interger value undeer spfoax? A example, if my value of spfoaux = 3,6, then I want that z assumes 3.

    Really thanks,

    Allexandre.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Using floor in IloVariables

    Posted 04/26/15 07:40 PM

    That depends. If larger values of the term being subtracted from spfo are always preferable to smaller ones (i.e., larger ones produce better objective results), you do not have to do anything extra; the solver will push z up to the desired value. On the other hand, if you cannot be confident of that, then you have to introduce a little bit of inaccuracy in the model:

    z <= spfoaux

    z >= spfoaux - 1 + epsilon

    for some small (but not too small) positive value of epsilon. The catch with this is that it prevents spfoaux from taking a value that is within epsilon of its ceiling.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Using floor in IloVariables

    Posted 04/27/15 07:34 AM

    Originally posted by: Allexandre


    Really interesting, I thought something.

    If I say that (spfoaux - 1) <= z <= spfoaux and z must be an integer, I believe that I would obtain exactly z = floor(spfoaux), right?

    I'll try this and text here saying if it works or not,

    Thanks,

    Allexandre;


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Using floor in IloVariables

    Posted 04/27/15 10:26 AM

    This is close, but it involves a somewhat hidden epsilon adjustment. CPLEX has a nonzero tolerance for constraint violations (parameter EpRHS), which is necessary due to rounding error. So if spfoaux ends up within EpRHS of an integer, z can take either of two values and satisfy CPLEX. For instance, using the default value 1e-6 for EpRHS, suppose that spfoaux takes the value 6.000005. CPLEX will accept either z = 6 or z = 5 as feasible.


    #CPLEXOptimizers
    #DecisionOptimization