Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Flag for integer solutions within the cutcallback ?

    Posted 03/15/11 05:57 AM

    Originally posted by: S.U.N.


    Hello,

    I use cplex callbacks to implement branch-and-cut algorithms in C and so far it works very well.

    In a post about "repeated incumbent", you stated that: "If the LP relaxation solution is integral, then first the cut callback is called and then, if no cuts have been generated, the incumbent callback is called."

    I have a new cut-generation procedure "SunCutGen" that inputs only INTEGER solutions. If I understand correctly, this should be implemented within the user cutcallback: with an "if" condition that checks if the node-solution is integer before applying "SunCutGen" (which will identify and add violated cuts).

    Therefore, my question is the following: how can I check if the solution is integer?

    ( I could read the current solution with "CPXgetcallbacknodex", then to check the value of each variable, but I suspect it would be too time-consuming.)

    Is there another way? (with a flag maybe? The same cplex probably uses to know when to call the incumbentcallback for example?)
    Best regards,

    S.U.N.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Flag for integer solutions within the cutcallback ?

    Posted 03/15/11 10:16 AM

    Originally posted by: SystemAdmin


    Take a look at CPXgetcallbacknodeinfo with whichinfo=CPX_CALLBACK_INFO_NODE_NIINF.

    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


  • 3.  Re: Flag for integer solutions within the cutcallback ?

    Posted 03/15/11 12:07 PM

    Originally posted by: S.U.N.


    Thank you for your reply,

    Just to confirm, I should use:

    • "status = CPXgetnodecallbackinfo(current_env, current_lp, wherefrom, 0, CPX_CALLBACK_INFO_NODE_NIINF, &nbinf)"
    • if (nbinf == 0) then (the current solution is integer)?

    Is it correct?

    SUN
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Flag for integer solutions within the cutcallback ?

    Posted 03/15/11 04:16 PM

    Originally posted by: SystemAdmin


    > S.U.N. wrote:

    >
    > Just to confirm, I should use:
    >
    > - "status = CPXgetnodecallbackinfo

    CPXgetcallbacknodeinfo

    >(current_env, current_lp,

    Correct if this was the "cbdata" argument used to set up the callback.

    > wherefrom, 0,

    0 if you want the number of infeasibilities at the root node. For the current node, get the index of the current node by calling CPXgetcallbacknodeinfo with whichinfo=CPX_CALLBACK_INFO_NODE_NODENUM.

    > CPX_CALLBACK_INFO_NODE_NIINF, &nbinf)"
    > - if (nbinf == 0) then (the current solution is integer)?

    Yes.

    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: Flag for integer solutions within the cutcallback ?

    Posted 03/15/11 08:43 PM

    Originally posted by: S.U.N.


    >> wherefrom, 0,

    >0 if you want the number of infeasibilities at the root node. For the current node, get the index of the current node by calling CPXgetcallbacknodeinfo with whichinfo=CPX_CALLBACK_INFO_NODE_NODENUM.

    How to obtain the index of the current node with "CPXgetcallbacknodeinfo" since it seems to require the node index as an input ?

    • status = CPXgetcallbacknodeinfo(current_env, current_lp, wherefrom, ?????, CPX_CALLBACK_INFO_NODE_NODENUM, &current_nodeindex).

    What should I replace "?????" with? 0 maybe?

    SUN
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Flag for integer solutions within the cutcallback ?

    Posted 03/16/11 08:28 AM

    Originally posted by: SystemAdmin


    From the reference documentation of CPXgetcallbacknodeinfo():

    To query the current node, specify a nodeindex value of 0. Other values of the wherefrom argument are invalid for this routine. An invalid nodeindex value or wherefrom argument value will result in an error return value.
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Flag for integer solutions within the cutcallback ?

    Posted 03/17/11 08:19 AM

    Originally posted by: S.U.N.


    Thank you for your reply,

    I read in detail the documentation, and my understanding is that I should use:


    static int CPXPUBLIC MyCutCallBack (CPXCENVptr env, void *cbdata,int wherefrom, void *cbhandle, int *useraction_p)
    {
    int status, nodeindex, nbinf;

    *useraction_p = CPX_CALLBACK_DEFAULT;

    status = CPXgetcallbacknodeinfo (env, cbdata, CPX_CALLBACK_MIP_CUT, 0, CPX_CALLBACK_INFO_NODE_NODENUM, &nodeindex);
    //To get the node index

    status = CPXgetcallbacknodeinfo(env, cbdata, CPX_CALLBACK_MIP_NODE, nodeindex, CPX_CALLBACK_INFO_NODE_NIINF, &nbinf) ;
    // to get the number of infeasibilities = fractionnal variables

    if (nbinf == 0)
    {
    // (The current Solution is integer)
    }
    }

    However:
    • the value of wherefrom is always 106 within MyCutCallBack (at least in the tests I ran)
    • I still cannot retrieve the nodeindex: CPXgetcallbacknodeinfo gives an error 1003 and does not give the right value to "nodeindex".
    SUN
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Flag for integer solutions within the cutcallback ?

    Posted 03/17/11 09:00 AM

    Originally posted by: SystemAdmin


    Hm, I think you only need this:
    status = CPXgetcallbacknodeinfo(env, cbdata, CPX_CALLBACK_MIP_NODE, 0, CPX_CALLBACK_INFO_NODE_NIINF, &nbinf) ;
    

    There is no need to query the node sequence number. Have you tried that?
    wherefrom=106 is CPX_CALLBACK_MIP_CUT, so that looks good for a cut callback. Error 1003 is CPXERR_BAD_ARGUMENT, for which of the two calls to CPXgetcallbacknodeinfo() do you get that?
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Flag for integer solutions within the cutcallback ?

    Posted 03/17/11 09:57 AM

    Originally posted by: S.U.N.


    > Hm, I think you only need this:
    > status = CPXgetcallbacknodeinfo(env, cbdata, CPX_CALLBACK_MIP_NODE, 0, CPX_CALLBACK_INFO_NODE_NIINF, &nbinf) ;
    > There is no need to query the node sequence number. Have you tried that?

    I just did, but then I obtained "nbinf = -1".
    Then I replaced "CPX_CALLBACK_MIP_NODE" with "wherefrom" and it seemed to give the right value, at least for the root node (still need to check what happens on instance large enough to require the exploration of more than a single node, I will confirm if it works).

    > Error 1003 is CPXERR_BAD_ARGUMENT, for which of the two calls to CPXgetcallbacknodeinfo() do you get that?

    That error happened for the first call to CPXgetcallbacknodeinfo(), when I tried to get the nodeindex.
    SUN
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Flag for integer solutions within the cutcallback ?

    Posted 03/17/11 10:05 AM

    Originally posted by: SystemAdmin


    Sorry, my fault. I just copy/pasted your code into mine without paying enough attention.
    You are right, the wherefrom argument to CPXgetcallbacknodeinfo() should always be the wherefrom you got from CPLEX when your callback was invoked.
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Flag for integer solutions within the cutcallback ?

    Posted 03/17/11 01:26 PM

    Originally posted by: S.U.N.


    Just to confirm that "status = CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0, CPX_CALLBACK_INFO_NODE_NIINF, &nbinf);" works fine. It does give the number of fractional variables of the current node (even if we are not at the root node), which is what I needed.

    Thank you for all your help !

    Best regards,

    SUN
    #CPLEXOptimizers
    #DecisionOptimization