Scippy

SCIP

Solving Constraint Integer Programs

heur_linesearchdiving.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-2017 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 email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file heur_linesearchdiving.c
17  * @brief LP diving heuristic that fixes variables with a large difference to their root solution
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <assert.h>
24 #include <string.h>
25 
27 
28 #define HEUR_NAME "linesearchdiving"
29 #define HEUR_DESC "LP diving heuristic that chooses fixings following the line from root solution to current solution"
30 #define HEUR_DISPCHAR 'l'
31 #define HEUR_PRIORITY -1006000
32 #define HEUR_FREQ 10
33 #define HEUR_FREQOFS 6
34 #define HEUR_MAXDEPTH -1
35 #define HEUR_TIMING SCIP_HEURTIMING_AFTERLPPLUNGE
36 #define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */
37 #define DIVESET_DIVETYPES SCIP_DIVETYPE_INTEGRALITY | SCIP_DIVETYPE_SOS1VARIABLE /**< bit mask that represents all supported dive types */
38 
39 
40 /*
41  * Default parameter settings
42  */
43 
44 #define DEFAULT_MINRELDEPTH 0.0 /**< minimal relative depth to start diving */
45 #define DEFAULT_MAXRELDEPTH 1.0 /**< maximal relative depth to start diving */
46 #define DEFAULT_MAXLPITERQUOT 0.05 /**< maximal fraction of diving LP iterations compared to node LP iterations */
47 #define DEFAULT_MAXLPITEROFS 1000 /**< additional number of allowed LP iterations */
48 #define DEFAULT_MAXDIVEUBQUOT 0.8 /**< maximal quotient (curlowerbound - lowerbound)/(cutoffbound - lowerbound)
49  * where diving is performed (0.0: no limit) */
50 #define DEFAULT_MAXDIVEAVGQUOT 0.0 /**< maximal quotient (curlowerbound - lowerbound)/(avglowerbound - lowerbound)
51  * where diving is performed (0.0: no limit) */
52 #define DEFAULT_MAXDIVEUBQUOTNOSOL 0.1 /**< maximal UBQUOT when no solution was found yet (0.0: no limit) */
53 #define DEFAULT_MAXDIVEAVGQUOTNOSOL 0.0 /**< maximal AVGQUOT when no solution was found yet (0.0: no limit) */
54 #define DEFAULT_BACKTRACK TRUE /**< use one level of backtracking if infeasibility is encountered? */
55 #define DEFAULT_LPRESOLVEDOMCHGQUOT 0.15 /**< percentage of immediate domain changes during probing to trigger LP resolve */
56 #define DEFAULT_LPSOLVEFREQ 0 /**< LP solve frequency for diving heuristics */
57 #define DEFAULT_ONLYLPBRANCHCANDS FALSE /**< should only LP branching candidates be considered instead of the slower but
58  * more general constraint handler diving variable selection? */
59 #define DEFAULT_RANDSEED 137 /**< default initialization for random seed number generation */
60 /*
61  * Data structures
62  */
63 
64 /** primal heuristic data */
65 struct SCIP_HeurData
66 {
67  SCIP_SOL* sol; /**< working solution */
68 };
69 
70 
71 /*
72  * Local methods
73  */
74 
75 
76 /*
77  * Callback methods of primal heuristic
78  */
79 
80 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
81 static
82 SCIP_DECL_HEURCOPY(heurCopyLinesearchdiving)
83 { /*lint --e{715}*/
84  assert(scip != NULL);
85  assert(heur != NULL);
86  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
87 
88  /* call inclusion method of primal heuristic */
90 
91  return SCIP_OKAY;
92 }
93 
94 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
95 static
96 SCIP_DECL_HEURFREE(heurFreeLinesearchdiving)
97 { /*lint --e{715}*/
98  SCIP_HEURDATA* heurdata;
99 
100  assert(heur != NULL);
101  assert(scip != NULL);
102 
103  /* free heuristic data */
104  heurdata = SCIPheurGetData(heur);
105  assert(heurdata != NULL);
106  SCIPfreeBlockMemory(scip, &heurdata);
107  SCIPheurSetData(heur, NULL);
108 
109  return SCIP_OKAY;
110 }
111 
112 
113 /** initialization method of primal heuristic (called after problem was transformed) */
114 static
115 SCIP_DECL_HEURINIT(heurInitLinesearchdiving)
116 { /*lint --e{715}*/
117  SCIP_HEURDATA* heurdata;
119  assert(heur != NULL);
120 
121  /* get heuristic data */
122  heurdata = SCIPheurGetData(heur);
123  assert(heurdata != NULL);
124 
125  /* create working solution */
126  SCIP_CALL( SCIPcreateSol(scip, &heurdata->sol, heur) );
127 
128  return SCIP_OKAY;
129 }
130 
131 
132 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
133 static
134 SCIP_DECL_HEUREXIT(heurExitLinesearchdiving)
135 { /*lint --e{715}*/
136  SCIP_HEURDATA* heurdata;
138  assert(heur != NULL);
139 
140  /* get heuristic data */
141  heurdata = SCIPheurGetData(heur);
142  assert(heurdata != NULL);
143 
144  /* free working solution */
145  SCIP_CALL( SCIPfreeSol(scip, &heurdata->sol) );
146 
147  return SCIP_OKAY;
148 }
149 
150 
151 /** execution method of primal heuristic */
152 static
153 SCIP_DECL_HEUREXEC(heurExecLinesearchdiving)
154 { /*lint --e{715}*/
155  SCIP_HEURDATA* heurdata;
156  SCIP_DIVESET* diveset;
157 
158  heurdata = SCIPheurGetData(heur);
159  assert(SCIPheurGetNDivesets(heur) > 0);
160  assert(SCIPheurGetDivesets(heur) != NULL);
161  diveset = SCIPheurGetDivesets(heur)[0];
162  assert(diveset != NULL);
163 
164  *result = SCIP_DIDNOTRUN;
165 
166  SCIP_CALL( SCIPperformGenericDivingAlgorithm(scip, diveset, heurdata->sol, heur, result, nodeinfeasible) );
167 
168  return SCIP_OKAY;
169 }
170 
171 /* diving setting callbacks */
172 
173 /** returns a score for the given candidate -- the best candidate maximizes the diving score */
174 static
175 SCIP_DECL_DIVESETGETSCORE(divesetGetScoreLinesearchdiving)
176 { /*lint --e{715}*/
177  SCIP_Real rootsolval;
178  SCIP_Real distquot;
179 
180  rootsolval = SCIPvarGetRootSol(cand);
181 
182  /* preferred branching direction is further away from the root LP solution */
183  if( SCIPisLT(scip, candsol, rootsolval) )
184  {
185  /* round down*/
186  *roundup = FALSE;
187 
188  switch( divetype )
189  {
191  distquot = (candsfrac + SCIPsumepsilon(scip)) / (rootsolval - candsol);
192  break;
194  if ( SCIPisFeasPositive(scip, candsol) )
195  distquot = (candsfrac + SCIPsumepsilon(scip)) / (rootsolval - candsol);
196  else
197  distquot = (1.0 - candsfrac + SCIPsumepsilon(scip)) / (candsol - rootsolval);
198  break;
199  default:
200  SCIPerrorMessage("Error: Unsupported diving type\n");
201  SCIPABORT();
202  return SCIP_INVALIDDATA; /*lint !e527*/
203  } /*lint !e788*/
204 
205  /* avoid roundable candidates */
206  if( SCIPvarMayRoundDown(cand) )
207  distquot *= 1000.0;
208  }
209  else if( SCIPisGT(scip, candsol, rootsolval) )
210  {
211  /* round up */
212  switch( divetype )
213  {
215  distquot = (1.0 - candsfrac + SCIPsumepsilon(scip)) / (candsol - rootsolval);
216  break;
218  if ( SCIPisFeasPositive(scip, candsol) )
219  distquot = (1.0 - candsfrac + SCIPsumepsilon(scip)) / (candsol - rootsolval);
220  else
221  distquot = (candsfrac + SCIPsumepsilon(scip)) / (rootsolval - candsol);
222  break;
223  default:
224  SCIPerrorMessage("Error: Unsupported diving type\n");
225  SCIPABORT();
226  return SCIP_INVALIDDATA; /*lint !e527*/
227  } /*lint !e788*/
228 
229  /* avoid roundable candidates */
230  if( SCIPvarMayRoundUp(cand) )
231  distquot *= 1000.0;
232  *roundup = TRUE;
233  }
234  else
235  {
236  /* if the solution values are equal, we arbitrarily select branching downwards;
237  * candidates with equal LP solution values are penalized with an infinite score
238  */
239  *roundup = FALSE;
240  distquot = SCIPinfinity(scip);
241  }
242 
243  *score = -distquot;
244 
245  return SCIP_OKAY;
246 }
247 
248 /*
249  * primal heuristic specific interface methods
250  */
251 
252 /** creates the linesearchdiving primal heuristic and includes it in SCIP */
254  SCIP* scip /**< SCIP data structure */
255  )
256 {
257  SCIP_HEURDATA* heurdata;
258  SCIP_HEUR* heur;
259 
260  /* create Linesearchdiving primal heuristic data */
261  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
262 
263  /* include primal heuristic */
264  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
266  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecLinesearchdiving, heurdata) );
267 
268  assert(heur != NULL);
269 
270  /* set non-NULL pointers to callback methods */
271  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyLinesearchdiving) );
272  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeLinesearchdiving) );
273  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitLinesearchdiving) );
274  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitLinesearchdiving) );
275 
276  /* create a diveset (this will automatically install some additional parameters for the heuristic)*/
280  DEFAULT_BACKTRACK, DEFAULT_ONLYLPBRANCHCANDS, DIVESET_DIVETYPES, divesetGetScoreLinesearchdiving) );
281 
282  return SCIP_OKAY;
283 }
#define DEFAULT_LPRESOLVEDOMCHGQUOT
#define HEUR_FREQOFS
#define DEFAULT_MAXLPITEROFS
#define HEUR_NAME
#define HEUR_FREQ
static SCIP_DECL_DIVESETGETSCORE(divesetGetScoreLinesearchdiving)
static SCIP_DECL_HEURFREE(heurFreeLinesearchdiving)
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip.c:8092
SCIP_DIVESET ** SCIPheurGetDivesets(SCIP_HEUR *heur)
Definition: heur.c:1379
SCIP_Real SCIPvarGetRootSol(SCIP_VAR *var)
Definition: var.c:12654
#define FALSE
Definition: def.h:64
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:45816
#define TRUE
Definition: def.h:63
#define HEUR_DISPCHAR
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define DEFAULT_MINRELDEPTH
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:51
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip.h:21907
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.c:7999
static SCIP_DECL_HEUREXIT(heurExitLinesearchdiving)
static SCIP_DECL_HEURCOPY(heurCopyLinesearchdiving)
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1102
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip.h:21890
static SCIP_DECL_HEURINIT(heurInitLinesearchdiving)
#define HEUR_MAXDEPTH
#define DEFAULT_MAXLPITERQUOT
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1181
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip.c:8060
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:45764
#define DEFAULT_RANDSEED
SCIP_SOL * sol
Definition: struct_heur.h:41
#define NULL
Definition: lpi_spx1.cpp:137
#define DEFAULT_MAXRELDEPTH
#define SCIP_CALL(x)
Definition: def.h:306
#define HEUR_DESC
int SCIPheurGetNDivesets(SCIP_HEUR *heur)
Definition: heur.c:1389
#define HEUR_PRIORITY
#define HEUR_USESSUBSCIP
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 specificsos1score, SCIP_DECL_DIVESETGETSCORE((*divesetgetscore)))
Definition: scip.c:8436
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip.c:37631
#define DEFAULT_BACKTRACK
#define DEFAULT_MAXDIVEAVGQUOTNOSOL
SCIP_RETCODE SCIPperformGenericDivingAlgorithm(SCIP *scip, SCIP_DIVESET *diveset, SCIP_SOL *worksol, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_Bool nodeinfeasible)
Definition: heuristics.c:192
LP diving heuristic that fixes variables with a large difference to their root solution.
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:45790
#define DEFAULT_LPSOLVEFREQ
static SCIP_DECL_HEUREXEC(heurExecLinesearchdiving)
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip.c:8076
SCIP_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
Definition: scip.c:46163
#define DEFAULT_ONLYLPBRANCHCANDS
#define SCIP_Real
Definition: def.h:135
#define DEFAULT_MAXDIVEUBQUOT
#define DEFAULT_MAXDIVEUBQUOTNOSOL
#define SCIP_DIVETYPE_SOS1VARIABLE
Definition: type_heur.h:46
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip.c:8044
SCIP_RETCODE SCIPincludeHeurLinesearchdiving(SCIP *scip)
SCIP_Real SCIPsumepsilon(SCIP *scip)
Definition: scip.c:45260
#define DIVESET_DIVETYPES
#define SCIP_DIVETYPE_INTEGRALITY
Definition: type_heur.h:45
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1092
#define SCIPABORT()
Definition: def.h:278
#define HEUR_TIMING
#define DEFAULT_MAXDIVEAVGQUOT
SCIP_Bool SCIPvarMayRoundUp(SCIP_VAR *var)
Definition: var.c:3280
SCIP_Bool SCIPvarMayRoundDown(SCIP_VAR *var)
Definition: var.c:3272
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip.c:37005