32 #define HEUR_NAME "crossover" 33 #define HEUR_DESC "LNS heuristic that fixes all variables that are identic in a couple of solutions" 34 #define HEUR_DISPCHAR 'C' 35 #define HEUR_PRIORITY -1104000 37 #define HEUR_FREQOFS 0 38 #define HEUR_MAXDEPTH -1 39 #define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE 40 #define HEUR_USESSUBSCIP TRUE 42 #define DEFAULT_MAXNODES 5000LL 43 #define DEFAULT_MINIMPROVE 0.01 44 #define DEFAULT_MINNODES 50LL 45 #define DEFAULT_MINFIXINGRATE 0.666 46 #define DEFAULT_NODESOFS 500LL 47 #define DEFAULT_NODESQUOT 0.1 48 #define DEFAULT_LPLIMFAC 2.0 49 #define DEFAULT_NUSEDSOLS 3 50 #define DEFAULT_NWAITINGNODES 200LL 51 #define DEFAULT_RANDOMIZATION TRUE 52 #define DEFAULT_DONTWAITATROOT FALSE 53 #define DEFAULT_USELPROWS FALSE 55 #define DEFAULT_COPYCUTS TRUE 58 #define DEFAULT_PERMUTE FALSE 59 #define HASHSIZE_SOLS 500 60 #define DEFAULT_BESTSOLLIMIT -1 61 #define DEFAULT_USEUCT FALSE 62 #define DEFAULT_RANDSEED 7 65 #define EVENTHDLR_NAME "Crossover" 66 #define EVENTHDLR_DESC "LP event handler for " HEUR_NAME " heuristic" 89 unsigned int nfailures;
141 indices1 = ((
SOLTUPLE*)key1)->indices;
142 indices2 = ((
SOLTUPLE*)key2)->indices;
145 assert(indices1 !=
NULL);
146 assert(indices2 !=
NULL);
152 for( i = 0; i < size; i++ )
154 if( indices1[i] != indices2[i] )
178 unsigned int hashkey;
182 for( i = 0; i < size; i++ )
183 hashkey *= indices[i] + 1;
184 for( i = 0; i < size; i++ )
185 hashkey += indices[i];
202 for( i = 1; i < size; i++ )
206 while( j >= 0 && a[j] > tmp )
233 (*elem)->size = size;
235 (*elem)->prev = heurdata->lasttuple;
238 heurdata->lasttuple = *elem;
254 for( i = 0; i < selectionsize; i++ )
281 assert( success !=
NULL );
284 nusedsols = heurdata->nusedsols;
287 assert(nusedsols < lastsol);
293 while( !*success && i < 10 )
298 for( j = 0; j < nusedsols && validtuple; j++ )
307 validtuple = (k >= nusedsols-j-1);
356 assert(sols !=
NULL);
357 assert(fixedvars !=
NULL);
358 assert(fixedvals !=
NULL);
362 assert(fixedvarssize >= nbinvars + nintvars);
367 for( i = 0; i < nbinvars + nintvars; i++ )
376 for( j = 1; j < heurdata->nusedsols; j++ )
379 varsolval =
SCIPgetSolVal(scip, sols[selection[j]], vars[i]);
380 if(
REALABS(solval - varsolval) > 0.5 )
393 fixedvars[(*nfixedvars)] = vars[i];
394 fixedvals[(*nfixedvars)] = solval;
404 *success = (*nfixedvars) < nbinvars + nintvars && fixingrate >= heurdata->minfixingrate;
430 nusedsols = heurdata->nusedsols;
432 assert(nusedsols > 1);
433 assert(nsols >= nusedsols);
437 if( !heurdata->randomization || nsols == nusedsols || heurdata->prevlastsol != sols[nusedsols-1] )
444 for( i = 0; i < nusedsols; i++ )
455 for( i = 1; i < nusedsols; i++ )
470 if( !(*success) && heurdata->randomization && nsols > nusedsols )
487 SCIP_CALL(
fixVariables(scip, fixedvars, fixedvals, nfixedvars, fixedvarssize, selection, heurdata, success) );
510 assert(scip !=
NULL);
511 assert(subscip !=
NULL);
512 assert(subvars !=
NULL);
513 assert(subsol !=
NULL);
547 heurdata->nfailures++;
548 heurdata->nextnodenumber = (heurdata->nfailures <= 25
564 assert(eventhdlr !=
NULL);
565 assert(eventdata !=
NULL);
567 assert(event !=
NULL);
571 assert(heurdata !=
NULL);
592 assert(heur !=
NULL);
607 assert(heur !=
NULL);
612 assert(heurdata !=
NULL);
627 assert(heur !=
NULL);
632 assert(heurdata !=
NULL);
635 heurdata->usednodes = 0;
636 heurdata->prevlastsol =
NULL;
637 heurdata->prevbestsol =
NULL;
638 heurdata->lasttuple =
NULL;
639 heurdata->nfailures = 0;
640 heurdata->prevnsols = 0;
641 heurdata->nextnodenumber = 0;
649 hashGetKeySols, hashKeyEqSols, hashKeyValSols,
NULL) );
650 assert(heurdata->hashtable !=
NULL);
662 assert(heur !=
NULL);
667 assert(heurdata !=
NULL);
668 soltuple = heurdata->lasttuple;
671 while( soltuple !=
NULL )
674 tmp = soltuple->prev;
684 assert(heurdata->hashtable !=
NULL);
720 assert(heur !=
NULL);
722 assert(result !=
NULL);
726 assert(heurdata !=
NULL);
727 nusedsols = heurdata->nusedsols;
736 assert(sols !=
NULL);
739 if( sols[nusedsols-1] != heurdata->prevlastsol )
742 if( sols[0] != heurdata->prevbestsol )
743 heurdata->nfailures = 0;
746 else if( !heurdata->randomization )
769 nstallnodes += heurdata->nodesofs;
772 nstallnodes -= heurdata->usednodes;
773 nstallnodes =
MIN(nstallnodes, heurdata->maxnodes);
776 if( nstallnodes < heurdata->minnodes )
793 if( nbinvars == 0 && nintvars == 0 )
807 heurdata->prevlastsol = sols[heurdata->nusedsols-1];
830 heurdata->uselprows, heurdata->copycuts, &success,
NULL) );
835 if( eventhdlr ==
NULL )
843 for( i = 0; i < nvars; i++ )
867 heurdata->nodelimit = nstallnodes;
936 cutoff =
MIN(upperbound, cutoff );
940 if( heurdata->permute )
950 #ifdef SCIP_DISABLED_CODE 985 for( i = 0; i < nsubsols && !success; ++i )
994 assert(solindex != -1);
1001 for( i = 0; i < nusedsols; i++ )
1005 selection[i] = solindex;
1013 if( !heurdata->randomization )
1063 assert(heur !=
NULL);
1074 "number of nodes added to the contingent of the total nodes",
1078 "maximum number of nodes to regard in the subproblem",
1082 "minimum number of nodes required to start the subproblem",
1086 "number of solutions to be taken into account",
1090 "number of nodes without incumbent change that heuristic should wait",
1094 "contingent of sub problem nodes in relation to the number of nodes of the original problem",
1098 "minimum percentage of integer variables that have to be fixed",
1102 "factor by which Crossover should at least improve the incumbent",
1106 "factor by which the limit on the number of LP depends on the node limit",
1110 "should the choice which sols to take be randomized?",
1114 "should the nwaitingnodes parameter be ignored at the root node?",
1118 "should subproblem be created out of the rows in the LP rows?",
1122 "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
1126 "should the subproblem be permuted to increase diversification?",
1130 "limit on number of improving incumbent solutions in sub-CIP",
1134 "should uct node selection be used at the beginning of the search?",
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
SCIP_RETCODE SCIPrandomCreate(SCIP_RANDNUMGEN **randnumgen, BMS_BLKMEM *blkmem, unsigned int initialseed)
#define SCIP_EVENTTYPE_LPSOLVED
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
static SCIP_DECL_HASHKEYEQ(hashKeyEqSols)
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
int SCIPgetNOrigVars(SCIP *scip)
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
static SCIP_DECL_HEURCOPY(heurCopyCrossover)
static SCIP_RETCODE createNewSol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEUR *heur, SCIP_SOL *subsol, int *solindex, SCIP_Bool *success)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
SCIP_SOL ** SCIPgetSols(SCIP *scip)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
#define DEFAULT_RANDOMIZATION
#define DEFAULT_NUSEDSOLS
enum SCIP_Retcode SCIP_RETCODE
SCIP_RETCODE SCIPwriteOrigProblem(SCIP *scip, const char *filename, const char *extension, SCIP_Bool genericnames)
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
static unsigned int calculateHashKey(int *indices, int size)
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
struct SCIP_HeurData SCIP_HEURDATA
#define SCIPfreeBlockMemory(scip, ptr)
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
int SCIPrandomGetInt(SCIP_RANDNUMGEN *randnumgen, int minrandval, int maxrandval)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
static SCIP_DECL_HASHGETKEY(hashGetKeySols)
static SCIP_DECL_EVENTEXEC(eventExecCrossover)
#define SCIPfreeBufferArray(scip, ptr)
SCIP_RETCODE SCIPcreate(SCIP **scip)
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
static SCIP_DECL_HEURFREE(heurFreeCrossover)
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
static SCIP_DECL_HEUREXEC(heurExecCrossover)
void SCIPrandomFree(SCIP_RANDNUMGEN **randnumgen)
SCIP_RETCODE SCIPsolve(SCIP *scip)
const char * SCIPheurGetName(SCIP_HEUR *heur)
LNS heuristic that tries to combine several feasible solutions.
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
#define DEFAULT_NODESQUOT
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
struct SCIP_EventData SCIP_EVENTDATA
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
SCIP_RETCODE SCIPmergeVariableStatistics(SCIP *sourcescip, SCIP *targetscip, SCIP_VAR **sourcevars, SCIP_VAR **targetvars, int nvars)
SCIP_HEUR * SCIPsolGetHeur(SCIP_SOL *sol)
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
static SCIP_DECL_HEUREXIT(heurExitCrossover)
static SCIP_RETCODE createSolTuple(SCIP *scip, SOLTUPLE **elem, int *indices, int size, SCIP_HEURDATA *heurdata)
#define SCIPallocBufferArray(scip, ptr, num)
public data structures and miscellaneous methods
static SCIP_RETCODE selectSolsRandomized(SCIP *scip, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
SCIP_RETCODE SCIPpermuteProb(SCIP *scip, unsigned int randseed, SCIP_Bool permuteconss, SCIP_Bool permutebinvars, SCIP_Bool permuteintvars, SCIP_Bool permuteimplvars, SCIP_Bool permutecontvars)
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
SCIP_Longint SCIPsolGetNodenum(SCIP_SOL *sol)
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
int SCIPgetDepth(SCIP *scip)
#define DEFAULT_DONTWAITATROOT
#define DEFAULT_BESTSOLLIMIT
SCIP_RETCODE SCIPtrySolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
unsigned int SCIPinitializeRandomSeed(SCIP *scip, int initialseedvalue)
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
static SCIP_DECL_HEURINIT(heurInitCrossover)
int SCIPgetNSols(SCIP *scip)
#define BMScopyMemoryArray(ptr, source, num)
SCIP_RETCODE SCIPincludeHeurCrossover(SCIP *scip)
static SCIP_RETCODE fixVariables(SCIP *scip, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int *nfixedvars, int fixedvarssize, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
Constraint handler for linear constraints in their most general form, .
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
static SCIP_DECL_HASHKEYVAL(hashKeyValSols)
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
#define DEFAULT_USELPROWS
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
SCIP_RETCODE SCIPcopyLargeNeighborhoodSearch(SCIP *sourcescip, SCIP *subscip, SCIP_HASHMAP *varmap, const char *suffix, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Bool uselprows, SCIP_Bool copycuts, SCIP_Bool *success, SCIP_Bool *valid)
SCIP_Bool SCIPisStopped(SCIP *scip)
#define DEFAULT_NWAITINGNODES
static SCIP_Bool solHasNewSource(SCIP_SOL **sols, int *selection, int selectionsize, int newsol)
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
#define DEFAULT_MINIMPROVE
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
SCIP_Real SCIPsumepsilon(SCIP *scip)
SCIP_RETCODE SCIPinterruptSolve(SCIP *scip)
SCIP_Real SCIPgetUpperbound(SCIP *scip)
static void sortArray(int *a, int size)
#define SCIP_CALL_ABORT(x)
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_Longint SCIPgetNLPs(SCIP *scip)
#define DEFAULT_MINFIXINGRATE
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
static void updateFailureStatistic(SCIP *scip, SCIP_HEURDATA *heurdata)
int SCIPsolGetIndex(SCIP_SOL *sol)
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
static SCIP_RETCODE determineVariableFixings(SCIP *scip, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int *nfixedvars, int fixedvarssize, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
SCIP_RETCODE SCIPfree(SCIP **scip)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_Longint SCIPgetSolNodenum(SCIP *scip, SCIP_SOL *sol)