/** create constraint data */ static SCIP_RETCODE consdataCreate( SCIP* scip, /**< SCIP data structure */ SCIP_CONSDATA** consdata, /**< pointer to store the constraint data */ int itemid1, /**< item id one */ int itemid2, /**< item id two */ CONSTYPE type, /**< stores whether the items have to be in the SAME or DIFFER packing */ SCIP_NODE* node /**< the node in the B&B-tree at which the cons is sticking */ ) { assert( scip != NULL ); assert( consdata != NULL ); assert( itemid1 >= 0 ); assert( itemid2 >= 0 ); assert( type == DIFFER || type == SAME ); SCIP_CALL( SCIPallocBlockMemory(scip, consdata) ); (*consdata)->itemid1 = itemid1; (*consdata)->itemid2 = itemid2; (*consdata)->type = type; (*consdata)->npropagatedvars = 0; (*consdata)->npropagations = 0; (*consdata)->propagated = FALSE; (*consdata)->node = node; return SCIP_OKAY; }
/** creates and captures a stp constraint */ SCIP_RETCODE SCIPcreateConsStp( SCIP* scip, /**< SCIP data structure */ SCIP_CONS** cons, /**< pointer to hold the created constraint */ const char* name, /**< name of constraint */ GRAPH* graph /**< graph data structure */ ) { SCIP_CONSHDLR* conshdlr; SCIP_CONSDATA* consdata; /* find the stp constraint handler */ conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME); if( conshdlr == NULL ) { SCIPerrorMessage("stp constraint handler not found\n"); return SCIP_PLUGINNOTFOUND; } SCIP_CALL( SCIPallocBlockMemory(scip, &consdata) ); consdata->graph = graph; /* create constraint */ SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) ); return SCIP_OKAY; }
/** transforms constraint data into data belonging to the transformed problem */ static SCIP_DECL_CONSTRANS(consTransStp) { /*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( SCIPallocBlockMemory(scip, &targetdata) ); targetdata->graph = sourcedata->graph; /* 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; }
SCIP_RETCODE SCIPpolicyCreate( SCIP* scip, SCIP_POLICY** policy ) { assert(scip != NULL); assert(policy != NULL); SCIP_CALL( SCIPallocBlockMemory(scip, policy) ); (*policy)->weights = NULL; (*policy)->size = 0; 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; }
/** create a vardata */ static SCIP_RETCODE vardataCreate( SCIP* scip, /**< SCIP data structure */ SCIP_VARDATA** vardata, /**< pointer to vardata */ int* consids, /**< array of constraints ids */ int nconsids /**< number of constraints */ ) { SCIP_CALL( SCIPallocBlockMemory(scip, vardata) ); SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(*vardata)->consids, consids, nconsids) ); SCIPsortInt((*vardata)->consids, nconsids); (*vardata)->nconsids = nconsids; 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; }
/** 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; }
/** creates a new tuple of solutions */ static SCIP_RETCODE createSolTuple( SCIP* scip, /**< original SCIP data structure */ SOLTUPLE** elem, /**< tuple of solutions which should be created */ int* indices, /**< indices of solutions */ int size, /**< number of solutions */ SCIP_HEURDATA* heurdata /**< primal heuristic data */ ) { /* memory allocation */ SCIP_CALL( SCIPallocBlockMemory(scip, elem) ); SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(*elem)->indices,size) ); BMScopyMemoryArray((*elem)->indices, indices, size); /* data input */ sortArray(indices,size); (*elem)->size = size; (*elem)->key = calculateHashKey((*elem)->indices, (*elem)->size); (*elem)->prev = heurdata->lasttuple; /* update heurdata */ heurdata->lasttuple = *elem; return SCIP_OKAY; }
/** creates and captures a origbranch constraint */ SCIP_RETCODE GCGcreateConsOrigbranch( SCIP* scip, /**< SCIP data structure */ SCIP_CONS** cons, /**< pointer to hold the created constraint */ const char* name, /**< name of constraint */ SCIP_NODE* node, /**< the node to which this origbranch constraint belongs */ SCIP_CONS* parentcons, /**< origbranch constraint associated with the father node */ SCIP_BRANCHRULE* branchrule, /**< the branching rule that created the b&b node the constraint belongs to */ GCG_BRANCHDATA* branchdata /**< branching data storing information about the branching restrictions at the * corresponding node */ ) { SCIP_CONSHDLR* conshdlr; SCIP_CONSDATA* consdata; assert(scip != NULL); assert((parentcons == NULL) == (node == NULL)); /* find the origbranch constraint handler */ conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME); if( conshdlr == NULL ) { SCIPerrorMessage("origbranch constraint handler not found\n"); return SCIP_PLUGINNOTFOUND; } /* create constraint data */ SCIP_CALL( SCIPallocBlockMemory(scip, &consdata) ); /* initialize the fields in the constraint data */ consdata->parentcons = parentcons; consdata->node = node; consdata->child1cons = NULL; consdata->child2cons = NULL; consdata->probingtmpcons = NULL; consdata->mastercons = NULL; consdata->branchrule = branchrule; consdata->branchdata = branchdata; consdata->npropbounds = 0; consdata->maxpropbounds = 0; consdata->propvars = NULL; consdata->propboundtypes = NULL; consdata->propbounds = NULL; SCIPdebugMessage("Creating branch orig constraint: <%s>.\n", name); /* create constraint */ SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE) ); /* store the pointer to the new constraint in the origbranch constraint of the parent node */ if( parentcons != NULL ) { SCIP_CONSDATA* parentdata; parentdata = SCIPconsGetData(parentcons); assert(parentdata != NULL); if( parentdata->child1cons == NULL ) { parentdata->child1cons = *cons; } else { assert(parentdata->child2cons == NULL || SCIPinProbing(scip)); /* store the second child in case we are in probing and have to overwrite it */ if( SCIPinProbing(scip) ) { assert(parentdata->probingtmpcons == NULL); parentdata->probingtmpcons = parentdata->child2cons; } parentdata->child2cons = *cons; } } return SCIP_OKAY; }