40 #define CONSHDLR_NAME "samediff" 41 #define CONSHDLR_DESC "stores the local branching decisions" 42 #define CONSHDLR_ENFOPRIORITY 0 43 #define CONSHDLR_CHECKPRIORITY 9999999 44 #define CONSHDLR_PROPFREQ 1 45 #define CONSHDLR_EAGERFREQ 1 47 #define CONSHDLR_DELAYPROP FALSE 48 #define CONSHDLR_NEEDSCONS TRUE 50 #define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_BEFORELP 81 SCIP_CONSDATA** consdata,
88 assert( scip != NULL );
89 assert( consdata != NULL );
90 assert( itemid1 >= 0 );
91 assert( itemid2 >= 0 );
94 SCIP_CALL( SCIPallocBlockMemory(scip, consdata) );
98 (*consdata)->type =
type;
99 (*consdata)->npropagatedvars = 0;
100 (*consdata)->npropagations = 0;
101 (*consdata)->propagated = FALSE;
102 (*consdata)->node =
node;
111 SCIP_CONSDATA* consdata,
115 SCIP_PROBDATA* probdata;
118 probdata = SCIPgetProbData(scip);
119 assert(probdata != NULL);
124 SCIPinfoMessage(scip, file,
"%s(%d,%d) at node %d\n",
125 consdata->type ==
SAME ?
"same" :
"diff",
126 ids[consdata->itemid1], ids[consdata->itemid2], SCIPnodeGetNumber(consdata->node) );
133 SCIP_CONSDATA* consdata,
139 SCIP_VARDATA* vardata;
148 SCIP_Bool infeasible;
152 assert(scip != NULL);
153 assert(consdata != NULL);
155 assert(nfixedvars != NULL);
156 assert(cutoff != NULL);
159 if( SCIPvarGetUbLocal(var) < 0.5 )
163 vardata = SCIPvarGetData(var);
168 existid1 = SCIPsortedvecFindInt(consids, consdata->itemid1, nconsids, &pos);
169 existid2 = SCIPsortedvecFindInt(consids, consdata->itemid2, nconsids, &pos);
170 type = consdata->type;
172 if( (
type ==
SAME && existid1 != existid2) || (
type ==
DIFFER && existid1 && existid2) )
174 SCIP_CALL( SCIPfixVar(scip, var, 0.0, &infeasible, &fixed) );
178 assert( SCIPvarGetLbLocal(var) > 0.5 );
179 SCIPdebugMessage(
"-> cutoff\n");
196 SCIP_CONSDATA* consdata,
209 SCIPdebugMessage(
"check variables %d to %d\n", consdata->npropagatedvars, nvars);
211 for( v = consdata->npropagatedvars; v < nvars && !cutoff; ++v )
213 SCIP_CALL(
checkVariable(scip, consdata, vars[v], &nfixedvars, &cutoff) );
216 SCIPdebugMessage(
"fixed %d variables locally\n", nfixedvars);
219 *result = SCIP_CUTOFF;
220 else if( nfixedvars > 0 )
221 *result = SCIP_REDUCEDDOM;
232 SCIP_PROBDATA* probdata,
233 SCIP_CONSDATA* consdata,
240 SCIP_VARDATA* vardata;
256 for( v = 0; v < nvars; ++v )
261 if( SCIPvarGetLbLocal(var) < 0.5 )
265 vardata = SCIPvarGetData(var);
270 existid1 = SCIPsortedvecFindInt(consids, consdata->itemid1, nconsids, &pos);
271 existid2 = SCIPsortedvecFindInt(consids, consdata->itemid2, nconsids, &pos);
272 type = consdata->type;
274 if( (
type ==
SAME && existid1 != existid2) || (
type ==
DIFFER && existid1 && existid2) )
278 SCIPdebug( SCIPprintVar(scip, var, NULL) );
292 SCIP_CONSDATA** consdata
295 assert(consdata != NULL);
296 assert(*consdata != NULL);
298 SCIPfreeBlockMemory(scip, consdata);
315 assert(conshdlr != NULL);
316 assert(strcmp(SCIPconshdlrGetName(conshdlr),
CONSHDLR_NAME) == 0);
317 assert(consdata != NULL);
318 assert(*consdata != NULL);
330 SCIP_CONSDATA* sourcedata;
331 SCIP_CONSDATA* targetdata;
333 assert(conshdlr != NULL);
334 assert(strcmp(SCIPconshdlrGetName(conshdlr),
CONSHDLR_NAME) == 0);
335 assert(SCIPgetStage(scip) == SCIP_STAGE_TRANSFORMING);
336 assert(sourcecons != NULL);
337 assert(targetcons != NULL);
339 sourcedata = SCIPconsGetData(sourcecons);
340 assert(sourcedata != NULL);
344 sourcedata->itemid1, sourcedata->itemid2, sourcedata->type, sourcedata->node) );
347 SCIP_CALL( SCIPcreateCons(scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata,
348 SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons), SCIPconsIsEnforced(sourcecons),
349 SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons),
350 SCIPconsIsLocal(sourcecons), SCIPconsIsModifiable(sourcecons),
351 SCIPconsIsDynamic(sourcecons), SCIPconsIsRemovable(sourcecons), SCIPconsIsStickingAtNode(sourcecons)) );
357 #define consEnfolpSamediff NULL 360 #define consEnfopsSamediff NULL 363 #define consCheckSamediff NULL 369 SCIP_PROBDATA* probdata;
370 SCIP_CONSDATA* consdata;
376 assert(scip != NULL);
377 assert(strcmp(SCIPconshdlrGetName(conshdlr),
CONSHDLR_NAME) == 0);
378 assert(result != NULL);
380 SCIPdebugMessage(
"propagation constraints of constraint handler <"CONSHDLR_NAME">\n");
382 probdata = SCIPgetProbData(scip);
383 assert(probdata != NULL);
388 *result = SCIP_DIDNOTFIND;
390 for( c = 0; c < nconss; ++c )
392 consdata = SCIPconsGetData(conss[c]);
397 SCIP_CONSDATA* consdata2;
400 for( i = c+1; i < nconss; ++i )
402 consdata2 = SCIPconsGetData(conss[i]);
403 assert( !(consdata->itemid1 == consdata2->itemid1
404 && consdata->itemid2 == consdata2->itemid2
405 && consdata->type == consdata2->type) );
406 assert( !(consdata->itemid1 == consdata2->itemid2
407 && consdata->itemid2 == consdata2->itemid1
408 && consdata->type == consdata2->type) );
413 if( !consdata->propagated )
415 SCIPdebugMessage(
"propagate constraint <%s> ", SCIPconsGetName(conss[c]));
419 consdata->npropagations++;
421 if( *result != SCIP_CUTOFF )
423 consdata->propagated = TRUE;
424 consdata->npropagatedvars = nvars;
438 #define consLockSamediff NULL 444 SCIP_CONSDATA* consdata;
445 SCIP_PROBDATA* probdata;
447 assert(scip != NULL);
448 assert(strcmp(SCIPconshdlrGetName(conshdlr),
CONSHDLR_NAME) == 0);
449 assert(cons != NULL);
451 probdata = SCIPgetProbData(scip);
452 assert(probdata != NULL);
454 consdata = SCIPconsGetData(cons);
455 assert(consdata != NULL);
458 SCIPdebugMessage(
"activate constraint <%s> at node <%"SCIP_LONGINT_FORMAT
"> in depth <%d>: ",
459 SCIPconsGetName(cons), SCIPnodeGetNumber(consdata->node), SCIPnodeGetDepth(consdata->node));
464 SCIPdebugMessage(
"-> mark constraint to be repropagated\n");
465 consdata->propagated = FALSE;
466 SCIP_CALL( SCIPrepropagateNode(scip, consdata->node) );
479 SCIP_CONSDATA* consdata;
480 SCIP_PROBDATA* probdata;
482 assert(scip != NULL);
483 assert(strcmp(SCIPconshdlrGetName(conshdlr),
CONSHDLR_NAME) == 0);
484 assert(cons != NULL);
486 consdata = SCIPconsGetData(cons);
487 assert(consdata != NULL);
488 assert(consdata->propagated || SCIPgetNChildren(scip) == 0);
490 probdata = SCIPgetProbData(scip);
491 assert(probdata != NULL);
493 SCIPdebugMessage(
"deactivate constraint <%s> at node <%"SCIP_LONGINT_FORMAT
"> in depth <%d>: ",
494 SCIPconsGetName(cons), SCIPnodeGetNumber(consdata->node), SCIPnodeGetDepth(consdata->node));
507 SCIP_CONSDATA* consdata;
509 consdata = SCIPconsGetData(cons);
510 assert(consdata != NULL);
529 SCIP_CONSHDLRDATA* conshdlrdata = NULL;
530 SCIP_CONSHDLR* conshdlr = NULL;
537 assert(conshdlr != NULL);
539 SCIP_CALL( SCIPsetConshdlrDelete(scip, conshdlr, consDeleteSamediff) );
540 SCIP_CALL( SCIPsetConshdlrTrans(scip, conshdlr, consTransSamediff) );
543 SCIP_CALL( SCIPsetConshdlrActive(scip, conshdlr, consActiveSamediff) );
544 SCIP_CALL( SCIPsetConshdlrDeactive(scip, conshdlr, consDeactiveSamediff) );
545 SCIP_CALL( SCIPsetConshdlrPrint(scip, conshdlr, consPrintSamediff) );
562 SCIP_CONSHDLR* conshdlr;
563 SCIP_CONSDATA* consdata;
567 if( conshdlr == NULL )
569 SCIPerrorMessage(
"samediff constraint handler not found\n");
570 return SCIP_PLUGINNOTFOUND;
577 SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, FALSE, FALSE, FALSE, FALSE, TRUE,
578 local, FALSE, FALSE, FALSE, TRUE) );
580 SCIPdebugMessage(
"created constraint: ");
592 SCIP_CONSDATA* consdata;
594 assert(cons != NULL);
596 consdata = SCIPconsGetData(cons);
597 assert(consdata != NULL);
599 return consdata->itemid1;
608 SCIP_CONSDATA* consdata;
610 assert(cons != NULL);
612 consdata = SCIPconsGetData(cons);
613 assert(consdata != NULL);
615 return consdata->itemid2;
624 SCIP_CONSDATA* consdata;
626 assert(cons != NULL);
628 consdata = SCIPconsGetData(cons);
629 assert(consdata != NULL);
631 return consdata->type;
static SCIP_DECL_CONSDELETE(consDeleteSamediff)
void SCIPvardataPrint(SCIP *scip, SCIP_VARDATA *vardata, FILE *file)
static SCIP_DECL_CONSDEACTIVE(consDeactiveSamediff)
static SCIP_RETCODE checkVariable(SCIP *scip, SCIP_CONSDATA *consdata, SCIP_VAR *var, int *nfixedvars, SCIP_Bool *cutoff)
Constraint handler stores the local branching decision data.
SCIP_RETCODE SCIPcreateConsSamediff(SCIP *scip, SCIP_CONS **cons, const char *name, int itemid1, int itemid2, CONSTYPE type, SCIP_NODE *node, SCIP_Bool local)
#define consEnfolpSamediff
static void consdataPrint(SCIP *scip, SCIP_CONSDATA *consdata, FILE *file)
Variable data containing the ids of constraints in which the variable appears.
int * SCIPvardataGetConsids(SCIP_VARDATA *vardata)
SCIP_VAR ** SCIPprobdataGetVars(SCIP_PROBDATA *probdata)
#define CONSHDLR_DELAYPROP
#define CONSHDLR_PROP_TIMING
#define CONSHDLR_ENFOPRIORITY
#define CONSHDLR_NEEDSCONS
int SCIPgetItemid2Samediff(SCIP *scip, SCIP_CONS *cons)
#define consEnfopsSamediff
int * SCIPprobdataGetIds(SCIP_PROBDATA *probdata)
#define CONSHDLR_EAGERFREQ
static SCIP_RETCODE consdataCreate(SCIP *scip, SCIP_CONSDATA **consdata, int itemid1, int itemid2, CONSTYPE type, SCIP_NODE *node)
SCIP_RETCODE SCIPincludeConshdlrSamediff(SCIP *scip)
Problem data for binpacking problem.
CONSTYPE SCIPgetTypeSamediff(SCIP *scip, SCIP_CONS *cons)
static SCIP_Bool consdataCheck(SCIP *scip, SCIP_PROBDATA *probdata, SCIP_CONSDATA *consdata, SCIP_Bool beforeprop)
int SCIPprobdataGetNVars(SCIP_PROBDATA *probdata)
static SCIP_RETCODE consdataFixVariables(SCIP *scip, SCIP_CONSDATA *consdata, SCIP_VAR **vars, int nvars, SCIP_RESULT *result)
int SCIPgetItemid1Samediff(SCIP *scip, SCIP_CONS *cons)
static SCIP_DECL_CONSPRINT(consPrintSamediff)
#define consCheckSamediff
#define CONSHDLR_PROPFREQ
static SCIP_DECL_CONSTRANS(consTransSamediff)
static SCIP_RETCODE consdataFree(SCIP *scip, SCIP_CONSDATA **consdata)
int SCIPvardataGetNConsids(SCIP_VARDATA *vardata)
#define CONSHDLR_CHECKPRIORITY
static SCIP_DECL_CONSPROP(consPropSamediff)
static SCIP_DECL_CONSACTIVE(consActiveSamediff)