Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

a strange thing when writing root node LP to .lp file

  • 1.  a strange thing when writing root node LP to .lp file

    Posted Thu June 17, 2010 11:50 PM

    Originally posted by: QiuFeng


    Hello everyone,
    I have a MIP, somehow I need to write the model into .lp file in cut callback. I use the following statement in cut callback to get node lp

    CPXgetcallbacknodelp(env, cbdata, wherefrom, &nodelp_p);
    


    then I use
    CPXwriteprob(env, lp, "rootnodelp.lp",NULL);
    


    to write the node lp into a file.

    The strange thing is that, when I open the .lp file, the bound section beomes:

    Bounds
    z0 = 0
    z1 = 1
    z2 = 0
    z3 = 0

    It looks that all these binaries has been fixed to 0 or 1. The callback is called when solving root node, so the .lp file should record a LP model--the LP relaxation of MIP model. I know CPLEX will do some domain reduction, however, those binaries shouldn't be fixed at this time. Here I attached the file I wrote in cut callback.

    Thanks in advance!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: a strange thing when writing root node LP to .lp file

    Posted Fri June 18, 2010 01:32 AM

    Originally posted by: SystemAdmin


    Is this just a typo or did you really write out 'lp' instead of 'nodelp_p'?
    Can you please also provide the original model, i.e. the one you attempt to solve?
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: a strange thing when writing root node LP to .lp file

    Posted Fri June 18, 2010 11:41 AM

    Originally posted by: QiuFeng


    Hi Denial, it's not a typo, nodelp_p was passed to other function, in which the CPXlpptr has the name 'lp'.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: a strange thing when writing root node LP to .lp file

    Posted Fri June 18, 2010 11:24 AM

    Originally posted by: SystemAdmin


    Did you turn off the presolver? If not, it might have fixed some bounds.

    /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


  • 5.  Re: a strange thing when writing root node LP to .lp file

    Posted Fri June 18, 2010 11:42 AM

    Originally posted by: QiuFeng


    hi Paul, here is my parameter settings:
    originalModel.setCPXParameter(CPX_PARAM_PRELINEAR, CPX_OFF);
            originalModel.setCPXParameter(CPX_PARAM_MIPCBREDLP, CPX_OFF);
            originalModel.setCPXParameter(CPX_PARAM_PREIND, CPX_OFF);
            originalModel.setCPXParameter(CPX_PARAM_NUMERICALEMPHASIS, CPX_ON );
    


    thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: a strange thing when writing root node LP to .lp file

    Posted Fri June 18, 2010 11:53 AM

    Originally posted by: SystemAdmin


    I'm never sure which parameters turn off which other parameters (if any), so here are a couple more you might want to switch off:

    CPX_PARAM_PRESLVND (presolving of nodes in the MIP tree -- might include the root node)
    CPX_PARAM_RELAXPREIND (LP presolve of the root relaxation).

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: a strange thing when writing root node LP to .lp file

    Posted Fri June 18, 2010 11:13 PM

    Originally posted by: QiuFeng


    Hi Paul:
    Thanks for your response. I turned off the parameters you suggested, it didn't work either.

    I found some pattern here. When the cut callback is executed for the first time, the node lp written into the file( attached in my first post ) looks strange: every binary is fixed. However, when the cut callback is called for the second time third time and so on, the node lp looks "correct", like the file attached to this post.

    Is this a normal behavior of CPLEX or Did I misunderstand anything? Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: a strange thing when writing root node LP to .lp file

    Posted Sat June 19, 2010 11:36 AM

    Originally posted by: SystemAdmin


    Something is clearly wrong with the node LP that you attached to your original message. I compared it to the MIP model you attached to a subsequent message, and they agree except that (a) the integrality restrictions on the z variables (the "Generals" section) is missing from the LP model, which is what we expect, and (b) the MIP model simply assigns lower bounds of 0 to the z variables, whereas as you noted the LP model fixes all of them to 0 or 1. Moreover, they are fixed to a suboptimal solution. For instance, z14 is fixed at 1; but the optimal solution to the MIP (objective value 40.2) has z14 = 0, and if you force z14 = 1 the objective value of the MIP increases to 40.85.

    There are various reductions done by presolve etc. that can fix some integer variables, but it is extremely unlikely they would fix all the integer variables. About the only way I know to do that other than by a lot of luck in the presolving stage is to convert the problem type from 'milp' to 'fixed_milp'. You did not invoke CPXchgprobtype at any point, did you?

    In any case, the fact that the z variables are fixed to a suboptimal solution is quite strange.

    /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 strange thing when writing root node LP to .lp file

    Posted Sat June 19, 2010 05:39 PM

    Originally posted by: SystemAdmin


    Everything looks as if the nodelp stores a heuristic solution. But calling the cut callback for a heuristic solution would be a bug, I think. Could you please check whether you get the same strange behavior if you disable heuristics by setting the CPX_PARAM_HEURFREQ parameter to -1?

    Thanks,

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: a strange thing when writing root node LP to .lp file

    Posted Sat June 19, 2010 11:48 PM

    Originally posted by: QiuFeng


    Hi Tobias:
    Thanks for your response. I turned off the heuristic and found that the model file has a much smaller 'bound' section-- only one line. Those fixed binaries are gone. I guess, since the heuristic is turned off, no feasible solution is found after the first LP solving. so that part is gone. But I think the 'z >= 0' part should not be missing in a model file. From what we observed so far, CPXwriteprob seems to write down a feasible solution here.

    One more thing: I printed out the solution using CPXgetx, it gives me an integer solution(the solution is just the values I saw in the model file, I attached the solution file to this post). My cuts rely on the fractional solution and the corresponding tableau.

    With all these observed, can we tentatively say that this is a bug?

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: a strange thing when writing root node LP to .lp file

    Posted Sat June 19, 2010 11:48 PM

    Originally posted by: QiuFeng


    Hi Tobias:
    Thanks for your response. I turned off the heuristic and found that the model file has a much smaller 'bound' section-- only one line. Those fixed binaries are gone. I guess, since the heuristic is turned off, no feasible solution is found after the first LP solving. so that part is gone. But I think the 'z >= 0' part should not be missing in a model file. From what we observed so far, CPXwriteprob seems to write down a feasible solution here.

    One more thing: I printed out the solution using CPXgetx, it gives me an integer solution(the solution is just the values I saw in the model file, I attached the solution file to this post). My cuts rely on the fractional solution and the corresponding tableau.

    With all these observed, can we tentatively say that this is a bug?

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: a strange thing when writing root node LP to .lp file

    Posted Sun June 20, 2010 01:04 PM

    Originally posted by: SystemAdmin


    > QiuFeng wrote:
    > Hi Tobias:
    > Thanks for your response. I turned off the heuristic and found that the model file has a much smaller 'bound' section-- only one line. Those fixed binaries are gone. I guess, since the heuristic is turned off, no feasible solution is found after the first LP solving. so that part is gone. But I think the 'z >= 0' part should not be missing in a model file. From what we observed so far, CPXwriteprob seems to write down a feasible solution here.

    No, CPXwriteprob does not write a feasible solution. The bug is most probably that for a solution candidate found by a heuristic, we call the cut callback (instead of the incumbent callback). Then the cut callback would see the nodelp to be temporarily fixed to the solution candidate.

    > With all these observed, can we tentatively say that this is a bug?

    Yes, I think so. Could you explain again in detail what you are doing to get this behavior? Is it just to install the cut callback (that just gets the nodelp and stores it to disk as *.lp file), read in the mode, and call CPXmipopt()?

    Would it be possible for you to send a small example program that shows the behavior, removing everything from your code that is not needed to trigger the bug?

    Which CPLEX version are you using?
    Thanks,

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: a strange thing when writing root node LP to .lp file

    Posted Sun June 20, 2010 05:12 PM

    Originally posted by: QiuFeng


    Hi Tobias:
    My purpose is to get the fractional solution and tableau to calculate cuts. What I did is just install cut callback and write the node lp to file. I'm using CPLEX 112. Here I wrote down a sample code quickly, it can repeat the behavior in my project. originalModelMIP.lp is the MIP model file and attached to this post again. the root node file will be written into the file node.lp. When the first time callback is called, you will find that vars are fixed in node.lp.

    Thanks for your help!

    static int CPXPUBLIC 
    myCutCallbackIC (CPXCENVptr env,
                                     void       *cbdata,
                                     int        wherefrom,
                                     void       *cbhandle,
                                     int        *useraction_p)
     
    {
     
            int* node_seq = new int;
            CPXgetcallbacknodeinfo( env,  cbdata, wherefrom, 0 /*nodeindex*/, CPX_CALLBACK_INFO_NODE_SEQNUM,  (void*)node_seq);
            cout << "CPX_CALLBACK_INFO_NODE_SEQNUM: "<< *node_seq << endl;
     
            if (*node_seq == 0)//root node
            {
                    CPXLPptr    nodelp_p ;
     
                    CPXgetcallbacknodelp(env, cbdata, wherefrom, &nodelp_p);
                    CPXwriteprob(env, nodelp_p, "node.lp", NULL);
            }
            else{// non-root node
            }
     
            *useraction_p = CPX_CALLBACK_SET;
            return 0;
     
    }
     
     
     
    int main(int argc,char *argv[])
    {
     
     
            CPXENVptr t_env = NULL;
            int           status = 0;
     
            /* Initialize the CPLEX environment */
            t_env = CPXopenCPLEX (&status);
     
            if ( t_env == NULL ) {
                    char  errmsg[1024];
                    fprintf (stderr, "Could not open CPLEX environment.\n");
                    CPXgeterrorstring (t_env, status, errmsg);
                    fprintf (stderr, "%s", errmsg);
                    return 0;
            }
     
            /* Turn on output to the screen */
            status = CPXsetintparam (t_env, CPX_PARAM_SCRIND, CPX_ON);
            if ( status ) {
                    fprintf (stderr, 
                            "Failure to turn on screen indicator, error %d.\n", status);
                    return 0;
            }
     
     
            CPXLPptr t_lp = CPXcreateprob (t_env, &status, "test");
            if ( t_lp == NULL ) {
                    fprintf (stderr, "Failed to create LP.\n");
                    return 0;
            }
     
            CPXreadcopyprob(t_env, t_lp, "originalModelMIP.lp", NULL);
     
            status = CPXsetintparam(t_env, CPX_PARAM_PRELINEAR, CPX_OFF); 
            status = CPXsetintparam(t_env, CPX_PARAM_MIPCBREDLP, CPX_OFF); 
            status = CPXsetintparam(t_env, CPX_PARAM_PREIND, CPX_OFF); 
            status = CPXsetintparam(t_env, CPX_PARAM_NUMERICALEMPHASIS, CPX_ON); 
            status = CPXsetcutcallbackfunc(t_env, myCutCallbackIC, NULL);
            status = CPXmipopt (t_env, t_lp);
     
     
            return 0; 
    }
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: a strange thing when writing root node LP to .lp file

    Posted Mon June 21, 2010 12:10 PM

    Originally posted by: SystemAdmin


    Sorry for the confusion. The behavior is not a bug. The nodelp comes indeed from a heuristic, and the cut callback is called to check whether the solution is indeed feasible.

    In your cut callback, you need to take into account that you will also have to deal with such fixed nodelps that you should check for feasibility. If your cut callback does not model any lazy constraints (i.e., every integer solution that is feasible for the LP and does not violate any lazy constraints that you have explicitly added to the model in advance is indeed feasible), then you can just ignore these fixed nodelps and do nothing in your cut callback.

    How to find out whether you are called for a heuristic solution or for a "true" LP relaxation? Unfortunately, the 'wherefrom' does not tell you anything. You could check the local bounds of the integer variables. If at least one of them is not fixed, you are in the "true LP relaxation" case.
    Hope this helps...

    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: a strange thing when writing root node LP to .lp file

    Posted Mon June 21, 2010 06:10 PM

    Originally posted by: QiuFeng


    Hi Tobias:
    Thanks for the explanation. It makes sense. I printed out the bounds of the binaries in the cut callback where I get a model file with fixed vars, the lower bound equals upper bound.

    Since the model file is just a heuristic solution, the tableau here doesn't make any sense, is this correct?

    In order to check if integer vars are all fixed, I could use CPXgetcallbacknodelb and CPXgetcallbacknodeub to get both upper bounds and lower bounds and compare them, But I'm wondering if there is a CPEX function that I can use to do the job more efficiently?

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 16.  Re: a strange thing when writing root node LP to .lp file

    Posted Sat June 19, 2010 06:44 PM

    Originally posted by: QiuFeng


    Hi Paul:
    Thanks for looking into this. As you pointed out, when the first time cut callback is called, CPXwriteprob seems to write down a feasible solution. But CPXwriteprob is supposed to write down a model, not a solution.

    I didn't use CPXchgprobtype. Even the problem type was changed, I shouldn't get a model file in which binaries are fixed to integers.

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization