Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Can I modify node LP in solve callback ?

    Posted 05/24/10 03:52 AM

    Originally posted by: QiuFeng


    Hi all:
    I want to add an extra constrain to the node lp(and all sub-nodes rooted from this node) based on the newly fixed variable at this node. I know that adding it as a cut is an alternative. But I'm wondering if I can add it as an real constrain before cplex solve this node?

    I read the manual, it seems that I can do the above in solve callback. But I'm not sure if this is safe way to do it because I don't if there will be some consequence from modifying the formulation of node lp.

    Thanks for your help!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Can I modify node LP in solve callback ?

    Posted 05/24/10 10:38 AM

    Originally posted by: SystemAdmin


    I don't know what you mean by "real constraint". If you mean adding it to the original model, that will not work unless you are willing to stop the solution process, modify the model, and start over. CPLEX will not let you modify the model while a call to solve() is in progress.

    If you want CPLEX to include the new constraint when solving nodes in the subtree rooted at the current node, the solve callback will not help you. You need to use a cut callback and employ the addLocal method to add the cut.

    /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: Can I modify node LP in solve callback ?

    Posted 05/24/10 10:52 PM

    Originally posted by: QiuFeng


    Hi Paul:
    Thanks for your reply!
    what I mean is just what you said in your reply: " want CPLEX to include the new constraint when solving nodes in the subtree rooted at the current node". The reason why I want to add it to the node lp before solving it is , I already have this cut immediately after a binary is fixed to 1. Therefore I don't need to solve the node lp to get the cut. By adding this cut as a constrain before solving it, I hope it can save some computation.

    If I understand you correctly, cut callback is the only way to throw in constrains into node lp? I can not just get the pointer to node lp and add new rows to it in solve callback. Did I get you correctly?
    If this is the case, then I have no choice but to use cut callback. Hope dual simplex will make the resolving efficient.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Can I modify node LP in solve callback ?

    Posted 05/25/10 09:13 AM

    Originally posted by: SystemAdmin


    > QiuFeng wrote:
    > The reason why I want to add it to the node lp before solving it is , I already have this cut immediately after a binary is fixed to 1. Therefore I don't need to solve the node lp to get the cut. By adding this cut as a constrain before solving it, I hope it can save some computation.

    I'm not sure how much computation it will save, but I think you can do what you want by using a branch callback. At each node, after solving the node LP (and assuming the node is not pruned after solving the node LP), CPLEX will call your branch callback and give you the option to create one or two child nodes. The way you create a child node is by adding one or more local cuts. So you can add the "fix x_j = 1" cut to one child and the "fix x_j = 0" cut to the other, and simultaneously add your new cut to the first child (and, by inheritance, all of its descendants).

    > If I understand you correctly, cut callback is the only way to throw in constrains into node lp? I can not just get the pointer to node lp and add new rows to it in solve callback. Did I get you correctly?

    No, you can add cuts via both cut and branch callbacks -- but not in a node callback (AFAIK).

    > If this is the case, then I have no choice but to use cut callback. Hope dual simplex will make the resolving efficient.

    It should. The disadvantage of the branch callback approach is that you have to decide on which variable to branch. It's not a major disadvantage: you can use the getBranches method to ask CPLEX how it was planning to branch, and then use the same branching with your extra cut. On the other hand, the only question with the cut callback (which IMHO is easier to implement) is whether adding the cut after solving the LP will result in a large number of dual simplex pivots or a fairly small number of extra pivots.

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Can I modify node LP in solve callback ?

    Posted 05/25/10 10:14 AM

    Originally posted by: QiuFeng


    Hi Paul, Thanks a lot for your suggestions.

    need to confirm several things with you:

    1, in order to add constrains while branching, I have to use CPXbranchcallbackbranchgeneral?

    2, I did an experiment today: In solve callback, I obtained the node lp pointer by CPXgetcallbacknodelp and added rows to node lp by CPXaddrows. After adding rows to node lp, I turned in the control back to CPLEX and ask CPLEX solve it. Would this cause some problem? I didn't observe any error report, however, I did notice that the optimal is different from the one without any callback. I'm not sure what is the cause. From what I read in the manual, we are supposed to only use query routines with node lp obtained by CPXgetcallbacknodelp. I'm not sure if it's safe to modify node lp in the ways other than CPXcutcallbackaddlocal and CPXbranchcallbackbranchgeneral

    3, I implemented cut callback you suggested in your earlier post: add cut with CPXcutcallbackaddlocal in cut callback. However, it seems that the cut was not used by cplex. To find out if the cut was used, I wrote the node lp into files and I didn't see my cuts there. I don't know if it's because CPLEX doesn't record user cuts in node lp file, or my cuts are dropped. I runned different set of data but still didn't see any of my cuts in node lp files. Do you have any idea how I can make sure that my cuts are used by cplex?

    Thanks again for your help!
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Can I modify node LP in solve callback ?

    Posted 05/25/10 10:59 AM

    Originally posted by: SystemAdmin


    > QiuFeng wrote:
    >
    > 1, in order to add constrains while branching, I have to use CPXbranchcallbackbranchgeneral?

    Yes.

    > 2, I did an experiment today: In solve callback, I obtained the node lp pointer by CPXgetcallbacknodelp and added rows to node lp by CPXaddrows. After adding rows to node lp, I turned in the control back to CPLEX and ask CPLEX solve it. Would this cause some problem? I didn't observe any error report, however, I did notice that the optimal is different from the one without any callback. I'm not sure what is the cause. From what I read in the manual, we are supposed to only use query routines with node lp obtained by CPXgetcallbacknodelp. I'm not sure if it's safe to modify node lp in the ways other than CPXcutcallbackaddlocal and CPXbranchcallbackbranchgeneral

    I do not know the answer to that one (I do not use the C API).
    >
    > 3, I implemented cut callback you suggested in your earlier post: add cut with CPXcutcallbackaddlocal in cut callback. However, it seems that the cut was not used by cplex. To find out if the cut was used, I wrote the node lp into files and I didn't see my cuts there. I don't know if it's because CPLEX doesn't record user cuts in node lp file, or my cuts are dropped. I runned different set of data but still didn't see any of my cuts in node lp files. Do you have any idea how I can make sure that my cuts are used by cplex?

    CPLEX does not write cuts when you output a problem. The best I can suggest is that you check the solution to the node LP and see if it satisfies your cut.

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Can I modify node LP in solve callback ?

    Posted 05/26/10 04:26 AM

    Originally posted by: QiuFeng


    Thanks, Paul, I will try checking the solution to the node LP and see if it satisfies my cut. I guess this is the only way.
    #CPLEXOptimizers
    #DecisionOptimization