static SCIP_Bool consdataCheck( SCIP* scip, /**< SCIP data structure */ SCIP_PROBDATA* probdata, /**< problem data */ SCIP_CONSDATA* consdata /**< constraint data */ ) { SCIP_VAR** vars; int nvars; SCIP_VARDATA* vardata; SCIP_VAR* var; int* consids; int nconsids; SCIP_Bool existid1; SCIP_Bool existid2; CONSTYPE type; int pos; int v; vars = SCIPprobdataGetVars(probdata); nvars = SCIPprobdataGetNVars(probdata); for( v = 0; v < nvars; ++v ) { var = vars[v]; /* if variables is locally fixed to zero continue */ if( SCIPvarGetLbLocal(var) < 0.5 ) continue; /* check if the packing which corresponds to the variable is feasible for this constraint */ vardata = SCIPvarGetData(var); nconsids = SCIPvardataGetNConsids(vardata); consids = SCIPvardataGetConsids(vardata); existid1 = SCIPsortedvecFindInt(consids, consdata->itemid1, nconsids, &pos); existid2 = SCIPsortedvecFindInt(consids, consdata->itemid2, nconsids, &pos); type = consdata->type; if( (type == SAME && existid1 != existid2) || (type == DIFFER && existid1 && existid2) ) { SCIPdebug( SCIPvardataPrint(scip, vardata, NULL) ); SCIPdebug( consdataPrint(scip, consdata, NULL) ); SCIPdebug( SCIPprintVar(scip, var, NULL) ); return FALSE; } } return TRUE; }
/** gets user variable data object for given problem variable * Warning! This method should only be called after a variable was created with SCIPcreateObjVar(). * Otherwise, a segmentation fault may arise, or an undefined pointer is returned. */ scip::ObjVardata* SCIPgetObjVardata( SCIP* scip, /**< SCIP data structure */ SCIP_VAR* var /**< problem variable */ ) { SCIP_VARDATA* vardata; vardata = SCIPvarGetData(var); assert(vardata != NULL); return vardata->objvardata; }
/** execution method of event handler */ static SCIP_DECL_EVENTEXEC(eventExecProbdatavardeleted) { SCIP_VAR* var; SCIP_PROBDATA* probdata; int idx; assert(SCIPeventGetType(event) == SCIP_EVENTTYPE_VARDELETED); var = SCIPeventGetVar(event); probdata = (SCIP_PROBDATA*) eventdata; assert(probdata != NULL); assert(var != NULL); /* get index of variable in stablesets array */ idx = (int)(size_t) SCIPvarGetData(var); SCIPdebugMessage("remove variable %s [%d] from list of stable sets\n", SCIPvarGetName(var), idx); assert(probdata->stablesetvars[idx] == var); /* remove variable from stablesets array and release it */ SCIPfreeBlockMemoryArray(scip, &(probdata->stablesets[idx]), probdata->stablesetlengths[idx]); /*lint !e866*/ SCIP_CALL( SCIPreleaseVar(scip, &(probdata->stablesetvars[idx])) ); /* move all subsequent variables to the front */ for( ; idx < probdata->nstablesets - 1; idx++) { probdata->stablesets[idx] = probdata->stablesets[idx + 1]; probdata->stablesetlengths[idx] = probdata->stablesetlengths[idx + 1]; probdata->stablesetvars[idx] = probdata->stablesetvars[idx + 1]; SCIPvarSetData(probdata->stablesetvars[idx], (SCIP_VARDATA*) (size_t) idx); /*lint !e571*/ } probdata->nstablesets--; return SCIP_OKAY; }/*lint !e715*/
/** fixes a variable to zero if the corresponding packings are not valid for this constraint/node (due to branching) */ static SCIP_RETCODE checkVariable( SCIP* scip, /**< SCIP data structure */ SCIP_CONSDATA* consdata, /**< constraint data */ SCIP_VAR* var, /**< variables to check */ int* nfixedvars, /**< pointer to store the number of fixed variables */ SCIP_Bool* cutoff /**< pointer to store if a cutoff was detected */ ) { SCIP_VARDATA* vardata; int* consids; int nconsids; SCIP_Bool existid1; SCIP_Bool existid2; CONSTYPE type; SCIP_Bool fixed; SCIP_Bool infeasible; int pos; assert(scip != NULL); assert(consdata != NULL); assert(var != NULL); assert(nfixedvars != NULL); assert(cutoff != NULL); /* if variables is locally fixed to zero continue */ if( SCIPvarGetUbLocal(var) < 0.5 ) return SCIP_OKAY; /* check if the packing which corresponds to the variable feasible for this constraint */ vardata = SCIPvarGetData(var); nconsids = SCIPvardataGetNConsids(vardata); consids = SCIPvardataGetConsids(vardata); existid1 = SCIPsortedvecFindInt(consids, consdata->itemid1, nconsids, &pos); existid2 = SCIPsortedvecFindInt(consids, consdata->itemid2, nconsids, &pos); type = consdata->type; if( (type == SAME && existid1 != existid2) || (type == DIFFER && existid1 && existid2) ) { SCIP_CALL( SCIPfixVar(scip, var, 0.0, &infeasible, &fixed) ); if( infeasible ) { assert( SCIPvarGetLbLocal(var) > 0.5 ); SCIPdebugMessage("-> cutoff\n"); (*cutoff) = TRUE; } else { assert(fixed); (*nfixedvars)++; } } return SCIP_OKAY; }
/** avoid to generate columns which are fixed to zero; therefore add for each variable which is fixed to zero a * corresponding logicor constraint to forbid this column * * @note variable which are fixed locally to zero should not be generated again by the pricing MIP */ static SCIP_RETCODE addFixedVarsConss( SCIP* scip, /**< SCIP data structure */ SCIP* subscip, /**< pricing SCIP data structure */ SCIP_VAR** vars, /**< variable array of the subscuip */ SCIP_CONS** conss, /**< array of setppc constraint for each item one */ int nitems /**< number of items */ ) { SCIP_VAR** origvars; int norigvars; SCIP_CONS* cons; int* consids; int nconsids; int consid; int nvars; SCIP_VAR** logicorvars; SCIP_VAR* var; SCIP_VARDATA* vardata; SCIP_Bool needed; int nlogicorvars; int v; int c; int o; /* collect all variable which are currently existing */ origvars = SCIPgetVars(scip); norigvars = SCIPgetNVars(scip); /* loop over all these variables and check if they are fixed to zero */ for( v = 0; v < norigvars; ++v ) { assert(SCIPvarGetType(origvars[v]) == SCIP_VARTYPE_BINARY); /* if the upper bound is smaller than 0.5 if follows due to the integrality that the binary variable is fixed to zero */ if( SCIPvarGetUbLocal(origvars[v]) < 0.5 ) { SCIPdebugMessage("variable <%s> glb=[%.15g,%.15g] loc=[%.15g,%.15g] is fixed to zero\n", SCIPvarGetName(origvars[v]), SCIPvarGetLbGlobal(origvars[v]), SCIPvarGetUbGlobal(origvars[v]), SCIPvarGetLbLocal(origvars[v]), SCIPvarGetUbLocal(origvars[v]) ); /* coolect the constraints/items the variable belongs to */ vardata = SCIPvarGetData(origvars[v]); nconsids = SCIPvardataGetNConsids(vardata); consids = SCIPvardataGetConsids(vardata); needed = TRUE; SCIP_CALL( SCIPallocBufferArray(subscip, &logicorvars, nitems) ); nlogicorvars = 0; consid = consids[0]; nvars = 0; /* loop over these items and create a linear (logicor) constraint which forbids this item combination in the * pricing problem; thereby check if this item combination is already forbidden */ for( c = 0, o = 0; o < nitems && needed; ++o ) { assert(o <= consid); cons = conss[o]; if( SCIPconsIsEnabled(cons) ) { assert( SCIPgetNFixedonesSetppc(scip, cons) == 0 ); var = vars[nvars]; nvars++; assert(var != NULL); if( o == consid ) { SCIP_CALL( SCIPgetNegatedVar(subscip, var, &var) ); } logicorvars[nlogicorvars] = var; nlogicorvars++; } else if( o == consid ) needed = FALSE; if( o == consid ) { c++; if ( c == nconsids ) consid = nitems + 100; else { assert(consid < consids[c]); consid = consids[c]; } } } if( needed ) { SCIP_CALL( SCIPcreateConsBasicLogicor(subscip, &cons, SCIPvarGetName(origvars[v]), nlogicorvars, logicorvars) ); SCIP_CALL( SCIPsetConsInitial(subscip, cons, FALSE) ); SCIP_CALL( SCIPaddCons(subscip, cons) ); SCIP_CALL( SCIPreleaseCons(subscip, &cons) ); } SCIPfreeBufferArray(subscip, &logicorvars); } } return SCIP_OKAY; }