Scippy

SCIP

Solving Constraint Integer Programs

heur_crossover.c File Reference

Detailed Description

crossover primal heuristic

Author
Timo Berthold

Definition in file heur_crossover.c.

#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "scip/scip.h"
#include "scip/scipdefplugins.h"
#include "scip/cons_linear.h"
#include "scip/heur_crossover.h"
#include "scip/pub_misc.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   'C'
 
#define HEUR_PRIORITY   -1104000
 
#define HEUR_FREQ   30
 
#define HEUR_FREQOFS   0
 
#define HEUR_MAXDEPTH   -1
 
#define HEUR_TIMING   SCIP_HEURTIMING_AFTERNODE
 
#define HEUR_USESSUBSCIP   TRUE
 
#define DEFAULT_MAXNODES   5000LL /* maximum number of nodes to regard in the subproblem */
 
#define DEFAULT_MINIMPROVE   0.01 /* factor by which Crossover should at least improve the incumbent */
 
#define DEFAULT_MINNODES   50LL /* minimum number of nodes to regard in the subproblem */
 
#define DEFAULT_MINFIXINGRATE   0.666 /* minimum percentage of integer variables that have to be fixed */
 
#define DEFAULT_NODESOFS   500LL /* number of nodes added to the contingent of the total nodes */
 
#define DEFAULT_NODESQUOT   0.1 /* subproblem nodes in relation to nodes of the original problem */
 
#define DEFAULT_LPLIMFAC   2.0 /* factor by which the limit on the number of LP depends on the node limit */
 
#define DEFAULT_NUSEDSOLS   3 /* number of solutions that will be taken into account */
 
#define DEFAULT_NWAITINGNODES   200LL /* number of nodes without incumbent change heuristic should wait */
 
#define DEFAULT_RANDOMIZATION   TRUE /* should the choice which sols to take be randomized? */
 
#define DEFAULT_DONTWAITATROOT   FALSE /* should the nwaitingnodes parameter be ignored at the root node? */
 
#define DEFAULT_USELPROWS
 
#define DEFAULT_COPYCUTS
 
#define DEFAULT_PERMUTE   FALSE /* should the subproblem be permuted to increase diversification? */
 
#define HASHSIZE_SOLS   500 /* size of hash table for solution tuples in crossover heuristic */
 
#define DEFAULT_BESTSOLLIMIT   -1 /* limit on number of improving incumbent solutions in sub-CIP */
 
#define DEFAULT_USEUCT   FALSE /* should uct node selection be used at the beginning of the search? */
 
#define DEFAULT_RANDSEED   7 /* initial random seed */
 
#define EVENTHDLR_NAME   "Crossover"
 
#define EVENTHDLR_DESC   "LP event handler for " HEUR_NAME " heuristic"
 

Typedefs

typedef struct SolTuple SOLTUPLE
 

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 SCIP_RETCODE createNewSol (SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEUR *heur, SCIP_SOL *subsol, int *solindex, 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"

◆ HEUR_DESC

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

Definition at line 33 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ HEUR_DISPCHAR

#define HEUR_DISPCHAR   'C'

Definition at line 34 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ HEUR_PRIORITY

#define HEUR_PRIORITY   -1104000

Definition at line 35 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ HEUR_FREQ

#define HEUR_FREQ   30

Definition at line 36 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ HEUR_FREQOFS

#define HEUR_FREQOFS   0

Definition at line 37 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ HEUR_MAXDEPTH

#define HEUR_MAXDEPTH   -1

Definition at line 38 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ HEUR_TIMING

#define HEUR_TIMING   SCIP_HEURTIMING_AFTERNODE

Definition at line 39 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ HEUR_USESSUBSCIP

#define HEUR_USESSUBSCIP   TRUE

does the heuristic use a secondary SCIP instance?

Definition at line 40 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_MAXNODES

#define DEFAULT_MAXNODES   5000LL /* maximum number of nodes to regard in the subproblem */

Definition at line 42 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_MINIMPROVE

#define DEFAULT_MINIMPROVE   0.01 /* factor by which Crossover should at least improve the incumbent */

Definition at line 43 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_MINNODES

#define DEFAULT_MINNODES   50LL /* minimum number of nodes to regard in the subproblem */

Definition at line 44 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_MINFIXINGRATE

#define DEFAULT_MINFIXINGRATE   0.666 /* minimum percentage of integer variables that have to be fixed */

Definition at line 45 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_NODESOFS

#define DEFAULT_NODESOFS   500LL /* number of nodes added to the contingent of the total nodes */

Definition at line 46 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_NODESQUOT

#define DEFAULT_NODESQUOT   0.1 /* subproblem nodes in relation to nodes of the original problem */

Definition at line 47 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_LPLIMFAC

#define DEFAULT_LPLIMFAC   2.0 /* factor by which the limit on the number of LP depends on the node limit */

Definition at line 48 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_NUSEDSOLS

#define DEFAULT_NUSEDSOLS   3 /* number of solutions that will be taken into account */

Definition at line 49 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_NWAITINGNODES

#define DEFAULT_NWAITINGNODES   200LL /* number of nodes without incumbent change heuristic should wait */

Definition at line 50 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_RANDOMIZATION

#define DEFAULT_RANDOMIZATION   TRUE /* should the choice which sols to take be randomized? */

Definition at line 51 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_DONTWAITATROOT

#define DEFAULT_DONTWAITATROOT   FALSE /* should the nwaitingnodes parameter be ignored at the root node? */

Definition at line 52 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_USELPROWS

#define DEFAULT_USELPROWS
Value:
FALSE /* should subproblem be created out of the rows in the LP rows,
* otherwise, the copy constructors of the constraints handlers are used */
#define FALSE
Definition: def.h:64

Definition at line 53 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_COPYCUTS

#define DEFAULT_COPYCUTS
Value:
TRUE /* if DEFAULT_USELPROWS is FALSE, then should all active cuts from the
* cutpool of the original scip be copied to constraints of the subscip
*/
#define TRUE
Definition: def.h:63

Definition at line 55 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_PERMUTE

#define DEFAULT_PERMUTE   FALSE /* should the subproblem be permuted to increase diversification? */

Definition at line 58 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ HASHSIZE_SOLS

#define HASHSIZE_SOLS   500 /* size of hash table for solution tuples in crossover heuristic */

Definition at line 59 of file heur_crossover.c.

Referenced by SCIP_DECL_HEURINIT().

◆ DEFAULT_BESTSOLLIMIT

#define DEFAULT_BESTSOLLIMIT   -1 /* limit on number of improving incumbent solutions in sub-CIP */

Definition at line 60 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_USEUCT

#define DEFAULT_USEUCT   FALSE /* should uct node selection be used at the beginning of the search? */

Definition at line 61 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

◆ DEFAULT_RANDSEED

#define DEFAULT_RANDSEED   7 /* initial random seed */

Definition at line 62 of file heur_crossover.c.

Referenced by SCIP_DECL_HEURINIT().

◆ EVENTHDLR_NAME

#define EVENTHDLR_NAME   "Crossover"

Definition at line 65 of file heur_crossover.c.

Referenced by SCIP_DECL_EVENTEXEC(), and setupAndSolveSubscipCrossover().

◆ EVENTHDLR_DESC

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

Definition at line 66 of file heur_crossover.c.

Referenced by setupAndSolveSubscipCrossover().

Typedef Documentation

◆ SOLTUPLE

typedef struct SolTuple SOLTUPLE

Definition at line 72 of file heur_crossover.c.

Function Documentation

◆ SCIP_DECL_HASHGETKEY()

static SCIP_DECL_HASHGETKEY ( hashGetKeySols  )
static

gets the hash key of a solution tuple

Definition at line 124 of file heur_crossover.c.

◆ SCIP_DECL_HASHKEYEQ()

static SCIP_DECL_HASHKEYEQ ( hashKeyEqSols  )
static

returns TRUE iff both solution tuples are identical

Definition at line 132 of file heur_crossover.c.

References FALSE, and TRUE.

◆ SCIP_DECL_HASHKEYVAL()

static SCIP_DECL_HASHKEYVAL ( hashKeyValSols  )
static

returns hashkey of a solution tuple

Definition at line 163 of file heur_crossover.c.

◆ calculateHashKey()

static 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 171 of file heur_crossover.c.

Referenced by createSolTuple().

◆ sortArray()

static 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 191 of file heur_crossover.c.

Referenced by createSolTuple().

◆ createSolTuple()

static 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 217 of file heur_crossover.c.

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

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

◆ solHasNewSource()

static 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 244 of file heur_crossover.c.

References FALSE, SCIPsolGetHeur(), SCIPsolGetNodenum(), and TRUE.

Referenced by selectSolsRandomized().

◆ selectSolsRandomized()

static 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 265 of file heur_crossover.c.

References createSolTuple(), FALSE, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIPgetNSols(), SCIPgetSols(), SCIPhashtableExists(), SCIPhashtableInsert(), SCIPrandomGetInt(), solHasNewSource(), and TRUE.

Referenced by determineVariableFixings().

◆ fixVariables()

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

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 332 of file heur_crossover.c.

References FALSE, MAX, REALABS, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPgetSols(), SCIPgetSolVal(), SCIPgetVarsData(), SCIPvarGetLbGlobal(), SCIPvarGetUbGlobal(), and TRUE.

Referenced by determineVariableFixings().

◆ determineVariableFixings()

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

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 410 of file heur_crossover.c.

References createSolTuple(), FALSE, fixVariables(), SCIP_Bool, SCIP_CALL, SCIP_Longint, SCIP_OKAY, SCIPgetNSols(), SCIPgetSols(), SCIPhashtableExists(), SCIPhashtableInsert(), SCIPsolGetHeur(), SCIPsolGetNodenum(), selectSolsRandomized(), and TRUE.

Referenced by SCIP_DECL_HEUREXEC().

◆ createNewSol()

static SCIP_RETCODE createNewSol ( SCIP scip,
SCIP subscip,
SCIP_VAR **  subvars,
SCIP_HEUR heur,
SCIP_SOL subsol,
int *  solindex,
SCIP_Bool success 
)
static

creates a new solution for the original problem by copying the solution of the subproblem

Parameters
sciporiginal SCIP data structure
subscipSCIP structure of the subproblem
subvarsthe variables of the subproblem
heurcrossover heuristic structure
subsolsolution of the subproblem
solindexindex of the solution
successused to store whether new solution was found or not

Definition at line 494 of file heur_crossover.c.

References FALSE, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPallocBufferArray, SCIPcreateSol(), SCIPfreeBufferArray, SCIPgetNOrigVars(), SCIPgetSolVals(), SCIPgetVarsData(), SCIPsetSolVals(), SCIPsolGetIndex(), SCIPtrySolFree(), and TRUE.

Referenced by setupAndSolveSubscipCrossover().

◆ updateFailureStatistic()

static void updateFailureStatistic ( SCIP scip,
SCIP_HEURDATA heurdata 
)
static

updates heurdata after a run of crossover

Parameters
sciporiginal SCIP data structure
heurdataprimal heuristic data

Definition at line 540 of file heur_crossover.c.

References SCIP_LONGINT_MAX, and SCIPgetNNodes().

Referenced by SCIP_DECL_HEUREXEC(), and setupAndSolveSubscipCrossover().

◆ SCIP_DECL_EVENTEXEC()

static SCIP_DECL_EVENTEXEC ( eventExecCrossover  )
static

◆ SCIP_DECL_HEURCOPY()

static SCIP_DECL_HEURCOPY ( heurCopyCrossover  )
static

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

Definition at line 588 of file heur_crossover.c.

References HEUR_NAME, SCIP_CALL, SCIP_OKAY, SCIPheurGetName(), and SCIPincludeHeurCrossover().

◆ setupAndSolveSubscipCrossover()

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

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 602 of file heur_crossover.c.

References createNewSol(), createSolTuple(), EVENTHDLR_DESC, EVENTHDLR_NAME, FALSE, HEUR_NAME, SCIP_Bool, SCIP_CALL, SCIP_CALL_ABORT, SCIP_EVENTTYPE_LPSOLVED, SCIP_FOUNDSOL, SCIP_OKAY, SCIP_PARAMSETTING_FAST, SCIP_PARAMSETTING_OFF, SCIP_PLUGINNOTFOUND, SCIP_Real, SCIPallocBufferArray, SCIPblkmem(), SCIPcatchEvent(), SCIPcopyLargeNeighborhoodSearch(), SCIPcopyLimits(), SCIPdebug, SCIPdebugMsg, SCIPdropEvent(), SCIPerrorMessage, SCIPfindBranchrule(), SCIPfindConshdlr(), 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(), SCIPwriteOrigProblem(), TRUE, and updateFailureStatistic().

Referenced by SCIP_DECL_HEUREXEC().

◆ SCIP_DECL_HEURFREE()

static SCIP_DECL_HEURFREE ( heurFreeCrossover  )
static

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

Definition at line 848 of file heur_crossover.c.

References SCIP_OKAY, SCIPfreeBlockMemory, SCIPheurGetData(), and SCIPheurSetData().

◆ SCIP_DECL_HEURINIT()

static SCIP_DECL_HEURINIT ( heurInitCrossover  )
static

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

Definition at line 868 of file heur_crossover.c.

References DEFAULT_RANDSEED, HASHSIZE_SOLS, SCIP_CALL, SCIP_OKAY, SCIPblkmem(), SCIPcreateRandom(), SCIPhashtableCreate(), and SCIPheurGetData().

◆ SCIP_DECL_HEUREXIT()

static SCIP_DECL_HEUREXIT ( heurExitCrossover  )
static

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

Definition at line 901 of file heur_crossover.c.

References SCIP_OKAY, SCIPfreeBlockMemory, SCIPfreeBlockMemoryArray, SCIPfreeRandom(), SCIPhashtableFree(), and SCIPheurGetData().

◆ SCIP_DECL_HEUREXEC()