Purpose
Declares a branching variable
callback function, called every time a new
branching variable is set or selected during the MIP
search.
Synopsis
int XPRS_CC XPRSsetcbchgbranch(XPRSprob prob, void (XPRS_CC *fucb)(XPRSprob my_prob, void *my_object, int
*entity, int *up, double *estdeg), void *object);
Arguments
prob
|
The current problem.
|
fucb
|
The callback function, which takes five arguments, my_prob, my_object, entity, up and estdeg, and has no return value. This function is called every time a new branching variable or set is selected.
|
my_prob
|
The problem passed to the callback function, fucb.
|
my_object
|
The user-defined object passed as object when setting up the callback with XPRSsetcbchgbranch.
|
entity
|
A pointer to the variable or set on which to branch. Ordinary global variables are identified by their column index, i.e.
0, 1,...( COLS- 1) and by their set index, i.e. 0, 1,...,( SETS- 1).
|
up
|
If entity is a variable, this is 1 if the upward branch is to be made first, or 0 otherwise. If entity is a set, this is 3 if the upward branch is to be made first, or 2 otherwise.
|
estdeg
|
The estimated degradation at the node.
|
object
|
A user-defined object to be passed to the callback function, fucb.
|
Example
The following example demonstrates use of the branching rule to branch on the most violated integer
of binary during the global search:
typedef struct {
double* soln;
char* type;
double tol;
int cols;
} solutionData;
...
solutionData nodeData;
...
XPRSminim(prob,"");
XPRSsetintcontrol(prob, XPRS_MIPLOG, 3);
XPRSsetintcontrol(prob, XPRS_CUTSTRATEGY, 0);
/* setup data */
XPRSgetintattrib(prob, XPRS_COLS, &(nodeData.cols));
XPRSgetdblcontrol(prob, XPRS_MATRIXTOL, &(nodeData.tol));
nodeData.soln =
(double*) malloc(sizeof(double)*nodeData.cols);
nodeData.type =
(char*) malloc(sizeof(char)*nodeData.cols);
XPRSgetcoltype(prob, nodeData.type, 0, nodeData.cols-1);
XPRSsetcbchgbranch(prob, varSelection, &nodeData);
XPRSglobal(prob);
The callback function might resemble:
void XPRS_CC varSelection(XPRSprob prob, void* vdata,
int *iColumn, int *iUp, double *dEstimate)
{
double dDist, dUpDist, dDownDist, dGreatestDist=0;
int iCol;
solutionData *nodeData = (solutionData*) vdata;
XPRSgetpresolvesol(prob, (*nodeData).soln, NULL, NULL,
NULL);
for(iCol=0;iCol<(*nodeData).cols;iCol++)
if((*nodeData).type[iCol]=='I' ||
(*nodeData).type[iCol]=='B')
{
dUpDist=ceil((*nodeData).soln[iCol]) -
(*nodeData).soln[iCol];
dDownDist = (*nodeData).soln[iCol] -
floor((*nodeData).soln[iCol]);
dDist = (dUpDist>dDownDist)?dUpDist:dDownDist;
if(dDownDist > (*nodeData).tol &&
dUpDist > (*nodeData).tol)
if( dDist > dGreatestDist )
{
*iColumn = iCol;
dGreatestDist = dDist;
}
}
}
Further information
The arguments initially contain the default values of the branching variable,
branching variable, branching direction and estimated degradation. If they are changed then the
Optimizer will use the new values, if they are not changed then the default values will be used.
Related topics
If you have any comments or suggestions about these pages,
please send mail to docs@dashoptimization.com.