branch_distribution.c
Go to the documentation of this file.
21 * The distribution branching rule selects a variable based on its impact on row activity distributions. More formally,
22 * let \f$ a(x) = a_1 x_1 + \dots + a_n x_n \leq b \f$ be a row of the LP. Let further \f$ l_i, u_i \in R\f$ denote the
24 * Viewing every variable \f$x_i \f$ as (continuously) uniformly distributed within its bounds, we can approximately
25 * understand the row activity \f$a(x)\f$ as a Gaussian random variate with mean value \f$ \mu = E[a(x)] = \sum_i a_i\frac{l_i + u_i}{2}\f$
26 * and variance \f$ \sigma^2 = \sum_i a_i^2 \sigma_i^2 \f$, with \f$ \sigma_i^2 = \frac{(u_i - l_i)^2}{12}\f$ for
28 * With these two parameters, we can calculate the probability to satisfy the row in terms of the cumulative distribution
31 * The impact of a variable on the probability to satisfy a constraint after branching can be estimated by altering
36 * The selection of the branching variable is subject to the parameter @p scoreparam. For both branching directions,
38 * - @b d: select a branching variable with largest difference in satisfaction probability after branching
41 * - @b v: highest number of votes for lowering row probability for all rows a variable appears in.
42 * - @b w: highest number of votes for increasing row probability for all rows a variable appears in.
44 * If the parameter @p usescipscore is set to @a TRUE, a single branching score is calculated from the respective
45 * up and down scores as defined by the SCIP branching score function (see advanced branching parameter @p scorefunc),
46 * otherwise, the variable with the single highest score is selected, and the maximizing direction is assigned
57 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
81 #define BRANCHRULE_DESC "branching rule based on variable influence on cumulative normal distribution of row activities"
91 #define DEFAULT_ONLYACTIVEROWS FALSE /**< should only rows which are active at the current node be considered? */
92 #define DEFAULT_USEWEIGHTEDSCORE FALSE /**< should the branching score weigh up- and down-scores of a variable */
96 #define EVENT_DISTRIBUTION SCIP_EVENTTYPE_BOUNDCHANGED /**< the event tyoe to be handled by this event handler */
111 int* rowinfinitiesdown; /**< count the number of variables with infinite bounds which allow for always
113 int* rowinfinitiesup; /**< count the number of variables with infinite bounds which allow for always
121 SCIP_Bool onlyactiverows; /**< should only rows which are active at the current node be considered? */
127 SCIP_BRANCHRULEDATA* branchruledata; /**< the branching rule data to access distribution arrays */
134 /** ensure that maxindex + 1 rows can be represented in data arrays; memory gets reallocated with 10% extra space
191 SCIP_CALL( SCIPcatchVarEvent(scip, vars[v], EVENT_DISTRIBUTION, branchruledata->eventhdlr, NULL, &(branchruledata->varfilterposs[v])) );
202 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &branchruledata->rowinfinitiesdown, branchruledata->memsize, newsize) );
203 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &branchruledata->rowinfinitiesup, branchruledata->memsize, newsize) );
204 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &branchruledata->rowmeans, branchruledata->memsize, newsize) );
205 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &branchruledata->rowvariances, branchruledata->memsize, newsize) );
208 /* loop over extended arrays and invalidate data to trigger initialization of this row when necessary */
248 /** calculate the variable's distribution parameters (mean and variance) for the bounds specified in the arguments.
277 /* if the variable is continuous, we assume a continuous uniform distribution, otherwise a discrete one */
289 /** calculates the cumulative distribution P(-infinity <= x <= value) that a normally distributed
322 /* scale and translate to standard normal distribution. Factor sqrt(2) is needed for SCIPerf() function */
325 SCIPdebugMsg(scip, " Normalized value %g = ( %g - %g ) / (%g * 1.4142136)\n", normvalue, value, mean, std);
327 /* calculate the cumulative distribution function for normvalue. For negative normvalues, we negate
328 * the normvalue and use the oddness of the SCIPerf()-function; special treatment for values close to zero.
356 * For equations (lhs==rhs), we use the centeredness measure p = min(PHI(lhs'), 1-PHI(lhs'))/max(PHI(lhs'), 1 - PHI(lhs')),
364 int rowinfinitiesdown, /**< the number of variables with infinite bounds to DECREASE activity */
380 /* use the cumulative distribution if the row contains no variable to repair every infeasibility */
384 /* use the cumulative distribution if the row contains no variable to repair every infeasibility
393 /* use centeredness measure for equations; for inequalities, the minimum of the two probabilities is the
408 SCIPdebugMsg(scip, " Row %s, mean %g, sigma2 %g, LHS %g, RHS %g has probability %g to be satisfied\n",
419 * \f$n \f$ is the number of variables, and \f$ c_i, lb_i, ub_i \f$ are the variable coefficient and
431 SCIP_Real* sigma2, /**< pointer to store the variance value of the gaussian normal distribution */
432 int* rowinfinitiesdown, /**< pointer to store the number of variables with infinite bounds to DECREASE activity */
433 int* rowinfinitiesup /**< pointer to store the number of variables with infinite bounds to INCREASE activity */
483 assert((branchruledata->currentlbs[varindex] == SCIP_INVALID) == (branchruledata->currentubs[varindex] == SCIP_INVALID)); /*lint !e777*/
500 /* an infinite upper bound gives the row an infinite maximum activity or minimum activity, if the coefficient is
509 /* an infinite lower bound gives the row an infinite maximum activity or minimum activity, if the coefficient is
520 SCIPvarCalcDistributionParameters(scip, colvarlb, colvarub, SCIPvarGetType(colvar), &varmean, &varvariance);
522 /* actual values are updated; the contribution of the variable to mu is the arithmetic mean of its bounds */
525 /* the variance contribution of a variable is c^2 * (u - l)^2 / 12.0 for continuous and c^2 * ((u - l + 1)^2 - 1) / 12.0 for integer */
533 SCIPdebugMsg(scip, " Row %s has a mean value of %g at a sigma2 of %g \n", SCIProwGetName(row), *mu, *sigma2);
536 /** update the up- and downscore of a single variable after calculating the impact of branching on a
614 SCIP_Real* upscore, /**< pointer to store the variable score when branching on it in upward direction */
615 SCIP_Real* downscore, /**< pointer to store the variable score when branching on it in downward direction */
636 SCIP_Bool onlyactiverows; /* should only rows which are active at the current node be considered? */
659 SCIPvarCalcDistributionParameters(scip, varlb, varub, vartype, ¤tmean, &squaredbounddiff);
672 SCIPvarCalcDistributionParameters(scip, varlb, newub, vartype, &meandown, &squaredbounddiffdown);
714 rowCalculateGauss(scip, branchruledata, row, &branchruledata->rowmeans[rowpos], &branchruledata->rowvariances[rowpos],
731 /* first, get the probability change for the row if the variable is branched on upwards. The probability
755 newrowprobup = SCIProwCalcProbability(scip, row, changedrowmean, changedrowvariance, rowinftiesdownafterbranch,
782 newrowprobdown = SCIProwCalcProbability(scip, row, changedrowmean, changedrowvariance, rowinftiesdownafterbranch,
789 SCIP_CALL( SCIPupdateDistributionScore(scip, currentrowprob, newrowprobup, newrowprobdown, upscore, downscore, scoreparam) );
791 SCIPdebugMsg(scip, " Variable %s changes probability of row %s from %g to %g (branch up) or %g;\n",
821 /** add variable to the bound change event queue; skipped if variable is already in there, or if variable has
854 assert((branchruledata->currentlbs[varindex] == SCIP_INVALID) == (branchruledata->currentubs[varindex] == SCIP_INVALID)); /*lint !e777*/
866 /** returns the next unprocessed variable (last in, first out) with pending bound changes, or NULL */
920 /* skip event execution if SCIP is in Probing mode because these bound changes will be undone anyway before branching
937 /* skip update if the variable has never been subject of previously calculated row activities */
1052 /** solving process deinitialization method of branching rule (called before branch and bound process data is freed) */
1067 /* drop variable events at the end of branch and bound process (cannot be used after restarts, anyway) */
1080 SCIP_CALL( SCIPdropVarEvent(scip, vars[v], EVENT_DISTRIBUTION, branchruledata->eventhdlr, NULL, branchruledata->varfilterposs[v]) );
1141 /* if branching rule data arrays were not initialized before (usually the first call of the branching execution),
1174 /* invalidate the current row distribution data which is initialized on the fly when looping over the candidates */
1190 /* in debug mode, ensure that all bound process events which occurred in the mean time have been captured
1196 assert((branchruledata->currentlbs[varindex] == SCIP_INVALID) == (branchruledata->currentubs[varindex] == SCIP_INVALID)); /*lint !e777*/
1198 || SCIPisFeasEQ(scip, SCIPvarGetLbLocal(lpcand), branchruledata->currentlbs[varindex])); /*lint !e777*/
1200 || SCIPisFeasEQ(scip, SCIPvarGetUbLocal(lpcand), branchruledata->currentubs[varindex])); /*lint !e777*/
1211 /* loop over candidate rows and determine the candidate up- and down- branching score w.r.t. the score parameter */
1215 /* if weighted scoring is enabled, use the branching score method of SCIP to weigh up and down score */
1251 SCIPdebugMsg(scip, " Candidate %s has score down %g and up %g \n", SCIPvarGetName(lpcand), downscore, upscore);
1252 SCIPdebugMsg(scip, " Best candidate: %s, score %g, direction %d\n", SCIPvarGetName(bestcand), bestscore, bestbranchdir);
1258 SCIPdebugMsg(scip, " Branching on variable %s with bounds [%g, %g] and solution value <%g>\n", SCIPvarGetName(bestcand),
1284 /** event execution method of distribution branching which handles bound change events of variables */
1299 /* add the variable to the queue of unprocessed variables; method itself ensures that every variable is added at most once */
1345 SCIP_CALL( SCIPincludeBranchruleBasic(scip, &branchrule, BRANCHRULE_NAME, BRANCHRULE_DESC, BRANCHRULE_PRIORITY, BRANCHRULE_MAXDEPTH,
1356 "the score;largest 'd'ifference, 'l'owest cumulative probability,'h'ighest c.p., 'v'otes lowest c.p., votes highest c.p.('w') ",
SCIP_RETCODE SCIPgetLPBranchCands(SCIP *scip, SCIP_VAR ***lpcands, SCIP_Real **lpcandssol, SCIP_Real **lpcandsfrac, int *nlpcands, int *npriolpcands, int *nfracimplvars)
Definition: scip_branch.c:384
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip_mem.h:105
Definition: type_result.h:33
void SCIPvarCalcDistributionParameters(SCIP *scip, SCIP_Real varlb, SCIP_Real varub, SCIP_VARTYPE vartype, SCIP_Real *mean, SCIP_Real *variance)
Definition: branch_distribution.c:250
SCIP_BRANCHRULEDATA * SCIPbranchruleGetData(SCIP_BRANCHRULE *branchrule)
Definition: branch.c:1848
probability based branching rule based on an article by J. Pryor and J.W. Chinneck ...
static SCIP_DECL_BRANCHFREE(branchFreeDistribution)
Definition: branch_distribution.c:1089
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:851
public methods for SCIP parameter handling
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:864
Definition: struct_scip.h:58
public methods for memory management
SCIP_RETCODE SCIPcatchVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:422
static void branchruledataFreeArrays(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata)
Definition: branch_distribution.c:802
SCIP_Bool SCIPisSumPositive(SCIP *scip, SCIP_Real val)
Definition: scip_numerics.c:827
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip_event.c:172
Definition: struct_var.h:198
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
Definition: scip_numerics.c:940
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:903
SCIP_RETCODE SCIPsetBranchruleFree(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHFREE((*branchfree)))
Definition: scip_branch.c:158
static SCIP_DECL_BRANCHCOPY(branchCopyDistribution)
Definition: branch_distribution.c:1043
SCIP_RETCODE SCIPsetBranchruleCopy(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHCOPY((*branchcopy)))
Definition: scip_branch.c:142
static void branchruledataAddBoundChangeVar(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, SCIP_VAR *var)
Definition: branch_distribution.c:825
public methods for problem variables
public methods for branching rules
SCIP_RETCODE SCIPincludeBranchruleBasic(SCIP *scip, SCIP_BRANCHRULE **branchruleptr, const char *name, const char *desc, int priority, int maxdepth, SCIP_Real maxbounddist, SCIP_BRANCHRULEDATA *branchruledata)
Definition: scip_branch.c:105
static void branchruledataUpdateCurrentBounds(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, SCIP_VAR *var)
Definition: branch_distribution.c:225
Definition: type_history.h:37
Definition: struct_tree.h:133
public methods for numerical tolerances
SCIP_RETCODE SCIPchgChildPrio(SCIP *scip, SCIP_NODE *child, SCIP_Real priority)
Definition: scip_prob.c:3844
SCIP_RETCODE SCIPsetBranchruleExecLp(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHEXECLP((*branchexeclp)))
Definition: scip_branch.c:238
Definition: struct_lp.h:126
void SCIPeventhdlrSetData(SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: event.c:334
SCIP_Real SCIPgetBranchScore(SCIP *scip, SCIP_VAR *var, SCIP_Real downgain, SCIP_Real upgain)
Definition: scip_branch.c:838
static SCIP_VAR * branchruledataPopBoundChangeVar(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata)
Definition: branch_distribution.c:868
SCIP_RETCODE SCIPbranchVar(SCIP *scip, SCIP_VAR *var, SCIP_NODE **downchild, SCIP_NODE **eqchild, SCIP_NODE **upchild)
Definition: scip_branch.c:992
SCIP_RETCODE SCIPsetEventhdlrFree(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTFREE((*eventfree)))
Definition: scip_event.c:218
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:529
Definition: type_retcode.h:42
SCIP_Real SCIPcalcCumulativeDistribution(SCIP *scip, SCIP_Real mean, SCIP_Real variance, SCIP_Real value)
Definition: branch_distribution.c:295
public methods for event handler plugins and event handlers
Definition: pqueue.h:28
static SCIP_RETCODE branchruledataEnsureArraySize(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, int maxindex)
Definition: branch_distribution.c:137
Definition: type_var.h:42
Definition: type_retcode.h:33
static SCIP_DECL_BRANCHEXECLP(branchExeclpDistribution)
Definition: branch_distribution.c:1109
static SCIP_RETCODE calcBranchScore(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, SCIP_VAR *var, SCIP_Real lpsolval, SCIP_Real *upscore, SCIP_Real *downscore, char scoreparam)
Definition: branch_distribution.c:609
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:877
Definition: struct_branch.h:69
public data structures and miscellaneous methods
SCIP_Real SCIProwCalcProbability(SCIP *scip, SCIP_ROW *row, SCIP_Real mu, SCIP_Real sigma2, int rowinfinitiesdown, int rowinfinitiesup)
Definition: branch_distribution.c:359
void SCIPbranchruleSetData(SCIP_BRANCHRULE *branchrule, SCIP_BRANCHRULEDATA *branchruledata)
Definition: branch.c:1858
Definition: struct_lp.h:192
public methods for LP management
SCIP_RETCODE SCIPsetBranchruleExitsol(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHEXITSOL((*branchexitsol)))
Definition: scip_branch.c:222
SCIP_RETCODE SCIPdropVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:468
static SCIP_RETCODE varProcessBoundChanges(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, SCIP_VAR *var)
Definition: branch_distribution.c:898
static SCIP_DECL_BRANCHEXITSOL(branchExitsolDistribution)
Definition: branch_distribution.c:1054
public methods for the LP relaxation, rows and columns
public methods for variable pricer plugins
Definition: type_history.h:34
public methods for branching rule plugins and branching
public methods for managing events
general public methods
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:555
SCIP_RETCODE SCIPaddCharParam(SCIP *scip, const char *name, const char *desc, char *valueptr, SCIP_Bool isadvanced, char defaultvalue, const char *allowedvalues, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:239
Definition: type_history.h:35
public methods for the probing mode
static SCIP_DECL_EVENTFREE(eventFreeDistribution)
Definition: branch_distribution.c:1024
static void rowCalculateGauss(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, SCIP_ROW *row, SCIP_Real *mu, SCIP_Real *sigma2, int *rowinfinitiesdown, int *rowinfinitiesup)
Definition: branch_distribution.c:426
public methods for message output
SCIP_Real SCIPgetRowLPFeasibility(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1911
static SCIP_DECL_EVENTEXEC(eventExecDistribution)
Definition: branch_distribution.c:1286
const char * SCIPbranchruleGetName(SCIP_BRANCHRULE *branchrule)
Definition: branch.c:1970
public methods for message handling
SCIP_RETCODE SCIPupdateDistributionScore(SCIP *scip, SCIP_Real currentprob, SCIP_Real newprobup, SCIP_Real newprobdown, SCIP_Real *upscore, SCIP_Real *downscore, char scoreparam)
Definition: branch_distribution.c:539
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip_lp.c:2094
Definition: type_set.h:44
Definition: type_result.h:45
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
Definition: scip_numerics.c:952
SCIP_EVENTHDLRDATA * SCIPeventhdlrGetData(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:324
Definition: objbenders.h:33
public methods for global and local (sub)problems
Definition: struct_event.h:186
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:129
SCIP_RETCODE SCIPincludeBranchruleDistribution(SCIP *scip)
Definition: branch_distribution.c:1311
Definition: type_var.h:58