Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  help with branch and bound callbacks

    Posted 05/17/10 10:59 PM

    Originally posted by: QiuFeng


    Recently I'm doing some computation that needs to embed my cut-generating code in the branch and bound process.I read the manual about cut callback, but I'm not sure if I got it correctly, I would like to ask help here, Please correct me if I'm wrong, thank you all!

    I need to add 2 type of cuts, I'm not sure which callbacks I should use for them.
    A: The first type of cuts are added after a binary variable is fixed, so I want to know
    1, which binaries are fixed at what value in this node, (I have no idea about this)
    2, which callback I should use to add cut at this moment(before this node is solved) ?(should I use CPXsetnodecallbackfunc? )
    B: The second type of cuts are added after a node LP is solved, I want to add a cut to this LP and solve it again. my question is that
    1, which callback I should use to add cut? (should I use CPXgetsolvecallbackfunc? and in the callback, should I use CPXgetcallbacknodelp to get the node LP and add cut to it? )
    2, after adding cut, should I just just call CPXlpopt to solve the LP obtained by CPXgetcallbacknodelp ? After solving, do I have to do anything to return the node LP to branch and bound process?

    The above is my understanding. Please correct me if I didn't get it right, thank you very much!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: help with branch and bound callbacks

    Posted 05/18/10 01:32 AM

    Originally posted by: SystemAdmin


    For part A please look at this thread. It explains how to know on which variable you branched in a cut callback. The examples in the thread are for Concert but usage of callbacks is pretty much the same in the C API.

    In part A, if you want to add the cut before CPLEX even attempts to solve the node LP then what you are doing is in fact a more general branching strategy. In this case you should add the cuts at branch creation time using a branch callback. In the branch callback you could query what branches CPLEX would create. Then you can create these branches but augment them with your cuts.

    For part B use a cut callback. CPLEX will invoke the cut callback during the solve of a node. From the cut callback function you can add cuts via functions CPXcutcallbackadd() and CPXcutcallbackaddlocal(). If you add at least one cut from this callback CPLEX will resolve the nodelp and invoke your callback again.
    And yes, CPXgetcallbacknodelp() is the correct function to get the LP relaxation at the current node.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: help with branch and bound callbacks

    Posted 05/21/10 12:09 PM

    Originally posted by: QiuFeng


    Hi Daniel:
    Thanks for your reply. It took me much time to to read link:this thread since I'm not familiar with Java. I still have some questions before starting experimenting

    1, in that thread, it seems that they first get the branch information and record it, then retrieve this information later in cut callback. To record which variables are branched on, it seems that I can use CPXsetbranchcallbackfunc to set the callback function, in which I can write the information into the address designated by the parameter "cbhandle". However, I don't know how to match this information with the sub-nodes created at this branch when cut callback is called later.

    2, "In the branch callback you could query what branches CPLEX would create. Then you can create these branches but augment them with your cuts."
    • I know how to query, but I don't know how to augment the branches with my cuts. Since in branch callback, what we could do is to choose the variables to branch on. it seems that we can not add cut at this time since the sub node LP hasn't been created at this time. Am I correct here? And I don't want to modify the branch process, all I need to do is just to add a cut immediately after a binary variable is fixed at 1.

    3. I read the manual about Concert callback, I like the way Concert organizes all related functions together. I found NodeCallbackI::getBranchVar seems to be the one I need: at every node, I can check which variables was just branched by calling getBranchVar, then I can add a cut before this node is solved. To do the same thing in C version, I need to:
    use CPXsetnodecallbackfunc to set my callback. In my callback, use CPXgetcallbacknodeinfo to check CPX_CALLBACK_INFO_NODE_VAR to find out which variable is just fixed. Then use CPXgetcallbacknodelp to access the node LP and add cut to this node LP. Am I correct here?

    Thanks again for your help!
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: help with branch and bound callbacks

    Posted 05/24/10 03:36 AM

    Originally posted by: QiuFeng


    Please ignore my previous post, I'm coding and had some problems here.

    I'm trying to do what Daniel mentioned earlier: store the branch information in the node created and retrieve it later in cut callback.

    I was using CPXbranchcallbackbranchbds to associate my data with the node just created.
    BRANCHCALLBACKINFO  *p_branch_info = new BRANCHCALLBACKINFO(indices[0]);
            int status = CPXbranchcallbackbranchbds (env, cbdata, wherefrom,
                    nodeest[0], 1, indices, lu, bd,
                    p_branch_info, &seqnum1);
            cout << "sequence node created: " << seqnum1<<endl;
    


    p_branch_info points to my data and is passed to CPXbranchcallbackbranchbds. In this way, my data is associated with this new node. However, when I tried to retrieve this data later in solve callback, I couldn't recover the data.

    BRANCHCALLBACKINFO branch_info;
            CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0, CPX_CALLBACK_INFO_NODE_USERHANDLE, &branch_info);
            cout << branch_info.test<<endl;
    


    it doesn't print the string I stored earlier in the branch callback.

    Did I miss something?

    Any input is appreciated!
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: help with branch and bound callbacks

    Posted 05/24/10 10:55 PM

    Originally posted by: QiuFeng


    Please ignore my previous posts, I know where I did wrong now.

    Daniel, thanks for your help!
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: help with branch and bound callbacks

    Posted 05/26/10 03:06 AM

    Originally posted by: SystemAdmin


    I assume all your problems are solved/questions answered? If not please ask again about what is still open.
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: help with branch and bound callbacks

    Posted 05/26/10 03:24 AM

    Originally posted by: QiuFeng


    hi Daniel, this problem is answered. However sometimes I didn't see the button where I can click to close this thread. sorry
    #CPLEXOptimizers
    #DecisionOptimization