Decision Optimization

Decision Optimization

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

 View Only
  • 1.  get list of branching decisions in each node

    Posted Thu June 15, 2017 11:07 AM

    Originally posted by: albaska


    Hi,

     

    I am trying to get the sequence of branching decisions on each node of the branch and cut tree. It easy to get the the branching variable in the current node by CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0, CPX_CALLBACK_INFO_NODE_VAR, &branch_var), but I need the sequence of all branching decisions from root to the current node. I really appreciate if someone can help.
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: get list of branching decisions in each node

    Posted Thu June 15, 2017 11:13 AM

    CPLEX does not maintain that information for you. You will have to track this yourself by means of a branch callback.

    How to do this has been discussed several times on this Forum. Please search the Forum and come back if you cannot find anything.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: get list of branching decisions in each node

    Posted Tue June 20, 2017 01:11 PM

    Originally posted by: albaska


    I managed to get the list of fixed branching variables based on the related discussions in this forum, but I observed a weird thing, I added the  current branch variable to a list and then add the list to the child. The problem is that I see variable duplication in my list? any idea what is wrong with my code? Thank you.

    static int 
    CPXPUBLIC usersetbranch(CPXCENVptr env, void *cbdata,
                   int wherefrom, void *cbhandle, int brtype, int brset,
                   int nodecnt, int bdcnt,
                   const int *nodebeg, const int *xindex, const char *lu,
                   const double *bd, const double *nodeest, int *useraction_p)
    
    {
      printf("====== begin branch callback ===========\n");
       int num, me;
       CPXINT seqno;
       int status;
    
      GSList *list = NULL;
      (void)cbhandle; (void)brtype; (void)brset; (void)bdcnt; (void)nodebeg;
      (void)xindex;   (void)lu;     (void)bd;    (void)nodeest;
    
       CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0, 
                               CPX_CALLBACK_INFO_NODE_USERHANDLE,(void *)&list);
    
       CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0,
                               CPX_CALLBACK_INFO_NODE_SEQNUM, &me);
    
      //get the list
       GSList *iterator = NULL;
       GSList *childlist = NULL;
       for (iterator = list; iterator; iterator = iterator->next) {  
        printf(" '%d' ", iterator->data);
         childlist = g_list_append(childlist, iterator->data);
       }
      printf("\n");
      g_slist_free(iterator);
    
     int depth = 0;
      status = CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0,
                                      CPX_CALLBACK_INFO_NODE_DEPTH, &depth);
      if (status) {
        fprintf(stdout, "Can't get node depth info.");
        //goto TERMINATE;
      }
    
      int var;
      status = CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0,
                                      CPX_CALLBACK_INFO_NODE_VAR, &var);
      if (status) {
        fprintf(stdout, "Can't get var branch on this node.");
        //goto TERMINATE;
      }
        printf("var branch on iiis = x_%d\n", var);
    
    
      if(var != -1) childlist = g_slist_append(childlist, var);
       printf("The tree depth is = %d \n", depth);
       printf("The child list is now = %d items long\n", g_slist_length(childlist));
       printf("The list is now = %d items long\n", g_slist_length(list));
       //add the list
       for (num = 0; num < nodecnt; ++num)
          CPXbranchcallbackbranchasCPLEX(env, cbdata, wherefrom,
                                          num, (void *)childlist, &seqno);
       *useraction_p = CPX_CALLBACK_SET;
      printf("====== end branch callback ===========\n");
       return 0;
    }
    
    
    

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: get list of branching decisions in each node

    Posted Tue June 20, 2017 02:31 PM

    Assume a branch callback invocation creates two children. In that case you are passing the same list to both children. Are you sure this is correct? Depending on how this list is implemented each child might require a separate copy of that list.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: get list of branching decisions in each node

    Posted Wed June 21, 2017 08:07 AM

    Originally posted by: albaska


    I applied your suggestion and  passed two copies of the list to the children, still the same problem showed up, any other idea? 


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: get list of branching decisions in each node

    Posted Mon July 03, 2017 12:34 PM

    Sorry, I have no more ideas. I guess you have to step through your code with a debugger and figure out where things go wrong.


    #CPLEXOptimizers
    #DecisionOptimization