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-2018 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 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 "scip/heuristics.h"
24 #include "scip/heur_veclendiving.h"
25 #include "scip/pub_heur.h"
26 #include "scip/pub_lp.h"
27 #include "scip/pub_message.h"
28 #include "scip/pub_var.h"
29 #include "scip/scip_heur.h"
30 #include "scip/scip_mem.h"
31 #include "scip/scip_numerics.h"
32 #include "scip/scip_prob.h"
33 #include "scip/scip_sol.h"
34 #include <string.h>
35 
36 #define HEUR_NAME "veclendiving"
37 #define HEUR_DESC "LP diving heuristic that rounds variables with long column vectors"
38 #define HEUR_DISPCHAR 'v'
39 #define HEUR_PRIORITY -1003100
40 #define HEUR_FREQ 10
41 #define HEUR_FREQOFS 4
42 #define HEUR_MAXDEPTH -1
43 #define HEUR_TIMING SCIP_HEURTIMING_AFTERLPPLUNGE
44 #define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */
45 #define DIVESET_DIVETYPES SCIP_DIVETYPE_INTEGRALITY /**< bit mask that represents all supported dive types */
46 
47 
48 /*
49  * Default parameter settings
50  */
51 
52 #define DEFAULT_MINRELDEPTH 0.0 /**< minimal relative depth to start diving */
53 #define DEFAULT_MAXRELDEPTH 1.0 /**< maximal relative depth to start diving */
54 #define DEFAULT_MAXLPITERQUOT 0.05 /**< maximal fraction of diving LP iterations compared to node LP iterations */
55 #define DEFAULT_MAXLPITEROFS 1000 /**< additional number of allowed LP iterations */
56 #define DEFAULT_MAXDIVEUBQUOT 0.8 /**< maximal quotient (curlowerbound - lowerbound)/(cutoffbound - lowerbound)
57  * where diving is performed (0.0: no limit) */
58 #define DEFAULT_MAXDIVEAVGQUOT 0.0 /**< maximal quotient (curlowerbound - lowerbound)/(avglowerbound - lowerbound)
59  * where diving is performed (0.0: no limit) */
60 #define DEFAULT_MAXDIVEUBQUOTNOSOL 0.1 /**< maximal UBQUOT when no solution was found yet (0.0: no limit) */
61 #define DEFAULT_MAXDIVEAVGQUOTNOSOL 0.0 /**< maximal AVGQUOT when no solution was found yet (0.0: no limit) */
62 #define DEFAULT_BACKTRACK TRUE /**< use one level of backtracking if infeasibility is encountered? */
63 #define DEFAULT_LPRESOLVEDOMCHGQUOT 0.15 /**< percentage of immediate domain changes during probing to trigger LP resolve */
64 #define DEFAULT_LPSOLVEFREQ 0 /**< LP solve frequency for diving heuristics */
65 #define DEFAULT_ONLYLPBRANCHCANDS FALSE /**< should only LP branching candidates be considered instead of the slower but
66  * more general constraint handler diving variable selection? */
67 #define DEFAULT_RANDSEED 113 /**< initial seed for random number generation */
68 
69 /* locally defined heuristic data */
70 struct SCIP_HeurData
71 {
72  SCIP_SOL* sol; /**< working solution */
73 };
74 
75 
76 /*
77  * local methods
78  */
79 
80 /*
81  * Callback methods
82  */
83 
84 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
85 static
86 SCIP_DECL_HEURCOPY(heurCopyVeclendiving)
87 { /*lint --e{715}*/
88  assert(scip != NULL);
89  assert(heur != NULL);
90  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
91 
92  /* call inclusion method of primal heuristic */
94 
95  return SCIP_OKAY;
96 }
97 
98 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
99 static
100 SCIP_DECL_HEURFREE(heurFreeVeclendiving) /*lint --e{715}*/
101 { /*lint --e{715}*/
102  SCIP_HEURDATA* heurdata;
104  assert(heur != NULL);
105  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
106  assert(scip != NULL);
107 
108  /* free heuristic data */
109  heurdata = SCIPheurGetData(heur);
110  assert(heurdata != NULL);
111 
112  SCIPfreeBlockMemory(scip, &heurdata);
113  SCIPheurSetData(heur, NULL);
114 
115  return SCIP_OKAY;
116 }
117 
118 
119 /** initialization method of primal heuristic (called after problem was transformed) */
120 static
121 SCIP_DECL_HEURINIT(heurInitVeclendiving) /*lint --e{715}*/
122 { /*lint --e{715}*/
123  SCIP_HEURDATA* heurdata;
125  assert(heur != NULL);
126  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
127 
128  /* get heuristic data */
129  heurdata = SCIPheurGetData(heur);
130  assert(heurdata != NULL);
131 
132  /* create working solution */
133  SCIP_CALL( SCIPcreateSol(scip, &heurdata->sol, heur) );
134 
135  return SCIP_OKAY;
136 }
137 
138 
139 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
140 static
141 SCIP_DECL_HEUREXIT(heurExitVeclendiving) /*lint --e{715}*/
142 { /*lint --e{715}*/
143  SCIP_HEURDATA* heurdata;
145  assert(heur != NULL);
146  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
147 
148  /* get heuristic data */
149  heurdata = SCIPheurGetData(heur);
150  assert(heurdata != NULL);
151 
152  /* free working solution */
153  SCIP_CALL( SCIPfreeSol(scip, &heurdata->sol) );
154 
155  return SCIP_OKAY;
156 }
157 
158 
159 /** execution method of primal heuristic */
160 static
161 SCIP_DECL_HEUREXEC(heurExecVeclendiving) /*lint --e{715}*/
162 { /*lint --e{715}*/
163  SCIP_HEURDATA* heurdata;
164  SCIP_DIVESET* diveset;
165 
166  heurdata = SCIPheurGetData(heur);
167  assert(SCIPheurGetNDivesets(heur) > 0);
168  assert(SCIPheurGetDivesets(heur) != NULL);
169  diveset = SCIPheurGetDivesets(heur)[0];
170  assert(diveset != NULL);
171 
172  *result = SCIP_DIDNOTRUN;
173 
174  /* terminate if there are no integer variables (note that, e.g., SOS1 variables may be present) */
176  return SCIP_OKAY;
177 
178  SCIP_CALL( SCIPperformGenericDivingAlgorithm(scip, diveset, heurdata->sol, heur, result, nodeinfeasible) );
179 
180  return SCIP_OKAY;
181 }
182 
183 /** calculate score and preferred rounding direction for the candidate variable */
184 static
185 SCIP_DECL_DIVESETGETSCORE(divesetGetScoreVeclendiving)
186 {
187  SCIP_Real obj;
188  SCIP_Real objdelta;
189  SCIP_Real colveclen;
190 
191  obj = SCIPvarGetObj(cand);
192  *roundup = (obj >= 0.0);
193  objdelta = ((*roundup) ? (1.0 - candsfrac) * obj : -candsfrac * obj);
194  assert(objdelta >= 0.0);
195 
196  colveclen = (SCIPvarGetStatus(cand) == SCIP_VARSTATUS_COLUMN ? SCIPcolGetNNonz(SCIPvarGetCol(cand)) : 0.0);
197 
198  /* larger score is better */
199  *score = (colveclen + 1.0) / (objdelta + SCIPsumepsilon(scip));
200 
201  /* prefer decisions on binary variables */
202  if( SCIPvarGetType(cand) != SCIP_VARTYPE_BINARY )
203  *score *= 0.001;
204 
205  return SCIP_OKAY;
206 }
207 
208 /*
209  * heuristic specific interface methods
210  */
211 
212 /** creates the veclendiving heuristic and includes it in SCIP */
214  SCIP* scip /**< SCIP data structure */
215  )
216 {
217  SCIP_HEURDATA* heurdata;
218  SCIP_HEUR* heur;
219 
220  /* create Veclendiving primal heuristic data */
221  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
222 
223  /* include primal heuristic */
224  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
226  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecVeclendiving, heurdata) );
227 
228  assert(heur != NULL);
229 
230  /* set non-NULL pointers to callback methods */
231  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyVeclendiving) );
232  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeVeclendiving) );
233  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitVeclendiving) );
234  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitVeclendiving) );
235 
236  /* veclendiving heuristic parameters */
237  /* create a diveset (this will automatically install some additional parameters for the heuristic) */
241 
242  return SCIP_OKAY;
243 }
244 
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2134
#define HEUR_NAME
#define DEFAULT_MAXDIVEAVGQUOTNOSOL
#define NULL
Definition: def.h:239
#define HEUR_TIMING
static SCIP_DECL_HEUREXEC(heurExecVeclendiving)
#define DEFAULT_MAXDIVEUBQUOTNOSOL
#define DEFAULT_LPSOLVEFREQ
#define HEUR_PRIORITY
#define HEUR_FREQ
public methods for memory management
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:280
#define DEFAULT_MINRELDEPTH
SCIP_DIVESET ** SCIPheurGetDivesets(SCIP_HEUR *heur)
Definition: heur.c:1452
static SCIP_DECL_DIVESETGETSCORE(divesetGetScoreVeclendiving)
static SCIP_DECL_HEURFREE(heurFreeVeclendiving)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
methods commonly used by primal heuristics
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:51
public methods for problem variables
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:114
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:187
#define DEFAULT_MAXRELDEPTH
static SCIP_DECL_HEUREXIT(heurExitVeclendiving)
#define DEFAULT_MAXDIVEAVGQUOT
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1175
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:97
#define DEFAULT_RANDSEED
public methods for numerical tolerances
#define DEFAULT_MAXDIVEUBQUOT
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1254
#define HEUR_DISPCHAR
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:248
static SCIP_DECL_HEURCOPY(heurCopyVeclendiving)
SCIP_SOL * sol
Definition: struct_heur.h:41
#define HEUR_MAXDEPTH
#define HEUR_USESSUBSCIP
#define SCIP_CALL(x)
Definition: def.h:351
int SCIPheurGetNDivesets(SCIP_HEUR *heur)
Definition: heur.c:1462
#define DEFAULT_LPRESOLVEDOMCHGQUOT
public methods for primal heuristic plugins and divesets
#define DEFAULT_BACKTRACK
public methods for LP management
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_heur.c:390
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:1034
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17191
#define HEUR_FREQOFS
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:17057
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2089
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:16713
static SCIP_DECL_HEURINIT(heurInitVeclendiving)
public methods for solutions
public methods for message output
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:264
#define DEFAULT_MAXLPITEROFS
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16848
LP diving heuristic that rounds variables with long column vectors.
#define SCIP_Real
Definition: def.h:150
#define HEUR_DESC
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16894
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:232
SCIP_Real SCIPsumepsilon(SCIP *scip)
public methods for primal heuristics
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1165
#define DEFAULT_MAXLPITERQUOT
public methods for global and local (sub)problems
#define DIVESET_DIVETYPES
SCIP_RETCODE SCIPincludeHeurVeclendiving(SCIP *scip)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:377