/** creates variable */ SCIP_RETCODE SCIPcreateVarBinpacking( SCIP* scip, /**< SCIP data structure */ SCIP_VAR** var, /**< pointer to variable object */ const char* name, /**< name of variable, or NULL for automatic name creation */ SCIP_Real obj, /**< objective function value */ SCIP_Bool initial, /**< should var's column be present in the initial root LP? */ SCIP_Bool removable, /**< is var's column removable from the LP (due to aging or cleanup)? */ SCIP_VARDATA* vardata /**< user data for this specific variable */ ) { assert(scip != NULL); assert(var != NULL); /* create a basic variable object */ SCIP_CALL( SCIPcreateVarBasic(scip, var, name, 0.0, 1.0, obj, SCIP_VARTYPE_BINARY) ); assert(*var != NULL); /* set callback functions */ SCIPvarSetData(*var, vardata); SCIPvarSetDeltransData(*var, vardataDelTrans); /* set initial and removable flag */ SCIP_CALL( SCIPvarSetInitial(*var, initial) ); SCIP_CALL( SCIPvarSetRemovable(*var, removable) ); SCIPvarMarkDeletable(*var); SCIPdebug( SCIPprintVar(scip, *var, NULL) ); return SCIP_OKAY; }
/** 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*/
/** create initial columns */ static SCIP_RETCODE createInitialColumns( SCIP* scip, /**< SCIP data structure */ SCIP_PROBDATA* probdata /**< problem data */ ) { SCIP_CONS** conss; SCIP_VARDATA* vardata; SCIP_VAR* var; char name[SCIP_MAXSTRLEN]; int* ids; SCIP_Longint* weights; int nitems; int i; conss = probdata->conss; ids = probdata->ids; weights = probdata->weights; nitems = probdata->nitems; /* create start solution each item in exactly one bin */ for( i = 0; i < nitems; ++i ) { (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "item_%d", ids[i]); SCIPdebugMessage("create variable for item %d with weight = %"SCIP_LONGINT_FORMAT"\n", ids[i], weights[i]); /* create variable for the packing pattern which contains only this item */ SCIP_CALL( SCIPcreateVarBinpacking(scip, &var, name, 1.0, TRUE, TRUE, NULL) ); /* add variable to the problem */ SCIP_CALL( SCIPaddVar(scip, var) ); /* store variable in the problme data */ SCIP_CALL( SCIPprobdataAddVar(scip, probdata, var) ); /* add variable to corresponding set covering constraint */ SCIP_CALL( SCIPaddCoefSetppc(scip, conss[i], var) ); /* create the variable data for the variable; the variable data contains the information in which constraints the * variable appears */ SCIP_CALL( SCIPvardataCreateBinpacking(scip, &vardata, &i, 1) ); /* add the variable data to the variable */ SCIPvarSetData(var, vardata); /* change the upper bound of the binary variable to lazy since the upper bound is already enforced * due to the objective function the set covering constraint; * The reason for doing is that, is to avoid the bound of x <= 1 in the LP relaxation since this bound * constraint would produce a dual variable which might have a positive reduced cost */ SCIP_CALL( SCIPchgVarUbLazy(scip, var, 1.0) ); /* release variable */ SCIP_CALL( SCIPreleaseVar(scip, &var) ); } return SCIP_OKAY; }