SCIP Doxygen Documentation
Loading...
Searching...
No Matches

Detailed Description

crossover primal heuristic

Author
Timo Berthold

Definition in file heur_crossover.c.

#include "blockmemshell/memory.h"
#include "scip/heur_crossover.h"
#include "scip/heuristics.h"
#include "scip/pub_event.h"
#include "scip/pub_heur.h"
#include "scip/pub_message.h"
#include "scip/pub_misc.h"
#include "scip/pub_sol.h"
#include "scip/pub_var.h"
#include "scip/scip_branch.h"
#include "scip/scip_cons.h"
#include "scip/scip_copy.h"
#include "scip/scip_event.h"
#include "scip/scip_general.h"
#include "scip/scip_heur.h"
#include "scip/scip_mem.h"
#include "scip/scip_message.h"
#include "scip/scip_nodesel.h"
#include "scip/scip_numerics.h"
#include "scip/scip_param.h"
#include "scip/scip_prob.h"
#include "scip/scip_randnumgen.h"
#include "scip/scip_sol.h"
#include "scip/scip_solve.h"
#include "scip/scip_solvingstats.h"
#include "scip/scip_tree.h"
#include "scip/scip_var.h"

Go to the source code of this file.

Macros

#define HEUR_NAME   "crossover"
#define HEUR_DESC   "LNS heuristic that fixes all variables that are identic in a couple of solutions"
#define HEUR_DISPCHAR   SCIP_HEURDISPCHAR_LNS
#define HEUR_PRIORITY   -1104000
#define HEUR_FREQ   15
#define HEUR_FREQOFS   0
#define HEUR_MAXDEPTH   -1
#define HEUR_TIMING   SCIP_HEURTIMING_AFTERNODE
#define HEUR_USESSUBSCIP   TRUE
#define DEFAULT_MAXNODES   5000LL
#define DEFAULT_MINIMPROVE   0.01
#define DEFAULT_MINNODES   50LL
#define DEFAULT_MINFIXINGRATE   0.666
#define DEFAULT_NODESOFS   500LL
#define DEFAULT_NODESQUOT   0.1
#define DEFAULT_LPLIMFAC   2.0
#define DEFAULT_NUSEDSOLS   3
#define DEFAULT_NWAITINGNODES   200LL
#define DEFAULT_RANDOMIZATION   TRUE
#define DEFAULT_DONTWAITATROOT   FALSE
#define DEFAULT_USELPROWS   FALSE
#define DEFAULT_COPYCUTS   TRUE
#define DEFAULT_PERMUTE   FALSE
#define HASHSIZE_SOLS   500
#define DEFAULT_BESTSOLLIMIT   -1
#define DEFAULT_USEUCT   FALSE
#define DEFAULT_RANDSEED   7
#define EVENTHDLR_NAME   "Crossover"
#define EVENTHDLR_DESC   "LP event handler for " HEUR_NAME " heuristic"

Functions

static SCIP_DECL_HASHGETKEY (hashGetKeySols)
static SCIP_DECL_HASHKEYEQ (hashKeyEqSols)
static SCIP_DECL_HASHKEYVAL (hashKeyValSols)
static unsigned int calculateHashKey (int *indices, int size)
static void sortArray (int *a, int size)
static SCIP_RETCODE createSolTuple (SCIP *scip, SOLTUPLE **elem, int *indices, int size, SCIP_HEURDATA *heurdata)
static SCIP_Bool solHasNewSource (SCIP_SOL **sols, int *selection, int selectionsize, int newsol)
static SCIP_RETCODE selectSolsRandomized (SCIP *scip, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
static SCIP_RETCODE fixVariables (SCIP *scip, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int *nfixedvars, int fixedvarssize, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
static SCIP_RETCODE determineVariableFixings (SCIP *scip, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int *nfixedvars, int fixedvarssize, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
static void updateFailureStatistic (SCIP *scip, SCIP_HEURDATA *heurdata)
static SCIP_DECL_EVENTEXEC (eventExecCrossover)
static SCIP_DECL_HEURCOPY (heurCopyCrossover)
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)
static SCIP_DECL_HEURFREE (heurFreeCrossover)
static SCIP_DECL_HEURINIT (heurInitCrossover)
static SCIP_DECL_HEUREXIT (heurExitCrossover)
static SCIP_DECL_HEUREXEC (heurExecCrossover)
SCIP_RETCODE SCIPincludeHeurCrossover (SCIP *scip)

Macro Definition Documentation

◆ HEUR_NAME

#define HEUR_NAME   "crossover"

Definition at line 62 of file heur_crossover.c.

◆ HEUR_DESC

#define HEUR_DESC   "LNS heuristic that fixes all variables that are identic in a couple of solutions"

Definition at line 63 of file heur_crossover.c.

◆ HEUR_DISPCHAR

#define HEUR_DISPCHAR   SCIP_HEURDISPCHAR_LNS

Definition at line 64 of file heur_crossover.c.

◆ HEUR_PRIORITY

#define HEUR_PRIORITY   -1104000

Definition at line 65 of file heur_crossover.c.

◆ HEUR_FREQ

#define HEUR_FREQ   15

Definition at line 66 of file heur_crossover.c.

◆ HEUR_FREQOFS

#define HEUR_FREQOFS   0

Definition at line 67 of file heur_crossover.c.

◆ HEUR_MAXDEPTH

#define HEUR_MAXDEPTH   -1

Definition at line 68 of file heur_crossover.c.

◆ HEUR_TIMING

#define HEUR_TIMING   SCIP_HEURTIMING_AFTERNODE

Definition at line 69 of file heur_crossover.c.

◆ HEUR_USESSUBSCIP

#define HEUR_USESSUBSCIP   TRUE

does the heuristic use a secondary SCIP instance?

Definition at line 70 of file heur_crossover.c.

◆ DEFAULT_MAXNODES

#define DEFAULT_MAXNODES   5000LL

Definition at line 72 of file heur_crossover.c.

◆ DEFAULT_MINIMPROVE

#define DEFAULT_MINIMPROVE   0.01

Definition at line 73 of file heur_crossover.c.

◆ DEFAULT_MINNODES

#define DEFAULT_MINNODES   50LL

Definition at line 74 of file heur_crossover.c.

◆ DEFAULT_MINFIXINGRATE

◆ DEFAULT_NODESOFS

#define DEFAULT_NODESOFS   500LL

Definition at line 76 of file heur_crossover.c.

◆ DEFAULT_NODESQUOT

#define DEFAULT_NODESQUOT   0.1

Definition at line 77 of file heur_crossover.c.

◆ DEFAULT_LPLIMFAC

#define DEFAULT_LPLIMFAC   2.0

Definition at line 78 of file heur_crossover.c.

◆ DEFAULT_NUSEDSOLS

#define DEFAULT_NUSEDSOLS   3

Definition at line 79 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_NWAITINGNODES

◆ DEFAULT_RANDOMIZATION

#define DEFAULT_RANDOMIZATION   TRUE

Definition at line 81 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_DONTWAITATROOT

#define DEFAULT_DONTWAITATROOT   FALSE

Definition at line 82 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_USELPROWS

◆ DEFAULT_COPYCUTS

#define DEFAULT_COPYCUTS   TRUE

Definition at line 85 of file heur_crossover.c.

◆ DEFAULT_PERMUTE

#define DEFAULT_PERMUTE   FALSE

Definition at line 88 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ HASHSIZE_SOLS

#define HASHSIZE_SOLS   500

Definition at line 89 of file heur_crossover.c.

Referenced by SCIP_DECL_HEURINIT().

◆ DEFAULT_BESTSOLLIMIT

◆ DEFAULT_USEUCT

◆ DEFAULT_RANDSEED

#define DEFAULT_RANDSEED   7

Definition at line 92 of file heur_crossover.c.

◆ EVENTHDLR_NAME

#define EVENTHDLR_NAME   "Crossover"

Definition at line 95 of file heur_crossover.c.

◆ EVENTHDLR_DESC

#define EVENTHDLR_DESC   "LP event handler for " HEUR_NAME " heuristic"

Definition at line 96 of file heur_crossover.c.

Typedef Documentation

◆ SOLTUPLE

typedef struct SolTuple SOLTUPLE

Definition at line 102 of file heur_crossover.c.

Function Documentation

◆ SCIP_DECL_HASHGETKEY()

SCIP_DECL_HASHGETKEY ( hashGetKeySols )
static

gets the hash key of a solution tuple

Definition at line 154 of file heur_crossover.c.

References SCIP_DECL_HASHGETKEY.

◆ SCIP_DECL_HASHKEYEQ()

SCIP_DECL_HASHKEYEQ ( hashKeyEqSols )
static

returns TRUE iff both solution tuples are identical

Definition at line 162 of file heur_crossover.c.

References assert(), FALSE, i, NULL, SCIP_DECL_HASHKEYEQ, and TRUE.

◆ SCIP_DECL_HASHKEYVAL()

SCIP_DECL_HASHKEYVAL ( hashKeyValSols )
static

returns hashkey of a solution tuple

Definition at line 193 of file heur_crossover.c.

References SCIP_DECL_HASHKEYVAL.

◆ calculateHashKey()

unsigned int calculateHashKey ( int * indices,
int size )
static

calculates a hash key for a given tuple of solution indices

Parameters
indicesindices of solutions
sizenumber of solutions

Definition at line 201 of file heur_crossover.c.

References calculateHashKey(), and i.

Referenced by calculateHashKey(), and createSolTuple().

◆ sortArray()

void sortArray ( int * a,
int size )
static

insertion sort for a small int array

Parameters
aarray to be sorted
sizesize of array

Definition at line 221 of file heur_crossover.c.

References a, i, and sortArray().

Referenced by createSolTuple(), and sortArray().

◆ createSolTuple()

SCIP_RETCODE createSolTuple ( SCIP * scip,
SOLTUPLE ** elem,
int * indices,
int size,
SCIP_HEURDATA * heurdata )
static

creates a new tuple of solutions

Parameters
sciporiginal SCIP data structure
elemtuple of solutions which should be created
indicesindices of solutions
sizenumber of solutions
heurdataprimal heuristic data

Definition at line 247 of file heur_crossover.c.

References BMScopyMemoryArray, calculateHashKey(), createSolTuple(), heurdata, SCIP_CALL, SCIP_OKAY, SCIPallocBlockMemory, SCIPallocBlockMemoryArray, and sortArray().

Referenced by createSolTuple(), determineVariableFixings(), selectSolsRandomized(), and setupAndSolveSubscipCrossover().

◆ solHasNewSource()

SCIP_Bool solHasNewSource ( SCIP_SOL ** sols,
int * selection,
int selectionsize,
int newsol )
static

checks whether the new solution was found at the same node by the same heuristic as an already selected one

Parameters
solsfeasible SCIP solutions
selectionpool of solutions crossover uses
selectionsizesize of solution pool
newsolcandidate solution

Definition at line 274 of file heur_crossover.c.

References FALSE, i, SCIP_Bool, SCIPsolGetHeur(), SCIPsolGetNodenum(), selection, solHasNewSource(), and TRUE.

Referenced by selectSolsRandomized(), and solHasNewSource().

◆ selectSolsRandomized()

SCIP_RETCODE selectSolsRandomized ( SCIP * scip,
int * selection,
SCIP_HEURDATA * heurdata,
SCIP_Bool * success )
static

randomly selects the solutions crossover will use from the pool of all solutions found so far

Parameters
sciporiginal SCIP data structure
selectionpool of solutions crossover uses
heurdataprimal heuristic data
successpointer to store whether the process was successful

Definition at line 295 of file heur_crossover.c.

References assert(), createSolTuple(), FALSE, heurdata, i, NULL, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIPgetNSols(), SCIPgetSols(), SCIPhashtableExists(), SCIPhashtableInsert(), SCIPrandomGetInt(), selection, selectSolsRandomized(), solHasNewSource(), and TRUE.

Referenced by determineVariableFixings(), and selectSolsRandomized().

◆ fixVariables()

SCIP_RETCODE fixVariables ( SCIP * scip,
SCIP_VAR ** fixedvars,
SCIP_Real * fixedvals,
int * nfixedvars,
int fixedvarssize,
int * selection,
SCIP_HEURDATA * heurdata,
SCIP_Bool * success )
static

determines the fixings for the CROSSOVER subproblem and checks whether enough fixings were found

Parameters
sciporiginal SCIP data structure
fixedvarsarray to store source SCIP variables whose copies should be fixed in the sub-SCIP
fixedvalsarray to store solution values for variable fixing
nfixedvarspointer to store the number of fixed variables
fixedvarssizesize of the arrays to store fixing variables
selectionpool of solutions crossover will use
heurdataprimal heuristic data
successpointer to store whether the problem was created successfully

Definition at line 362 of file heur_crossover.c.

References assert(), FALSE, fixVariables(), heurdata, i, MAX, NULL, nvars, REALABS, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPgetSols(), SCIPgetSolVal(), SCIPgetVarsData(), SCIPvarGetLbGlobal(), SCIPvarGetUbGlobal(), selection, TRUE, and vars.

◆ determineVariableFixings()

SCIP_RETCODE determineVariableFixings ( SCIP * scip,
SCIP_VAR ** fixedvars,
SCIP_Real * fixedvals,
int * nfixedvars,
int fixedvarssize,
int * selection,
SCIP_HEURDATA * heurdata,
SCIP_Bool * success )
static

creates a subproblem for subscip by fixing a number of variables

Parameters
sciporiginal SCIP data structure
fixedvarsarray to store source SCIP variables whose copies should be fixed in the sub-SCIP
fixedvalsarray to store solution values for variable fixing
nfixedvarspointer to store the number of fixed variables
fixedvarssizesize of the arrays to store fixing variables
selectionpool of solutions crossover will use
heurdataprimal heuristic data
successpointer to store whether the problem was created successfully

Definition at line 440 of file heur_crossover.c.

References assert(), createSolTuple(), determineVariableFixings(), FALSE, fixVariables(), heurdata, i, SCIP_Bool, SCIP_CALL, SCIP_Longint, SCIP_OKAY, SCIP_Real, SCIPgetNSols(), SCIPgetSols(), SCIPhashtableExists(), SCIPhashtableInsert(), SCIPsolGetHeur(), SCIPsolGetNodenum(), selection, selectSolsRandomized(), and TRUE.

Referenced by determineVariableFixings(), determineVariableFixings(), determineVariableFixings(), determineVariableFixings(), determineVariableFixings(), SCIP_DECL_HEUREXEC(), SCIP_DECL_HEUREXEC(), SCIP_DECL_HEUREXEC(), SCIP_DECL_HEUREXEC(), and SCIP_DECL_HEUREXEC().

◆ updateFailureStatistic()

void updateFailureStatistic ( SCIP * scip,
SCIP_HEURDATA * heurdata )
static

◆ SCIP_DECL_EVENTEXEC()

◆ SCIP_DECL_HEURCOPY()

SCIP_DECL_HEURCOPY ( heurCopyCrossover )
static

copy method for primal heuristic plugins (called when SCIP copies plugins)

Definition at line 571 of file heur_crossover.c.

References assert(), HEUR_NAME, NULL, SCIP_CALL, SCIP_DECL_HEURCOPY, SCIP_INVALIDCALL, SCIP_OKAY, SCIP_STRINGEQ, SCIPheurGetName(), and SCIPincludeHeurCrossover().

◆ setupAndSolveSubscipCrossover()

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 )
static

setup and solve the subproblem and catch the return code

Parameters
scipSCIP data structure
subscipsub-SCIP data structure
heurmutation heuristic
heurdataheuristics data
varsSCIP variables
fixedvarsarray to store the variables that should be fixed in the subproblem
fixedvalsarray to store the fixing values to fix variables in the subproblem
nstallnodesnode limit for the subproblem
resultpointer to store the result
selectionpool of solutions crossover uses
nvarsnumber of original problem's variables
nfixedvarsthe number of variables that should be fixed
nusedsolsnumber of solutions which will be chosen

Definition at line 586 of file heur_crossover.c.

References assert(), createSolTuple(), cutoff, EVENTHDLR_DESC, EVENTHDLR_NAME, FALSE, HEUR_NAME, heurdata, i, MIN, NULL, nvars, result, SCIP_Bool, SCIP_CALL, SCIP_CALL_ABORT, SCIP_EVENTTYPE_LPSOLVED, SCIP_FOUNDSOL, SCIP_Longint, SCIP_OKAY, SCIP_PARAMSETTING_FAST, SCIP_PARAMSETTING_OFF, SCIP_PLUGINNOTFOUND, SCIP_Real, SCIPallocBufferArray, SCIPblkmem(), SCIPcatchEvent(), SCIPcopyLargeNeighborhoodSearch(), SCIPcopyLimits(), SCIPdebug, SCIPdebugMsg, SCIPdropEvent(), SCIPerrorMessage, SCIPfindBranchrule(), SCIPfindNodesel(), SCIPfreeBufferArray, SCIPgetBestSol(), SCIPgetLowerbound(), SCIPgetNNodes(), SCIPgetNSols(), SCIPgetSols(), SCIPgetUpperbound(), SCIPhashmapCreate(), SCIPhashmapFree(), SCIPhashmapGetImage(), SCIPhashtableInsert(), SCIPheurGetNCalls(), SCIPincludeEventhdlrBasic(), SCIPinitializeRandomSeed(), SCIPisInfinity(), SCIPisParamFixed(), SCIPmergeVariableStatistics(), SCIPpermuteProb(), SCIPprintStatistics(), SCIPsetBoolParam(), SCIPsetCharParam(), SCIPsetIntParam(), SCIPsetLongintParam(), SCIPsetObjlimit(), SCIPsetPresolving(), SCIPsetSeparating(), SCIPsetSubscipsOff(), SCIPsolGetIndex(), SCIPsolve(), SCIPsumepsilon(), SCIPtransformProb(), SCIPtranslateSubSols(), SCIPwriteOrigProblem(), selection, setupAndSolveSubscipCrossover(), TRUE, updateFailureStatistic(), and vars.

Referenced by SCIP_DECL_HEUREXEC(), and setupAndSolveSubscipCrossover().

◆ SCIP_DECL_HEURFREE()

SCIP_DECL_HEURFREE ( heurFreeCrossover )
static

destructor of primal heuristic to free user data (called when SCIP is exiting)

Definition at line 815 of file heur_crossover.c.

References assert(), heurdata, NULL, SCIP_DECL_HEURFREE, SCIP_OKAY, SCIPfreeBlockMemory, SCIPheurGetData(), and SCIPheurSetData().

◆ SCIP_DECL_HEURINIT()

SCIP_DECL_HEURINIT ( heurInitCrossover )
static

initialization method of primal heuristic (called after problem was transformed)

Definition at line 835 of file heur_crossover.c.

References assert(), DEFAULT_RANDSEED, HASHSIZE_SOLS, heurdata, NULL, SCIP_CALL, SCIP_DECL_HEURINIT, SCIP_OKAY, SCIPblkmem(), SCIPcreateRandom(), SCIPhashtableCreate(), SCIPheurGetData(), and TRUE.

◆ SCIP_DECL_HEUREXIT()

SCIP_DECL_HEUREXIT ( heurExitCrossover )
static

deinitialization method of primal heuristic (called before transformed problem is freed)

Definition at line 868 of file heur_crossover.c.

References assert(), heurdata, NULL, SCIP_DECL_HEUREXIT, SCIP_OKAY, SCIPfreeBlockMemory, SCIPfreeBlockMemoryArray, SCIPfreeRandom(), SCIPhashtableFree(), and SCIPheurGetData().

◆ SCIP_DECL_HEUREXEC()