29 #define HEUR_NAME "zirounding" 30 #define HEUR_DESC "LP rounding heuristic as suggested by C. Wallace taking row slacks and bounds into account" 31 #define HEUR_DISPCHAR 'z' 32 #define HEUR_PRIORITY -500 34 #define HEUR_FREQOFS 0 35 #define HEUR_MAXDEPTH -1 36 #define HEUR_TIMING SCIP_HEURTIMING_AFTERLPNODE 37 #define HEUR_USESSUBSCIP FALSE 39 #define DEFAULT_MAXROUNDINGLOOPS 2 40 #define DEFAULT_STOPZIROUND TRUE 41 #define DEFAULT_STOPPERCENTAGE 0.02 42 #define DEFAULT_MINSTOPNCALLS 1000 86 return MIN(upgap, downgap);
109 assert(scip !=
NULL);
111 assert(upslacks !=
NULL);
112 assert(downslacks !=
NULL);
113 assert(upperbound !=
NULL);
114 assert(lowerbound !=
NULL);
126 assert(colvals !=
NULL);
127 assert(colrows !=
NULL);
146 for( i = 0; i < ncolvals && (*lowerbound > 0.0 || *upperbound > 0.0); ++i )
158 assert(0 <= rowpos && rowpos < nslacks);
166 *numericalerror =
TRUE;
170 SCIPdebugMsg(scip,
"colval: %15.8g, downslack: %15.8g, upslack: %5.2g, lb: %5.2g, ub: %5.2g\n", colvals[i], downslacks[rowpos], upslacks[rowpos],
171 *lowerbound, *upperbound);
181 upslack =
MAX(upslacks[rowpos], 0.0);
182 *upperbound =
MIN(*upperbound, upslack/colvals[i]);
188 downslack =
MAX(downslacks[rowpos], 0.0);
189 *lowerbound =
MIN(*lowerbound, downslack/colvals[i]);
194 assert(colvals[i] != 0.0);
199 upslack =
MAX(upslacks[rowpos], 0.0);
200 *lowerbound =
MIN(*lowerbound, -upslack/colvals[i]);
206 downslack =
MAX(downslacks[rowpos], 0.0);
207 *upperbound =
MIN(*upperbound, -downslack/colvals[i]);
234 assert(scip !=
NULL);
237 assert(upslacks !=
NULL);
238 assert(downslacks !=
NULL);
239 assert(activities !=
NULL);
240 assert(nslacks >= 0);
248 assert(nrows == 0 || (rows !=
NULL && colvals !=
NULL));
251 for( i = 0; i < nrows; ++i )
256 assert(-1 <= rowpos && rowpos < nslacks);
263 val = colvals[i] * shiftvalue;
271 assert(slackvars[rowpos] !=
NULL);
274 slackvarsolval =
SCIPgetSolVal(scip, sol, slackvars[rowpos]);
275 slackvarshiftval = -val / slackcoeffs[rowpos];
283 activities[rowpos] += val;
287 upslacks[rowpos] -= val;
289 downslacks[rowpos] += val;
313 assert(varpointer !=
NULL);
314 assert(coeffpointer !=
NULL);
320 assert(nrowvals == 0 || rowvals !=
NULL);
321 assert(nrowvals == 0 || rowcols !=
NULL);
324 for( v = nrowvals - 1; v >= 0; --v )
328 assert(rowcols[v] !=
NULL);
340 *coeffpointer = rowvals[v];
341 *varpointer = colvar;
362 assert(heur !=
NULL);
380 assert(heurdata !=
NULL);
398 assert(heurdata !=
NULL);
415 assert(heurdata !=
NULL);
432 assert(heurdata !=
NULL);
434 heurdata->lastlp = -1;
473 assert(result !=
NULL);
492 assert(heurdata !=
NULL);
502 if( nlps == heurdata->lastlp )
505 heurdata->lastlp = nlps;
509 nlpcands = nlpcands + nimplfracs;
514 assert(nlpcands > 0);
515 assert(lpcands !=
NULL);
516 assert(lpcandssol !=
NULL);
526 assert(rows !=
NULL);
559 numericalerror =
FALSE;
563 for( c = 0; c < nlpcands; ++c )
571 assert(cand !=
NULL);
577 assert(candrows ==
NULL || ncandrows > 0);
579 for( r = 0; r < ncandrows; ++r )
583 assert(candrows !=
NULL);
584 assert(candrows[r] !=
NULL);
589 rowneedsslackvar[rowpos] =
TRUE;
599 for( i = 0; i < nslacks; ++i )
620 downslacks[i] = activities[i] - lhs;
625 upslacks[i] = rhs - activities[i];
627 SCIPdebugMsg(
scip,
"lhs:%5.2f <= act:%5.2g <= rhs:%5.2g --> down: %5.2g, up:%5.2g\n", lhs, activities[i], rhs, downslacks[i], upslacks[i]);
638 if( slackvars[i] ==
NULL )
657 coeffslackvar = slackvarcoeffs[i];
660 ubgap = ubslackvar - solvalslackvar;
661 lbgap = solvalslackvar - lbslackvar;
671 upslacks[i] += coeffslackvar * lbgap;
675 downslacks[i] += coeffslackvar * ubgap;
682 upslacks[i] -= coeffslackvar * ubgap;
686 downslacks[i] -= coeffslackvar * lbgap;
690 SCIPdebugMsg(
scip,
" Slack variable for row %s at pos %d: %g <= %s = %g <= %g; Coeff %g, upslack = %g, downslack = %g \n",
692 upslacks[i], downslacks[i]);
702 assert(nslacks == 0 || (upslacks !=
NULL && downslacks !=
NULL && activities !=
NULL));
705 currentlpcands = nlpcands;
706 improvementfound =
TRUE;
709 while( currentlpcands > 0 && improvementfound && (heurdata->maxroundingloops == -1 || nroundings < heurdata->maxroundingloops) )
711 improvementfound =
FALSE;
713 SCIPdebugMsg(
scip,
"zirounding enters while loop for %d time with %d candidates left. \n", nroundings, currentlpcands);
716 for( c = 0; c < currentlpcands; ++c )
732 oldsolval = solarray[c];
741 calculateBounds(
scip, var, oldsolval, &upperbound, &lowerbound, upslacks, downslacks, nslacks, &numericalerror);
747 up = oldsolval + upperbound;
748 down = oldsolval - lowerbound;
759 down =
MAX(down, floorx);
780 shiftval = (direction ==
DIRECTION_UP ? up - oldsolval : down - oldsolval);
784 shiftval =
MIN(shiftval, upperbound);
786 shiftval =
MIN(shiftval, lowerbound);
793 downslacks, activities, slackvars, slackvarcoeffs, nslacks) );
795 SCIPdebugMsg(
scip,
"zirounding update step : %d var index, oldsolval=%g, shiftval=%g\n",
799 improvementfound =
TRUE;
807 zilpcands[c] = zilpcands[currentlpcands - 1];
808 solarray[c] = solarray[currentlpcands - 1];
812 if( c < currentlpcands )
815 else if( nroundings == heurdata->maxroundingloops - 1 )
823 if( currentlpcands == 0 )
873 assert(heur !=
NULL);
884 "determines maximum number of rounding loops",
887 "flag to determine if Zirounding is deactivated after a certain percentage of unsuccessful calls",
890 "if percentage of found solutions falls below this parameter, Zirounding will be deactivated",
893 "determines the minimum number of calls before percentage-based deactivation of Zirounding is applied",
static void calculateBounds(SCIP *scip, SCIP_VAR *var, SCIP_Real currentvalue, SCIP_Real *upperbound, SCIP_Real *lowerbound, SCIP_Real *upslacks, SCIP_Real *downslacks, int nslacks, SCIP_Bool *numericalerror)
SCIP_RETCODE SCIPgetLPBranchCands(SCIP *scip, SCIP_VAR ***lpcands, SCIP_Real **lpcandssol, SCIP_Real **lpcandsfrac, int *nlpcands, int *npriolpcands, int *nfracimplvars)
static SCIP_Real getZiValue(SCIP *scip, SCIP_Real val)
SCIP_ROW ** SCIPgetLPRows(SCIP *scip)
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPlinkLPSol(SCIP *scip, SCIP_SOL *sol)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPgetCutoffbound(SCIP *scip)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
SCIP_Real * SCIPcolGetVals(SCIP_COL *col)
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
int SCIProwGetNNonz(SCIP_ROW *row)
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
const char * SCIProwGetName(SCIP_ROW *row)
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
#define DEFAULT_MAXROUNDINGLOOPS
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
SCIP_Real SCIPinfinity(SCIP *scip)
enum SCIP_Retcode SCIP_RETCODE
#define SCIPstatisticMessage
struct SCIP_HeurData SCIP_HEURDATA
#define SCIPfreeBlockMemory(scip, ptr)
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
SCIP_RETCODE SCIPincludeHeurZirounding(SCIP *scip)
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
#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)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
SCIP_RETCODE SCIPsetHeurInitsol(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINITSOL((*heurinitsol)))
static SCIP_DECL_HEUREXIT(heurExitZirounding)
#define DEFAULT_STOPZIROUND
const char * SCIPheurGetName(SCIP_HEUR *heur)
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
SCIP_ROW ** SCIPcolGetRows(SCIP_COL *col)
#define SCIPfreeBufferArrayNull(scip, ptr)
const char * SCIPvarGetName(SCIP_VAR *var)
static SCIP_DECL_HEURCOPY(heurCopyZirounding)
int SCIPgetNLPRows(SCIP *scip)
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 DEFAULT_MINSTOPNCALLS
#define SCIPallocBufferArray(scip, ptr, num)
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
#define BMScopyMemoryArray(ptr, source, num)
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
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)
ZI Round primal heuristic.
#define DEFAULT_STOPPERCENTAGE
SCIP_Real SCIPgetLPObjval(SCIP *scip)
static SCIP_DECL_HEUREXEC(heurExecZirounding)
static SCIP_DECL_HEURINITSOL(heurInitsolZirounding)
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
static SCIP_RETCODE updateSlacks(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real shiftvalue, SCIP_Real *upslacks, SCIP_Real *downslacks, SCIP_Real *activities, SCIP_VAR **slackvars, SCIP_Real *slackcoeffs, int nslacks)
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
SCIP_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
int SCIProwGetLPPos(SCIP_ROW *row)
static SCIP_DECL_HEURFREE(heurFreeZirounding)
SCIP_Longint SCIPheurGetNSolsFound(SCIP_HEUR *heur)
int SCIPvarGetIndex(SCIP_VAR *var)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
static void rowFindSlackVar(SCIP *scip, SCIP_ROW *row, SCIP_VAR **varpointer, SCIP_Real *coeffpointer)
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
static SCIP_DECL_HEURINIT(heurInitZirounding)
#define BMSclearMemoryArray(ptr, num)
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
SCIP_Longint SCIPgetNLPs(SCIP *scip)
int SCIPcolGetNLPNonz(SCIP_COL *col)
int SCIPcolGetLPPos(SCIP_COL *col)
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_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_Real SCIPgetRowActivity(SCIP *scip, SCIP_ROW *row)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)