Scippy

SCIP

Solving Constraint Integer Programs

heur_veclendiving.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2020 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_veclendiving.c
17  * @ingroup DEFPLUGINS_HEUR
18  * @brief LP diving heuristic that rounds variables with long column vectors
19  * @author Tobias Achterberg
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include "scip/heuristics.h"
25 #include "scip/heur_veclendiving.h"
26 #include "scip/pub_heur.h"
27 #include "scip/pub_lp.h"
28 #include "scip/pub_message.h"
29 #include "scip/pub_var.h"
30 #include "scip/scip_heur.h"
31 #include "scip/scip_mem.h"
32 #include "scip/scip_numerics.h"
33 #include "scip/scip_prob.h"
34 #include "scip/scip_sol.h"
35 #include <string.h>
36 
37 #define HEUR_NAME "veclendiving"
38 #define HEUR_DESC "LP diving heuristic that rounds variables with long column vectors"
39 #define HEUR_DISPCHAR SCIP_HEURDISPCHAR_DIVING
40 #define HEUR_PRIORITY -1003100
41 #define HEUR_FREQ 10
42 #define HEUR_FREQOFS 4
43 #define HEUR_MAXDEPTH -1
44 #define HEUR_TIMING SCIP_HEURTIMING_AFTERLPPLUNGE
45 #define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */
46 #define DIVESET_DIVETYPES SCIP_DIVETYPE_INTEGRALITY /**< bit mask that represents all supported dive types */
47 #define DIVESET_ISPUBLIC TRUE /**< is this dive set publicly available (ie., can be used by other primal heuristics?) */
48 
49 
50 /*
51  * Default parameter settings
52  */
53 
54 #define DEFAULT_MINRELDEPTH 0.0 /**< minimal relative depth to start diving */
55 #define DEFAULT_MAXRELDEPTH 1.0 /**< maximal relative depth to start diving */
56 #define DEFAULT_MAXLPITERQUOT 0.05 /**< maximal fraction of diving LP iterations compared to node LP iterations */
57 #define DEFAULT_MAXLPITEROFS 1000 /**< additional number of allowed LP iterations */
58 #define DEFAULT_MAXDIVEUBQUOT 0.8 /**< maximal quotient (curlowerbound - lowerbound)/(cutoffbound - lowerbound)
59  * where diving is performed (0.0: no limit) */
60 #define DEFAULT_MAXDIVEAVGQUOT 0.0 /**< maximal quotient (curlowerbound - lowerbound)/(avglowerbound - lowerbound)
61  * where diving is performed (0.0: no limit) */
62 #define DEFAULT_MAXDIVEUBQUOTNOSOL 0.1 /**< maximal UBQUOT when no solution was found yet (0.0: no limit) */
63 #define DEFAULT_MAXDIVEAVGQUOTNOSOL 0.0 /**< maximal AVGQUOT when no solution was found yet (0.0: no limit) */
64 #define DEFAULT_BACKTRACK TRUE /**< use one level of backtracking if infeasibility is encountered? */
65 #define DEFAULT_LPRESOLVEDOMCHGQUOT 0.15 /**< percentage of immediate domain changes during probing to trigger LP resolve */
66 #define DEFAULT_LPSOLVEFREQ 0 /**< LP solve frequency for diving heuristics */
67 #define DEFAULT_ONLYLPBRANCHCANDS FALSE /**< should only LP branching candidates be considered instead of the slower but
68  * more general constraint handler diving variable selection? */
69 #define DEFAULT_RANDSEED 113 /**< initial seed for random number generation */
70 
71 /* locally defined heuristic data */
72 struct SCIP_HeurData
73 {
74  SCIP_SOL* sol; /**< working solution */
75 };
76 
77 
78 /*
79  * local methods
80  */
81 
82 /*
83  * Callback methods
84  */
85 
86 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
87 static
88 SCIP_DECL_HEURCOPY(heurCopyVeclendiving)
89 { /*lint --e{715}*/
90  assert(scip != NULL);
91  assert(heur != NULL);
92  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
93 
94  /* call inclusion method of primal heuristic */
96 
97  return SCIP_OKAY;
98 }
99 
100 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
101 static
102 SCIP_DECL_HEURFREE(heurFreeVeclendiving) /*lint --e{715}*/
103 { /*lint --e{715}*/
104  SCIP_HEURDATA* heurdata;
106  assert(heur != NULL);
107  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
108  assert(scip != NULL);
109 
110  /* free heuristic data */
111  heurdata = SCIPheurGetData(heur);
112  assert(heurdata != NULL);
113 
114  SCIPfreeBlockMemory(scip, &heurdata);
115  SCIPheurSetData(heur, NULL);
116 
117  return SCIP_OKAY;
118 }
119 
120 
121 /** initialization method of primal heuristic (called after problem was transformed) */
122 static
123 SCIP_DECL_HEURINIT(heurInitVeclendiving) /*lint --e{715}*/
124 { /*lint --e{715}*/
125  SCIP_HEURDATA* heurdata;
127  assert(heur != NULL);
128  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
129 
130  /* get heuristic data */
131  heurdata = SCIPheurGetData(heur);
132  assert(heurdata != NULL);
133 
134  /* create working solution */
135  SCIP_CALL( SCIPcreateSol(scip, &heurdata->sol, heur) );
136 
137  return SCIP_OKAY;
138 }
139 
140 
141 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
142 static
143 SCIP_DECL_HEUREXIT(heurExitVeclendiving) /*lint --e{715}*/
144 { /*lint --e{715}*/
145  SCIP_HEURDATA* heurdata;
147  assert(heur != NULL);
148  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
149 
150  /* get heuristic data */
151  heurdata = SCIPheurGetData(heur);
152  assert(heurdata != NULL);
153 
154  /* free working solution */
155  SCIP_CALL( SCIPfreeSol(scip, &heurdata->sol) );
156 
157  return SCIP_OKAY;
158 }
159 
160 
161 /** execution method of primal heuristic */
162 static
163 SCIP_DECL_HEUREXEC(heurExecVeclendiving) /*lint --e{715}*/
164 { /*lint --e{715}*/
165  SCIP_HEURDATA* heurdata;
166  SCIP_DIVESET* diveset;
167 
168  heurdata = SCIPheurGetData(heur);
169  assert(SCIPheurGetNDivesets(heur) > 0);
170  assert(SCIPheurGetDivesets(heur) != NULL);
171  diveset = SCIPheurGetDivesets(heur)[0];
172  assert(diveset != NULL);
173 
174  *result = SCIP_DIDNOTRUN;
175 
176  /* terminate if there are no integer variables (note that, e.g., SOS1 variables may be present) */
178  return SCIP_OKAY;
179 
180  SCIP_CALL( SCIPperformGenericDivingAlgorithm(scip, diveset, heurdata->sol, heur, result, nodeinfeasible, -1L, SCIP_DIVECONTEXT_SINGLE) );
181 
182  return SCIP_OKAY;
183 }
184 
185 /** calculate score and preferred rounding direction for the candidate variable */
186 static
187 SCIP_DECL_DIVESETGETSCORE(divesetGetScoreVeclendiving)
188 {
189  SCIP_Real obj;
190  SCIP_Real objdelta;
191  SCIP_Real colveclen;
192 
193  obj = SCIPvarGetObj(cand);
194  *roundup = (obj >= 0.0);
195  objdelta = ((*roundup) ? (1.0 - candsfrac) * obj : -candsfrac * obj);
196  assert(objdelta >= 0.0);
197 
198  colveclen = (SCIPvarGetStatus(cand) == SCIP_VARSTATUS_COLUMN ? SCIPcolGetNNonz(SCIPvarGetCol(cand)) : 0.0);
199 
200  /* larger score is better */
201  *score = (colveclen + 1.0) / (objdelta + SCIPsumepsilon(scip));
202 
203  /* prefer decisions on binary variables */
204  if( SCIPvarGetType(cand) != SCIP_VARTYPE_BINARY )
205  *score *= 0.001;
206 
207  return SCIP_OKAY;
208 }
209 
210 #define divesetAvailableVeclendiving NULL
211 
212 /*
213  * heuristic specific interface methods
214  */
215 
216 /** creates the veclendiving heuristic and includes it in SCIP */
218  SCIP* scip /**< SCIP data structure */
219  )
220 {
221  SCIP_HEURDATA* heurdata;
222  SCIP_HEUR* heur;
223 
224  /* create Veclendiving primal heuristic data */
225  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
226 
227  /* include primal heuristic */
228  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
230  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecVeclendiving, heurdata) );
231 
232  assert(heur != NULL);
233 
234  /* set non-NULL pointers to callback methods */
235  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyVeclendiving) );
236  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeVeclendiving) );
237  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitVeclendiving) );
238  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitVeclendiving) );
239 
240  /* veclendiving heuristic parameters */
241  /* create a diveset (this will automatically install some additional parameters for the heuristic) */
245  DIVESET_ISPUBLIC, DIVESET_DIVETYPES, divesetGetScoreVeclendiving, divesetAvailableVeclendiving) );
246 
247  return SCIP_OKAY;
248 }
249 
#define HEUR_NAME
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:977
#define DEFAULT_MAXDIVEAVGQUOTNOSOL
SCIP_Real SCIPsumepsilon(SCIP *scip)
#define HEUR_TIMING
static SCIP_DECL_HEUREXEC(heurExecVeclendiving)
#define DEFAULT_MAXDIVEUBQUOTNOSOL
#define DEFAULT_LPSOLVEFREQ
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1429
#define HEUR_PRIORITY
#define HEUR_FREQ
public methods for memory management
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1340
#define DEFAULT_MINRELDEPTH
int SCIPcolGetNNonz(SCIP_COL *col)
Definition: lp.c:16975
static SCIP_DECL_DIVESETGETSCORE(divesetGetScoreVeclendiving)
SCIP_RETCODE SCIPperformGenericDivingAlgorithm(SCIP *scip, SCIP_DIVESET *diveset, SCIP_SOL *worksol, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_Bool nodeinfeasible, SCIP_Longint iterlim, SCIP_DIVECONTEXT divecontext)
Definition: heuristics.c:209
static SCIP_DECL_HEURFREE(heurFreeVeclendiving)
SCIP_EXPORT SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17510
SCIP_EXPORT SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:17177
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
methods commonly used by primal heuristics
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:67
public methods for problem variables
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:95
#define DEFAULT_MAXRELDEPTH
static SCIP_DECL_HEUREXIT(heurExitVeclendiving)
SCIP_EXPORT SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:17131
#define DEFAULT_MAXDIVEAVGQUOT
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:78
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:185
#define DEFAULT_RANDSEED
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2076
public methods for numerical tolerances
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:320
#define DIVESET_ISPUBLIC
#define DEFAULT_MAXDIVEUBQUOT
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)
Definition: scip_heur.c:108
#define HEUR_DISPCHAR
int SCIPheurGetNDivesets(SCIP_HEUR *heur)
Definition: heur.c:1637
static SCIP_DECL_HEURCOPY(heurCopyVeclendiving)
SCIP_SOL * sol
Definition: struct_heur.h:62
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1350
#define NULL
Definition: lpi_spx1.cpp:155
#define HEUR_MAXDEPTH
#define HEUR_USESSUBSCIP
#define SCIP_CALL(x)
Definition: def.h:364
#define DEFAULT_LPRESOLVEDOMCHGQUOT
public methods for primal heuristic plugins and divesets
#define DEFAULT_BACKTRACK
SCIP_EXPORT SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:17376
SCIP_DIVESET ** SCIPheurGetDivesets(SCIP_HEUR *heur)
Definition: heur.c:1627
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:201
#define divesetAvailableVeclendiving
public methods for LP management
#define HEUR_FREQOFS
SCIP_RETCODE SCIPcreateDiveset(SCIP *scip, SCIP_DIVESET **diveset, SCIP_HEUR *heur, const char *name, SCIP_Real minreldepth, SCIP_Real maxreldepth, SCIP_Real maxlpiterquot, SCIP_Real maxdiveubquot, SCIP_Real maxdiveavgquot, SCIP_Real maxdiveubquotnosol, SCIP_Real maxdiveavgquotnosol, SCIP_Real lpresolvedomchgquot, int lpsolvefreq, int maxlpiterofs, unsigned int initialseed, SCIP_Bool backtrack, SCIP_Bool onlylpbranchcands, SCIP_Bool ispublic, SCIP_Bool specificsos1score, SCIP_DECL_DIVESETGETSCORE((*divesetgetscore)), SCIP_DECL_DIVESETAVAILABLE((*divesetavailable)))
Definition: scip_heur.c:311
SCIP_RETCODE SCIPincludeHeurVeclendiving(SCIP *scip)
#define DEFAULT_ONLYLPBRANCHCANDS
static SCIP_DECL_HEURINIT(heurInitVeclendiving)
public methods for solutions
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:153
public methods for message output
#define DEFAULT_MAXLPITEROFS
LP diving heuristic that rounds variables with long column vectors.
#define SCIP_Real
Definition: def.h:163
#define HEUR_DESC
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2031
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:169
public methods for primal heuristics
#define DEFAULT_MAXLPITERQUOT
public methods for global and local (sub)problems
#define DIVESET_DIVETYPES