/** adds constraint to the disjunction of constraints */ SCIP_RETCODE SCIPaddConsElemDisjunction( SCIP* scip, /**< SCIP data structure */ SCIP_CONS* cons, /**< disjunction constraint */ SCIP_CONS* addcons /**< additional constraint in disjunction */ ) { SCIP_CONSDATA* consdata; assert(cons != NULL); assert(addcons != NULL); if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 ) { SCIPerrorMessage("constraint is not a disjunction constraint\n"); return SCIP_INVALIDDATA; } consdata = SCIPconsGetData(cons); assert(consdata != NULL); SCIP_CALL( consdataAddCons(scip, consdata, addcons) ); return SCIP_OKAY; }
/** initializes the pricing problem for the given capacity */ static SCIP_RETCODE initPricing( SCIP* scip, /**< SCIP data structure */ SCIP_PRICERDATA* pricerdata, /**< pricer data */ SCIP* subscip, /**< pricing SCIP data structure */ SCIP_VAR** vars /**< variable array for the items */ ) { SCIP_CONS** conss; SCIP_Longint* vals; SCIP_CONS* cons; SCIP_VAR* var; SCIP_Longint* weights; SCIP_Longint capacity; SCIP_Real dual; int nitems; int nvars; int c; assert( SCIPgetStage(subscip) == SCIP_STAGE_PROBLEM ); assert(pricerdata != NULL); nitems = pricerdata->nitems; conss = pricerdata->conss; weights = pricerdata->weights; capacity = pricerdata->capacity; nvars = 0; SCIP_CALL( SCIPallocBufferArray(subscip, &vals, nitems) ); /* create for each order, which is not assigned yet, a variable with objective coefficient */ for( c = 0; c < nitems; ++c ) { cons = conss[c]; /* check if each constraint is setppc constraint */ assert( !strncmp( SCIPconshdlrGetName( SCIPconsGetHdlr(cons) ), "setppc", 6) ); /* constraints which are (locally) disabled/redundant are not of * interest since the corresponding job is assigned to a packing */ if( !SCIPconsIsEnabled(cons) ) continue; if( SCIPgetNFixedonesSetppc(scip, cons) == 1 ) { /* disable constraint locally */ SCIP_CALL( SCIPdelConsLocal(scip, cons) ); continue; } /* dual value in original SCIP */ dual = SCIPgetDualsolSetppc(scip, cons); SCIP_CALL( SCIPcreateVarBasic(subscip, &var, SCIPconsGetName(cons), 0.0, 1.0, dual, SCIP_VARTYPE_BINARY) ); SCIP_CALL( SCIPaddVar(subscip, var) ); vals[nvars] = weights[c]; vars[nvars] = var; nvars++; /* release variable */ SCIP_CALL( SCIPreleaseVar(subscip, &var) ); } /* create capacity constraint */ SCIP_CALL( SCIPcreateConsBasicKnapsack(subscip, &cons, "capacity", nvars, vars, vals, capacity) ); SCIP_CALL( SCIPaddCons(subscip, cons) ); SCIP_CALL( SCIPreleaseCons(subscip, &cons) ); /* add constraint of the branching decisions */ SCIP_CALL( addBranchingDecisionConss(scip, subscip, vars, pricerdata->conshdlr) ); /* avoid to generate columns which are fixed to zero */ SCIP_CALL( addFixedVarsConss(scip, subscip, vars, conss, nitems) ); SCIPfreeBufferArray(subscip, &vals); return SCIP_OKAY; }
/** writes problem to file */ SCIP_RETCODE SCIPwriteCcg( SCIP* scip, /**< SCIP data structure */ FILE* file, /**< output file, or NULL if standard output should be used */ const char* name, /**< problem name */ SCIP_Bool transformed, /**< TRUE iff problem is the transformed problem */ SCIP_VAR** vars, /**< array with active variables ordered binary, integer, implicit, continuous */ int nvars, /**< number of active variables in the problem */ SCIP_CONS** conss, /**< array with constraints of the problem */ int nconss, /**< number of constraints in the problem */ SCIP_RESULT* result /**< pointer to store the result of the file writing call */ ) { /*lint --e{715}*/ int c; int v; int i; SCIP_CONSHDLR* conshdlr; const char* conshdlrname; SCIP_CONS* cons; SCIP_VAR** consvars; SCIP_Real* consvals; int nconsvars; SparseGraph G; assert( scip != NULL ); assert( nvars >= 0 ); /* initialize graph */ SCIP_CALL( initGraph(scip, &G, (unsigned int) nvars, 10) ); /* check all constraints */ for( c = 0; c < nconss; ++c) { cons = conss[c]; assert( cons != NULL); /* in case the transformed is written only constraint are posted which are enabled in the current node */ assert(!transformed || SCIPconsIsEnabled(cons)); conshdlr = SCIPconsGetHdlr(cons); assert( conshdlr != NULL ); conshdlrname = SCIPconshdlrGetName(conshdlr); assert( transformed == SCIPconsIsTransformed(cons) ); if( strcmp(conshdlrname, "linear") == 0 ) { consvars = SCIPgetVarsLinear(scip, cons); nconsvars = SCIPgetNVarsLinear(scip, cons); assert( consvars != NULL || nconsvars == 0 ); if( nconsvars > 0 ) { SCIP_CALL( handleLinearCons(scip, SCIPgetVarsLinear(scip, cons), SCIPgetValsLinear(scip, cons), SCIPgetNVarsLinear(scip, cons), transformed, &G) ); } } else if( strcmp(conshdlrname, "setppc") == 0 ) { consvars = SCIPgetVarsSetppc(scip, cons); nconsvars = SCIPgetNVarsSetppc(scip, cons); assert( consvars != NULL || nconsvars == 0 ); if( nconsvars > 0 ) { SCIP_CALL( handleLinearCons(scip, consvars, NULL, nconsvars, transformed, &G) ); } } else if( strcmp(conshdlrname, "logicor") == 0 ) { consvars = SCIPgetVarsLogicor(scip, cons); nconsvars = SCIPgetNVarsLogicor(scip, cons); assert( consvars != NULL || nconsvars == 0 ); if( nconsvars > 0 ) { SCIP_CALL( handleLinearCons(scip, SCIPgetVarsLogicor(scip, cons), NULL, SCIPgetNVarsLogicor(scip, cons), transformed, &G) ); } } else if( strcmp(conshdlrname, "knapsack") == 0 ) { SCIP_Longint* w; consvars = SCIPgetVarsKnapsack(scip, cons); nconsvars = SCIPgetNVarsKnapsack(scip, cons); assert( consvars != NULL || nconsvars == 0 ); /* copy Longint array to SCIP_Real array */ w = SCIPgetWeightsKnapsack(scip, cons); SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nconsvars) ); for( v = 0; v < nconsvars; ++v ) consvals[v] = (SCIP_Real)w[v]; if( nconsvars > 0 ) { SCIP_CALL( handleLinearCons(scip, consvars, consvals, nconsvars, transformed, &G) ); } SCIPfreeBufferArray(scip, &consvals); } else if( strcmp(conshdlrname, "varbound") == 0 ) { SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 2) ); SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 2) ); consvars[0] = SCIPgetVarVarbound(scip, cons); consvars[1] = SCIPgetVbdvarVarbound(scip, cons); consvals[0] = 1.0; consvals[1] = SCIPgetVbdcoefVarbound(scip, cons); SCIP_CALL( handleLinearCons(scip, consvars, consvals, 2, transformed, &G) ); SCIPfreeBufferArray(scip, &consvars); SCIPfreeBufferArray(scip, &consvals); } else { SCIPwarningMessage(scip, "constraint handler <%s> cannot print requested format\n", conshdlrname ); SCIPinfoMessage(scip, file, "\\ "); SCIP_CALL( SCIPprintCons(scip, cons, file) ); SCIPinfoMessage(scip, file, ";\n"); } } /* output graph */ SCIPinfoMessage(scip, file, "c graph generated from %s\n", name); SCIPinfoMessage(scip, file, "p edge %d %d\n", nvars, G.m); for( i = 0; i < nvars; ++i ) { unsigned int k; int a; k = 0; a = G.A[i][k]; while( a >= 0 ) { /* only output edges from lower to higher number */ if( i < a ) { /* note: node numbers start with 1 in the DIMACS format */ SCIPinfoMessage(scip, file, "e %d %d %f\n", i+1, a+1, G.W[i][k]); } a = G.A[i][++k]; assert( k <= G.size[i] ); } assert( k == G.deg[i] ); } freeGraph(scip, &G); *result = SCIP_SUCCESS; return SCIP_OKAY; }
/** writes problem to file */ SCIP_RETCODE SCIPwritePpm( SCIP* scip, /**< SCIP data structure */ FILE* file, /**< output file, or NULL if standard output should be used */ const char* name, /**< problem name */ SCIP_READERDATA* readerdata, /**< information for reader */ SCIP_Bool transformed, /**< TRUE iff problem is the transformed problem */ SCIP_VAR** vars, /**< array with active variables ordered binary, integer, implicit, continuous */ int nvars, /**< number of active variables in the problem */ SCIP_CONS** conss, /**< array with constraints of the problem */ int nconss, /**< number of constraints in the problem */ SCIP_RESULT* result /**< pointer to store the result of the file writing call */ ) { /*lint --e{715}*/ int c; int v; int i; int linecnt; char linebuffer[PPM_MAX_LINELEN]; SCIP_CONSHDLR* conshdlr; const char* conshdlrname; SCIP_CONS* cons; SCIP_VAR** consvars; SCIP_Real* consvals; int nconsvars; int i_max = 1; SCIP_Real maxcoef = 0; SCIP_Bool printbool = FALSE; assert( scip != NULL ); assert(readerdata != NULL); /* print statistics as comment to file */ if(readerdata->rgb_ascii) SCIPinfoMessage(scip, file, "P6\n"); else SCIPinfoMessage(scip, file, "P3\n"); SCIPinfoMessage(scip, file, "# %s\n", name); SCIPinfoMessage(scip, file, "%d %d\n", nvars, nconss); SCIPinfoMessage(scip, file, "255\n"); clearLine(linebuffer, &linecnt); if(!(readerdata->rgb_relativ)) { i_max = 2; } for(i = 0; i < i_max; ++i) { if(i) { printbool = TRUE; SCIPdebugPrintf("Maximal coefficient = %g\n", maxcoef); } for(c = 0; c < nconss; ++c) { cons = conss[c]; assert( cons != NULL); /* in case the transformed is written only constraint are posted which are enabled in the current node */ assert(!transformed || SCIPconsIsEnabled(cons)); conshdlr = SCIPconsGetHdlr(cons); assert( conshdlr != NULL ); conshdlrname = SCIPconshdlrGetName(conshdlr); assert( transformed == SCIPconsIsTransformed(cons) ); if( strcmp(conshdlrname, "linear") == 0 ) { consvars = SCIPgetVarsLinear(scip, cons); nconsvars = SCIPgetNVarsLinear(scip, cons); assert( consvars != NULL || nconsvars == 0 ); if( nconsvars > 0 ) { SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, SCIPgetValsLinear(scip, cons), nconsvars, nvars, transformed, &maxcoef, printbool) ); } } else if( strcmp(conshdlrname, "setppc") == 0 ) { consvars = SCIPgetVarsSetppc(scip, cons); nconsvars = SCIPgetNVarsSetppc(scip, cons); assert( consvars != NULL || nconsvars == 0 ); if( nconsvars > 0 ) { SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, NULL, nconsvars, nvars, transformed, &maxcoef, printbool) ); } } else if( strcmp(conshdlrname, "logicor") == 0 ) { consvars = SCIPgetVarsLogicor(scip, cons); nconsvars = SCIPgetNVarsLogicor(scip, cons); assert( consvars != NULL || nconsvars == 0 ); if( nconsvars > 0 ) { SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, NULL, nconsvars, nvars, transformed, &maxcoef, printbool) ); } } else if( strcmp(conshdlrname, "knapsack") == 0 ) { SCIP_Longint* weights; consvars = SCIPgetVarsKnapsack(scip, cons); nconsvars = SCIPgetNVarsKnapsack(scip, cons); assert( consvars != NULL || nconsvars == 0 ); /* copy Longint array to SCIP_Real array */ weights = SCIPgetWeightsKnapsack(scip, cons); SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nconsvars) ); for( v = 0; v < nconsvars; ++v ) consvals[v] = (SCIP_Real)weights[v]; if( nconsvars > 0 ) { SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, consvals, nconsvars, nvars, transformed, &maxcoef, printbool) ); } SCIPfreeBufferArray(scip, &consvals); } else if( strcmp(conshdlrname, "varbound") == 0 ) { SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 2) ); SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 2) ); consvars[0] = SCIPgetVarVarbound(scip, cons); consvars[1] = SCIPgetVbdvarVarbound(scip, cons); consvals[0] = 1.0; consvals[1] = SCIPgetVbdcoefVarbound(scip, cons); SCIP_CALL( printLinearCons(scip, file, readerdata, consvars, consvals, 2, nvars, transformed, &maxcoef, printbool) ); SCIPfreeBufferArray(scip, &consvars); SCIPfreeBufferArray(scip, &consvals); } else { SCIPwarningMessage(scip, "constraint handler <%s> cannot print requested format\n", conshdlrname ); SCIPinfoMessage(scip, file, "\\ "); SCIP_CALL( SCIPprintCons(scip, cons, file) ); SCIPinfoMessage(scip, file, ";\n"); } } } *result = SCIP_SUCCESS; return SCIP_OKAY; }
/** constraint copying method of constraint handler */ static SCIP_DECL_CONSCOPY(consCopyConjunction) { /*lint --e{715}*/ SCIP_CONSDATA* sourcedata; SCIP_CONS** sourceconss; SCIP_CONS** conss; int nconss; int c; *valid = TRUE; sourcedata = SCIPconsGetData(sourcecons); assert(sourcedata != NULL); sourceconss = sourcedata->conss; nconss = sourcedata->nconss; if( nconss > 0 ) { assert(sourceconss != NULL); SCIP_CALL( SCIPallocBufferArray(scip, &conss, nconss) ); /* copy each constraint one by one */ for( c = 0; c < nconss && (*valid); ++c ) { SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourceconss[c], &conss[c], SCIPconsGetHdlr(sourceconss[c]), varmap, consmap, SCIPconsGetName(sourceconss[c]), SCIPconsIsInitial(sourceconss[c]), SCIPconsIsSeparated(sourceconss[c]), SCIPconsIsEnforced(sourceconss[c]), SCIPconsIsChecked(sourceconss[c]), SCIPconsIsPropagated(sourceconss[c]), SCIPconsIsLocal(sourceconss[c]), SCIPconsIsModifiable(sourceconss[c]), SCIPconsIsDynamic(sourceconss[c]), SCIPconsIsRemovable(sourceconss[c]), SCIPconsIsStickingAtNode(sourceconss[c]), global, valid) ); assert(!(*valid) || conss[c] != NULL); } if( *valid ) { if( name == NULL ) { SCIP_CALL( SCIPcreateConsConjunction(scip, cons, SCIPconsGetName(sourcecons), nconss, conss, enforce, check, local, modifiable, dynamic) ); } else { SCIP_CALL( SCIPcreateConsConjunction(scip, cons, name, nconss, conss, enforce, check, local, modifiable, dynamic) ); } } /* release the copied constraints */ for( c = (*valid ? c - 1 : c - 2); c >= 0; --c ) { assert(conss[c] != NULL); SCIP_CALL( SCIPreleaseCons(scip, &conss[c]) ); } SCIPfreeBufferArray(scip, &conss); } return SCIP_OKAY; }