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;
140 indices1 = ((
SOLTUPLE*)key1)->indices;
141 indices2 = ((
SOLTUPLE*)key2)->indices;
144 assert(indices1 != NULL);
145 assert(indices2 != NULL);
151 for( i = 0; i < size; i++ )
153 if( indices1[i] != indices2[i] )
177 unsigned int hashkey;
181 for( i = 0; i < size; i++ )
182 hashkey *= indices[i] + 1;
183 for( i = 0; i < size; i++ )
184 hashkey += indices[i];
201 for( i = 1; i < size; i++ )
205 while( j >= 0 && a[j] > tmp )
232 (*elem)->size = size;
234 (*elem)->prev = heurdata->lasttuple;
237 heurdata->lasttuple = *elem;
253 for( i = 0; i < selectionsize; i++ )
280 assert( success != NULL );
283 nusedsols = heurdata->nusedsols;
286 assert(nusedsols < lastsol);
292 while( !*success && i < 10 )
297 for( j = 0; j < nusedsols && validtuple; j++ )
306 validtuple = (k >= nusedsols-j-1);
355 assert(sols != NULL);
356 assert(fixedvars != NULL);
357 assert(fixedvals != NULL);
361 assert(fixedvarssize >= nbinvars + nintvars);
366 for( i = 0; i < nbinvars + nintvars; i++ )
375 for( j = 1; j < heurdata->nusedsols; j++ )
378 varsolval =
SCIPgetSolVal(scip, sols[selection[j]], vars[i]);
379 if(
REALABS(solval - varsolval) > 0.5 )
392 fixedvars[(*nfixedvars)] = vars[i];
393 fixedvals[(*nfixedvars)] = solval;
403 *success = (*nfixedvars) < nbinvars + nintvars && fixingrate >= heurdata->minfixingrate;
429 nusedsols = heurdata->nusedsols;
431 assert(nusedsols > 1);
432 assert(nsols >= nusedsols);
436 if( !heurdata->randomization || nsols == nusedsols || heurdata->prevlastsol != sols[nusedsols-1] )
443 for( i = 0; i < nusedsols; i++ )
454 for( i = 1; i < nusedsols; i++ )
469 if( !(*success) && heurdata->randomization && nsols > nusedsols )
486 SCIP_CALL(
fixVariables(scip, fixedvars, fixedvals, nfixedvars, fixedvarssize, selection, heurdata, success) );
509 assert(scip != NULL);
510 assert(subscip != NULL);
511 assert(subvars != NULL);
512 assert(subsol != NULL);
546 heurdata->nfailures++;
547 heurdata->nextnodenumber = (heurdata->nfailures <= 25
563 assert(eventhdlr != NULL);
564 assert(eventdata != NULL);
566 assert(event != NULL);
570 assert(heurdata != NULL);
590 assert(
scip != NULL);
591 assert(heur != NULL);
626 assert(scip != NULL);
627 assert(subscip != NULL);
628 assert(heur != NULL);
629 assert(heurdata != NULL);
637 heurdata->uselprows, heurdata->copycuts, &success, NULL) );
642 if( eventhdlr == NULL )
650 for( i = 0; i < nvars; i++ )
674 heurdata->nodelimit = nstallnodes;
747 cutoff = MIN(upperbound, cutoff );
751 if( heurdata->permute )
761 #ifdef SCIP_DISABLED_CODE 781 SCIPdebugMsg(scip,
"Transferring variable histories complete\n");
796 for( i = 0; i < nsubsols && !success; ++i )
805 assert(solindex != -1);
812 for( i = 0; i < nusedsols; i++ )
816 selection[i] = solindex;
824 if( !heurdata->randomization )
827 heurdata->prevlastsol =
SCIPgetSols(scip)[heurdata->nusedsols-1];
852 assert(heur != NULL);
853 assert(
scip != NULL);
857 assert(heurdata != NULL);
872 assert(heur != NULL);
873 assert(
scip != NULL);
877 assert(heurdata != NULL);
880 heurdata->usednodes = 0;
881 heurdata->prevlastsol = NULL;
882 heurdata->prevbestsol = NULL;
883 heurdata->lasttuple = NULL;
884 heurdata->nfailures = 0;
885 heurdata->prevnsols = 0;
886 heurdata->nextnodenumber = 0;
893 hashGetKeySols, hashKeyEqSols, hashKeyValSols, NULL) );
894 assert(heurdata->hashtable != NULL);
906 assert(heur != NULL);
907 assert(
scip != NULL);
911 assert(heurdata != NULL);
912 soltuple = heurdata->lasttuple;
915 while( soltuple != NULL )
918 tmp = soltuple->prev;
928 assert(heurdata->hashtable != NULL);
954 assert(heur != NULL);
955 assert(
scip != NULL);
956 assert(result != NULL);
960 assert(heurdata != NULL);
961 nusedsols = heurdata->nusedsols;
970 assert(sols != NULL);
973 if( sols[nusedsols-1] != heurdata->prevlastsol )
976 if( sols[0] != heurdata->prevbestsol )
977 heurdata->nfailures = 0;
980 else if( !heurdata->randomization )
1003 nstallnodes += heurdata->nodesofs;
1006 nstallnodes -= heurdata->usednodes;
1007 nstallnodes = MIN(nstallnodes, heurdata->maxnodes);
1010 if( nstallnodes < heurdata->minnodes )
1027 if( nbinvars == 0 && nintvars == 0 )
1041 heurdata->prevlastsol = sols[heurdata->nusedsols-1];
1060 fixedvars, fixedvals, nstallnodes, result, selection, nvars, nfixedvars, nusedsols);
1095 assert(heur != NULL);
1106 "number of nodes added to the contingent of the total nodes",
1110 "maximum number of nodes to regard in the subproblem",
1114 "minimum number of nodes required to start the subproblem",
1118 "number of solutions to be taken into account",
1122 "number of nodes without incumbent change that heuristic should wait",
1126 "contingent of sub problem nodes in relation to the number of nodes of the original problem",
1130 "minimum percentage of integer variables that have to be fixed",
1134 "factor by which Crossover should at least improve the incumbent",
1138 "factor by which the limit on the number of LP depends on the node limit",
1142 "should the choice which sols to take be randomized?",
1146 "should the nwaitingnodes parameter be ignored at the root node?",
1150 "should subproblem be created out of the rows in the LP rows?",
1154 "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
1158 "should the subproblem be permuted to increase diversification?",
1162 "limit on number of improving incumbent solutions in sub-CIP",
1166 "should uct node selection be used at the beginning of the search?",
enum SCIP_Result SCIP_RESULT
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
#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 SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed)
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)
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)
static SCIP_RETCODE setupAndSolveSubscipCrossover(SCIP *scip, SCIP *subscip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata, SCIP_VAR **vars, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, SCIP_Longint nstallnodes, SCIP_RESULT *result, int *selection, int nvars, int nfixedvars, int nusedsols)
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)
SCIP_RETCODE SCIPsetCharParam(SCIP *scip, const char *name, char value)
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)