/** frees user data of variable */ static SCIP_RETCODE vardataDelete( SCIP* scip, /**< SCIP data structure */ SCIP_VARDATA** vardata /**< vardata to delete */ ) { SCIPfreeBlockMemoryArray(scip, &(*vardata)->consids, (*vardata)->nconsids); SCIPfreeBlockMemoryArray(scip, &(*vardata)->oriFlowVars, (*vardata)->nOriFlowVars); SCIPfreeBlockMemory(scip, vardata); return SCIP_OKAY; }
/** deinitialization method of primal heuristic (called before transformed problem is freed) */ static SCIP_DECL_HEUREXIT(heurExitCrossover) { /*lint --e{715}*/ SCIP_HEURDATA* heurdata; SOLTUPLE* soltuple; assert(heur != NULL); assert(scip != NULL); /* get heuristic data */ heurdata = SCIPheurGetData(heur); assert(heurdata != NULL); soltuple = heurdata->lasttuple; /* free all soltuples iteratively */ while( soltuple != NULL ) { SOLTUPLE* tmp; tmp = soltuple->prev; SCIPfreeBlockMemoryArray(scip,&soltuple->indices,soltuple->size); SCIPfreeBlockMemory(scip,&soltuple); soltuple = tmp; } /* free hash table */ assert(heurdata->hashtable != NULL ); SCIPhashtableFree(&heurdata->hashtable); return SCIP_OKAY; }
/** deletes the transformed problem */ static SCIP_DECL_PROBDELTRANS(probdeltransColoring) { int i; assert(scip != NULL); assert(probdata != NULL); /* relese constraints and free array for constraints */ for ( i = 0; i < tcliqueGetNNodes((*probdata)->graph); i++) { SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->constraints[i])) ); } SCIPfreeMemoryArray(scip, &((*probdata)->constraints)); /* free the arrays for the stable sets and relese the related variables */ for ( i = (*probdata)->nstablesets-1; i >= 0; i-- ) { SCIPfreeBlockMemoryArray(scip, &((*probdata)->stablesets[i]), (*probdata)->stablesetlengths[i]); /*lint !e866*/ SCIP_CALL( SCIPreleaseVar(scip, &((*probdata)->stablesetvars[i])) ); } SCIPfreeMemoryArray(scip, &((*probdata)->new2oldnode)); SCIPfreeMemoryArray(scip, &((*probdata)->deletednodes)); SCIPfreeMemoryArray(scip, &((*probdata)->stablesetvars)); SCIPfreeMemoryArray(scip, &((*probdata)->stablesetlengths)); SCIPfreeMemoryArray(scip, &((*probdata)->stablesets)); tcliqueFree(&(*probdata)->graph); SCIPfreeMemory(scip, probdata); return SCIP_OKAY; }
/** execution method of event handler */ static SCIP_DECL_EVENTEXEC(eventExecProbdatavardeleted) { SCIP_VAR* var; SCIP_PROBDATA* probdata; int idx; assert(SCIPeventGetType(event) == SCIP_EVENTTYPE_VARDELETED); var = SCIPeventGetVar(event); probdata = (SCIP_PROBDATA*) eventdata; assert(probdata != NULL); assert(var != NULL); /* get index of variable in stablesets array */ idx = (int)(size_t) SCIPvarGetData(var); SCIPdebugMessage("remove variable %s [%d] from list of stable sets\n", SCIPvarGetName(var), idx); assert(probdata->stablesetvars[idx] == var); /* remove variable from stablesets array and release it */ SCIPfreeBlockMemoryArray(scip, &(probdata->stablesets[idx]), probdata->stablesetlengths[idx]); /*lint !e866*/ SCIP_CALL( SCIPreleaseVar(scip, &(probdata->stablesetvars[idx])) ); /* move all subsequent variables to the front */ for( ; idx < probdata->nstablesets - 1; idx++) { probdata->stablesets[idx] = probdata->stablesets[idx + 1]; probdata->stablesetlengths[idx] = probdata->stablesetlengths[idx + 1]; probdata->stablesetvars[idx] = probdata->stablesetvars[idx + 1]; SCIPvarSetData(probdata->stablesetvars[idx], (SCIP_VARDATA*) (size_t) idx); /*lint !e571*/ } probdata->nstablesets--; return SCIP_OKAY; }/*lint !e715*/
/** pass partial solution for indicator variables to heuristic */ SCIP_RETCODE SCIPheurPassIndicator( SCIP* scip, /**< SCIP data structure */ SCIP_HEUR* heur, /**< indicator heuristic */ int nindconss, /**< number of indicator constraints */ SCIP_CONS** indconss, /**< indicator constraints */ SCIP_Bool* solcand /**< values for indicator variables in partial solution */ ) { SCIP_HEURDATA* heurdata; assert( scip != NULL ); assert( heur != NULL ); assert( strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0 ); assert( nindconss > 0 ); assert( indconss != NULL ); assert( solcand != NULL ); /* get heuristic's data */ heurdata = SCIPheurGetData(heur); assert( heurdata != NULL ); /* copy indicator information */ if ( heurdata->indconss != NULL ) SCIPfreeBlockMemoryArray(scip, &(heurdata->indconss), heurdata->nindconss); SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(heurdata->indconss), indconss, nindconss) ); heurdata->nindconss = nindconss; /* copy partial solution */ if ( heurdata->solcand != NULL ) BMScopyMemoryArray(heurdata->solcand, solcand, nindconss); else SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(heurdata->solcand), solcand, nindconss) ); return SCIP_OKAY; }
static SCIP_DECL_PROBDELORIG(probdelorigColoring) { int i; assert(probdata != NULL); assert(*probdata != NULL); SCIPfreeMemoryArray(scip, &((*probdata)->new2oldnode)); SCIPfreeMemoryArray(scip, &((*probdata)->deletednodes)); for ( i = (*probdata)->nstablesets-1; i >= 0; i-- ) { SCIPfreeBlockMemoryArray(scip, &((*probdata)->stablesets[i]), (*probdata)->stablesetlengths[i]); /*lint !e866*/ SCIP_CALL( SCIPreleaseVar(scip, &((*probdata)->stablesetvars[i])) ); } SCIPfreeMemoryArray(scip, &((*probdata)->stablesetvars)); SCIPfreeMemoryArray(scip, &((*probdata)->stablesetlengths)); SCIPfreeMemoryArray(scip, &((*probdata)->stablesets)); /* release Constraints */ for ( i = 0; i < tcliqueGetNNodes((*probdata)->graph); i++ ) { SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->constraints[i])) ); } SCIPfreeMemoryArray(scip, &((*probdata)->constraints)); /* free memory used for graph */ tcliqueFree(&((*probdata)->graph)); tcliqueFree(&((*probdata)->oldgraph)); /* free probdata */ SCIPfreeMemory(scip, probdata); return SCIP_OKAY; }
/** execution method of primal heuristic */ static SCIP_DECL_HEUREXEC(heurExecIndicator) { /*lint --e{715}*/ SCIP_HEURDATA* heurdata; int nfoundsols = 0; assert( heur != NULL ); assert( scip != NULL ); assert( result != NULL ); *result = SCIP_DIDNOTRUN; if ( SCIPgetSubscipDepth(scip) > 0 ) return SCIP_OKAY; /* get heuristic's data */ heurdata = SCIPheurGetData(heur); assert( heurdata != NULL ); /* call heuristic, if solution candidate is available */ if ( heurdata->solcand != NULL ) { assert( heurdata->nindconss > 0 ); assert( heurdata->indconss != NULL ); /* The heuristic will only be successful if there are no integral variables and no binary variables except the * indicator variables. */ if ( SCIPgetNIntVars(scip) > 0 || heurdata->nindconss < SCIPgetNBinVars(scip) ) return SCIP_OKAY; SCIP_CALL( trySolCandidate(scip, heur, heurdata, heurdata->nindconss, heurdata->indconss, heurdata->solcand, &nfoundsols) ); if ( nfoundsols > 0 ) *result = SCIP_FOUNDSOL; else *result = SCIP_DIDNOTFIND; /* free memory */ SCIPfreeBlockMemoryArray(scip, &(heurdata->solcand), heurdata->nindconss); SCIPfreeBlockMemoryArray(scip, &(heurdata->indconss), heurdata->nindconss); } else { SCIP_CONS** indconss; SCIP_Bool* solcand; SCIP_SOL* bestsol; int nindconss; int i; if ( heurdata->indicatorconshdlr == NULL ) return SCIP_OKAY; /* check whether a new best solution has been found */ bestsol = SCIPgetBestSol(scip); if ( bestsol == heurdata->lastsol ) return SCIP_OKAY; heurdata->lastsol = bestsol; /* avoid solutions produced by this heuristic */ if ( SCIPsolGetHeur(bestsol) == heur ) return SCIP_OKAY; /* The heuristic will only be successful if there are no integral variables and no binary variables except the * indicator variables. */ if ( SCIPgetNIntVars(scip) > 0 || SCIPconshdlrGetNConss(heurdata->indicatorconshdlr) < SCIPgetNBinVars(scip) ) return SCIP_OKAY; nindconss = SCIPconshdlrGetNConss(heurdata->indicatorconshdlr); if ( nindconss == 0 ) return SCIP_OKAY; indconss = SCIPconshdlrGetConss(heurdata->indicatorconshdlr); assert( indconss != NULL ); /* fill solutin candidate */ SCIP_CALL( SCIPallocBufferArray(scip, &solcand, nindconss) ); for (i = 0; i < nindconss; ++i) { SCIP_VAR* binvar; SCIP_Real val; solcand[i] = FALSE; if ( SCIPconsIsActive(indconss[i]) ) { binvar = SCIPgetBinaryVarIndicator(indconss[i]); assert( binvar != NULL ); val = SCIPgetSolVal(scip, bestsol, binvar); assert( SCIPisFeasIntegral(scip, val) ); if ( val > 0.5 ) solcand[i] = TRUE; } } SCIPdebugMessage("Trying to improve best solution of value %f.\n", SCIPgetSolOrigObj(scip, bestsol) ); /* try one-opt heuristic */ SCIP_CALL( tryOneOpt(scip, heur, heurdata, nindconss, indconss, solcand, &nfoundsols) ); if ( nfoundsols > 0 ) *result = SCIP_FOUNDSOL; else *result = SCIP_DIDNOTFIND; SCIPfreeBufferArray(scip, &solcand); } return SCIP_OKAY; }