cons_exactsol.c
Go to the documentation of this file.
32/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
64#define CONSHDLR_DESC "constraint handler for repairing floating-point primal solutions to satisfy exact feasibility"
65#define CONSHDLR_ENFOPRIORITY -9999999 /**< priority of the constraint handler for constraint enforcing */
66#define CONSHDLR_CHECKPRIORITY -999999 /**< priority of the constraint handler for checking feasibility */
67#define CONSHDLR_EAGERFREQ 100 /**< frequency for using all instead of only the useful constraints in separation,
69#define CONSHDLR_NEEDSCONS FALSE /**< should the constraint handler be skipped, if no constraints are available? */
71#define DEFAULT_CHECKFPFEASIBILITY TRUE /**< should a solution be checked in floating-point arithmetic prior to being processed? */
73#define DEFAULT_CHECKCONTIMPLINT TRUE /**< should integrality of continuous implied integral variables be ensured? */
75#define DEFAULT_ABORTFRAC 1e-9 /**< fractionality of enforced integral value above which reparation is aborted */
77#define DEFAULT_UNFIXFRAC 0.0 /**< fractionality of weakly implied value up to which reparation fixes variable */
80#define DEFAULT_MINIMPROVE 0.2 /**< minimal percentage of primal improvement to trigger solution processing */
94 SCIP_HASHTABLE* solhash; /**< hash solutions so we don't use the same integer assignment twice */
100 int probhasconteqs; /**< does the problem have equations with continuous variables? (-1 unknown, 0 no, 1 yes) */
102 SCIP_Bool checkfpfeasibility; /**< should a solution be checked in floating-point arithmetic prior to being processed? */
103 SCIP_Bool checkcontimplint; /**< should integrality of continuous implied integral variables be ensured? */
104 SCIP_Real abortfrac; /**< fractionality of enforced integral value above which reparation is aborted */
105 SCIP_Real unfixfrac; /**< fractionality of weakly implied value up to which reparation fixes variable */
108 SCIP_Real minimprove; /**< minimal percentage of primal improvement to trigger solution processing */
171 SCIPdebugMessage("buffering solution from heuristic %s \n", SCIPheurGetName(SCIPsolGetHeur(sol)));
213 SCIP_Bool checkcontimplint, /**< whether continuous implied integral variables should be included */
229 SCIP_CALL( SCIPgetSolVarsData(scip, sol, &vars, &nvars, NULL, NULL, NULL, NULL, NULL, &ncontvars) );
237 SCIP_CALL( SCIPgetSolVarsData(scip, sol, &vars, &nvars, NULL, NULL, NULL, NULL, &ncontimplvars, &ncontvars) );
303 if( SCIPrationalIsEQ(SCIPconsGetRhsExact(scip, conss[c], &success), SCIPconsGetLhsExact(scip, conss[c], &success)) ) /*lint !e864*/
324 SCIPerrorMessage("Unsupported constraint type in exactsol constraint handler: %s\n", SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])));
409 /**@todo add event handler to check again if constraints were added/modified or a variable (impl) type changed */
421 /* do not run if the solution comes from the trivial heuristic for the following reason: it typically creates the
422 * first solution, which would be processed immediately, because it improves the primal bound by an infinite amount;
423 * however, its quality is usually bad and superseeded quickly by solutions from other heuristics
455 if( SCIPgetStage(scip) != SCIP_STAGE_SOLVING || !SCIPhasCurrentNodeLP(scip) || SCIPnodeGetType(SCIPgetCurrentNode(scip)) != SCIP_NODETYPE_FOCUSNODE )
491 if( SCIPisFeasLT(scip, activity, SCIProwGetLhs(row)) || SCIPisFeasGT(scip, activity, SCIProwGetRhs(row)) )
533 /* stop if exact diving is not possible at this point in time (mostly if lp state is not clean) */
540 /* stop if the new solution does not improve the current upperbound sufficiently and the buffer is not full;
547 multiplier = SCIPgetSolTransObj(scip, sol) > 0 ? 1 + conshdlrdata->minimprove : 1 - conshdlrdata->minimprove;
598 SCIPdebugMessage("attempting to repair solution from heuristic %s with floating point objval %g \n",
601 /* set the bounds of the variables: fixed for integral variables, global bounds for continuous ones */
612 /* for all integer and implied integer variables we check if their solution value is near-integral and abort
613 * if not, except for continuous variables whose integrality is weakly implied: then the solution value
614 * could be fractional in a floating-point feasible solution and we only know that a feasible solution with
617 if( SCIPvarGetType(vars[i]) != SCIP_VARTYPE_CONTINUOUS && !EPSISINT(solval, conshdlrdata->abortfrac) )
623 && SCIPvarGetImplType(vars[i]) == SCIP_IMPLINTTYPE_WEAK && !EPSISINT(solval, conshdlrdata->unfixfrac) )
665 /* Errors in the LP solver should not kill the overall solving process, if the LP is just needed for a constraint
666 * handler. Hence in optimized mode, the return code is caught and a warning is printed, only in debug mode, SCIP
673 SCIPwarningMessage(scip, "Error while solving LP in Exactsol Constraint Handler; exact LP solve terminated with code <%d>\n",retstat);
688 /* if we found a solution we do not try to complete the others, since they have worse objective values */
718 SCIPdebugMessage("repaired solution not feasible or not improving, objval %g, upperbound %g \n",
734/** destructor of constraint handler to free constraint handler data (called when SCIP is exiting) */
771 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &conshdlrdata->hashedassignments, DEFAULT_SOLBUFSIZE) );
772 SCIP_CALL( SCIPhashtableCreate(&(conshdlrdata->solhash), SCIPblkmem(scip), DEFAULT_SOLBUFSIZE, hashGetKeyAssignment, hashKeyEqAssignment, hashKeyValAssignment, NULL) );
788/** deinitialization method of constraint handler (called before transformed problem is freed) */
814 SCIPfreeBlockMemoryArray(scip, &conshdlrdata->hashedassignments[i]->idx, conshdlrdata->hashedassignments[i]->len);
815 SCIPfreeBlockMemoryArray(scip, &conshdlrdata->hashedassignments[i]->vals, conshdlrdata->hashedassignments[i]->len);
Constraint handler for linear constraints in their most general form, .
static SCIP_DECL_CONSHDLRCOPY(conshdlrCopyExactSol)
Definition: cons_exactsol.c:834
static SCIP_DECL_HASHKEYVAL(hashKeyValAssignment)
Definition: cons_exactsol.c:147
static SCIP_DECL_CONSENFORELAX(consEnforelaxExactSol)
Definition: cons_exactsol.c:350
static void clearSoluBuffer(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata)
Definition: cons_exactsol.c:193
static SCIP_RETCODE bufferSolution(SCIP *scip, SCIP_SOL *sol, SCIP_CONSHDLRDATA *conshdlrdata)
Definition: cons_exactsol.c:163
static void checkProbHasContEqs(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata)
Definition: cons_exactsol.c:276
static void solFreeAssignment(SCIP *scip, SOLINTASSIGNMENT **assignment)
Definition: cons_exactsol.c:261
static SCIP_RETCODE solCreateSolAssignment(SCIP *scip, SCIP_SOL *sol, SCIP_Bool checkcontimplint, SOLINTASSIGNMENT **assignment)
Definition: cons_exactsol.c:210
static SCIP_DECL_HASHGETKEY(hashGetKeyAssignment)
Definition: cons_exactsol.c:113
constraint handler for ensuring that primal solution is exact
common defines and data types used in all packages of SCIP
SCIP_VAR ** SCIPgetVarsExactLinear(SCIP *scip, SCIP_CONS *cons)
Definition: cons_exactlinear.c:7230
int SCIPgetNVarsExactLinear(SCIP *scip, SCIP_CONS *cons)
Definition: cons_exactlinear.c:7211
SCIP_RETCODE SCIPincludeConshdlrExactSol(SCIP *scip)
Definition: cons_exactsol.c:854
SCIP_RETCODE SCIPgetSolVarsData(SCIP *scip, SCIP_SOL *sol, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nbinimplvars, int *nintimplvars, int *ncontimplvars, int *ncontvars)
Definition: scip_prob.c:3114
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2647
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
Definition: misc.c:2298
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2535
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:120
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)
Definition: scip_param.c:83
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)
Definition: scip_param.c:139
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:57
void SCIPconshdlrSetData(SCIP_CONSHDLR *conshdlr, SCIP_CONSHDLRDATA *conshdlrdata)
Definition: cons.c:4350
SCIP_RETCODE SCIPsetConshdlrInit(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINIT((*consinit)))
Definition: scip_cons.c:396
SCIP_RETCODE SCIPincludeConshdlrBasic(SCIP *scip, SCIP_CONSHDLR **conshdlrptr, const char *name, const char *desc, int enfopriority, int chckpriority, int eagerfreq, SCIP_Bool needscons, SCIP_DECL_CONSENFOLP((*consenfolp)), SCIP_DECL_CONSENFOPS((*consenfops)), SCIP_DECL_CONSCHECK((*conscheck)), SCIP_DECL_CONSLOCK((*conslock)), SCIP_CONSHDLRDATA *conshdlrdata)
Definition: scip_cons.c:181
SCIP_RETCODE SCIPsetConshdlrFree(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSFREE((*consfree)))
Definition: scip_cons.c:372
SCIP_RETCODE SCIPsetConshdlrEnforelax(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSENFORELAX((*consenforelax)))
Definition: scip_cons.c:323
SCIP_RETCODE SCIPsetConshdlrExit(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXIT((*consexit)))
Definition: scip_cons.c:420
SCIP_Bool SCIPconshdlrNeedsCons(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:5306
SCIP_RETCODE SCIPsetConshdlrCopy(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSHDLRCOPY((*conshdlrcopy)), SCIP_DECL_CONSCOPY((*conscopy)))
Definition: scip_cons.c:347
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip_cons.c:940
void SCIPconshdlrSetNeedsCons(SCIP_CONSHDLR *conshdlr, SCIP_Bool needscons)
Definition: cons.c:5316
SCIP_CONSHDLRDATA * SCIPconshdlrGetData(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4340
SCIP_RETCODE SCIPchgVarLbDive(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_lp.c:2384
SCIP_RETCODE SCIPchgVarUbDive(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip_lp.c:2416
SCIP_RETCODE SCIPsolveExactDiveLP(SCIP *scip, int itlim, SCIP_Bool *lperror, SCIP_Bool *cutoff)
Definition: scip_lpexact.c:653
SCIP_RETCODE SCIPchgVarLbExactDive(SCIP *scip, SCIP_VAR *var, SCIP_RATIONAL *newbound)
Definition: scip_lpexact.c:710
SCIP_RETCODE SCIPchgVarUbExactDive(SCIP *scip, SCIP_VAR *var, SCIP_RATIONAL *newbound)
Definition: scip_lpexact.c:742
#define SCIPallocClearBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:97
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip_mem.h:99
void SCIPrationalRoundInteger(SCIP_RATIONAL *res, SCIP_RATIONAL *src, SCIP_ROUNDMODE_RAT roundmode)
Definition: rational.cpp:2157
void SCIPrationalSetReal(SCIP_RATIONAL *res, SCIP_Real real)
Definition: rational.cpp:604
void SCIPrationalFreeBuffer(BMS_BUFMEM *bufmem, SCIP_RATIONAL **rational)
Definition: rational.cpp:474
SCIP_RETCODE SCIPrationalCreateBuffer(BMS_BUFMEM *bufmem, SCIP_RATIONAL **rational)
Definition: rational.cpp:124
SCIP_Bool SCIPrationalIsEQ(SCIP_RATIONAL *rat1, SCIP_RATIONAL *rat2)
Definition: rational.cpp:1405
SCIP_Bool SCIPrationalIsLE(SCIP_RATIONAL *rat1, SCIP_RATIONAL *rat2)
Definition: rational.cpp:1522
SCIP_Real SCIPgetRowSolActivity(SCIP *scip, SCIP_ROW *row, SCIP_SOL *sol)
Definition: scip_lp.c:2108
SCIP_RETCODE SCIPcreateSolCopy(SCIP *scip, SCIP_SOL **sol, SCIP_SOL *sourcesol)
Definition: scip_sol.c:882
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
Definition: scip_sol.c:2351
SCIP_RETCODE SCIPtrySolFreeExact(SCIP *scip, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition: scip_sol.c:4525
SCIP_RETCODE SCIPoverwriteFPsol(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:4494
SCIP_RETCODE SCIPcreateLPSolExact(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:634
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1763
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:2003
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:784
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:810
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip_numerics.c:449
SCIP_RATIONAL * SCIPvarGetLbGlobalExact(SCIP_VAR *var)
Definition: var.c:24162
SCIP_RATIONAL * SCIPvarGetUbGlobalExact(SCIP_VAR *var)
Definition: var.c:24184
void SCIPsortPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
SCIP_RATIONAL * SCIPconsGetRhsExact(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *success)
Definition: misc_linear.c:176
SCIP_RATIONAL * SCIPconsGetLhsExact(SCIP *scip, SCIP_CONS *cons, SCIP_Bool *success)
Definition: misc_linear.c:213
Definition: multiprecision.hpp:66
public methods for managing constraints
public methods for primal heuristics
public methods for LP management
public methods for LP management
public methods for message output
public data structures and miscellaneous methods
public methods for primal CIP solutions
public methods for problem variables
wrapper for rational number arithmetic
public methods for certified solving
public methods for constraint handler plugins and constraints
public methods for exact solving
general public methods
public methods for the LP relaxation, rows and columns
public methods for the LP relaxation, rows and columns
public methods for memory management
public methods for message handling
public methods for numerical tolerances
public methods for SCIP parameter handling
public methods for global and local (sub)problems
public methods for querying solving statistics
public methods for the branch-and-bound tree
internal methods for global SCIP settings
Definition: struct_cons.h:47
Definition: struct_cons.h:128
Definition: struct_misc.h:90
Definition: struct_rational.h:47
Definition: struct_lp.h:205
Definition: struct_sol.h:74
Definition: struct_var.h:262
Definition: struct_scip.h:72
Definition: cons_exactsol.c:84