Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Node ID differs in different callbacks

    Posted 06/15/17 11:14 AM

    Originally posted by: albaska


    Hi,

     

    I am trying to get the node id by the following command in three different callbacks, (solve, branch and node callback).

    status = CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0,
                                      CPX_CALLBACK_INFO_NODE_SEQNUM, &nodeid);

      

    The node id I get in solve and branch callbacks are always the same, but sometimes node callback returns a different number than the other callbacks. Can someone explain why this is happening? Thank you.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Node ID differs in different callbacks

    Posted 06/15/17 11:31 AM

    In the branch and solve callbacks, node number 0 refers to the current node.

    In the node callback node number 0 refers to the next node to be selected. Maybe this can explain?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Node ID differs in different callbacks

    Posted 06/15/17 11:44 AM

    Originally posted by: albaska


    That could be the reason for that. I also have another question, is it possible to get the parent's nodeid of the current node in Cplex? Thank you


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Node ID differs in different callbacks

    Posted 06/15/17 12:56 PM

    No, that information is not available. However, you can easily track this yourself from a branch callback.

    In the branch callback store the current node's seqnum, then call CPXbranchasCPLEX() and pass (void *)seqnum as user data for each new node. Then, when a node is processed you can call CPXgetcallbacknodeinfo(CPX_CALLBACK_INFO_NODE_USERHANDLE), cast the obtained void* back to CPXCNT and you have the sequence number of the parent node.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Node ID differs in different callbacks

    Posted 06/15/17 02:10 PM

    Originally posted by: albaska


    I did this like below, but I always get 0 as parented in each node

    in the branch callback:

      //ASSIGN THE CURRENT NODE ID TO THE CHILD

      int nodeid;
      status = CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0,
                                      CPX_CALLBACK_INFO_NODE_SEQNUM, &nodeid);

      status = CPXbranchcallbackbranchbds(env, cbdata, wherefrom, 1, &bestj, varlu,
                                          varbd, objval, (void *)nodeid, &seqnum1);  
      status = CPXbranchcallbackbranchbds(env, cbdata, wherefrom, 1, &bestj, varlu,
                                          varbd, objval, (void *)nodeid, &seqnum2);

     

    Then again in the branch callback to get the parent nodeid:

      void * data= NULL;
      CPXINT parentid;
      status = CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0, 
                  CPX_CALLBACK_INFO_NODE_USERHANDLE, &data);

      parentid = (CPXINT)(data);

      printf("parent node id is = %d\n",parentid);
      

     

    do you have any suggestions? why parentid is always 0?


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Node ID differs in different callbacks

    Posted 06/20/17 06:01 AM

    Note that the parent id of the first node (the root node) will always be 0 since the node data for the root data is NULL. Other than that, the parent ids should be different from zero. This callback implementation

    static int
    branchcallback(CPXCENVptr env, void *cbdata,
                   int wherefrom, void *cbhandle, int brtype, CPXDIM brset,
                   int nodecnt, CPXDIM bdcnt,
                   const CPXDIM *nodebeg, const CPXDIM *xindex, const char *lu,
                   const double *bd, const double *nodeest, int *useraction_p)
    
    {
       int num, me;
       CPXCNT seqno;
       void *parent;
       int status;
    
       (void)cbhandle; (void)brtype; (void)brset; (void)bdcnt; (void)nodebeg;
       (void)xindex;   (void)lu;     (void)bd;    (void)nodeest;
    
       CPXXgetcallbacknodeinfo(env, cbdata, wherefrom, 0, 
                               CPX_CALLBACK_INFO_NODE_USERHANDLE, &parent);
    
       CPXXgetcallbacknodeinfo(env, cbdata, wherefrom, 0,
                               CPX_CALLBACK_INFO_NODE_SEQNUM, &me);
    
       printf("Branch callback on %d (parent %d)\n", me, (int)parent);
    
       for (num = 0; num < nodecnt; ++num)
          CPXXbranchcallbackbranchasCPLEX(env, cbdata, wherefrom,
                                          num, (void *)me, &seqno);
       *useraction_p = CPX_CALLBACK_SET;
    
       return 0;
    }
    

    produces the following output for me, which looks reasonable:

    Branch callback on 0 (parent 0)
    Branch callback on 2 (parent 0)
    Branch callback on 3 (parent 2)
    Branch callback on 5 (parent 3)
    Branch callback on 7 (parent 5)
    Branch callback on 9 (parent 7)
    Branch callback on 11 (parent 9)
    ...


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Node ID differs in different callbacks

    Posted 06/20/17 09:28 AM

    Originally posted by: albaska


    Thank you. it is what I want 


    #CPLEXOptimizers
    #DecisionOptimization