Decision Optimization

Decision Optimization

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


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

A question about using Callback

  • 1.  A question about using Callback

    Posted 06/02/10 07:45 PM

    Originally posted by: SystemAdmin


    I want to let cplex stop after it gets the root relaxation node during branch and cut, so I read the manual and wrote a piece of codes which is similar to the example on the manual, but there are errors during compiling.

    My code is:

    ...
    cplex.extract(model);

    ILOMIPCALLBACK1(MyCallback, IloInt, num)
    {
    cout<<"The number of nodes processed: "<<getNnodes()<<endl;
    if(getNnodes()==num)
    {
    masteropt = getBestObjValue();
    abort();
    }
    else;
    }
    cplex.use(MyCallback(env, 1));
    cplex.solve();
    The errors are located in the line of "ILOMIPCALLBACK1(MyCallback, IloInt, num)" :

    error C2599: 'main' : local class member functions must be defined within the class
    see declaration of 'main'
    error C2601: 'MyCallback' : local function definitions are illegal
    error C2601: 'main' : local function definitions are illegal

    Can someone give me some help in it? thanks very much.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: A question about using Callback

    Posted 06/03/10 05:39 AM

    Originally posted by: SystemAdmin


    Macro ILOMIPCALLBACK1 defined a new class.
    You should not use it within a function scope but only outside of functions. The macro is not designed to define a local class.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: A question about using Callback

    Posted 06/04/10 06:03 PM

    Originally posted by: SystemAdmin


    Daniel, thanks. I tried to use another approach to let cplex stop after it get the LP relaxation root node in each iteration.

    cplex.setParam(IloCplex::NodeLim, 1);

    Is it correct? when I did it, it seems cplex did not stop after root node. The solving process output is as follows:

    The first iteration:

    Nodes Cuts/
    Node Left Objective IInf Best Integer Best Node ItCnt Gap Variable B Parent Depth

    0 0 4643.0000 15 4643.0000 39
    • 0+ 0 0 5893.0000 4643.0000 39 21.21%
    • 5370.0000 0 5370.0000 Fract: 15 56 0.00%

    The second iteration is:
    Nodes Cuts/
    Node Left Objective IInf Best Integer Best Node ItCnt Gap Variable B Parent Depth

    0 0 4643.8333 27 4643.8333 48
    • 0+ 0 0 5956.0000 4643.8333 48 22.03%
    4913.2000 24 5956.0000 Cuts: 28 73 17.51%
    • 0+ 0 0 5896.0000 4913.2000 73 16.67%
    5140.3333 17 5896.0000 Fract: 23 96 12.82%
    • 0+ 0 0 5549.0000 5140.3333 96 7.36%
    I think the root node's obj vaule should be 4643, but cplex stop at the node with obj value 5370, and in 2nd itertaion, the root node's obj vaule should be 464383, but cplex stop at the node with obj value 5549.

    May I have some help about this?
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: A question about using Callback

    Posted 06/07/10 09:24 AM

    Originally posted by: SystemAdmin


    When looking at your output in plain text it seems that CPLEX did stop after the root node.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: A question about using Callback

    Posted 06/07/10 01:26 PM

    Originally posted by: SystemAdmin


    when I solved the problem without the integer constraints (so it is a LP), the objective value is 2185; but when I solve the MIP and let cplex stop after getting the root node, the objective value is 5370. They are different, but I think they should be same, shouldn't them?

    the MIP's root relaxation node is the optimal solution for LP, right?
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: A question about using Callback

    Posted 06/07/10 02:53 PM

    Originally posted by: SystemAdmin


    > wxh wrote:
    > when I solved the problem without the integer constraints (so it is a LP), the objective value is 2185; but when I solve the MIP and let cplex stop after getting the root node, the objective value is 5370. They are different, but I think they should be same, shouldn't them?
    >
    > the MIP's root relaxation node is the optimal solution for LP, right?

    Not if you have presolve turned on (which it is by default). I'm pretty sure the presolver may use integrality restrictions in the MIP to tighten bounds or possibly even fix variables. As a simple example, if x is an integer variable and the model contains 1.5 <= x <= 2.5, then the LP relaxation will let x be anything in that interval; but if you solve it as a MIP, the presolver probably recognizes that x has to be 2, and fixes x at 2 before solving the LP relaxation at the root node.

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: A question about using Callback

    Posted 06/07/10 03:30 PM

    Originally posted by: SystemAdmin


    Paul, thanks.

    When I turned off the presolve, the objective value still not same:

    this is the case without presolve, and cplex solve MIP and stop after getting root node:

    Nodes                                         Cuts/ 
       Node  Left     Objective  IInf  Best Integer     Best Node    ItCnt     Gap         Variable B Parent  Depth
     
          0     0     2185.0000    57                   2185.0000      546
    *     0+    0                   0     6183.0000     2185.0000      546   64.66%
                      4608.8000    34     6183.0000     Cuts:  58      767   25.46%
                      4852.0000    15     6183.0000    Fract:  34      944   21.53%
    *     0+    0                   0     6005.0000     4852.0000      944   19.20%
    *     0+    0                   0     5370.0000     4852.0000      944    9.65%
    


    the objective value is 5370 which is in last line, it is the best integer value.

    but when I just solved the LP problem (MIP without integer constraints), I got follows:

    Initializing dual steep norms . . .
     
    Iteration log . . .
    Iteration:     1   Dual objective     =             0.000000
    Perturbation started.
    Iteration:    52   Dual objective     =             0.000000
    Iteration:   114   Dual objective     =             0.000003
    Iteration:   176   Dual objective     =           233.434910
    Iteration:   238   Dual objective     =           731.642871
    Iteration:   300   Dual objective     =          1254.400483
    Iteration:   362   Dual objective     =          1819.581988
    Iteration:   424   Dual objective     =          2163.277422
    Iteration:   486   Dual objective     =          2184.719507
    Removing perturbation.
     
    Master Problem's objective value is: 2185
    


    actually, in MIP root node, I am not sure why cplex does not stop after it getting a LP solution 2185 showed in first line? why it keeps solving to get a integer solution?
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: A question about using Callback

    Posted 06/07/10 04:34 PM

    Originally posted by: SystemAdmin


    > wxh wrote:
    > actually, in MIP root node, I am not sure why cplex does not stop after it getting a LP solution 2185 showed in first line? why it keeps solving to get a integer solution?

    In addition to the presolver, CPLEX automatically adds a number of cuts at the root node (and perhaps at some other nodes), including Gomory cuts, cover cuts, clique cuts, ... Not all cuts may be applied at a particular node, but it usually applies at least some (unless you turn them off). The cuts typically tighten the model (make the convex hull closer to the integer hull), and may lead to the discovery of an integer feasible solution. The "Cuts: 58" you see in the output indicates cuts have indeed been added.

    In addition, CPLEX may apply heuristics to the LP solution that can lead to an integer solution (again, unless you turn the heuristics off).

    If, for some reason, you really need the solution to the LP relaxation at the root node to match what you get when you relax the problem to an LP, then you'll need to turn off presolving and all types of cuts (which can be done by setting parameter values).

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: A question about using Callback

    Posted 06/07/10 04:57 PM

    Originally posted by: SystemAdmin


    Paul, thank you very much for your detail answer.

    I have another quesiton, in the log file for solving MIP root node, it said:

    Root relaxation solution time =    0.02 sec.
    


    is this time for getting the LP solution 2185 in first line, or getting the integer solution 5370 in last line? Thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: A question about using Callback

    Posted 06/07/10 05:55 PM

    Originally posted by: SystemAdmin


    > wxh wrote:
    >
    > I have another quesiton, in the log file for solving MIP root node, it said:
    >
    >
    Root relaxation solution time =    0.02 sec.
    

    >
    > is this time for getting the LP solution 2185 in first line, or getting the integer solution 5370 in last line?

    I believe that's the entire time spent on the root node (getting to the last line).

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: A question about using Callback

    Posted 06/07/10 06:19 PM

    Originally posted by: SystemAdmin


    thanks.

    I tried your suggestion(turn off heuristic, and turn off cuts generation), cplex did stop after it get the LP solution of 2185. But when I want to get those LP solution value, I found that I cann't, since ther is no integer feasisble solution exists, do you know how can I get those LP solutions?

    part of my code looks like:

    IloNumVarArray y(env, n, 0, 1, ILOINT);
          obj = ...
          model.add(IloMinimize(env, obj));
          obj.end();
     
          IloCplex cplex(env);
     
          cplex.extract(model);
            
          cplex.setParam(IloCplex::PreInd, false); //disable the presolve 
          cplex.setParam(IloCplex::NodeLim, 1);//stop as soon as get root node
            
          cplex.setParam(IloCplex::HeurFreq, -1);//turn off heuristic
          cplex.setParam(IloCplex::CutsFactor, 1.0);//add no cuts
          
          cplex.solve();
     
          objvalue=cplex.getBestObjValue();
     
          cout<<"Test!"<<endl;
          cout<<cplex.getValue(y[0])<<endl; //~~~~~~~~~~~error happend here~~~~~~~~~~~~~~~~~~~~~~~~~
          cout<<"Test!!!"<<endl;
    


    I know since the definition of y is IloInt, and I did not get the integer solution, so it should have error, but I do not know the other way to get those LP solution values.

    the output is:
    Root relaxation solution time =    0.11 sec.
     
            Nodes                                         Cuts/ 
       Node  Left     Objective  IInf  Best Integer     Best Node    ItCnt     Gap         Variable B Parent  Depth
     
          0     0     2185.0000    57                   2185.0000      546
     
    objective value (LP relaxation root node) is: 2219.75
    Test!
     ERROR: CPLEX Error  3017: No integer feasible solution exists.
     
    CPLEX error
    The Solving Time: 1
    Press any key to continue
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: A question about using Callback

    Posted 06/07/10 06:42 PM

    Originally posted by: SystemAdmin


    > wxh wrote:

    > I tried your suggestion(turn off heuristic, and turn off cuts generation), cplex did stop after it get the LP solution of 2185. But when I want to get those LP solution value, I found that I cann't, since ther is no integer feasisble solution exists, do you know how can I get those LP solutions?
    >

    One possibility is to build the MIP model, then add relax the integer variables using IloConversion objects, solve the LP, query the solution values, then remove the relaxations. The code might look something like this:

    IloCplex cplex = new IloCplex();
    IloIntVar x = cplex.intVar(...);  // define other variables too
    ArrayList<IloConversion> list = new ArrayList<IloConversion>();  // we'll need to store the conversions
    // finish building the MIP model
    IloConversion relax = cplex.conversion(x, IloNumVarType.Float);  // this will relax x to float
    list.add(relax);  // store it
    // repeat the last two statements for all other integer variables
    for (IloConversion c : list) {
      cplex.add(c);  // conversions have to be added to take effect
    }
    cplex.solve();  // the model is an LP now
    double xval = cplex.getValue(x);  // get the relaxation solution
    // repeat for other variables
    for (IloConversion c : list) {
      cplex.remove(c);  // remove all conversions to get back to the MIP model
    }
    


    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: A question about using Callback

    Posted 06/08/10 02:37 AM

    Originally posted by: SystemAdmin


    It is the time to solve the LP relaxation, i.e. the time required to get the 2185 solution.
    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: A question about using Callback

    Posted 06/07/10 05:10 PM

    Originally posted by: SystemAdmin


    Hi Ashley,

    I think in your last question, you are also asking why the solution 2185.0000 is not accepted as the optimal solution. While this objective value is an integer (at least to four decimal places), the solution vector does not satisfy all integrality constraints of the problem. The column IInf reports the number of integer infeasibilities, in this case indicating that 57 of the integer variables in the problem take on non-integer values in the root node solution.

    Philip Starhill
    CPLEX Research Engineer
    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: A question about using Callback

    Posted 06/04/10 06:07 PM

    Originally posted by: SystemAdmin


    Sorry, the solving process stream can not be showed in correct format, since the reply input window is too narrow to show the whole piece, does anyone know how to change it to the correct format?
    #CPLEXOptimizers
    #DecisionOptimization


  • 16.  Re: A question about using Callback

    Posted 06/07/10 05:23 AM

    Originally posted by: SystemAdmin


    You can use the { code } ... { code } (without spaces) environment in your posts here for source code or log file output.

    What you are seeing in your log files is the progress that CPLEX makes at the root node of the search tree. The very first line shows the dual bound of the initial LP relaxation. Then you see some lines that indicate new primal solutions found by heuristics and some lines with new dual bounds that are obtained after adding cutting planes.

    Please read the user's manual about solving mixed integer problems. There you will find a section that explains what can be seen in the log file and what the various columns in the log mean.

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 17.  Re: A question about using Callback

    Posted 06/07/10 06:36 PM

    Originally posted by: SystemAdmin


    another question is still about the solution time, actually the reason that I want cplex to stop with LP solution is to save solution time. Since I saw the "root relaxation solution time" is always very small, I want cplex only use that small time and stop, so I tried to solve the problem like this way. But when I tried a bigger instance, I saw there is a gap between cplex really stop (getting LP solution) and the "Root relaxation solution time", the output is:

    here I use presolve to delete rows and columns.

    Presolve has eliminated 629184 rows and 236161 columns...
    Presolve has improved bounds 23232 times...
    Tried aggregator 2 times.
    MIP Presolve eliminated 638820 rows and 236161 columns.
    MIP Presolve modified 434676 coefficients.
    Aggregator did 2880 substitutions.
    Reduced MIP has 9483 rows, 3522 columns, and 38190 nonzeros.
    Presolve time =    6.88 sec.
    Clique table members: 8832
    MIP emphasis: balance optimality and feasibility
    Root relaxation solution time =    7.25 sec.
     
            Nodes                                         Cuts/ 
       Node  Left     Objective  IInf  Best Integer     Best Node    ItCnt     Gap         Variable B Parent  Depth
     
          0     0     4277.2222    99                   4277.2222    10994
    Elapsed time =  21.03 sec. (tree size =  0.00 MB)
     
    objective value (LP relaxation root node) is: 4277.45
    Test!
     ERROR: CPLEX Error  3017: No integer feasible solution exists.
     
    CPLEX error
    The Solving Time: 25
    Press any key to continue
    


    we can see that the "Root relaxation solution time = 7.25s." but cplex uses 25 s to stop, and here cplex only get one LP solution, so I want to know where the left 18 s are spent on? is there anyway that I can save these time up? since it is only a small instance, and only one iteration, if for large instance and lots of iteration, the saving time can be large. Thank you very much!
    #CPLEXOptimizers
    #DecisionOptimization


  • 18.  Re: A question about using Callback

    Posted 06/08/10 02:43 AM

    Originally posted by: SystemAdmin


    As you can see in the output 6.88 seconds are spent for presolve.
    The remaining time is probably for heuristics and cuts during the root node.
    Does your total time decrease if you disable both?

    To save time you could also disable presolve. But it is not clear if that will save time in the long run as presolving simplifies your problem and therefore usually speeds up the solution process.
    If you only want to solve the LP relaxation then it is best to follow Paul's suggestion and use IloConversion to turn your MIP into an LP.
    #CPLEXOptimizers
    #DecisionOptimization


  • 19.  Re: A question about using Callback

    Posted 06/08/10 03:39 PM

    Originally posted by: SystemAdmin


    I tried the IloConversion approach, but I had some errors during compiling, would you help me look at it? Thank you.

    the code is:
    typedef IloArray<IloNumArray>      IloNumArray2;
    IloEnv env;
    IloModel model(env);
    IloNumVarArray y_shelter(env, n, 0, 1, ILOINT);
    IloNumVarArray2 y_edge(env, o);
    for(i = 0; i < o; i++)
    z[i] = IloNumVarArray(env, o, 0, 1, ILOINT);
            
    vector<IloConversion> list;
     
    obj = ...;
    model.add(IloMinimize(env, obj));
    obj.end();
     
    IloCplex cplex(env);
     
    //~~~~~~~~~error happened here~~~~~~~~~~~~~~~~~~~~~~~~~~
    IloConversion relax = cplex.conversion(y, IloNumVarType.Float);  
    list.push_back(relax); 
    relax = cplex.conversion(z, IloNumVarType.Float);  
    list.push_back(relax); 
     
    for (i=0; i<list.size(); i++) 
         model.add(list.at(i)); 
     
    cplex.extract(model); 
    cplex.solve();
     
    for (i=0; i<list.size(); i++)
         list.at(i).end(); 
     
    IloCplex::clearModel;
    cplex.end();
    env.end();
    


    the error messages are:
    error C2039: 'Conversion' : is not a member of 'IloCplex'
    error C2065: 'IloNumVarType' : undeclared identifier
    error C2228: left of '.Float' must have class/struct/union type
    #CPLEXOptimizers
    #DecisionOptimization


  • 20.  Re: A question about using Callback

    Posted 06/08/10 03:39 PM

    Originally posted by: SystemAdmin


    I tried the IloConversion approach, but I had some errors during compiling, would you help me look at it? Thank you.

    the code is:
    typedef IloArray<IloNumArray>      IloNumArray2;
    IloEnv env;
    IloModel model(env);
    IloNumVarArray y_shelter(env, n, 0, 1, ILOINT);
    IloNumVarArray2 y_edge(env, o);
    for(i = 0; i < o; i++)
    z[i] = IloNumVarArray(env, o, 0, 1, ILOINT);
            
    vector<IloConversion> list;
     
    obj = ...;
    model.add(IloMinimize(env, obj));
    obj.end();
     
    IloCplex cplex(env);
     
    //~~~~~~~~~error happened here~~~~~~~~~~~~~~~~~~~~~~~~~~
    IloConversion relax = cplex.conversion(y, IloNumVarType.Float);  
    list.push_back(relax); 
    relax = cplex.conversion(z, IloNumVarType.Float);  
    list.push_back(relax); 
     
    for (i=0; i<list.size(); i++) 
         model.add(list.at(i)); 
     
    cplex.extract(model); 
    cplex.solve();
     
    for (i=0; i<list.size(); i++)
         list.at(i).end(); 
     
    IloCplex::clearModel;
    cplex.end();
    env.end();
    


    the error messages are:
    error C2039: 'Conversion' : is not a member of 'IloCplex'
    error C2065: 'IloNumVarType' : undeclared identifier
    error C2228: left of '.Float' must have class/struct/union type
    #CPLEXOptimizers
    #DecisionOptimization


  • 21.  Re: A question about using Callback

    Posted 06/08/10 03:58 PM

    Originally posted by: SystemAdmin


    Sorry, I thought you were using the Java API; C++ works a little differently. Try

    IloConversion relax = IloConversion(env, y, ILOFLOAT);
    


    (assuming y is a scalar variable -- I don't see it defined in your code).

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 22.  Re: A question about using Callback

    Posted 06/08/10 03:46 PM

    Originally posted by: SystemAdmin


    sorry post twice (the above two replies) by mistake.

    some typo for defining the variables' names at beginning, but it does not matter, the error happened at the place I pointed out in code.

    I tried to use arraylist, but there is some errors, so I changed it to vector, than the compilling error there disappeared, I hope it can also work when run the result.
    #CPLEXOptimizers
    #DecisionOptimization


  • 23.  Re: A question about using Callback

    Posted 06/08/10 03:47 PM

    Originally posted by: SystemAdmin


    there is no way to edit a reply's content, after it has been posted, right?
    #CPLEXOptimizers
    #DecisionOptimization


  • 24.  Re: A question about using Callback

    Posted 06/08/10 05:18 PM

    Originally posted by: SystemAdmin


    Paul, thanks. I changed the code, and it works very well.

    But it seems that cplex solve the problem as a pure LP after I adding IloConversion, and it took a long time to solve. But if cplex solve the MIP and stop after getting root node, it took a very short time. Thus, is there any approach that I can still solve MIP to get LP solution in root node, and extract those LP solutions out? Thanks.
    The output for MIP to get LP solution in root node is as follows:

    Presolve has eliminated 629184 rows and 236161 columns...
    Presolve has improved bounds 23232 times...
    Tried aggregator 2 times.
    MIP Presolve eliminated 638820 rows and 236161 columns.
    MIP Presolve modified 434676 coefficients.
    Aggregator did 2880 substitutions.
    Reduced MIP has 9483 rows, 3522 columns, and 38190 nonzeros.
    Presolve time =    6.88 sec.
    Clique table members: 8832
    MIP emphasis: balance optimality and feasibility
    Root relaxation solution time =    7.17 sec.
     
            Nodes                                         Cuts/ 
       Node  Left     Objective  IInf  Best Integer     Best Node    ItCnt     Gap         Variable B Parent  Depth
     
          0     0     4277.2222    99                   4277.2222    10994
    Elapsed time =  20.86 sec. (tree size =  0.00 MB)
     
    Master Problem's objective value (LP relaxation root node) is: 4277.45
    Test!
     ERROR: CPLEX Error  3017: No integer feasible solution exists.
     
    CPLEX error
    The Solving Time for MP: 24
    Press any key to continue
    

    The out put for solving LP is as follows:

    Tried aggregator 1 time.
    LP Presolve eliminated 4155 rows and 761276 columns.
    Reduced LP has 647028 rows, 241287 columns, and 3407901 nonzeros.
    Presolve time =    3.63 sec.
    Initializing dual steep norms . . .
     
    Iteration log . . .
    Iteration:     1   Dual objective     =           455.144991
    Perturbation started.
    Iteration:   203   Dual objective     =           455.144991
    Iteration:   800   Dual objective     =           455.144991
    Iteration:  1398   Dual objective     =           455.144991
    Iteration:  1991   Dual objective     =           455.144991
    Elapsed time =   11.00 sec. (2000 iterations).
    Iteration:  2564   Dual objective     =           455.144991
    Iteration:  3130   Dual objective     =           455.144991
    Iteration:  3754   Dual objective     =           455.144992
    Iteration:  4411   Dual objective     =           455.144992
    Iteration:  5030   Dual objective     =           455.144992
    Iteration:  5692   Dual objective     =           455.144992
    Elapsed time =   24.05 sec. (6000 iterations).
    Iteration:  6329   Dual objective     =           455.144992
    Iteration:  6857   Dual objective     =           455.144992
    Iteration:  7488   Dual objective     =           455.144993
    Iteration:  7987   Dual objective     =           455.144993
    Iteration:  8610   Dual objective     =           455.144993
    Elapsed time =   36.11 sec. (9000 iterations).
    Iteration:  9218   Dual objective     =           455.144993
    Iteration:  9720   Dual objective     =           455.144994
    Iteration: 10299   Dual objective     =           455.144994
    Iteration: 10801   Dual objective     =           455.144994
    Iteration: 11362   Dual objective     =           455.144994
    Iteration: 11772   Dual objective     =           455.144994
    Elapsed time =   50.22 sec. (12000 iterations).
    Iteration: 12242   Dual objective     =           455.144995
    Iteration: 12760   Dual objective     =           455.144995
    Iteration: 13264   Dual objective     =           455.144995
    Iteration: 13661   Dual objective     =           455.144995
    Elapsed time =   60.42 sec. (14000 iterations).
    Iteration: 14060   Dual objective     =           455.144995
    Iteration: 14460   Dual objective     =           455.144996
    Iteration: 14863   Dual objective     =           455.144996
    Iteration: 15262   Dual objective     =           455.144996
    Iteration: 15670   Dual objective     =           455.144996
    Elapsed time =   71.77 sec. (16000 iterations).
    Iteration: 16065   Dual objective     =           455.144997
    Iteration: 16465   Dual objective     =           455.144997
    Iteration: 16864   Dual objective     =           455.144997
    Iteration: 17256   Dual objective     =           455.144997
    Iteration: 17661   Dual objective     =           455.144997
    Elapsed time =   83.00 sec. (18000 iterations).
    Iteration: 18056   Dual objective     =           455.144998
    Iteration: 18461   Dual objective     =           455.144998
    Iteration: 18864   Dual objective     =           455.144998
    Iteration: 19264   Dual objective     =           455.144999
    Iteration: 19659   Dual objective     =           455.144999
    Elapsed time =   94.52 sec. (20000 iterations).
    Iteration: 20158   Dual objective     =           464.127523
    Iteration: 20759   Dual objective     =           500.197685
    Iteration: 21336   Dual objective     =           511.175561
    Iteration: 21746   Dual objective     =           511.175561
    Elapsed time =  126.06 sec. (22000 iterations).
    Iteration: 22178   Dual objective     =           511.175562
    Iteration: 22667   Dual objective     =           525.708590
    Elapsed time =  151.69 sec. (23000 iterations).
    Iteration: 23304   Dual objective     =           535.147496
    Iteration: 23968   Dual objective     =           538.043778
    Elapsed time =  196.41 sec. (24000 iterations).
    Iteration: 24642   Dual objective     =           543.448658
    Elapsed time =  248.28 sec. (25000 iterations).
    Iteration: 25425   Dual objective     =           550.995900
    Iteration: 25868   Dual objective     =           554.369167
    Elapsed time =  297.26 sec. (26000 iterations).
    Iteration: 26402   Dual objective     =           557.920950
    Elapsed time =  350.19 sec. (27000 iterations).
    Iteration: 27066   Dual objective     =           560.484157
    Iteration: 27947   Dual objective     =           564.147910
    Iteration: 28734   Dual objective     =           566.646747
    Elapsed time =  363.36 sec. (29000 iterations).
    Iteration: 29472   Dual objective     =           568.738011
    Iteration: 30285   Dual objective     =           574.254172
    Iteration: 30791   Dual objective     =           579.696674
    Iteration: 31854   Dual objective     =           591.009634
    Elapsed time =  377.42 sec. (32000 iterations).
    Iteration: 32437   Dual objective     =           596.365286
    Iteration: 33438   Dual objective     =           605.920841
    Iteration: 33798   Dual objective     =           615.149996
    Elapsed time =  389.05 sec. (34000 iterations).
    Iteration: 34515   Dual objective     =           616.433215
    Iteration: 35390   Dual objective     =           636.627524
    Iteration: 35950   Dual objective     =           636.863030
    Elapsed time =  403.48 sec. (36000 iterations).
    Iteration: 36947   Dual objective     =           668.773574
    Iteration: 37415   Dual objective     =           691.400193
    Elapsed time =  422.47 sec. (38000 iterations).
    Iteration: 38485   Dual objective     =           706.946073
    Elapsed time =  433.55 sec. (39000 iterations).
    Iteration: 39053   Dual objective     =           711.880955
    Iteration: 39462   Dual objective     =           717.867604
    Elapsed time =  448.66 sec. (40000 iterations).
    Iteration: 40202   Dual objective     =           747.217267
    Iteration: 41040   Dual objective     =           800.991198
    Iteration: 41928   Dual objective     =           819.383935
    Elapsed time =  468.19 sec. (42000 iterations).
    Iteration: 42418   Dual objective     =           819.383936
    Elapsed time =  483.73 sec. (43000 iterations).
    Iteration: 43075   Dual objective     =           840.308233
    Iteration: 43764   Dual objective     =           863.382038
    Elapsed time =  502.59 sec. (44000 iterations).
    Iteration: 44439   Dual objective     =           882.765401
    Iteration: 45181   Dual objective     =           913.524897
    Elapsed time =  519.56 sec. (46000 iterations).
    Iteration: 46078   Dual objective     =           935.614669
    Iteration: 46406   Dual objective     =           945.117793
    Iteration: 47079   Dual objective     =           954.346913
    Iteration: 47933   Dual objective     =           962.265521
    Elapsed time =  535.11 sec. (48000 iterations).
    Iteration: 48834   Dual objective     =           974.819516
    Elapsed time =  545.78 sec. (49000 iterations).
    Iteration: 49369   Dual objective     =           976.792648
    Elapsed time =  557.56 sec. (50000 iterations).
    Iteration: 50441   Dual objective     =           979.556498
    Elapsed time =  573.30 sec. (51000 iterations).
    Iteration: 51015   Dual objective     =           985.480436
    Iteration: 51851   Dual objective     =           989.277730
    Elapsed time =  592.11 sec. (52000 iterations).
    Iteration: 52845   Dual objective     =           997.640274
    Elapsed time =  609.78 sec. (53000 iterations).
    Iteration: 53412   Dual objective     =          1000.115813
    Elapsed time =  623.70 sec. (54000 iterations).
    Iteration: 54302   Dual objective     =          1005.103449
    Iteration: 54524   Dual objective     =          1007.738138
    Elapsed time =  642.70 sec. (55000 iterations).
    Iteration: 55229   Dual objective     =          1011.468584
    Elapsed time =  658.98 sec. (56000 iterations).
    Iteration: 56096   Dual objective     =          1014.691906
    Iteration: 56691   Dual objective     =          1017.555787
    Elapsed time =  677.47 sec. (57000 iterations).
    Iteration: 57283   Dual objective     =          1017.829990
    Elapsed time =  688.55 sec. (58000 iterations).
    Iteration: 58389   Dual objective     =          1018.505012
    Iteration: 58823   Dual objective     =          1022.404906
    Elapsed time =  698.63 sec. (59000 iterations).
    Iteration: 59531   Dual objective     =          1026.579740
    Elapsed time =  712.69 sec. (60000 iterations).
    Iteration: 60479   Dual objective     =          1031.111772
    Iteration: 60913   Dual objective     =          1047.336122
    Elapsed time =  728.16 sec. (61000 iterations).
    Iteration: 61741   Dual objective     =          1057.632392
    Elapsed time =  743.53 sec. (62000 iterations).
    Iteration: 62452   Dual objective     =          1064.304185
    Iteration: 62932   Dual objective     =          1069.534720
    Elapsed time =  758.78 sec. (63000 iterations).
    Iteration: 63812   Dual objective     =          1084.547497
    Elapsed time =  772.72 sec. (64000 iterations).
    Iteration: 64416   Dual objective     =          1087.997487
    Elapsed time =  784.45 sec. (65000 iterations).
    Iteration: 65457   Dual objective     =          1097.822139
    Iteration: 65997   Dual objective     =          1098.990910
    Elapsed time =  799.75 sec. (66000 iterations).
    Iteration: 66741   Dual objective     =          1110.122537
    Elapsed time =  815.55 sec. (67000 iterations).
    


    we can see it used 20's sec to solve MIP root node, but used 800's sec still can not finish LP, since MIP can delete more columns and rows in presolve, so I wonder is there any method I can solve MIP root node, and extract the LP solutions. Thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 25.  Re: A question about using Callback

    Posted 06/08/10 05:47 PM

    Originally posted by: SystemAdmin


    It appears from the output that your LP may be highly degenerate, and that the degeneracy is mitigated in the root node of the MIP because the MIP presolver eliminates much of it. (I'm not positive about that, but that's what I think I see in the output.)

    Which brings us back to the question of why you need the solution to the LP relaxation without the MIP reductions (in other words, why the solution to the LP relaxation at the root node of the MIP is not sufficient). If you really need to solve the LP without the MIP presolve reductions, then you will need to investigate ways to deal with the degeneracy (if I'm right about it being degenerate). Maybe you should try the barrier method on the LP?

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 26.  Re: A question about using Callback

    Posted 06/08/10 10:42 PM

    Originally posted by: SystemAdmin


    actually, I am looking for a method which can get the LP solutions very fast, not only the value of objective function but also the solutions values.

    I tried 2 methods: first, solve LP by adding IloConversion; second, solve MIP and let it stop after getting LP solution at root node

    the first method uses a long time to solve

    the second method can solve quickly, but I can not extract the solutions out, I can only get the value for objective function, but can not get the values for variables (i.e. x, y)

    do you know which method I can use to get what I need? I mean to get LP solutions of a MIP very fast, get both of objective value and solutions values.

    thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 27.  Re: A question about using Callback

    Posted 06/09/10 02:33 AM

    Originally posted by: SystemAdmin


    In the second method you can use a cut callback to extract the solution.
    When the callback is invoked for the first time just read out the solution using getValues() (it is the solution to the current LP) and then call CallbackI.abort().
    #CPLEXOptimizers
    #DecisionOptimization


  • 28.  Re: A question about using Callback

    Posted 06/09/10 11:58 AM

    Originally posted by: SystemAdmin


    Hi Danial, do you have some sample code for using cut callback to do that? thank you.
    #CPLEXOptimizers
    #DecisionOptimization


  • 29.  Re: A question about using Callback

    Posted 06/10/10 04:01 AM

    Originally posted by: SystemAdmin


    Here is an example I already posted in a different thread. It uses a branch-callback instead of a cut-callback, so it stops after the root node is complete. If you replace the branch-callback by a cut-callback it should stop the program right after the LP relaxation is solved.
    #include <vector>
    #include <cstring>
    #include <iostream>
    #include <ilcplex/ilocplex.h>
     
    #define NEWER_CPLEX_VERSION
     
    // The callback.
    // This implements a branch callback that stops the optimization the first
    // time it is invoked. Before it stops the optimization it reads out all
    // variable values at the current node (the root node) to store the
    // x vector of the LP relaxation.
    struct Callback : public IloCplex::BranchCallbackI {
       IloNumVarArray *const vars;
       std::vector<double> *const vals;
       double *const objval;
     
       Callback(IloEnv env, IloNumVarArray *ivars, std::vector<double> *ivals,
                double *iobjval)
    #if defined (NEWER_CPLEX_VERSION)
          : IloCplex::BranchCallbackI(env),
    #else
          : IloCplex::BranchCallbackI(),
    #endif
            vars(ivars),
            vals(ivals),
            objval(iobjval)
       {
       }
     
       Callback(Callback const& cp)
    #if defined (NEWER_CPLEX_VERSION)
          : IloCplex::BranchCallbackI(cp.getEnv()),
    #else
          : IloCplex::BranchCallbackI(*this),
    #endif
            vars(cp.vars),
            vals(cp.vals),
            objval(cp.objval)
       {
       }
     
       IloCplex::CallbackI *duplicateCallback() const {
          return new (getEnv()) Callback(*this);
       }
     
       void main() {
          // Read values of root relaxation, then stop.
          vals->clear();
          for (int i = 0; i < vars->getSize(); ++i)
             vals->push_back(getValue((*vars)[i]));
          *objval = getBestObjValue();
          IloCplex::BranchCallbackI::abort();
       }
    };
     
    int
    main(int argc, char **argv)
    {
       for (int i = 1; i < argc; ++i) {
          IloEnv env;
          try {
             IloModel model(env);
             IloCplex cplex(model);
     
             // Pull in model from file and store all variables in an array.
             cplex.importModel(model, argv[i]);
             IloNumVarArray vars(env);
    #if defined (NEWER_CPLEX_VERSION)
             for (IloModel::Iterator it(cplex.getModel()); it.ok(); ++it) {
                if ( (*it).isVariable() )
                   vars.add((*it).asVariable());
             }
    #else
             for (IloModel::Iterator it(model); it.ok(); ++it) {
                IloNumVarI *test = dynamic_cast<IloNumVarI*>((*it).getImpl());
                if ( test ) {
                   // Indeed a variable!
                   vars.add(IloNumVar(test));
                }
             }
    #endif
     
             // The array that will store the x vector of the root relaxation.
             std::vector<double> vals;
             double objval;
     
             cplex.use(new (env) Callback(env, &vars, &vals, &objval));
             if ( cplex.solve() ) {
                if ( vals.size() == 0 ) {
                   // The callback was not invoked, i.e. the problem
                   // was solved to optimality in the root node. We can read
                   // the values directly from CPLEX.
                   for (int i = 0; i < vars.getSize(); ++i)
                      vals.push_back(cplex.getValue(vars[i]));
                   objval = cplex.getBestObjValue();
                }
     
                std::cout << "Relaxation/optimal values for " << argv[i]
                          << " (" << objval << "):"
                          << std::endl;
                for (int j = 0; j < vars.getSize(); ++j) {
                   std::cout << "\t" << vars[j].getName() << ": " << vals[j]
                             << " \t(" << vars[j].getType() << ")"
                             << std::endl;
                }
             }
          } catch (IloException& e) {
             std::cerr << "Exception: " << e << std::endl;
          }
          env.end();
       }
    }
    

    If you use a very old version of CPLEX and the code does not compile then undefine NEWER_CPLEX_VERSION.
    #CPLEXOptimizers
    #DecisionOptimization


  • 30.  Re: A question about using Callback

    Posted 07/12/11 02:42 PM

    Originally posted by: an_drade


    Hi Daniel!

    Your code is very useful, but I have a problem yet. I want to solve the root node, with all heuristics and cuts turned on, for a particular time, for example, 2s. So, we can obtain a tighter formulation/relaxation. I need to extract the LP relaxation.

    I have been tried to use the branch callback (and others) but unfortunately this method doesn't work. When the time is vanished, Cplex doesn't call the branch callback, and returns only the best integer solution (using getValues()). I have been looked for solution in others threads, but I couldn't find one.

    Could you help?

    My best regards,

    Carlos Eduardo
    #CPLEXOptimizers
    #DecisionOptimization


  • 31.  Re: A question about using Callback

    Posted 07/12/11 02:45 PM

    Originally posted by: SystemAdmin


    The cuts are added to the nodelp, which lives in the presolved model space. Because Concert (and thus the C++ API) works exclusively on the original model, you cannot access the cuts added by CPLEX through the C++ API. If you want to do this, then you need to use the C API instead. There, you can add a cut callback and query the nodelp, which contains the cuts.

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 32.  Re: A question about using Callback

    Posted 07/12/11 05:10 PM

    Originally posted by: an_drade


    Hi Tobias,

    Thank you for your response. In fact, I want only the variables' values of a LP relaxation after optimizing the first node. I hope that cplex tighting the model as much as possible in a particular time (1s or 2s), and I want take the relaxation values of this optimization. I will feed an heuristic with this values. I don't care about the generated cuts.

    I have been tried several types of callbacks but none can handle the event where the maximum time is reached and optimization stops.

    I tried to optimization twice the same model (only first node). The first optimization is done over the MIP model. So, cplex put a lot of cuts and finish in maximum time. After this, I tried to relax the variables using "model.add(IloConversion(env, variables, ILOFLOAT))" and reoptimize. But, unfortunataly, cplex doesn't keep the generated cuts in first optimization. "solveFixed()" doesn't work to.

    In resume, I'm looking for a method to get relaxation values from the first node after its optimization.

    My best regards,

    Carlos
    #CPLEXOptimizers
    #DecisionOptimization


  • 33.  Re: A question about using Callback

    Posted 07/13/11 03:09 AM

    Originally posted by: SystemAdmin


    This should be very simple to do. The heuristic callback and the cut callback are called at every iteration of the root cutting plane loop. And from these callbacks you are able to access the current LP solution.

    Of course it could be that the problem is so hard to solve that in 1-2 seconds CPLEX does not even reach the root cutting plane loop (presolving, probing, and the solving of the initial root LP taking too long). In this case, you have bad luck and the only thing you can do is to change parameter settings in the hope to be able to solve the root LP faster (for example, by using barrier as start algorithm).

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 34.  Re: A question about using Callback

    Posted 07/13/11 09:15 AM

    Originally posted by: an_drade


    Thank you Tobias. Heuristic callback works fine to me. Instead of using time limit, I will use a iteration limit, implementing a "time/iteration limit" callback.

    Sorry to bore you and, again, thank you very much.

    Carlos
    #CPLEXOptimizers
    #DecisionOptimization