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-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_veclendiving.c
17  * @brief LP diving heuristic that rounds variables with long column vectors
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 
26 #include "scip/heur_veclendiving.h"
27 
28 #define HEUR_NAME "veclendiving"
29 #define HEUR_DESC "LP diving heuristic that rounds variables with long column vectors"
30 #define HEUR_DISPCHAR 'v'
31 #define HEUR_PRIORITY -1003100
32 #define HEUR_FREQ 10
33 #define HEUR_FREQOFS 4
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 /**< 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 113 /**< initial seed for random number generation */
60 
61 /* locally defined heuristic data */
62 struct SCIP_HeurData
63 {
64  SCIP_SOL* sol; /**< working solution */
65 };
66 
67 
68 /*
69  * local methods
70  */
71 
72 /*
73  * Callback methods
74  */
75 
76 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
77 static
78 SCIP_DECL_HEURCOPY(heurCopyVeclendiving)
79 { /*lint --e{715}*/
80  assert(scip != NULL);
81  assert(heur != NULL);
82  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
83 
84  /* call inclusion method of primal heuristic */
86 
87  return SCIP_OKAY;
88 }
89 
90 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
91 static
92 SCIP_DECL_HEURFREE(heurFreeVeclendiving) /*lint --e{715}*/
93 { /*lint --e{715}*/
94  SCIP_HEURDATA* heurdata;
95 
96  assert(heur != NULL);
97  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
98  assert(scip != NULL);
99 
100  /* free heuristic data */
101  heurdata = SCIPheurGetData(heur);
102  assert(heurdata != NULL);
103 
104  SCIPfreeBlockMemory(scip, &heurdata);
105  SCIPheurSetData(heur, NULL);
106 
107  return SCIP_OKAY;
108 }
109 
110 
111 /** initialization method of primal heuristic (called after problem was transformed) */
112 static
113 SCIP_DECL_HEURINIT(heurInitVeclendiving) /*lint --e{715}*/
114 { /*lint --e{715}*/
115  SCIP_HEURDATA* heurdata;
117  assert(heur != NULL);
118  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
119 
120  /* get heuristic data */
121  heurdata = SCIPheurGetData(heur);
122  assert(heurdata != NULL);
123 
124  /* create working solution */
125  SCIP_CALL( SCIPcreateSol(scip, &heurdata->sol, heur) );
126 
127  return SCIP_OKAY;
128 }
129 
130 
131 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
132 static
133 SCIP_DECL_HEUREXIT(heurExitVeclendiving) /*lint --e{715}*/
134 { /*lint --e{715}*/
135  SCIP_HEURDATA* heurdata;
137  assert(heur != NULL);
138  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
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(heurExecVeclendiving) /*lint --e{715}*/
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  /* terminate if there are no integer variables (note that, e.g., SOS1 variables may be present) */
168  return SCIP_OKAY;
169 
170  SCIP_CALL( SCIPperformGenericDivingAlgorithm(scip, diveset, heurdata->sol, heur, result, nodeinfeasible) );
171 
172  return SCIP_OKAY;
173 }
174 
175 /** calculate score and preferred rounding direction for the candidate variable */
176 static
177 SCIP_DECL_DIVESETGETSCORE(divesetGetScoreVeclendiving)
178 {
179  SCIP_Real obj;
180  SCIP_Real objdelta;
181  SCIP_Real colveclen;
182 
183  obj = SCIPvarGetObj(cand);
184  *roundup = (obj >= 0.0);
185  objdelta = ((*roundup) ? (1.0 - candsfrac) * obj : -candsfrac * obj);
186  assert(objdelta >= 0.0);
187 
188  colveclen = (SCIPvarGetStatus(cand) == SCIP_VARSTATUS_COLUMN ? SCIPcolGetNNonz(SCIPvarGetCol(cand)) : 0.0);
189 
190  /* larger score is better */
191  *score = (colveclen + 1.0) / (objdelta + SCIPsumepsilon(scip));
192 
193  /* prefer decisions on binary variables */
194  if( SCIPvarGetType(cand) != SCIP_VARTYPE_BINARY )
195  *score *= 0.001;
196 
197  return SCIP_OKAY;
198 
199 }
200 
201 /*
202  * heuristic specific interface methods
203  */
204 
205 /** creates the veclendiving heuristic and includes it in SCIP */
207  SCIP* scip /**< SCIP data structure */
208  )
209 {
210  SCIP_HEURDATA* heurdata;
211  SCIP_HEUR* heur;
212 
213  /* create Veclendiving primal heuristic data */
214  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
215 
216  /* include primal heuristic */
217  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
219  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecVeclendiving, heurdata) );
220 
221  assert(heur != NULL);
222 
223  /* set non-NULL pointers to callback methods */
224  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyVeclendiving) );
225  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeVeclendiving) );
226  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitVeclendiving) );
227  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitVeclendiving) );
228 
229  /* veclendiving heuristic parameters */
230  /* create a diveset (this will automatically install some additional parameters for the heuristic) */
234 
235  return SCIP_OKAY;
236 }
237 
int SCIPgetNIntVars(SCIP *scip)
Definition: scip.c:11770
#define HEUR_NAME
#define DEFAULT_MAXDIVEAVGQUOTNOSOL
#define HEUR_TIMING
static SCIP_DECL_HEUREXEC(heurExecVeclendiving)
#define DEFAULT_MAXDIVEUBQUOTNOSOL
#define DEFAULT_LPSOLVEFREQ
#define HEUR_PRIORITY
#define HEUR_FREQ
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip.c:8127
#define DEFAULT_MINRELDEPTH
SCIP_DIVESET ** SCIPheurGetDivesets(SCIP_HEUR *heur)
Definition: heur.c:1379
static SCIP_DECL_DIVESETGETSCORE(divesetGetScoreVeclendiving)
static SCIP_DECL_HEURFREE(heurFreeVeclendiving)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:51
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip.h:21973
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:8034
#define DEFAULT_MAXRELDEPTH
static SCIP_DECL_HEUREXIT(heurExitVeclendiving)
#define DEFAULT_MAXDIVEAVGQUOT
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1102
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip.h:21956
#define DEFAULT_RANDSEED
#define DEFAULT_MAXDIVEUBQUOT
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1181
#define HEUR_DISPCHAR
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip.c:8095
static SCIP_DECL_HEURCOPY(heurCopyVeclendiving)
SCIP_SOL * sol
Definition: struct_heur.h:41
#define NULL
Definition: lpi_spx1.cpp:137
#define HEUR_MAXDEPTH
#define HEUR_USESSUBSCIP
#define SCIP_CALL(x)
Definition: def.h:316
int SCIPheurGetNDivesets(SCIP_HEUR *heur)
Definition: heur.c:1389
#define DEFAULT_LPRESOLVEDOMCHGQUOT
#define DEFAULT_BACKTRACK
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:8471
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip.c:37806
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17017
#define HEUR_FREQOFS
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:16883
int SCIPgetNBinVars(SCIP *scip)
Definition: scip.c:11725
SCIP_RETCODE SCIPperformGenericDivingAlgorithm(SCIP *scip, SCIP_DIVESET *diveset, SCIP_SOL *worksol, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_Bool nodeinfeasible)
Definition: heuristics.c:192
#define DEFAULT_ONLYLPBRANCHCANDS
int SCIPcolGetNNonz(SCIP_COL *col)
Definition: lp.c:16235
static SCIP_DECL_HEURINIT(heurInitVeclendiving)
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip.c:8111
#define DEFAULT_MAXLPITEROFS
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16674
LP diving heuristic that rounds variables with long column vectors.
#define SCIP_Real
Definition: def.h:145
#define HEUR_DESC
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16720
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip.c:8079
SCIP_Real SCIPsumepsilon(SCIP *scip)
Definition: scip.c:45494
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1092
#define DEFAULT_MAXLPITERQUOT
#define DIVESET_DIVETYPES
SCIP_RETCODE SCIPincludeHeurVeclendiving(SCIP *scip)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip.c:37178