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