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   11113 /* size of hash table for solution tuples in crossover heuristic */
 
#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 *subscip, SCIP_VAR **subvars, int *selection, SCIP_HEURDATA *heurdata, SCIP_Bool *success)
 
static SCIP_RETCODE createRows (SCIP *scip, SCIP *subscip, SCIP_VAR **subvars)
 
static SCIP_RETCODE setupSubproblem (SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, 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_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

#define HEUR_NAME   "crossover"
#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().

#define HEUR_DISPCHAR   'C'

Definition at line 34 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

#define HEUR_PRIORITY   -1104000

Definition at line 35 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

#define HEUR_FREQ   30

Definition at line 36 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

#define HEUR_FREQOFS   0

Definition at line 37 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

#define HEUR_MAXDEPTH   -1

Definition at line 38 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

#define HEUR_TIMING   SCIP_HEURTIMING_AFTERNODE

Definition at line 39 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

#define HEUR_USESSUBSCIP   TRUE

does the heuristic use a secondary SCIP instance?

Definition at line 40 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

#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().

#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().

#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().

#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().

#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().

#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().

#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().

#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().

#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().

#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().

#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().

#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 */

Definition at line 53 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

#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
*/

Definition at line 54 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

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

Definition at line 55 of file heur_crossover.c.

Referenced by SCIPincludeHeurCrossover().

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

Definition at line 56 of file heur_crossover.c.

Referenced by SCIP_DECL_HEURINIT().

#define EVENTHDLR_NAME   "Crossover"

Definition at line 59 of file heur_crossover.c.

Referenced by SCIP_DECL_EVENTEXEC(), and SCIP_DECL_HEUREXEC().

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

Definition at line 60 of file heur_crossover.c.

Referenced by SCIP_DECL_HEUREXEC().

Typedef Documentation

typedef struct SolTuple SOLTUPLE

Definition at line 66 of file heur_crossover.c.

Function Documentation

static SCIP_DECL_HASHGETKEY ( hashGetKeySols  )
static

gets the hash key of a solution tuple

Definition at line 117 of file heur_crossover.c.

static SCIP_DECL_HASHKEYEQ ( hashKeyEqSols  )
static

returns TRUE iff both solution tuples are identical

Definition at line 125 of file heur_crossover.c.

References FALSE, NULL, and TRUE.

static SCIP_DECL_HASHKEYVAL ( hashKeyValSols  )
static

returns hashkey of a solution tuple

Definition at line 156 of file heur_crossover.c.

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

Referenced by createSolTuple().

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

Referenced by 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 210 of file heur_crossover.c.

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

Referenced by SCIP_DECL_HEUREXEC(), selectSolsRandomized(), and setupSubproblem().

static SCIP_Bool solHasNewSource ( SCIP_SOL **  sols,
int *  selection,
int  selectionsize,
int  newsol 
)
static
Parameters
solsfeasible SCIP solutions
selectionpool of solutions crossover uses
selectionsizesize of solution pool
newsolcandidate solution

Definition at line 236 of file heur_crossover.c.

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

Referenced by 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 255 of file heur_crossover.c.

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

Referenced by setupSubproblem().

static SCIP_RETCODE fixVariables ( SCIP scip,
SCIP subscip,
SCIP_VAR **  subvars,
int *  selection,
SCIP_HEURDATA heurdata,
SCIP_Bool success 
)
static

creates the all variables of the subproblem

Parameters
sciporiginal SCIP data structure
subscipSCIP data structure for the subproblemd
subvarsthe variables of the subproblem
selectionpool of solutions crossover will use
heurdataprimal heuristic data
successpointer to store whether the problem was created successfully

Definition at line 320 of file heur_crossover.c.

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

Referenced by setupSubproblem().

static SCIP_RETCODE createRows ( SCIP scip,
SCIP subscip,
SCIP_VAR **  subvars 
)
static

creates the rows of the subproblem

Parameters
sciporiginal SCIP data structure
subscipSCIP data structure for the subproblem
subvarsthe variables of the subproblem

Definition at line 393 of file heur_crossover.c.

References FALSE, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPaddCons(), SCIPallocBufferArray, SCIPcolGetVar(), SCIPcreateConsLinear(), SCIPfreeBufferArray, SCIPgetLPRowsData(), SCIPreleaseCons(), SCIProwGetCols(), SCIProwGetConstant(), SCIProwGetLhs(), SCIProwGetName(), SCIProwGetNNonz(), SCIProwGetRhs(), SCIProwGetVals(), SCIProwIsLocal(), SCIPvarGetProbindex(), and TRUE.

Referenced by setupSubproblem().

static SCIP_RETCODE setupSubproblem ( SCIP scip,
SCIP subscip,
SCIP_VAR **  subvars,
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
subscipSCIP data structure for the subproblem
subvarsthe variables of the subproblem
selectionpool of solutions crossover will use
heurdataprimal heuristic data
successpointer to store whether the problem was created successfully

Definition at line 454 of file heur_crossover.c.

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

Referenced by SCIP_DECL_HEUREXEC().

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

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

Referenced by SCIP_DECL_HEUREXEC().

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

References SCIP_LONGINT_MAX, and SCIPgetNNodes().

Referenced by SCIP_DECL_HEUREXEC().

static SCIP_DECL_EVENTEXEC ( eventExecCrossover  )
static
static SCIP_DECL_HEURCOPY ( heurCopyCrossover  )
static

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

Definition at line 643 of file heur_crossover.c.

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

static SCIP_DECL_HEURFREE ( heurFreeCrossover  )
static

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

Definition at line 657 of file heur_crossover.c.

References NULL, SCIP_OKAY, SCIPfreeMemory, SCIPheurGetData(), and SCIPheurSetData().

static SCIP_DECL_HEURINIT ( heurInitCrossover  )
static

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

Definition at line 677 of file heur_crossover.c.

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

static SCIP_DECL_HEUREXIT ( heurExitCrossover  )
static

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

Definition at line 708 of file heur_crossover.c.

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

static SCIP_DECL_HEUREXEC ( heurExecCrossover  )
static

execution method of primal heuristic

Definition at line 741 of file heur_crossover.c.

References createNewSol(), createSolTuple(), EVENTHDLR_DESC, EVENTHDLR_NAME, FALSE, HEUR_NAME, MIN, NULL, SCIP_Bool, SCIP_CALL, SCIP_DELAYED, SCIP_DIDNOTFIND, SCIP_DIDNOTRUN, SCIP_EVENTTYPE_LPSOLVED, SCIP_FOUNDSOL, SCIP_Longint, SCIP_MAXSTRLEN, SCIP_OKAY, SCIP_PARAMSETTING_FAST, SCIP_PARAMSETTING_OFF, SCIP_PLUGINNOTFOUND, SCIP_Real, SCIPallocBufferArray, SCIPblkmem(), SCIPcalcHashtableSize(), SCIPcatchEvent(), SCIPcopy(), SCIPcopyCuts(), SCIPcopyVars(), SCIPcreate(), SCIPcreateProb(), SCIPdebug, SCIPdebugMessage, SCIPdropEvent(), SCIPerrorMessage, SCIPfindBranchrule(), SCIPfindConshdlr(), SCIPfindNodesel(), SCIPfree(), SCIPfreeBufferArray, SCIPgetBestSol(), SCIPgetDepth(), SCIPgetLowerbound(), SCIPgetMemExternEstim(), SCIPgetMemUsed(), SCIPgetNNodes(), SCIPgetNSols(), SCIPgetProbName(), SCIPgetRealParam(), SCIPgetSolNodenum(), SCIPgetSols(), SCIPgetSolvingTime(), SCIPgetUpperbound(), SCIPgetVarsData(), SCIPhashmapCreate(), SCIPhashmapFree(), SCIPhashmapGetImage(), SCIPhashtableInsert(), SCIPheurGetData(), SCIPheurGetNBestSolsFound(), SCIPheurGetNCalls(), SCIPincludeDefaultPlugins(), SCIPincludeEventhdlrBasic(), SCIPinfinity(), SCIPisInfinity(), SCIPisParamFixed(), SCIPisStopped(), SCIPpermuteProb(), SCIPprintStatistics(), SCIPsetBoolParam(), SCIPsetIntParam(), SCIPsetLongintParam(), SCIPsetObjlimit(), SCIPsetPresolving(), SCIPsetRealParam(), SCIPsetSeparating(), SCIPsetSubscipsOff(), SCIPsnprintf(), SCIPsolGetIndex(), SCIPsolve(), SCIPsumepsilon(), SCIPtransformProb(), SCIPwarningMessage(), setupSubproblem(), TRUE, and updateFailureStatistic().