Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  (C API) attach the user data object to node

    Posted 06/29/12 10:20 AM

    Originally posted by: NSopt


    Hello.
    I'm implementing multi-child branching.(i.e., branch on more than 2 nodes)
    For this, I'd like to attach user information to every node.
    Also, I want to read attached information from every node.
    Here goes short snippet for this implementation.

    struct test1
        {
            int testindex;
            int testindex2;
        };
     
        struct test1 m;
        struct test1 *branch_info=NULL;
        branch_info = &m;
        branch_info->testindex = 10;
        branch_info->testindex2 = 20;
     
        status = CPXbranchcallbackbranchbds (env,cbdata,wherefrom,objval,1,&minmaxj,varlu,varbd,branch_info,&seqnum1);
        *useraction_p = CPX_CALLBACK_SET;
     
        status = CPXgetcallbacknodeinfo (env,cbdata,wherefrom,0,CPX_CALLBACK_INFO_NODE_USERHANDLE,(void*)&branch_info);
        printf("branch info %d \n",(const*)&branch_info->testindex);
    

    However, last line gives me 'address-like number' such as -126888112 not 10.
    Could you please help me for this problem?
    Thank you.

    Best,
    NS
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: (C API) attach the user data object to node

    Posted 06/30/12 03:18 PM

    Originally posted by: SystemAdmin


    Several issues:
    • As far as I can see you allocate your user data object on the stack? The data must be allocated on the heap, otherwise it will no longer be valid when the branch callback returns. Does this work better:
    struct test1 {
        int testindex;
        int testindex2;
    };
    struct test1 *branch_info = malloc(sizeof(*branch_info));
    branch_info->testindex = 10;
    branch_info->testindex2 = 20;
    

    • I am not sure whether you call CPXgetcallbacknodeinfo() directly after CPXbranchcallbackbranchbds()? I think you cannot expect the node to be actually created before the branch callback returns. In other words, within the branch callback you cannot query the node data of nodes that were just created at this very same call to the branch callback.
    • Note that at the root node the user data object will always be NULL since the root node is not created by means of a branch callback.

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: (C API) attach the user data object to node

    Posted 07/06/12 03:04 PM

    Originally posted by: NSopt


    Thank you. Now it works.
    I still have a problem.

    
    struct test1 
    { 
    
    int testindex; 
    }; struct test1 *branch_info = malloc(sizeof(*branch_info));   
    
    if (nodecount!=0) 
    // if we are not at root, so this happens after branchcallback 
    { status = CPXgetcallbacknodeinfo(env,cbdata,wherefrom,0,CPX_CALLBACK_INFO_NODE_USERHANDLE,(void*)&branch_info); printf(
    "which node %d",branch_info->a); 
    }   
    // down branch branch_info->testindex = 10; var = 1; varlu[0]=
    'B';varbd[0]=1; status = CPXbranchcallbackbranchbds (env,cbdata,wherefrom,objval,1,&var, varlu, varbd, branch_info, &seqnum1);   
    // up branch branch_info->testindex = 20; var = 2; varlu[0]=
    'B';varbd[0]=1; status = CPXbranchcallbackbranchbds (env,cbdata,wherefrom,objval,1,&var, varlu, varbd, branch_info, &seqnum1); *useraction_p=CPX_CALLBACK_SET;
    


    Suppose above simple example. Assume that CPLEX choose the down branch node for next search. Since we attached testindex value as 10 to down branch, CPXgetcallbacknodeinfo must restore testindex as 10. However, I found out that testindex value is always 20 even though we are not at up branch. How this can happen? Could you please let me know the mistake of my code?
    Thank you.

    Sincerely,
    NS
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: (C API) attach the user data object to node

    Posted 07/06/12 03:54 PM

    Originally posted by: NSopt


    I think I found the problem. So, please disregard above question.
    Thank you anyway.

    Sincerely,
    NS
    #CPLEXOptimizers
    #DecisionOptimization