Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problems to convert continuos variables into integer variables

    Posted 08/01/19 06:08 PM

    Originally posted by: lbr33


    Hi,

     

    I'm using Concert Technology to solve a MIP problem.

    Variables x and y are integer.

     

    If I declare the variables as integer (as following), Cplex easily finds the optimal solution.

    y = IloNumVarArray(env, SIZE_y, 0.0, 1.0, ILOINT);
    x = IloNumVarArray(env, SIZE_x, 0.0, +IloInfinity, ILOINT);

    If I first declare  y as continuous and x as integer as following:

    y = IloNumVarArray(env, SIZE_y, 0.0, 1.0, ILOFLOAT);
    x = IloNumVarArray(env, SIZE_x, 0.0, +IloInfinity, ILOINT);

    and in sequence I do the command:
    for(int i = 0; i < y.getSize(); i++) {
      mod.add(IloConversion(env, y[i],ILOINT));
    }

    It still working perfectly.

     

    However, If I first declare x and y as continuous as following:

    y = IloNumVarArray(env, SIZE_y, 0.0, 1.0, ILOFLOAT);
    x = IloNumVarArray(env, SIZE_x, 0.0, +IloInfinity, ILOFLOAT);

    and after solving the linear relaxation of the problem I integralize the variables as following:

    for(int i = 0; i < y.getSize(); i++) {
       mod.add(IloConversion(env, monoPM.y[i],ILOINT));
    }
    for(int i = 0; i < x.getSize(); i++) {
      mod.add(IloConversion(env, monoPM.x[i],ILOINT));
    }

    Then, Cplex searches forever the optimal solution.

    What is wrong?

    Thank you!
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problems to convert continuos variables into integer variables

    Posted 08/02/19 01:47 AM

    Originally posted by: T_O


    Are y and monoPM.y (x and monoPM.x respectively) the same variables?

    Have you tried exporting LP files and compare the models?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Problems to convert continuos variables into integer variables

    Posted 08/02/19 10:27 AM

    Originally posted by: lbr33


    Sorry for the confusion.

    Yes, monoPM.y is the same variable as y.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Problems to convert continuos variables into integer variables

    Posted 08/02/19 02:30 AM

    Can you show the logs of the three solves here?

    Can you also cplex.exportModel("model.lp") all the three models and make sure that the first and last LP files are identical?


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Problems to convert continuos variables into integer variables

    Posted 08/02/19 10:38 AM

    Originally posted by: lbr33


    First, I declare the variables as follows:

     

    y = IloNumVarArray(env, SIZE_y, 0.0, 1.0, ILOFLOAT);
    x = IloNumVarArray(env, SIZE_x, 0.0, +IloInfinity, ILOFLOAT);

     

    The .lp file follows attached (PM-continuous.lp).

    Then, when I solve the model I obtain the output below:

     

    CPXPARAM_Threads                                 1
    Tried aggregator 1 time.
    No LP presolve or aggregator reductions.
    Presolve time = 0.00 sec. (1.50 ticks)
    Initializing dual steep norms . . .

    Iteration log . . .
    Iteration:     1   Dual objective     =             0.000000
    Iteration:    81   Dual objective     =         22000.000000
    Iteration:   158   Dual objective     =         41277.661327
    of , 41277.6613
    time ,             0.1100
    status = Optimal

     

    In sequence, I integralize the variables as follows:

     

    for(int i = 0; i < y.getSize(); i++) {
       mod.add(IloConversion(env, y[i],ILOINT));
    }
    for(int i = 0; i < x.getSize(); i++) {
      mod.add(IloConversion(env, x[i],ILOINT));
    }

     

    The .lp file follows attached (PM-integer.lp).

    If I directly give CPLEX this .lp file, I get the answer.

    But when my code in c++/Concert tries to solve it, I get the output below:

     

    CPXPARAM_Threads                                 1
    MIP emphasis: balance optimality and feasibility.
    MIP search method: dynamic search.
    Parallel mode: none, using 1 thread.
    Root relaxation solution time = 0.00 sec. (4.13 ticks)

            Nodes                                         Cuts/
       Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

          0     0    41277.6613    14                  41277.6613        0         
    *     0+    0                        47132.6225    41277.6613            12.42%
          0     0    45038.2373     3    47132.6225       Cuts: 2       12    4.44%
          0     0    45038.2373     4    47132.6225    MIRcuts: 8       27    4.44%
          0     0    45038.2373     6    47132.6225    MIRcuts: 4       35    4.44%
          0     2    45038.2373     6    47132.6225    45038.2373       35    4.44%
    Elapsed time = 0.06 sec. (67.45 ticks, tree = 0.01 MB, solutions = 1)
        418   306    45038.2373     2    47132.6225    45038.2373     1085    4.44%
        933   684    45038.2373     3    47132.6225    45038.2373     2608    4.44%
       1510  1180    45038.2373     2    47132.6225    45038.2373     4028    4.44%
       2095  1698    45038.2373     4    47132.6225    45038.2373     5667    4.44%
       2731  2263    45038.2373     2    47132.6225    45038.2373     6987    4.44%
       3370  2828    45038.2373     2    47132.6225    45038.2373     8420    4.44%
       4000  3377    46085.4299     1    47132.6225    45038.2373    10005    4.44%
       4628  3928    46085.4299     1    47132.6225    45038.2373    11568    4.44%
       5332  4533    45038.2373     2    47132.6225    45038.2373    13476    4.44%
       8238  6621    46085.4299     2    47132.6225    45038.2373    22129    4.44%
    Elapsed time = 2.32 sec. (3173.27 ticks, tree = 15.98 MB, solutions = 1)

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Problems to convert continuos variables into integer variables

    Posted 08/20/19 05:26 AM

    What you observe is expected behavior.

    What happens is this:

    1. You solve the model with all variables continuous.
    2. The model solves to optimality. That saves the optimal basis in the IloCplex object.
    3. You change the type of some variables to ILOINT. This change does not discard the optimal LP basis stored before.
    4. You solve the new model.
    5. The solve starts from scratch (because the problem type changed from LP to MIP), however, since there still is an optimal basis stored, CPLEX skips presolve and starts optimization from this basis. So you end up solving the unpresolved model and that is why it takes so long.

    You can avoid this by calling cplex.setParam(IloCplex::AdvInd, 0) before the second solve. That tells CPLEX to ignore the resident basis and do presolve.


    #CPLEXOptimizers
    #DecisionOptimization