/** added problem specific data to pricer and activates pricer */ SCIP_RETCODE SCIPpricerBinpackingActivate( SCIP* scip, /**< SCIP data structure */ SCIP_CONS** conss, /**< set covering constraints for the items */ SCIP_Longint* weights, /**< weight of the items */ SCIP_Longint* values, int* ids, /**< array of item ids */ int nitems, /**< number of items to be packed */ SCIP_Longint* capacities, /**< capacity of the bins */ int* binids, int nbins ) { SCIP_PRICER* pricer; SCIP_PRICERDATA* pricerdata; int c; assert(scip != NULL); assert(conss != NULL); assert(weights != NULL); assert(nitems > 0); pricer = SCIPfindPricer(scip, PRICER_NAME); assert(pricer != NULL); pricerdata = SCIPpricerGetData(pricer); assert(pricerdata != NULL); /* copy arrays */ SCIP_CALL(SCIPduplicateMemoryArray(scip, &pricerdata->conss, conss, nitems+nbins)); SCIP_CALL(SCIPduplicateMemoryArray(scip, &pricerdata->weights, weights, nitems)); SCIP_CALL(SCIPduplicateMemoryArray(scip, &pricerdata->values, values, nitems)); SCIP_CALL(SCIPduplicateMemoryArray(scip, &pricerdata->ids, ids, nitems)); SCIP_CALL(SCIPduplicateMemoryArray(scip, &pricerdata->binids, binids, nbins)); SCIP_CALL(SCIPduplicateMemoryArray(scip, &pricerdata->capacities, capacities, nbins)); pricerdata->nitems = nitems; pricerdata->nbins = nbins; //SCIPdebugMessage(" nitems: %d capacity: %"SCIP_LONGINT_FORMAT" \n", nitems, capacity); SCIPdebugMessage(" # id weights x \n"); /* capture constraints */ /* capture all constraints */ for (c = 0; c < nitems; ++c) { SCIP_CALL(SCIPcaptureCons(scip, conss[c])); SCIPdebugPrintf("%4d %3"SCIP_LONGINT_FORMAT"\n", c, weights[c]); } for (c = 0; c < nbins; ++c) { SCIP_CALL(SCIPcaptureCons(scip, conss[nitems+c])); } /* activate pricer */ SCIP_CALL(SCIPactivatePricer(scip, pricer)); return SCIP_OKAY; }
/** adds constraint to conjunction */ static SCIP_RETCODE consdataAddCons( SCIP* scip, /**< SCIP data structure */ SCIP_CONSDATA* consdata, /**< constraint data */ SCIP_CONS* cons /**< constraint to add to the conjunction */ ) { assert(consdata != NULL); /* get memory for additional constraint */ SCIP_CALL( SCIPensureBlockMemoryArray(scip, &consdata->conss, &consdata->consssize, consdata->nconss+1) ); assert(consdata->conss != NULL); assert(consdata->nconss < consdata->consssize); /* insert constraint in array */ consdata->conss[consdata->nconss] = cons; consdata->nconss++; if( SCIPisTransformed(scip) ) { SCIP_CALL( SCIPtransformCons(scip, consdata->conss[consdata->nconss - 1], &(consdata->conss[consdata->nconss - 1])) ); } else { /* capture constraint */ SCIP_CALL( SCIPcaptureCons(scip, cons) ); } return SCIP_OKAY; }
/** initialization method of variable pricer (called after problem was transformed) */ static SCIP_DECL_PRICERINIT(pricerInitBinpacking) { /*lint --e{715}*/ SCIP_PRICERDATA* pricerdata; SCIP_CONS* cons; int c; assert(scip != NULL); assert(pricer != NULL); pricerdata = SCIPpricerGetData(pricer); assert(pricerdata != NULL); /* get transformed constraints */ for( c = 0; c < pricerdata->nitems; ++c ) { cons = pricerdata->conss[c]; /* release original constraint */ SCIP_CALL( SCIPreleaseCons(scip, &pricerdata->conss[c]) ); /* get transformed constraint */ SCIP_CALL( SCIPgetTransformedCons(scip, cons, &pricerdata->conss[c]) ); /* capture transformed constraint */ SCIP_CALL( SCIPcaptureCons(scip, pricerdata->conss[c]) ); } return SCIP_OKAY; }
/** creates disjunction constraint data, captures initial constraints of disjunction */ static SCIP_RETCODE consdataCreate( SCIP* scip, /**< SCIP data structure */ SCIP_CONSDATA** consdata, /**< pointer to constraint data */ SCIP_CONS** conss, /**< initial constraint in disjunction */ int nconss /**< number of initial constraints in disjunction */ ) { assert(scip != NULL); assert(consdata != NULL); SCIP_CALL( SCIPallocBlockMemory(scip, consdata) ); if( nconss > 0 ) { assert(conss != NULL); SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(*consdata)->conss, conss, nconss) ); (*consdata)->consssize = nconss; (*consdata)->nconss = nconss; /* we need to capture the constraints to avoid that SCIP deletes them since they are not (yet) added to the * problem */ if( SCIPisTransformed(scip) ) { SCIP_CALL( SCIPtransformConss(scip, nconss, (*consdata)->conss, (*consdata)->conss) ); } else { int c; for( c = 0; c < nconss; ++c ) { assert(conss[c] != NULL); SCIP_CALL( SCIPcaptureCons(scip, conss[c]) ); } } } else { (*consdata)->conss = NULL; (*consdata)->consssize = 0; (*consdata)->nconss = 0; } return SCIP_OKAY; }
/** creates conjunction constraint data, captures initial constraints of conjunction */ static SCIP_RETCODE consdataCreate( SCIP* scip, /**< SCIP data structure */ SCIP_CONSDATA** consdata, /**< pointer to constraint data */ SCIP_CONS** conss, /**< initial constraint in conjunction */ int nconss /**< number of initial constraints in conjunction */ ) { assert(consdata != NULL); SCIP_CALL( SCIPallocBlockMemory(scip, consdata) ); if( nconss > 0 ) { SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(*consdata)->conss, conss, nconss) ); (*consdata)->consssize = nconss; (*consdata)->nconss = nconss; if( SCIPisTransformed(scip) ) { SCIP_CALL( SCIPtransformConss(scip, nconss, (*consdata)->conss, (*consdata)->conss) ); } else { int c; for( c = 0; c < nconss; ++c ) { SCIP_CALL( SCIPcaptureCons(scip, conss[c]) ); } } } else { (*consdata)->conss = NULL; (*consdata)->consssize = 0; (*consdata)->nconss = 0; } return SCIP_OKAY; }