/** tries to upgrade a linear constraint into a xyz constraint */ static SCIP_DECL_LINCONSUPGD(linconsUpgdXyz) { /*lint --e{715}*/ SCIP_Bool upgrade; assert(upgdcons != NULL); /* check, if linear constraint can be upgraded to xyz constraint */ upgrade = FALSE; /* TODO: put the constraint's properties here, in terms of the statistics given by nposbin, nnegbin, ... */ if( upgrade ) { SCIPdebugMessage("upgrading constraint <%s> to xyz constraint\n", SCIPconsGetName(cons)); /* create the bin Xyz constraint (an automatically upgraded constraint is always unmodifiable) */ assert(!SCIPconsIsModifiable(cons)); SCIP_CALL( SCIPcreateConsXyz(scip, upgdcons, SCIPconsGetName(cons), nvars, vars, vals, lhs, rhs, SCIPconsIsInitial(cons), SCIPconsIsSeparated(cons), SCIPconsIsEnforced(cons), SCIPconsIsChecked(cons), SCIPconsIsPropagated(cons), SCIPconsIsLocal(cons), SCIPconsIsModifiable(cons), SCIPconsIsDynamic(cons), SCIPconsIsRemovable(cons), SCIPconsIsStickingAtNode(cons)) ); } return SCIP_OKAY; }
/** transforms constraint data into data belonging to the transformed problem */ static SCIP_DECL_CONSTRANS(consTransSamediff) { /*lint --e{715}*/ SCIP_CONSDATA* sourcedata; SCIP_CONSDATA* targetdata; assert(conshdlr != NULL); assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0); assert(SCIPgetStage(scip) == SCIP_STAGE_TRANSFORMING); assert(sourcecons != NULL); assert(targetcons != NULL); sourcedata = SCIPconsGetData(sourcecons); assert(sourcedata != NULL); /* create constraint data for target constraint */ SCIP_CALL( consdataCreate(scip, &targetdata, sourcedata->itemid1, sourcedata->itemid2, sourcedata->type, sourcedata->node) ); /* create target constraint */ SCIP_CALL( SCIPcreateCons(scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata, SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons), SCIPconsIsEnforced(sourcecons), SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons), SCIPconsIsLocal(sourcecons), SCIPconsIsModifiable(sourcecons), SCIPconsIsDynamic(sourcecons), SCIPconsIsRemovable(sourcecons), SCIPconsIsStickingAtNode(sourcecons)) ); return SCIP_OKAY; }
/** constraint copying method of constraint handler */ static SCIP_DECL_CONSCOPY(consCopyConjuction) { /*lint --e{715}*/ SCIP_CONSDATA* sourcedata; SCIP_CONS** sourceconss; SCIP_CONS** conss; int nconss; int c; sourcedata = SCIPconsGetData(sourcecons); assert(sourcedata != NULL); nconss = sourcedata->nconss; if( nconss == 0 && !SCIPconsIsModifiable(sourcecons) ) { *valid = TRUE; return SCIP_OKAY; } SCIP_CALL( SCIPallocBufferArray(scip, &conss, nconss) ); sourceconss = sourcedata->conss; /* copy each constraint one by one */ for( c = 0; c < nconss && (*valid); ++c ) { SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourceconss[c], &conss[c], sourceconshdlr, 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 ) { SCIP_CALL( SCIPcreateConsDisjunction(scip, cons, name, nconss, conss, initial, enforce, check, local, modifiable, dynamic) ); } SCIPfreeBufferArray(scip, &conss); return SCIP_OKAY; }
/** presolving method of constraint handler */ static SCIP_DECL_CONSPRESOL(consPresolConjunction) { /*lint --e{715}*/ SCIP_CONSDATA* consdata; int c; int i; assert(result != NULL); *result = SCIP_DIDNOTFIND; /* all constraints in a conjunction constraint of the global problem can be added directly to the problem and * removed from the conjunction constraint; * an unmodifiable conjunction constraint can be deleted */ for( c = 0; c < nconss; ++c ) { consdata = SCIPconsGetData(conss[c]); assert(consdata != NULL); /* add all inactive constraints to the global problem */ for( i = 0; i < consdata->nconss; ++i ) { /* update check flag for sub constraints when upgrade takes place */ if( SCIPconsIsChecked(conss[c]) ) { /* make sure, the constraint is checked for feasibility */ SCIP_CALL( SCIPsetConsChecked(scip, consdata->conss[i], TRUE) ); } /* add constraint, if it is not active yet */ if( !SCIPconsIsActive(consdata->conss[i]) ) { SCIPdebugMessage("adding constraint <%s> from add conjunction <%s>\n", SCIPconsGetName(consdata->conss[i]), SCIPconsGetName(conss[c])); SCIP_CALL( SCIPaddCons(scip, consdata->conss[i]) ); *result = SCIP_SUCCESS; } /* release constraint because it will be removed from the conjunction constraint */ SCIP_CALL( SCIPreleaseCons(scip, &(consdata->conss[i])) ); } /* all constraints where removed, so we need to clear the array */ consdata->nconss = 0; /* delete conjunction constraint, if it is unmodifiable */ if( !SCIPconsIsModifiable(conss[c]) ) { SCIP_CALL( SCIPdelCons(scip, conss[c]) ); } } return SCIP_OKAY; }
/** branches on disjunctive constraint */ static SCIP_RETCODE branchCons( SCIP* scip, /**< SCIP data structure */ SCIP_CONS* cons, /**< active disjunction constraint */ SCIP_RESULT* result /**< pointer to store the result */ ) { SCIP_CONSDATA* consdata; SCIP_CONS** conss; SCIP_NODE* child; SCIP_Real estimate; int nconss; int i; assert(result != NULL); /* cannot branch on modifiable constraint */ if( SCIPconsIsModifiable(cons) ) return SCIP_OKAY; consdata = SCIPconsGetData(cons); assert(consdata != NULL); conss = consdata->conss; assert(conss != NULL); nconss = consdata->nconss; assert(nconss > 0); estimate = SCIPgetLocalTransEstimate(scip); /* add all inactive constraints to local subproblem */ for( i = 0; i < nconss; ++i ) { /* create the branch-and-bound tree child nodes of the current node */ SCIP_CALL( SCIPcreateChild(scip, &child, 0.0, estimate) ); /* add constraints to nodes */ SCIP_CALL( SCIPaddConsNode(scip, child, conss[i], NULL) ); /* remove disjunction constraint, from child node */ SCIP_CALL( SCIPdelConsNode(scip, child, cons) ); } /* reset constraint age */ SCIP_CALL( SCIPresetConsAge(scip, cons) ); *result = SCIP_BRANCHED; return SCIP_OKAY; }
/** adds all constraints in conjunction constraints to the problem; disables unmodifiable conjunction constraints */ static SCIP_RETCODE addAllConss( SCIP* scip, /**< SCIP data structure */ SCIP_CONS** conss, /**< active conjunction constraints */ int nconss, /**< number of active conjunction constraints */ SCIP_RESULT* result /**< pointer to store the result */ ) { SCIP_CONSDATA* consdata; int c; int i; assert(result != NULL); for( c = 0; c < nconss; ++c ) { consdata = SCIPconsGetData(conss[c]); assert(consdata != NULL); /* add all inactive constraints to local subproblem */ for( i = 0; i < consdata->nconss; ++i ) { /* update check flag for sub constraints when upgrade takes place */ if( SCIPconsIsChecked(conss[c]) ) { /* make sure, the constraint is checked for feasibility */ SCIP_CALL( SCIPsetConsChecked(scip, consdata->conss[i], TRUE) ); } if( !SCIPconsIsActive(consdata->conss[i]) ) { SCIPdebugMessage("adding constraint <%s> from add conjunction <%s>\n", SCIPconsGetName(consdata->conss[i]), SCIPconsGetName(conss[c])); SCIP_CALL( SCIPaddConsLocal(scip, consdata->conss[i], NULL) ); *result = SCIP_CONSADDED; } } /* disable conjunction constraint, if it is unmodifiable */ if( !SCIPconsIsModifiable(conss[c]) ) { SCIP_CALL( SCIPdelConsLocal(scip, conss[c]) ); } } return SCIP_OKAY; }
/** presolving method of constraint handler */ static SCIP_DECL_CONSPRESOL(consPresolDisjunction) { /*lint --e{715}*/ SCIP_CONSDATA* consdata; int oldndelconss; int c; assert(result != NULL); *result = SCIP_DIDNOTFIND; oldndelconss = *ndelconss; /* all disjunction constraints with one constraint can be replaced with that corresponding constraint */ for( c = 0; c < nconss; ++c ) { consdata = SCIPconsGetData(conss[c]); assert(consdata != NULL); if( !SCIPconsIsModifiable(conss[c]) && consdata->nconss == 1 ) { /* add constraint to the problem */ if( !SCIPconsIsActive(consdata->conss[0]) ) { SCIP_CALL( SCIPaddCons(scip, consdata->conss[0]) ); /* release constraint from the disjunction constraint */ SCIP_CALL( SCIPreleaseCons(scip, &consdata->conss[0]) ); } /* remove disjunction constraint */ SCIP_CALL( SCIPdelCons(scip, conss[0]) ); *result = SCIP_SUCCESS; } /* propagate constraint */ SCIP_CALL( propagateCons(scip, conss[c], ndelconss) ); } if( *ndelconss > oldndelconss ) *result = SCIP_SUCCESS; return SCIP_OKAY; }
/** transforms constraint data into data belonging to the transformed problem */ static SCIP_DECL_CONSTRANS(consTransDisjunction) { /*lint --e{715}*/ SCIP_CONSDATA* sourcedata; SCIP_CONSDATA* targetdata; /* get constraint data of source constraint */ sourcedata = SCIPconsGetData(sourcecons); assert(sourcedata != NULL); SCIP_CALL( consdataCreate(scip, &targetdata, sourcedata->conss, sourcedata->nconss) ); /* create target constraint */ SCIP_CALL( SCIPcreateCons(scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata, SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons), SCIPconsIsEnforced(sourcecons), SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons), SCIPconsIsLocal(sourcecons), SCIPconsIsModifiable(sourcecons), SCIPconsIsDynamic(sourcecons), SCIPconsIsRemovable(sourcecons), SCIPconsIsStickingAtNode(sourcecons)) ); return SCIP_OKAY; }
/** transforms constraint data into data belonging to the transformed problem */ static SCIP_DECL_CONSTRANS(consTransConjunction) { /*lint --e{715}*/ SCIP_CONSDATA* sourcedata; SCIP_CONSDATA* targetdata; int c; /* create constraint data for target constraint */ SCIP_CALL( SCIPallocBlockMemory(scip, &targetdata) ); /* get constraint data of source constraint */ sourcedata = SCIPconsGetData(sourcecons); if( sourcedata->nconss > 0 ) { targetdata->consssize = sourcedata->nconss; targetdata->nconss = sourcedata->nconss; SCIP_CALL( SCIPallocBlockMemoryArray(scip, &targetdata->conss, targetdata->consssize) ); for( c = 0; c < sourcedata->nconss; ++c ) { SCIP_CALL( SCIPtransformCons(scip, sourcedata->conss[c], &targetdata->conss[c]) ); } } else { targetdata->conss = NULL; targetdata->consssize = 0; targetdata->nconss = 0; } /* create target constraint */ SCIP_CALL( SCIPcreateCons(scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata, SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons), SCIPconsIsEnforced(sourcecons), SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons), SCIPconsIsLocal(sourcecons), SCIPconsIsModifiable(sourcecons), SCIPconsIsDynamic(sourcecons), SCIPconsIsRemovable(sourcecons), SCIPconsIsStickingAtNode(sourcecons)) ); 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; }