Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  NodeCallback getObjValue function

    Posted 07/22/13 01:10 PM

    Originally posted by: SifengLin


    Hi,

    I'm trying to implement a node selection procedure by implementing the NodeCallback, when I call the function getObjValue, something really weired happens.  I am pretty sure that the objective value value is positive in any situation, but get GetObjValue function gives me a negative value.  Its absolute value looks like the value it should be.

    Since my problem is a maximization problem.  Is it because CPLEX reformulate it as a minimization problem?  Can any one tells what is happening here?

    Thanks so much.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: NodeCallback getObjValue function

    Posted 07/22/13 07:55 PM

    This should not be the result of your maximizing. Is it possible for your objective function to be negative, or should that be mathematically impossible (say, nonnegatively-weighted sum of nonnegative variables)? Have you exported your model or printed your objective function to confirm that it is coded correctly?

    Paul


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: NodeCallback getObjValue function

    Posted 07/23/13 12:31 PM

    Originally posted by: SifengLin


    Dr. Rubin, Thanks to your reply.  I tried your suggestion to print out the model, it looks alright to me.  I can solve the model correctly using the cplex default option.  But when I tried to improve the performance using the node selection callback, the "getObjValue" funtion does not give me the right number.  I check the log file, it seems that the number it returns it is the negative of the value is shows on the log file.  What I do now is use absolute value function to get rid of this.  Do you have other insights about this?

     

    BTW, I usually visit your blog "OR in an OB World". it is wonderful!

    Sifeng


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: NodeCallback getObjValue function

    Posted 07/23/13 04:58 PM

    Sifeng,

    Thanks for the kind words. In your callback, what argument do you give to the getObjValue() function? Also, which version of CPLEX are you using, and which API (C++, Java or something else)?

    Paul


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: NodeCallback getObjValue function

    Posted 07/23/13 05:19 PM

    Originally posted by: SifengLin


    Dr. Rubin,

    I use JAVA and the Cplex version is 12.4.

      I try to implement the strict best-bound model by calling the funtion getObjValue(int node) in the following way (I add Math.abs() since it gives me negative values),

    int index = 0;

    for(int i=1; i < getNremainingNodes(); i++){
         if( Math.abs(getObjValue(index))< Math.abs(getObjValue(i)) ){
                index = i;
         }
    }

    selectNode(index);


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: NodeCallback getObjValue function

    Posted 07/23/13 05:48 PM

    I'm not sure this would cause the problem you encountered, but I believe your code has a subtle error. Try the following:

    int index = 0;

    for(int i=1; i < getNremainingNodes(); i++){
         if( Math.abs(getObjValue(getNodeId(index)))< Math.abs(getObjValue(getNodeId(i))) ){
                index = i;
         }
    }

    selectNode(index);

    The selectNode() method wants a node number, which is the 0-indexed ordinal of the node on the list of currently surviving nodes (so between 0 and getNremainingNodes() - 1). The getObjValue() Method, on the other hand, wants a node id, which is a permanent number assigned to each node (unlike the node number, which can change as nodes ahead of it on the node list are pruned).

    Assuming I am correct, this needs to be fixed whether or not it caused the negative objective value. As far as that goes, I wonder what happens if you give getObjValue() an argument that happens to be the node id for an infeasible node? Does it throw an IloException, or does it return the last dual objective value encountered (if the node problem is infeasible, its dual is likely to be unbounded), or what?

    Paul


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: NodeCallback getObjValue function

    Posted 07/30/13 10:22 AM

    Originally posted by: SifengLin


    Dr. Rubin,

    Sorry about not having replying earlier.  I tried the idea of using the getNodeId(index) as the argument to the function getObjValue.  It still gives me the wrong value.  It is probably that cplex runs into a bug here, as Daniel suggests.  I tried to multiply the objective function by -1 and change the objective function to minimization, and the value given by getObjValue() is right. 

    I assume that if we are using getNodeId(index) to get the node id of the node, we obtain a node that is not solved yet. The getObjValue(NodeId) gives us the objective function value of its parent node.  So it is impossible to incur the problem you mentioned.  I do not know what it will happen if we give getObjValue() with an node id that is already solved.  

    Thanks so much for the help!

    Sifeng


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: NodeCallback getObjValue function

    Posted 07/30/13 10:47 AM

    Sifeng,

    getObjValue(getNodeId(index)) will indeed return the objective value of a live (unsolved) node. I don't know if that's always the objective value of the parent or not; it's possible that CPLEX adjusts the parent value by the up/down penalty for branching on the variable used to create the children, at least in some cases. In any event, it should be a valid objective value.

    If you omit the call to getNodeId, though, you may not be looking at an unsolved node. For instance, suppose that the 47th node created (nodeid=47) is, at some point, fifth on the list of unsolved nodes (index = 4). If you call getObjValue(4), you do not get the objective value of the 47th node, you get the objective value of the fourth node created (nodeid=4), and that node may have been pruned for one reason or another, including possibly because it was feasible.

    It does appear that you've hit a bug, but I think you need to the call to getNodeId regardless.

    Cheers,

    Paul


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: NodeCallback getObjValue function

    Posted 07/31/13 04:48 PM

    Originally posted by: SifengLin


    Dr. Rubin,

    Thanks for your suggestions.  They are really helpful. 

    Sifeng


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: NodeCallback getObjValue function

    Posted 07/29/13 04:12 AM

    It is possible that you have hit a bug in CPLEX here. Does the problem persist if you multiply the objective function by -1 and change the objective sens to "minimize"? Or does that still give invalid values for getObjValue(nodenumber)?


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: NodeCallback getObjValue function

    Posted 07/30/13 10:24 AM

    Originally posted by: SifengLin


    Daniel,

    Thanks for your reply.  I tried your idea of minimizing the negative of my objective function, and getObjValue(node number) gives me the right value.  Is it because Cplex always try to transform a maximization problem into a minimization one?

    Thanks.

    Sifeng


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: NodeCallback getObjValue function

    Posted 07/30/13 10:34 AM

    OK, this confirms that you have hit the bug I had in mind :-(
    Correct, CPLEX internally transforms the problem to a minimization problem and due to this bug getObjValue(node number) returns the objective value for the minimization problem.


    #CPLEXOptimizers
    #DecisionOptimization