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