29 #define HEUR_NAME "locks" 30 #define HEUR_DESC "heuristic that fixes variables based on their rounding locks" 31 #define HEUR_DISPCHAR 'k' 32 #define HEUR_PRIORITY 3000 34 #define HEUR_FREQOFS 0 35 #define HEUR_MAXDEPTH -1 36 #define HEUR_TIMING SCIP_HEURTIMING_BEFORENODE 37 #define HEUR_USESSUBSCIP TRUE 39 #define DEFAULT_MAXNODES 5000LL 40 #define DEFAULT_ROUNDUPPROBABILITY 0.67 41 #define DEFAULT_MINFIXINGRATE 0.65 42 #define DEFAULT_MINIMPROVE 0.01 45 #define DEFAULT_MINNODES 500LL 46 #define DEFAULT_NODESOFS 500LL 47 #define DEFAULT_NODESQUOT 0.1 48 #define DEFAULT_MAXPROPROUNDS 2 49 #define DEFAULT_UPDATELOCKS TRUE 50 #define DEFAULT_COPYCUTS TRUE 52 #define DEFAULT_USEFINALSUBMIP TRUE 54 #define DEFAULT_RANDSEED 73 96 assert(subscip != NULL);
97 assert(subvars != NULL);
98 assert(subsol != NULL);
99 assert(success != NULL);
128 assert(scip != NULL);
129 assert(heur != NULL);
144 assert(scip != NULL);
145 assert(heur != NULL);
164 assert(heurdata != NULL);
167 heurdata->usednodes = 0;
186 assert(heurdata != NULL);
194 #define heurInitsolLocks NULL 195 #define heurExitsolLocks NULL 233 int nglbfulfilledrows;
247 assert(scip != NULL);
248 assert(cutoff != NULL);
249 assert(allrowsfulfilled != NULL);
252 if( heurdata == NULL )
257 assert(heurdata != NULL);
260 *allrowsfulfilled =
FALSE;
262 propagate = (heurdata->maxproprounds != 0);
264 if( heurdata->maxproprounds == -2 )
267 maxproprounds = heurdata->maxproprounds;
269 roundupprobability = heurdata->roundupprobability;
277 assert(vars != NULL);
292 nglbfulfilledrows = 0;
295 for( v = 0; v < nbinvars; ++v )
303 for( r = 0; r < nlprows; ++r )
316 lastbestscore = INT_MAX;
319 for( v = 0; v < nbinvars; v++ )
336 bestscore = nuplocks[v] + ndownlocks[v];
339 if( bestscore < lastbestscore )
341 for( i = v + 1; i < nbinvars; ++i )
350 sortvars[i] = sortvars[v];
354 nuplocks[i] = nuplocks[v];
357 locks = ndownlocks[i];
358 ndownlocks[i] = ndownlocks[v];
359 ndownlocks[v] = locks;
375 score = nuplocks[i] + ndownlocks[i];
376 assert(score <= lastbestscore);
378 if( score > bestscore )
383 if( bestscore == lastbestscore )
390 lastbestscore = bestscore;
397 var = sortvars[bestpos];
398 sortvars[bestpos] = sortvars[v];
401 locks = nuplocks[bestpos];
402 nuplocks[bestpos] = nuplocks[v];
405 locks = ndownlocks[bestpos];
406 ndownlocks[bestpos] = ndownlocks[v];
407 ndownlocks[v] = locks;
421 assert(v == nbinvars);
437 if( ndownlocks[v] > nuplocks[v] )
439 else if( ndownlocks[v] < nuplocks[v] )
451 if( randnumber < roundupprobability )
458 lastfixlocks = lastfixval > 0.5 ? nuplocks[v] : ndownlocks[v];
462 SCIPdebugMsg(scip,
"iteration %d: fixing variable <%s> to %d with locks (%d, %d)\n", v,
SCIPvarGetName(var), lastfixval > 0.5 ? 1 : 0, ndownlocks[v], nuplocks[v]);
464 if( propagate && lastfixlocks > 0 )
472 SCIPdebugMsg(scip,
"last fixing led to infeasibility trying other bound\n");
478 if( lastfixval < 0.5 )
536 for( r = 0; r < ncolrows; ++r )
545 assert(lprows[rowpos] == row);
552 if( fulfilled[rowpos] )
559 assert(hasrhs || haslhs);
561 if( ((colvals[r] > 0) == (lastfixval < 0.5)) )
563 maxact[rowpos] -=
REALABS(colvals[r]);
565 if( ((colvals[r] > 0) == (lastfixval > 0.5)) )
567 minact[rowpos] +=
REALABS(colvals[r]);
588 for( pos = 0; pos < nbinvars; ++pos )
593 fulfilled[rowpos] =
TRUE;
599 for( w = ncols - 1; w >= 0; --w )
635 SCIPdebugMsg(scip,
"found infeasible row, stopping heur\n");
639 nglbfulfilledrows += nfulfilledrows;
640 SCIPdebugMsg(scip,
"last fixing led to %d fulfilled rows, now %d of %d rows are fulfilled\n", nfulfilledrows, nglbfulfilledrows, nlprows);
642 if( nglbfulfilledrows == nlprows )
644 *allrowsfulfilled =
TRUE;
719 assert(heurdata != NULL);
740 #ifdef COLLECTSTATISTICS 755 SCIPdebugMsg(scip,
"npscands=%d, oldnpscands=%d, allrowsfulfilled=%u heurdata->minfixingrate=%g\n",
756 npscands, oldnpscands, allrowsfulfilled, heurdata->minfixingrate);
758 if( !allrowsfulfilled && npscands > oldnpscands * (1 - heurdata->minfixingrate) )
778 SCIPwarningMessage(scip,
"Error while solving LP in LOCKS heuristic; LP solve terminated with code <%d>\n",
816 #ifdef SCIP_MORE_DEBUG 847 nstallnodes += heurdata->nodesofs;
850 nstallnodes -= heurdata->usednodes;
851 nstallnodes = MIN(nstallnodes, heurdata->maxnodes);
854 if( nstallnodes < heurdata->minnodes )
856 SCIPdebugMsg(scip,
"skipping " HEUR_NAME ": nstallnodes=%" SCIP_LONGINT_FORMAT
", minnodes=%" SCIP_LONGINT_FORMAT
"\n", nstallnodes, heurdata->minnodes);
880 if( heurdata->copycuts )
886 for( i = 0; i < nvars; i++ )
946 minimprove = heurdata->minimprove;
953 cutoffbound = (1-minimprove) *
SCIPgetUpperbound(scip) + minimprove * lowerbound;
962 cutoffbound = MIN(upperbound, cutoffbound);
964 SCIPdebugMsg(scip,
"setting objlimit for subscip to %g\n", cutoffbound);
979 SCIPwarningMessage(scip,
"Error while presolving subMIP in locks heuristic; sub-SCIP terminated with code <%d>\n", retstat);
981 goto FREESCIPANDTERMINATE;
999 SCIPdebugMsg(scip,
"solving subproblem: nstallnodes=%" SCIP_LONGINT_FORMAT
", maxnodes=%" SCIP_LONGINT_FORMAT
"\n", nstallnodes, heurdata->maxnodes);
1007 SCIPwarningMessage(scip,
"Error while solving subMIP in locks heuristic; sub-SCIP terminated with code <%d>\n",retstat);
1009 goto FREESCIPANDTERMINATE;
1024 for( i = 0; i < nsubsols && !success; ++i )
1038 FREESCIPANDTERMINATE:
1083 heurFreeLocks, heurInitLocks, heurExitLocks,
1088 "maximum number of propagation rounds to be performed in each propagation call (-1: no limit, -2: parameter settings)",
1092 "minimum percentage of integer variables that have to be fixable",
1096 "probability for rounding a variable up in case of ties",
1100 "should a final sub-MIP be solved to costruct a feasible solution if the LP was not roundable?",
1104 "maximum number of nodes to regard in the subproblem",
1108 "number of nodes added to the contingent of the total nodes",
1112 "minimum number of nodes required to start the subproblem",
1116 "contingent of sub problem nodes in relation to the number of nodes of the original problem",
1120 "factor by which " HEUR_NAME " heuristic should at least improve the incumbent",
1124 "should all active cuts from cutpool be copied to constraints in subproblem?",
1128 "should the locks be updated based on LP rows?",
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
int SCIPgetNCheckConss(SCIP *scip)
SCIP_RETCODE SCIPlinkLPSol(SCIP *scip, SCIP_SOL *sol)
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
#define DEFAULT_MINIMPROVE
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
SCIP_RETCODE SCIPbacktrackProbing(SCIP *scip, int probingdepth)
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
int SCIPgetProbingDepth(SCIP *scip)
#define SCIPallocClearBufferArray(scip, ptr, num)
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed)
SCIP_Real * SCIPcolGetVals(SCIP_COL *col)
int SCIProwGetNNonz(SCIP_ROW *row)
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
int SCIPgetNOrigVars(SCIP *scip)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
int SCIPgetNPseudoBranchCands(SCIP *scip)
const char * SCIProwGetName(SCIP_ROW *row)
static SCIP_DECL_HEUREXEC(heurExecLocks)
static SCIP_RETCODE createNewSol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_SOL *newsol, SCIP_SOL *subsol, SCIP_Bool *success)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
SCIP_SOL ** SCIPgetSols(SCIP *scip)
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
SCIP_RETCODE SCIPcutoffNode(SCIP *scip, SCIP_NODE *node)
SCIP_RETCODE SCIPapplyLockFixings(SCIP *scip, SCIP_HEURDATA *heurdata, SCIP_Bool *cutoff, SCIP_Bool *allrowsfulfilled)
enum SCIP_Retcode SCIP_RETCODE
SCIP_RETCODE SCIPincludeHeur(SCIP *scip, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEURCOPY((*heurcopy)), SCIP_DECL_HEURFREE((*heurfree)), SCIP_DECL_HEURINIT((*heurinit)), SCIP_DECL_HEUREXIT((*heurexit)), SCIP_DECL_HEURINITSOL((*heurinitsol)), SCIP_DECL_HEUREXITSOL((*heurexitsol)), SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
int SCIPvarGetProbindex(SCIP_VAR *var)
struct SCIP_HeurData SCIP_HEURDATA
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
SCIP_RETCODE SCIPconstructLP(SCIP *scip, SCIP_Bool *cutoff)
#define SCIPfreeBufferArray(scip, ptr)
enum SCIP_LPSolStat SCIP_LPSOLSTAT
SCIP_RETCODE SCIPcreate(SCIP **scip)
#define SCIPallocBlockMemory(scip, ptr)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
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)
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
static SCIP_DECL_HEUREXIT(heurExitLocks)
SCIP_Real SCIPgetRowMaxActivity(SCIP *scip, SCIP_ROW *row)
#define DEFAULT_ROUNDUPPROBABILITY
SCIP_Bool SCIPisLPConstructed(SCIP *scip)
SCIP_RETCODE SCIPsolve(SCIP *scip)
const char * SCIPheurGetName(SCIP_HEUR *heur)
SCIP_HEUR * SCIPfindHeur(SCIP *scip, const char *name)
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
SCIP_ROW ** SCIPcolGetRows(SCIP_COL *col)
SCIP_RETCODE SCIPpropagateProbing(SCIP *scip, int maxproprounds, SCIP_Bool *cutoff, SCIP_Longint *ndomredsfound)
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_RETCODE SCIPfixVarProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval)
#define SCIPfreeBufferArrayNull(scip, ptr)
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
SCIP_STATUS SCIPgetStatus(SCIP *scip)
SCIP_RETCODE SCIPpresolve(SCIP *scip)
static SCIP_DECL_HEURINIT(heurInitLocks)
SCIP_RETCODE SCIPcopyCuts(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, int *ncutsadded)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
static SCIP_DECL_HEURCOPY(heurCopyLocks)
SCIP_RETCODE SCIPendProbing(SCIP *scip)
const char * SCIPvarGetName(SCIP_VAR *var)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
#define DEFAULT_NODESQUOT
#define DEFAULT_UPDATELOCKS
int SCIPgetNLPRows(SCIP *scip)
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPsolveProbingLP(SCIP *scip, int itlim, SCIP_Bool *lperror, SCIP_Bool *cutoff)
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
#define SCIPallocBufferArray(scip, ptr, num)
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
SCIP_RETCODE SCIPcheckSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *feasible)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
SCIP_RETCODE SCIProundSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *success)
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
#define DEFAULT_MAXPROPROUNDS
int SCIPgetDepth(SCIP *scip)
int SCIPvarGetNLocksUp(SCIP_VAR *var)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
SCIP_RETCODE SCIPincludeHeurLocks(SCIP *scip)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
void SCIPenableVarHistory(SCIP *scip)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
int SCIPgetNSols(SCIP *scip)
#define DEFAULT_USEFINALSUBMIP
int SCIPgetNRuns(SCIP *scip)
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
SCIP_RETCODE SCIPflushLP(SCIP *scip)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPtrySol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
#define SCIP_MAXTREEDEPTH
int SCIPgetNBinVars(SCIP *scip)
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
SCIP_Bool SCIPinProbing(SCIP *scip)
int SCIProwGetRank(SCIP_ROW *row)
int SCIPgetNVars(SCIP *scip)
int SCIPcolGetNNonz(SCIP_COL *col)
int SCIPvarGetNLocksDown(SCIP_VAR *var)
SCIP_Real SCIPgetLPObjval(SCIP *scip)
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
int SCIPgetNConss(SCIP *scip)
SCIP_RETCODE SCIPcopy(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
int SCIProwGetLPPos(SCIP_ROW *row)
SCIP_Bool SCIPisStopped(SCIP *scip)
SCIP_Real SCIPgetRowMinActivity(SCIP *scip, SCIP_ROW *row)
int SCIPconshdlrGetNCheckConss(SCIP_CONSHDLR *conshdlr)
static SCIP_DECL_HEURFREE(heurFreeLocks)
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
SCIP_RETCODE SCIPnewProbingNode(SCIP *scip)
SCIP_Real SCIPsumepsilon(SCIP *scip)
SCIP_Real SCIPgetUpperbound(SCIP *scip)
SCIP_RETCODE SCIPstartProbing(SCIP *scip)
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
#define SCIP_CALL_ABORT(x)
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
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_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
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)
SCIP_RETCODE SCIPfree(SCIP **scip)
#define DEFAULT_MINFIXINGRATE
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)