branch_distribution.c
Go to the documentation of this file.
22 * The distribution branching rule selects a variable based on its impact on row activity distributions. More formally,
23 * 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
25 * Viewing every variable \f$x_i \f$ as (continuously) uniformly distributed within its bounds, we can approximately
26 * 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$
27 * 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
29 * With these two parameters, we can calculate the probability to satisfy the row in terms of the cumulative distribution
32 * The impact of a variable on the probability to satisfy a constraint after branching can be estimated by altering
37 * The selection of the branching variable is subject to the parameter @p scoreparam. For both branching directions,
39 * - @b d: select a branching variable with largest difference in satisfaction probability after branching
42 * - @b v: highest number of votes for lowering row probability for all rows a variable appears in.
43 * - @b w: highest number of votes for increasing row probability for all rows a variable appears in.
45 * If the parameter @p usescipscore is set to @a TRUE, a single branching score is calculated from the respective
46 * up and down scores as defined by the SCIP branching score function (see advanced branching parameter @p scorefunc),
47 * otherwise, the variable with the single highest score is selected, and the maximizing direction is assigned
58 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
82 #define BRANCHRULE_DESC "branching rule based on variable influence on cumulative normal distribution of row activities"
92 #define DEFAULT_ONLYACTIVEROWS FALSE /**< should only rows which are active at the current node be considered? */
93 #define DEFAULT_USEWEIGHTEDSCORE FALSE /**< should the branching score weigh up- and down-scores of a variable */
97 #define EVENT_DISTRIBUTION SCIP_EVENTTYPE_BOUNDCHANGED /**< the event tyoe to be handled by this event handler */
112 int* rowinfinitiesdown; /**< count the number of variables with infinite bounds which allow for always
114 int* rowinfinitiesup; /**< count the number of variables with infinite bounds which allow for always
122 SCIP_Bool onlyactiverows; /**< should only rows which are active at the current node be considered? */
128 SCIP_BRANCHRULEDATA* branchruledata; /**< the branching rule data to access distribution arrays */
135 /** ensure that maxindex + 1 rows can be represented in data arrays; memory gets reallocated with 10% extra space
192 SCIP_CALL( SCIPcatchVarEvent(scip, vars[v], EVENT_DISTRIBUTION, branchruledata->eventhdlr, NULL, &(branchruledata->varfilterposs[v])) );
203 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &branchruledata->rowinfinitiesdown, branchruledata->memsize, newsize) );
204 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &branchruledata->rowinfinitiesup, branchruledata->memsize, newsize) );
205 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &branchruledata->rowmeans, branchruledata->memsize, newsize) );
206 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &branchruledata->rowvariances, branchruledata->memsize, newsize) );
209 /* loop over extended arrays and invalidate data to trigger initialization of this row when necessary */
249 /** calculate the variable's distribution parameters (mean and variance) for the bounds specified in the arguments.
278 /* if the variable is continuous, we assume a continuous uniform distribution, otherwise a discrete one */
290 /** calculates the cumulative distribution P(-infinity <= x <= value) that a normally distributed
323 /* scale and translate to standard normal distribution. Factor sqrt(2) is needed for SCIPerf() function */
326 SCIPdebugMsg(scip, " Normalized value %g = ( %g - %g ) / (%g * 1.4142136)\n", normvalue, value, mean, std);
328 /* calculate the cumulative distribution function for normvalue. For negative normvalues, we negate
329 * the normvalue and use the oddness of the SCIPerf()-function; special treatment for values close to zero.
357 * For equations (lhs==rhs), we use the centeredness measure p = min(PHI(lhs'), 1-PHI(lhs'))/max(PHI(lhs'), 1 - PHI(lhs')),
365 int rowinfinitiesdown, /**< the number of variables with infinite bounds to DECREASE activity */
381 /* use the cumulative distribution if the row contains no variable to repair every infeasibility */
385 /* use the cumulative distribution if the row contains no variable to repair every infeasibility
394 /* use centeredness measure for equations; for inequalities, the minimum of the two probabilities is the
409 SCIPdebugMsg(scip, " Row %s, mean %g, sigma2 %g, LHS %g, RHS %g has probability %g to be satisfied\n",
420 * \f$n \f$ is the number of variables, and \f$ c_i, lb_i, ub_i \f$ are the variable coefficient and
432 SCIP_Real* sigma2, /**< pointer to store the variance value of the gaussian normal distribution */
433 int* rowinfinitiesdown, /**< pointer to store the number of variables with infinite bounds to DECREASE activity */
434 int* rowinfinitiesup /**< pointer to store the number of variables with infinite bounds to INCREASE activity */
484 assert((branchruledata->currentlbs[varindex] == SCIP_INVALID) == (branchruledata->currentubs[varindex] == SCIP_INVALID)); /*lint !e777*/
501 /* an infinite upper bound gives the row an infinite maximum activity or minimum activity, if the coefficient is
510 /* an infinite lower bound gives the row an infinite maximum activity or minimum activity, if the coefficient is
521 SCIPvarCalcDistributionParameters(scip, colvarlb, colvarub, SCIPvarGetType(colvar), &varmean, &varvariance);
523 /* actual values are updated; the contribution of the variable to mu is the arithmetic mean of its bounds */
526 /* 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 */
534 SCIPdebugMsg(scip, " Row %s has a mean value of %g at a sigma2 of %g \n", SCIProwGetName(row), *mu, *sigma2);
537 /** update the up- and downscore of a single variable after calculating the impact of branching on a
615 SCIP_Real* upscore, /**< pointer to store the variable score when branching on it in upward direction */
616 SCIP_Real* downscore, /**< pointer to store the variable score when branching on it in downward direction */
637 SCIP_Bool onlyactiverows; /* should only rows which are active at the current node be considered? */
660 SCIPvarCalcDistributionParameters(scip, varlb, varub, vartype, ¤tmean, &squaredbounddiff);
673 SCIPvarCalcDistributionParameters(scip, varlb, newub, vartype, &meandown, &squaredbounddiffdown);
715 rowCalculateGauss(scip, branchruledata, row, &branchruledata->rowmeans[rowpos], &branchruledata->rowvariances[rowpos],
732 /* first, get the probability change for the row if the variable is branched on upwards. The probability
756 newrowprobup = SCIProwCalcProbability(scip, row, changedrowmean, changedrowvariance, rowinftiesdownafterbranch,
783 newrowprobdown = SCIProwCalcProbability(scip, row, changedrowmean, changedrowvariance, rowinftiesdownafterbranch,
790 SCIP_CALL( SCIPupdateDistributionScore(scip, currentrowprob, newrowprobup, newrowprobdown, upscore, downscore, scoreparam) );
792 SCIPdebugMsg(scip, " Variable %s changes probability of row %s from %g to %g (branch up) or %g;\n",
822 /** 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 */
919 /* skip event execution if SCIP is in Probing mode because these bound changes will be undone anyway before branching
936 /* 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
1197 assert((branchruledata->currentlbs[varindex] == SCIP_INVALID) == (branchruledata->currentubs[varindex] == SCIP_INVALID));
1212 /* loop over candidate rows and determine the candidate up- and down- branching score w.r.t. the score parameter */
1216 /* if weighted scoring is enabled, use the branching score method of SCIP to weigh up and down score */
1252 SCIPdebugMsg(scip, " Candidate %s has score down %g and up %g \n", SCIPvarGetName(lpcand), downscore, upscore);
1253 SCIPdebugMsg(scip, " Best candidate: %s, score %g, direction %d\n", SCIPvarGetName(bestcand), bestscore, bestbranchdir);
1259 SCIPdebugMsg(scip, " Branching on variable %s with bounds [%g, %g] and solution value <%g>\n", SCIPvarGetName(bestcand),
1285 /** event execution method of distribution branching which handles bound change events of variables */
1300 /* add the variable to the queue of unprocessed variables; method itself ensures that every variable is added at most once */
1346 SCIP_CALL( SCIPincludeBranchruleBasic(scip, &branchrule, BRANCHRULE_NAME, BRANCHRULE_DESC, BRANCHRULE_PRIORITY, BRANCHRULE_MAXDEPTH,
1357 "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 SCIPsetBranchruleExecLp(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHEXECLP((*branchexeclp)))
Definition: scip_branch.c:240
void SCIPeventhdlrSetData(SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: event.c:335
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip_mem.h:86
Definition: type_result.h:33
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
static SCIP_VAR * branchruledataPopBoundChangeVar(SCIP_BRANCHRULEDATA *branchruledata)
Definition: branch_distribution.c:868
public methods for SCIP parameter handling
SCIP_RETCODE SCIPsetBranchruleFree(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHFREE((*branchfree)))
Definition: scip_branch.c:160
Definition: struct_scip.h:59
SCIP_Bool SCIPisSumPositive(SCIP *scip, SCIP_Real val)
Definition: scip_numerics.c:749
public methods for memory management
void SCIPvarCalcDistributionParameters(SCIP *scip, SCIP_Real varlb, SCIP_Real varub, SCIP_VARTYPE vartype, SCIP_Real *mean, SCIP_Real *variance)
Definition: branch_distribution.c:251
const char * SCIPbranchruleGetName(SCIP_BRANCHRULE *branchrule)
Definition: branch.c:1971
static void branchruledataFreeArrays(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata)
Definition: branch_distribution.c:803
SCIP_RETCODE SCIPincludeBranchruleDistribution(SCIP *scip)
Definition: branch_distribution.c:1312
SCIP_BRANCHRULEDATA * SCIPbranchruleGetData(SCIP_BRANCHRULE *branchrule)
Definition: branch.c:1849
static void branchruledataAddBoundChangeVar(SCIP_BRANCHRULEDATA *branchruledata, SCIP_VAR *var)
Definition: branch_distribution.c:826
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip_lp.c:2152
Definition: struct_var.h:198
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:144
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
Definition: scip_numerics.c:862
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:799
public methods for problem variables
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:48
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:107
static void branchruledataUpdateCurrentBounds(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, SCIP_VAR *var)
Definition: branch_distribution.c:226
Definition: type_history.h:37
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
Definition: scip_numerics.c:874
Definition: struct_tree.h:132
public methods for numerical tolerances
Definition: struct_lp.h:126
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:540
SCIP_EVENTHDLRDATA * SCIPeventhdlrGetData(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:325
SCIP_EXPORT SCIP_Real SCIPvarGetSol(SCIP_VAR *var, SCIP_Bool getlpval)
Definition: var.c:13021
SCIP_RETCODE SCIPsetEventhdlrFree(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTFREE((*eventfree)))
Definition: scip_event.c:141
Definition: type_retcode.h:42
public methods for event handler plugins and event handlers
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:773
Definition: pqueue.h:28
static SCIP_RETCODE branchruledataEnsureArraySize(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, int maxindex)
Definition: branch_distribution.c:138
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:610
Definition: struct_branch.h:69
SCIP_RETCODE SCIPbranchVar(SCIP *scip, SCIP_VAR *var, SCIP_NODE **downchild, SCIP_NODE **eqchild, SCIP_NODE **upchild)
Definition: scip_branch.c:1041
public data structures and miscellaneous methods
SCIP_RETCODE SCIPchgChildPrio(SCIP *scip, SCIP_NODE *child, SCIP_Real priority)
Definition: scip_prob.c:3785
SCIP_RETCODE SCIPdropVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip_event.c:391
SCIP_Real SCIProwCalcProbability(SCIP *scip, SCIP_ROW *row, SCIP_Real mu, SCIP_Real sigma2, int rowinfinitiesdown, int rowinfinitiesup)
Definition: branch_distribution.c:360
Definition: struct_lp.h:192
public methods for LP management
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:825
static SCIP_RETCODE varProcessBoundChanges(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, SCIP_VAR *var)
Definition: branch_distribution.c:897
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:95
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
Definition: type_history.h:35
public methods for the probing mode
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:786
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:427
public methods for message output
static SCIP_DECL_EVENTEXEC(eventExecDistribution)
Definition: branch_distribution.c:1287
SCIP_Real SCIPcalcCumulativeDistribution(SCIP *scip, SCIP_Real mean, SCIP_Real variance, SCIP_Real value)
Definition: branch_distribution.c:296
SCIP_RETCODE SCIPsetBranchruleExitsol(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHEXITSOL((*branchexitsol)))
Definition: scip_branch.c:224
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:451
public methods for message handling
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:477
SCIP_RETCODE SCIPgetLPBranchCands(SCIP *scip, SCIP_VAR ***lpcands, SCIP_Real **lpcandssol, SCIP_Real **lpcandsfrac, int *nlpcands, int *npriolpcands, int *nfracimplvars)
Definition: scip_branch.c:386
SCIP_Real SCIPgetRowLPFeasibility(SCIP *scip, SCIP_ROW *row)
Definition: scip_lp.c:1950
Definition: type_set.h:44
SCIP_RETCODE SCIPcatchVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip_event.c:345
Definition: type_result.h:45
SCIP_Real SCIPgetBranchScore(SCIP *scip, SCIP_VAR *var, SCIP_Real downgain, SCIP_Real upgain)
Definition: scip_branch.c:840
Definition: objbenders.h:33
void SCIPbranchruleSetData(SCIP_BRANCHRULE *branchrule, SCIP_BRANCHRULEDATA *branchruledata)
Definition: branch.c:1859
public methods for global and local (sub)problems
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:158
Definition: struct_event.h:195
Definition: type_var.h:58