30 #define BRANCHRULE_NAME "pscost" 31 #define BRANCHRULE_DESC "branching on pseudo cost values" 32 #define BRANCHRULE_PRIORITY 2000 33 #define BRANCHRULE_MAXDEPTH -1 34 #define BRANCHRULE_MAXBOUNDDIST 1.0 36 #define BRANCHRULE_STRATEGIES "cdsu" 37 #define BRANCHRULE_STRATEGY_DEFAULT 'u' 38 #define BRANCHRULE_SCOREMINWEIGHT_DEFAULT 0.8 39 #define BRANCHRULE_SCOREMAXWEIGHT_DEFAULT 1.3 40 #define BRANCHRULE_SCORESUMWEIGHT_DEFAULT 0.1 41 #define BRANCHRULE_NCHILDREN_DEFAULT 2 42 #define BRANCHRULE_NARYMAXDEPTH_DEFAULT -1 43 #define BRANCHRULE_NARYMINWIDTH_DEFAULT 0.001 44 #define BRANCHRULE_NARYWIDTHFAC_DEFAULT 2.0 45 #define BRANCHRULE_RANDSEED_DEFAULT 47 48 #define WEIGHTEDSCORING(data, min, max, sum) \ 49 ((data)->scoreminweight * (min) + (data)->scoremaxweight * (max) + (data)->scoresumweight * (sum)) 52 struct SCIP_BranchruleData
101 assert(scip != NULL);
102 assert(branchruledata != NULL);
103 assert(bestvar != NULL);
104 assert(bestbrpoint != NULL);
105 assert(bestscore != NULL);
106 assert(cand != NULL);
146 for( i = 0; i < nmultvars; ++i )
151 if(
SCIPisEQ(scip, multvarlb, multvarub) )
154 assert(multscalars != NULL);
155 assert(multscalars[i] != 0.0);
161 if( multscalars[i] > 0.0 )
167 aggrvarsol1 = (candsol - maxact) / multscalars[i] + multvarub;
173 aggrvarsol2 = (candsol - minact) / multscalars[i] + multvarlb;
181 aggrvarsol2 = (candsol - maxact) / multscalars[i] + multvarlb;
187 aggrvarsol1 = (candsol - minact) / multscalars[i] + multvarub;
200 aggrvarsol = aggrvarsol2;
205 aggrvarsol = aggrvarsol1;
207 aggrvarsol =
REALABS(aggrvarsol1) <
REALABS(aggrvarsol2) ? aggrvarsol1 : aggrvarsol2;
212 multvars[i], candscoremin, candscoremax, candscoresum, candrndscore, aggrvarsol) );
217 for( i = 0; i < nmultvars; ++i )
222 if(
SCIPisEQ(scip, multvarlb, multvarub) )
226 multvars[i], candscoremin, candscoremax, candscoresum, candrndscore,
SCIP_INVALID) );
229 assert(*bestvar != NULL);
248 strategy = (branchruledata->strategy ==
'u' ? branchruledata->updatestrategy : branchruledata->strategy);
250 strategy = (branchruledata->strategy ==
'u' ?
'l' : branchruledata->strategy);
291 deltaminus = deltaplus;
311 SCIPdebugMsg(scip,
"branching score variable <%s>[%g,%g] = %g; wscore = %g; type=%d bestbrscore=%g\n",
320 (*bestscore) = branchscore;
321 (*bestrndscore) = candrndscore;
323 (*bestbrpoint) = candbrpoint;
342 (*bestscore) = branchscore;
343 (*bestrndscore) = candrndscore;
345 (*bestbrpoint) = candbrpoint;
363 (*bestscore) = branchscore;
364 (*bestrndscore) = candrndscore;
366 (*bestbrpoint) = candbrpoint;
385 (*bestscore) = branchscore;
386 (*bestrndscore) = candrndscore;
388 (*bestbrpoint) = candbrpoint;
403 (*bestscore) = branchscore;
404 (*bestrndscore) = candrndscore;
406 (*bestbrpoint) = candbrpoint;
416 if( candrndscore >= (*bestrndscore) )
418 (*bestscore) = branchscore;
419 (*bestrndscore) = candrndscore;
421 (*bestbrpoint) = candbrpoint;
458 assert(brvar != NULL);
459 assert(brpoint != NULL);
468 assert(branchruledata != NULL);
473 for( i = 0; i < ncands; ++i )
476 SCIPsortPtrInt((
void**)candssorted, candsorigidx, SCIPvarComp, ncands);
478 bestbranchscore = -1.0;
481 for( i = 0; i < ncands; ++i )
483 cand = candssorted[i];
490 scoremin = candsscore[candsorigidx[i]];
493 candsol = candssol[candsorigidx[i]];
494 for( j = i+1 ; j < ncands &&
SCIPvarCompare(candssorted[j], cand) == 0; ++j )
496 assert(candsscore[candsorigidx[j]] >= 0.0);
497 scoresum += candsscore[candsorigidx[j]];
498 if( candsscore[candsorigidx[j]] < scoremin )
499 scoremin = candsscore[candsorigidx[j]];
500 else if( candsscore[candsorigidx[j]] > scoremax )
501 scoremax = candsscore[candsorigidx[j]];
505 candsol = candssol[candsorigidx[j]];
509 assert(candssorted[i] == cand);
513 scoremin, scoremax, scoresum,
SCIPrandomGetReal(branchruledata->randnumgen, 0.0, 1.0), candsol) );
520 if( (*brvar) == NULL )
522 SCIPerrorMessage(
"no branching could be created: all external candidates have huge bounds\n");
541 assert(
scip != NULL);
542 assert(branchrule != NULL);
559 assert(branchruledata != NULL);
579 assert(branchruledata != NULL);
598 assert(branchrule != NULL);
600 assert(
scip != NULL);
601 assert(result != NULL);
607 assert(nlpcands > 0);
612 for( c = 0; c < nlpcands; ++c )
620 rootdiff =
REALABS(lpcandssol[c] - rootsolval);
625 bestrootdiff = rootdiff;
628 assert(0 <= bestcand && bestcand < nlpcands);
633 SCIPdebugMsg(
scip,
" -> %d cands, selected cand %d: variable <%s> (solval=%g, score=%g)\n",
634 nlpcands, bestcand,
SCIPvarGetName(lpcands[bestcand]), lpcandssol[bestcand], bestscore);
652 int nprioexterncands;
657 assert(branchrule != NULL);
659 assert(
scip != NULL);
660 assert(result != NULL);
663 assert(branchruledata != NULL);
669 assert(nprioexterncands > 0);
672 if( branchruledata->strategy ==
'u' )
689 SCIPdebugMsg(
scip,
"branching on variable <%s>: new intervals: [%g, %g] and [%g, %g]\n",
743 assert(branchrule != NULL);
756 "strategy for utilizing pseudo-costs of external branching candidates (multiply as in pseudo costs 'u'pdate rule, or by 'd'omain reduction, or by domain reduction of 's'ibling, or by 'v'ariable score)",
760 "weight for minimum of scores of a branching candidate when building weighted sum of min/max/sum of scores",
764 "weight for maximum of scores of a branching candidate when building weighted sum of min/max/sum of scores",
768 "weight for sum of scores of a branching candidate when building weighted sum of min/max/sum of scores",
772 "number of children to create in n-ary branching",
776 "maximal depth where to do n-ary branching, -1 to turn off",
780 "minimal domain width in children when doing n-ary branching, relative to global bounds",
784 "factor of domain width in n-ary branching when creating nodes with increasing distance from branching value",
804 assert(scip != NULL);
808 assert(branchrule != NULL);
811 SCIP_CALL(
selectBranchVar(scip, branchrule, branchcands, branchcandssol, branchcandsscore, nbranchcands, var, brpoint) );
SCIP_RETCODE SCIPgetLPBranchCands(SCIP *scip, SCIP_VAR ***lpcands, SCIP_Real **lpcandssol, SCIP_Real **lpcandsfrac, int *nlpcands, int *npriolpcands, int *nfracimplvars)
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
void SCIPsortPtrInt(void **ptrarray, int *intarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
SCIP_RETCODE SCIPgetCharParam(SCIP *scip, const char *name, char *value)
SCIP_BRANCHRULEDATA * SCIPbranchruleGetData(SCIP_BRANCHRULE *branchrule)
static SCIP_RETCODE updateBestCandidate(SCIP *scip, SCIP_BRANCHRULEDATA *branchruledata, SCIP_VAR **bestvar, SCIP_Real *bestbrpoint, SCIP_Real *bestscore, SCIP_Real *bestrndscore, SCIP_VAR *cand, SCIP_Real candscoremin, SCIP_Real candscoremax, SCIP_Real candscoresum, SCIP_Real candrndscore, SCIP_Real candsol)
#define BRANCHRULE_NCHILDREN_DEFAULT
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
SCIP_Real * SCIPvarGetMultaggrScalars(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
#define BRANCHRULE_NARYMAXDEPTH_DEFAULT
SCIP_Real SCIPgetVarPseudocostVal(SCIP *scip, SCIP_VAR *var, SCIP_Real solvaldelta)
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed)
void SCIPsetRandomSeed(SCIP *scip, SCIP_RANDNUMGEN *randnumgen, unsigned int seed)
SCIP_VAR ** SCIPvarGetMultaggrVars(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
struct SCIP_BranchruleData SCIP_BRANCHRULEDATA
SCIP_Real SCIPgetBranchingPoint(SCIP *scip, SCIP_VAR *var, SCIP_Real suggestion)
SCIP_Real SCIPvarGetSol(SCIP_VAR *var, SCIP_Bool getlpval)
SCIP_Real SCIPvarGetRootSol(SCIP_VAR *var)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPsetBranchruleFree(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHFREE((*branchfree)))
static SCIP_DECL_BRANCHEXECEXT(branchExecextPscost)
SCIP_Real SCIPadjustedVarUb(SCIP *scip, SCIP_VAR *var, SCIP_Real ub)
SCIP_RETCODE SCIPbranchVarValNary(SCIP *scip, SCIP_VAR *var, SCIP_Real val, int n, SCIP_Real minwidth, SCIP_Real widthfactor, int *nchildren)
SCIP_Real SCIPrelDiff(SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
static SCIP_DECL_BRANCHCOPY(branchCopyPscost)
SCIP_RETCODE SCIPsetBranchruleCopy(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHCOPY((*branchcopy)))
enum SCIP_Retcode SCIP_RETCODE
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
#define BRANCHRULE_NARYMINWIDTH_DEFAULT
#define SCIPfreeBlockMemory(scip, ptr)
static SCIP_DECL_BRANCHINIT(branchInitPscost)
SCIP_RETCODE SCIPincludeBranchruleBasic(SCIP *scip, SCIP_BRANCHRULE **branchruleptr, const char *name, const char *desc, int priority, int maxdepth, SCIP_Real maxbounddist, SCIP_BRANCHRULEDATA *branchruledata)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
#define BRANCHRULE_STRATEGY_DEFAULT
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
int SCIPnodeGetDepth(SCIP_NODE *node)
SCIP_RETCODE SCIPgetExternBranchCands(SCIP *scip, SCIP_VAR ***externcands, SCIP_Real **externcandssol, SCIP_Real **externcandsscore, int *nexterncands, int *nprioexterncands, int *nprioexternbins, int *nprioexternints, int *nprioexternimpls)
#define SCIPfreeBufferArray(scip, ptr)
SCIP_Real SCIPadjustedVarLb(SCIP *scip, SCIP_VAR *var, SCIP_Real lb)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
#define WEIGHTEDSCORING(data, min, max, sum)
SCIP_Real SCIPcomputeVarLbLocal(SCIP *scip, SCIP_VAR *var)
SCIP_Real SCIPgetVarPseudocostScore(SCIP *scip, SCIP_VAR *var, SCIP_Real solval)
SCIP_RETCODE SCIPsetBranchruleExecLp(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHEXECLP((*branchexeclp)))
SCIP_Real SCIPgetBranchScore(SCIP *scip, SCIP_VAR *var, SCIP_Real downgain, SCIP_Real upgain)
static SCIP_DECL_BRANCHEXECLP(branchExeclpPscost)
SCIP_RETCODE SCIPselectBranchVarPscost(SCIP *scip, SCIP_VAR **branchcands, SCIP_Real *branchcandssol, SCIP_Real *branchcandsscore, int nbranchcands, SCIP_VAR **var, SCIP_Real *brpoint)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
SCIP_VAR * SCIPvarGetProbvar(SCIP_VAR *var)
#define BRANCHRULE_STRATEGIES
SCIP_RETCODE SCIPbranchVar(SCIP *scip, SCIP_VAR *var, SCIP_NODE **downchild, SCIP_NODE **eqchild, SCIP_NODE **upchild)
const char * SCIPvarGetName(SCIP_VAR *var)
static SCIP_DECL_BRANCHFREE(branchFreePscost)
SCIP_Bool SCIPisSumEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPcomputeVarUbLocal(SCIP *scip, SCIP_VAR *var)
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define BRANCHRULE_PRIORITY
SCIP_Bool SCIPisHugeValue(SCIP *scip, SCIP_Real val)
#define SCIPallocBufferArray(scip, ptr, num)
static SCIP_RETCODE selectBranchVar(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_VAR **cands, SCIP_Real *candssol, SCIP_Real *candsscore, int ncands, SCIP_VAR **brvar, SCIP_Real *brpoint)
public data structures and miscellaneous methods
pseudo costs branching rule
SCIP_Bool SCIPisSumGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define BRANCHRULE_RANDSEED_DEFAULT
#define BRANCHRULE_MAXDEPTH
void SCIPbranchruleSetData(SCIP_BRANCHRULE *branchrule, SCIP_BRANCHRULEDATA *branchruledata)
int SCIPvarCompare(SCIP_VAR *var1, SCIP_VAR *var2)
SCIP_RETCODE SCIPsetBranchruleExecExt(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHEXECEXT((*branchexecext)))
#define BRANCHRULE_SCORESUMWEIGHT_DEFAULT
#define BRANCHRULE_SCOREMAXWEIGHT_DEFAULT
int SCIPvarGetMultaggrNVars(SCIP_VAR *var)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
SCIP_Bool SCIPisIntegral(SCIP *scip, SCIP_Real val)
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)
#define BRANCHRULE_MAXBOUNDDIST
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
const char * SCIPbranchruleGetName(SCIP_BRANCHRULE *branchrule)
SCIP_RETCODE SCIPsetBranchruleInit(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_DECL_BRANCHINIT((*branchinit)))
#define BRANCHRULE_NARYWIDTHFAC_DEFAULT
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
SCIP_RETCODE SCIPincludeBranchrulePscost(SCIP *scip)
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
#define BRANCHRULE_SCOREMINWEIGHT_DEFAULT
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)