/** 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 */ int* ids, /**< array of item ids */ int nitems, /**< number of items to be packed */ SCIP_Longint capacity /**< capacity of the bins */ ) { 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) ); SCIP_CALL( SCIPduplicateMemoryArray(scip, &pricerdata->weights, weights, nitems) ); SCIP_CALL( SCIPduplicateMemoryArray(scip, &pricerdata->ids, ids, nitems) ); pricerdata->nitems = nitems; pricerdata->capacity = capacity; SCIPdebugMessage(" nitems: %d capacity: %"SCIP_LONGINT_FORMAT" \n", nitems, capacity); SCIPdebugMessage(" # profits 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]); } /* activate pricer */ SCIP_CALL( SCIPactivatePricer(scip, pricer) ); return SCIP_OKAY; }
/** creates problem data */ static SCIP_RETCODE probdataCreate( SCIP* scip, /**< SCIP data structure */ SCIP_PROBDATA** probdata, /**< pointer to problem data */ SCIP_VAR** vars, /**< all exist variables */ SCIP_CONS** conss, /**< set partitioning constraints for each job exactly one */ SCIP_Longint* weights, /**< array containing the item weights */ int* ids, /**< array of item ids */ int nvars, /**< number of variables */ int nitems, /**< number of items */ SCIP_Longint capacity /**< bin capacity */ ) { assert(scip != NULL); assert(probdata != NULL); /* allocate memory */ SCIP_CALL( SCIPallocMemory(scip, probdata) ); if( nvars > 0 ) { /* copy variable array */ SCIP_CALL( SCIPduplicateMemoryArray(scip, &(*probdata)->vars, vars, nvars) ); } else (*probdata)->vars = NULL; /* duplicate arrays */ SCIP_CALL( SCIPduplicateMemoryArray(scip, &(*probdata)->conss, conss, nitems) ); SCIP_CALL( SCIPduplicateMemoryArray(scip, &(*probdata)->weights, weights, nitems) ); SCIP_CALL( SCIPduplicateMemoryArray(scip, &(*probdata)->ids, ids, nitems) ); (*probdata)->nvars = nvars; (*probdata)->varssize = nvars; (*probdata)->nitems = nitems; (*probdata)->capacity = capacity; return SCIP_OKAY; }
/** read constraint */ static SCIP_RETCODE getConstraint( SCIP* scip, /**< SCIP data structure */ CIPINPUT* cipinput, /**< CIP parsing data */ SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */ SCIP_Bool dynamic, /**< Is constraint subject to aging? * Usually set to FALSE. Set to TRUE for own cuts which * are separated as constraints. */ SCIP_Bool removable /**< should the relaxation be removed from the LP due to aging or cleanup? * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */ ) { SCIP_CONS* cons; char* buf; char* copybuf; SCIP_RETCODE retcode; SCIP_Bool separate; SCIP_Bool enforce; SCIP_Bool check; SCIP_Bool propagate; SCIP_Bool local; SCIP_Bool modifiable; SCIP_Bool success; int len; buf = cipinput->strbuf; if( strncmp(buf, "END", 3) == 0 ) { cipinput->section = CIP_END; return SCIP_OKAY; } SCIPdebugMessage("parse constraints in line %d\n", cipinput->linenumber); separate = TRUE; enforce = TRUE; check = TRUE; propagate = TRUE; local = FALSE; modifiable = FALSE; /* get length of line and check for correct ending of constraint line */ len = (int)strlen(buf); if( len < 1 ) { SCIPerrorMessage("syntax error: expected constraint in line %d.\n", cipinput->linenumber); cipinput->haserror = TRUE; return SCIP_OKAY; } if ( buf[len - 1] != ';' ) { SCIPerrorMessage("syntax error: line has to end with ';' (line: %d)\n", cipinput->linenumber); cipinput->haserror = TRUE; return SCIP_OKAY; } /* copy buffer for working purpose */ SCIP_CALL( SCIPduplicateMemoryArray(scip, ©buf, buf, len) ); copybuf[len - 1] = '\0'; /* parse the constraint */ retcode = SCIPparseCons(scip, &cons, copybuf, initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, FALSE, &success); /* free temporary buffer */ SCIPfreeMemoryArray(scip, ©buf); SCIP_CALL( retcode ); if( !success ) { SCIPerrorMessage("syntax error when reading constraint (line: %d):\n%s\n", cipinput->linenumber, cipinput->strbuf); cipinput->haserror = TRUE; return SCIP_OKAY; } SCIP_CALL( SCIPaddCons(scip, cons) ); SCIPdebugPrintCons(scip, cons, NULL); SCIP_CALL( SCIPreleaseCons(scip, &cons) ); return SCIP_OKAY; }