Scippy

GCG

Branch-and-Price & Column Generation for Everyone

heur_masterdiving.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* GCG --- Generic Column Generation */
5/* a Dantzig-Wolfe decomposition based extension */
6/* of the branch-cut-and-price framework */
7/* SCIP --- Solving Constraint Integer Programs */
8/* */
9/* Copyright (C) 2010-2026 Operations Research, RWTH Aachen University */
10/* Zuse Institute Berlin (ZIB) */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
21/* See the License for the specific language governing permissions and */
22/* limitations under the License. */
23/* */
24/* You should have received a copy of the Apache-2.0 license */
25/* along with GCG; see the file LICENSE. If not visit gcg.or.rwth-aachen.de.*/
26/* */
27/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
29/**@file heur_masterdiving.c
30 * @brief primal heuristic interface for LP diving heuristics on the master variables
31 * @author Tobias Achterberg
32 * @author Christian Puchert
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37#include <assert.h>
38#include <string.h>
39
41#include "gcg/pricer_gcg.h"
42#include "gcg/relax_gcg.h"
43
44
45#define HEUR_TIMING SCIP_HEURTIMING_AFTERLPPLUNGE
46#define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */
47
48
49/*
50 * Default parameter settings for all diving heuristics
51 */
52
53#define DEFAULT_MINRELDEPTH 0.0 /**< minimal relative depth to start diving */
54#define DEFAULT_MAXRELDEPTH 1.0 /**< maximal relative depth to start diving */
55#define DEFAULT_MAXLPITERQUOT 0.05 /**< maximal fraction of diving LP iterations compared to node LP iterations */
56#define DEFAULT_MAXLPITEROFS 1000 /**< additional number of allowed LP iterations */
57#define DEFAULT_MAXPRICEROUNDS 0 /**< maximal number of allowed pricing rounds (-1: no limit) */
58#define DEFAULT_USEFARKASONLY FALSE /**< perform pricing only if infeasibility is encountered */
59#define DEFAULT_MAXDIVEUBQUOT 0.8 /**< maximal quotient (curlowerbound - lowerbound)/(cutoffbound - lowerbound)
60 * where diving is performed (0.0: no limit) */
61#define DEFAULT_MAXDIVEAVGQUOT 0.0 /**< maximal quotient (curlowerbound - lowerbound)/(avglowerbound - lowerbound)
62 * where diving is performed (0.0: no limit) */
63#define DEFAULT_MAXDIVEUBQUOTNOSOL 0.1 /**< maximal UBQUOT when no solution was found yet (0.0: no limit) */
64#define DEFAULT_MAXDIVEAVGQUOTNOSOL 0.0 /**< maximal AVGQUOT when no solution was found yet (0.0: no limit) */
65#define DEFAULT_BACKTRACK FALSE /**< single backtracking by choosing another variable in case of infeasibility */
66#define DEFAULT_MAXDISCREPANCY 2 /**< maximal discrepancy allowed in backtracking and limited discrepancy search */
67#define DEFAULT_MAXDISCDEPTH 0 /**< maximal depth until which a limited discrepancy search is performed */
68
69#define MINLPITER 10000 /**< minimal number of LP iterations allowed in each LP solving call */
70
71#ifdef SCIP_STATISTIC
72#define EVENTHDLR_NAME "masterdiving"
73#define EVENTHDLR_DESC "event handler for masterdiving solution statistics"
74#endif
75
76
77/* locally defined heuristic data for all diving heuristics */
78struct SCIP_HeurData
79{
80 GCG* gcg; /**< GCG data structure */
81 GCG_DECL_MASTER_DIVINGFREE ((*divingfree)); /**< destructor of diving heuristic */
82 GCG_DECL_MASTER_DIVINGINIT ((*divinginit)); /**< initialize diving heuristic */
83 GCG_DECL_MASTER_DIVINGEXIT ((*divingexit)); /**< deinitialize diving heuristic */
84 GCG_DECL_MASTER_DIVINGINITSOL ((*divinginitsol)); /**< solving process initialization method of diving heuristic */
85 GCG_DECL_MASTER_DIVINGEXITSOL ((*divingexitsol)); /**< solving process deinitialization method of diving heuristic */
86 GCG_DECL_MASTER_DIVINGINITEXEC ((*divinginitexec)); /**< execution initialization method of diving heuristic */
87 GCG_DECL_MASTER_DIVINGEXITEXEC ((*divingexitexec)); /**< execution deinitialization method of diving heuristic */
88 GCG_DECL_MASTER_DIVINGSELECTVAR ((*divingselectvar)); /**< variable selection method of diving heuristic */
89 GCG_MASTER_DIVINGDATA* divingdata; /**< diving rule specific data */
90
91 SCIP_SOL* sol; /**< working solution */
92 SCIP_Real minreldepth; /**< minimal relative depth to start diving */
93 SCIP_Real maxreldepth; /**< maximal relative depth to start diving */
94 SCIP_Real maxlpiterquot; /**< maximal fraction of diving LP iterations compared to node LP iterations */
95 int maxlpiterofs; /**< additional number of allowed LP iterations */
96 int maxpricerounds; /**< maximal number of allowed pricing rounds (-1: no limit) */
97 SCIP_Bool usefarkasonly; /**< perform pricing only if infeasibility is encountered */
98 SCIP_Real maxdiveubquot; /**< maximal quotient (curlowerbound - lowerbound)/(cutoffbound - lowerbound)
99 * where diving is performed (0.0: no limit) */
100 SCIP_Real maxdiveavgquot; /**< maximal quotient (curlowerbound - lowerbound)/(avglowerbound - lowerbound)
101 * where diving is performed (0.0: no limit) */
102 SCIP_Real maxdiveubquotnosol; /**< maximal UBQUOT when no solution was found yet (0.0: no limit) */
103 SCIP_Real maxdiveavgquotnosol;/**< maximal AVGQUOT when no solution was found yet (0.0: no limit) */
104 SCIP_Bool backtrack; /**< single backtracking by choosing another variable in case of infeasibility */
105 int maxdiscrepancy; /**< maximal discrepancy allowed in backtracking and limited discrepancy search */
106 int maxdiscdepth; /**< maximal depth until which a limited discrepancy search is performed */
107 SCIP_Longint nlpiterations; /**< LP iterations used in this heuristic */
108 SCIP_Longint npricerounds; /**< pricing rounds used in this heuristic */
109 int nsuccess; /**< number of runs that produced at least one feasible solution */
110
111#ifdef SCIP_STATISTIC
112 SCIP_Longint ncalls; /**< number of calls */
113 SCIP_Longint nsols; /**< number of solutions */
114 SCIP_Longint nimpsols; /**< number of improving solutions */
115 SCIP_Longint ndivesols; /**< number of integral diving LP solutions */
116 SCIP_Longint nimpdivesols; /**< number of improving integral diving LP solutions */
117 SCIP_Longint nroundsols; /**< number of integral solutions that have been obtained by rounding */
118 SCIP_Longint nimproundsols; /**< number of improving integral solutions obtained by rounding */
119 SCIP_Longint ndivenodes; /**< number of diving nodes */
120 SCIP_Longint nfarkas; /**< number of times an infeasibility was resolved by Farkas pricing */
121 SCIP_Longint notherdirections; /**< number of times a cutoff was resolved by branching in the other direction */
122 SCIP_Longint nbacktracks; /**< number of times a single backtracking at a deeper node was performed */
123 SCIP_Longint ndiscsearches; /**< number of times a limited discrepancy search was performed */
124 SCIP_Real bestprimalbd; /**< objective value of best solution found by this heuristic */
125 SCIP_Bool bestsolrounded; /**< was the best solution obtained by rounding? */
126#endif
127};
128
129#ifdef SCIP_STATISTIC
130/** event handler data */
132{
133 SCIP_HEUR** heurs; /**< diving heuristics known to the event handler */
134 int nheurs; /**< number of diving heuristics known to the event handler */
135 SCIP_HEUR* runningheur; /**< the diving heuristic that is currently running, or NULL */
136};
137#endif
138
139
140/*
141 * local methods
142 */
143
144
145
146/*
147 * Callback methods
148 */
149
150/** destructor of primal heuristic to free user data (called when SCIP is exiting) */
151static
152SCIP_DECL_HEURFREE(heurFreeMasterdiving) /*lint --e{715}*/
153{ /*lint --e{715}*/
154 SCIP_HEURDATA* heurdata;
155
156 assert(heur != NULL);
157 assert(scip != NULL);
158
159 /* get heuristic data */
160 heurdata = SCIPheurGetData(heur);
161 assert(heurdata != NULL);
162
163 if( heurdata->divingfree != NULL )
164 {
165 SCIP_CALL( heurdata->divingfree(heurdata->gcg, heur) );
166 }
167
168 /* free heuristic data */
169 SCIPfreeMemory(scip, &heurdata);
170 SCIPheurSetData(heur, NULL);
171
172 return SCIP_OKAY;
173}
174
175
176/** initialization method of primal heuristic (called after problem was transformed) */
177static
178SCIP_DECL_HEURINIT(heurInitMasterdiving) /*lint --e{715}*/
179{ /*lint --e{715}*/
180 SCIP_HEURDATA* heurdata;
181
182 assert(heur != NULL);
183
184 /* get heuristic data */
185 heurdata = SCIPheurGetData(heur);
186 assert(heurdata != NULL);
187
188 /* create working solution */
189 SCIP_CALL( SCIPcreateSol(scip, &heurdata->sol, heur) );
190
191 heurdata->nlpiterations = 0;
192 heurdata->npricerounds = 0;
193 heurdata->nsuccess = 0;
194
195 /* diving rule specific initialization */
196 if( heurdata->divinginit != NULL )
197 {
198 SCIP_CALL( heurdata->divinginit(heurdata->gcg, heur) );
199 }
200
201 return SCIP_OKAY;
202}
203
204
205/** deinitialization method of primal heuristic (called before transformed problem is freed) */
206static
207SCIP_DECL_HEUREXIT(heurExitMasterdiving) /*lint --e{715}*/
208{ /*lint --e{715}*/
209 SCIP_HEURDATA* heurdata;
210
211 assert(heur != NULL);
212
213 /* get heuristic data */
214 heurdata = SCIPheurGetData(heur);
215 assert(heurdata != NULL);
216
217 /* diving rule specific deinitialization */
218 if( heurdata->divingexit != NULL )
219 {
220 SCIP_CALL( heurdata->divingexit(heurdata->gcg, heur) );
221 }
222
223 /* free working solution */
224 SCIP_CALL( SCIPfreeSol(scip, &heurdata->sol) );
225
226 return SCIP_OKAY;
227}
228
229
230/** solving process initialization method of primal heuristic (called when branch and bound process is about to begin) */
231static
232SCIP_DECL_HEURINITSOL(heurInitsolMasterdiving)
233{ /*lint --e{715}*/
234 SCIP_HEURDATA* heurdata;
235
236 assert(heur != NULL);
237 assert(scip != NULL);
238
239 /* get heuristic data */
240 heurdata = SCIPheurGetData(heur);
241 assert(heurdata != NULL);
242
243#ifdef SCIP_STATISTIC
244 /* initialize statistics */
245 heurdata->ncalls = 0;
246 heurdata->nsols = 0;
247 heurdata->nimpsols = 0;
248 heurdata->ndivesols = 0;
249 heurdata->nimpdivesols = 0;
250 heurdata->nroundsols = 0;
251 heurdata->nimproundsols = 0;
252 heurdata->ndivenodes = 0;
253 heurdata->nfarkas = 0;
254 heurdata->notherdirections = 0;
255 heurdata->nbacktracks = 0;
256 heurdata->ndiscsearches = 0;
257 heurdata->bestprimalbd = SCIPinfinity(scip);
258 heurdata->bestsolrounded = FALSE;
259#endif
260
261 /* diving rule specific initialization */
262 if( heurdata->divinginitsol != NULL )
263 {
264 SCIP_CALL( heurdata->divinginitsol(heurdata->gcg, heur) );
265 }
266
267 return SCIP_OKAY;
268}
269
270
271/** solving process deinitialization method of primal heuristic (called before branch and bound process data is freed) */
272static
273SCIP_DECL_HEUREXITSOL(heurExitsolMasterdiving)
274{ /*lint --e{715}*/
275 SCIP_HEURDATA* heurdata;
276
277 assert(heur != NULL);
278 assert(scip != NULL);
279
280 /* get heuristic data */
281 heurdata = SCIPheurGetData(heur);
282 assert(heurdata != NULL);
283
284 /* diving rule specific deinitialization */
285 if( heurdata->divingexitsol != NULL )
286 {
287 SCIP_CALL( heurdata->divingexitsol(heurdata->gcg, heur) );
288 }
289
290 return SCIP_OKAY;
291}
292
293
294/** execution method of primal heuristic */
295static
296SCIP_DECL_HEUREXEC(heurExecMasterdiving) /*lint --e{715}*/
297{ /*lint --e{715}*/
298#ifdef SCIP_STATISTIC
299 SCIP_EVENTHDLR* eventhdlr;
300 SCIP_EVENTHDLRDATA* eventhdlrdata;
301#endif
302 SCIP_HEURDATA* heurdata;
303 SCIP_LPSOLSTAT lpsolstat;
304 SCIP_VAR** selectedvars;
305 SCIP_VAR** tabulist;
306 int* discrepancies;
307 SCIP_Real searchubbound;
308 SCIP_Real searchavgbound;
309 SCIP_Real searchbound;
310 SCIP_Real objval;
311 SCIP_Real oldobjval;
312 SCIP_Bool lperror;
313 SCIP_Bool cutoff;
314 SCIP_Longint ncalls;
315 SCIP_Longint nsolsfound;
316 SCIP_Longint nlpiterations; /* lp iterations performed in one single diving loop */
317 SCIP_Longint maxnlpiterations;
318 int totalpricerounds; /* pricing rounds performed in one call of the heuristic */
319 int nlpcands;
320 int startnlpcands;
321 int depth;
322 int maxdepth;
323 int maxdivedepth;
324 int divedepth;
325 int discrepancy;
326
327#ifdef NDEBUG
328 SCIP_RETCODE retstat;
329#endif
330
331#ifdef SCIP_STATISTIC
332 /* variable declarations for additional statistics */
333 int ndivenodes; /* number of diving nodes */
334 int maxreacheddepth; /* maximal diving depth reached in this call */
335 int nfarkas; /* number of times an infeasibility was resolved by Farkas pricing */
336 int nbacktracks; /* number of times a single backtracking at a deeper node was performed */
337 int ndiscsearches; /* number of times a limited discrepancy search was performed */
338 SCIP_Longint totallpiters; /* lp iterations performed in one call of the heuristic */
339 SCIP_CLOCK* lptime; /* time spent for solving diving LPs */
340#endif
341
342 int i;
343
344 assert(heur != NULL);
345 assert(scip != NULL);
346 assert(result != NULL);
347
348 /* get heuristic data */
349 heurdata = SCIPheurGetData(heur);
350 assert(heurdata != NULL);
351
352#ifdef SCIP_STATISTIC
353 /* get the masterdiving event handler and its data */
355 assert(eventhdlr != NULL);
356 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
357 assert(eventhdlrdata != NULL);
358#endif
359
360 *result = SCIP_DELAYED;
361
362 /* only call heuristic, if an optimal LP solution is at hand */
364 return SCIP_OKAY;
365
366 /* only call heuristic, if the LP solution is basic (which allows fast resolve in diving) */
367 if( !SCIPisLPSolBasic(scip) )
368 return SCIP_OKAY;
369
370 /* don't dive two times at the same node */
372 return SCIP_OKAY;
373
374 *result = SCIP_DIDNOTRUN;
375
376 /* check if fundamental diving callbacks are present */
377 assert(heurdata->divingselectvar != NULL);
378
379 /* only try to dive, if we are in the correct part of the tree, given by minreldepth and maxreldepth */
380 depth = SCIPgetDepth(scip);
381 maxdepth = SCIPgetMaxDepth(scip);
382 maxdepth = MAX(maxdepth, 30);
383 if( depth < heurdata->minreldepth*maxdepth || depth > heurdata->maxreldepth*maxdepth )
384 return SCIP_OKAY;
385
386 /* calculate the maximal number of LP iterations until heuristic is aborted */
387 nlpiterations = SCIPgetNNodeLPIterations(scip);
388 ncalls = SCIPheurGetNCalls(heur);
389 nsolsfound = 10*SCIPheurGetNBestSolsFound(heur) + heurdata->nsuccess;
390 maxnlpiterations = (SCIP_Longint)((1.0 + 10.0*(nsolsfound+1.0)/(ncalls+1.0)) * heurdata->maxlpiterquot * nlpiterations);
391 maxnlpiterations += heurdata->maxlpiterofs;
392
393 /* don't try to dive, if we took too many LP iterations during diving */
394 if( heurdata->nlpiterations >= maxnlpiterations )
395 return SCIP_OKAY;
396
397 /* allow at least a certain number of LP iterations in this dive */
398 maxnlpiterations = MAX(maxnlpiterations, heurdata->nlpiterations + MINLPITER);
399
400 /* get number of fractional variables that should be integral */
401 nlpcands = SCIPgetNLPBranchCands(scip);
402
403 /* don't try to dive, if there are no fractional variables */
404 if( nlpcands == 0 )
405 return SCIP_OKAY;
406
407 /* calculate the objective search bound */
408 if( SCIPgetNSolsFound(scip) == 0 )
409 {
410 if( heurdata->maxdiveubquotnosol > 0.0 )
411 searchubbound = SCIPgetLowerbound(scip)
413 else
414 searchubbound = SCIPinfinity(scip);
415 if( heurdata->maxdiveavgquotnosol > 0.0 )
416 searchavgbound = SCIPgetLowerbound(scip)
418 else
419 searchavgbound = SCIPinfinity(scip);
420 }
421 else
422 {
423 if( heurdata->maxdiveubquot > 0.0 )
424 searchubbound = SCIPgetLowerbound(scip)
426 else
427 searchubbound = SCIPinfinity(scip);
428 if( heurdata->maxdiveavgquot > 0.0 )
429 searchavgbound = SCIPgetLowerbound(scip)
431 else
432 searchavgbound = SCIPinfinity(scip);
433 }
434 searchbound = MIN(searchubbound, searchavgbound);
436 searchbound = SCIPceil(scip, searchbound);
437
438 /* calculate the maximal diving depth: 10 * min{number of integer variables, max depth} */
439 maxdivedepth = SCIPgetNBinVars(scip) + SCIPgetNIntVars(scip);
440 maxdivedepth = MIN(maxdivedepth, maxdepth);
441 maxdivedepth *= 10;
442
443 /* allocate memory */
444 SCIP_CALL( SCIPallocBufferArray(scip, &discrepancies, heurdata->maxdiscdepth) );
445 SCIP_CALL( SCIPallocBufferArray(scip, &tabulist, heurdata->maxdiscrepancy) );
446 SCIP_CALL( SCIPallocBufferArray(scip, &selectedvars, heurdata->maxdiscdepth) );
447
449
450 /* initialize arrays */
451 for( i = 0; i < heurdata->maxdiscdepth; ++i )
452 {
453 discrepancies[i] = 0;
454 selectedvars[i] = NULL;
455 }
456 for( i = 0; i < heurdata->maxdiscrepancy; ++i )
457 tabulist[i] = NULL;
458
459 /* diving rule specific initialization */
460 if( heurdata->divinginitexec != NULL )
461 {
462 SCIP_CALL( heurdata->divinginitexec(heurdata->gcg, heur) );
463 }
464
465
466 *result = SCIP_DIDNOTFIND;
467
468#ifdef SCIP_STATISTIC
469 /* notify the event handler of the diving heuristic that is now running */
470 eventhdlrdata->runningheur = heur;
471 ++heurdata->ncalls;
472#endif
473
474 /* start diving */
476
477 /* enables collection of variable statistics during probing */
479
480 /* get LP objective value*/
481 lpsolstat = SCIP_LPSOLSTAT_OPTIMAL;
482 objval = SCIPgetLPObjval(scip);
483
484 SCIPdebugMessage("(node %"SCIP_LONGINT_FORMAT") executing %s heuristic: depth=%d, %d fractionals, dualbound=%g, searchbound=%g\n",
486
487 /* dive as long we are in the given objective, depth and iteration limits and fractional variables exist, but
488 * - if possible, we dive at least with the depth 10
489 * - if the number of fractional variables decreased at least with 1 variable per 2 dive depths, we continue diving
490 */
491 lperror = FALSE;
492 cutoff = FALSE;
493 divedepth = 0;
494 discrepancy = 0;
495 totalpricerounds = 0;
496 startnlpcands = nlpcands;
497
498#ifdef SCIP_STATISTIC
499 ndivenodes = 0;
500 maxreacheddepth = 0;
501 nfarkas = 0;
502 nbacktracks = 0;
503 ndiscsearches = 0;
504 totallpiters = 0;
505#endif
506
507 while( !lperror && !cutoff && lpsolstat == SCIP_LPSOLSTAT_OPTIMAL && nlpcands > 0
508 && (divedepth < 10
509 || nlpcands <= startnlpcands - divedepth/2
510 || (divedepth < maxdivedepth && heurdata->nlpiterations < maxnlpiterations && objval < searchbound))
511 && !SCIPisStopped(scip) )
512 {
513 SCIP_VAR* bestcand;
514 SCIP_Real bestcandsol;
515 SCIP_Real bestfrac;
516 SCIP_Bool bestcandmayround;
517
518 SCIP_Bool backtracked;
519 SCIP_Bool farkaspricing;
520
522 divedepth++;
523
524#ifdef SCIP_STATISTIC
525 maxreacheddepth = MAX(maxreacheddepth, divedepth);
526 ++ndivenodes;
527#endif
528
529 /* get the current LP solution */
530 SCIP_CALL( SCIPlinkLPSol(scip, heurdata->sol) );
531
532 bestcand = NULL;
533 bestcandmayround = TRUE;
534
535 /* choose a variable to dive on */
536 SCIP_CALL( heurdata->divingselectvar(heurdata->gcg, heur, tabulist, heurdata->maxdiscrepancy, &bestcand, &bestcandmayround) );
537
538 /* if no variable could be chosen, abort diving */
539 if( bestcand == NULL )
540 {
541 SCIPdebugMessage("No variable for diving could be selected, diving aborted\n");
542 break;
543 }
544 assert(bestcand != NULL);
545
546 bestcandsol = SCIPgetSolVal(scip, heurdata->sol, bestcand);
547 bestfrac = SCIPfeasFrac(scip, bestcandsol);
548
549 assert(SCIPisFeasGT(scip, bestcandsol, SCIPvarGetLbLocal(bestcand))
550 && SCIPisFeasLT(scip, bestcandsol, SCIPvarGetUbLocal(bestcand)));
551
552 /* memorize selected variables up to the maximal depth for discrepancy search */
553 if( divedepth-1 < heurdata->maxdiscdepth )
554 selectedvars[divedepth-1] = bestcand;
555
556 /* if all candidates are roundable, try to round the solution */
557 if( bestcandmayround )
558 {
559 SCIP_Bool success;
560
561 /* try to round solution from diving LP */
562 SCIP_CALL( SCIProundSol(scip, heurdata->sol, &success) );
563
564 if( success )
565 {
566 SCIPdebugMessage("%s found roundable primal solution: obj=%g\n", SCIPheurGetName(heur), SCIPgetSolOrigObj(scip, heurdata->sol));
567
568 /* try to add solution to SCIP */
569 SCIP_CALL( SCIPtrySol(scip, heurdata->sol, FALSE, FALSE, FALSE, FALSE, FALSE, &success) );
570
571 /* check, if solution was feasible and good enough */
572 if( success )
573 {
574 SCIPdebugMessage(" -> solution was feasible and good enough\n");
575 *result = SCIP_FOUNDSOL;
576 }
577 }
578 }
579
580 /* If the variable is already fixed, numerical troubles may have occurred => abort diving! */
581 if( SCIPvarGetLbLocal(bestcand) >= SCIPvarGetUbLocal(bestcand) - 0.5 )
582 {
583 SCIPdebugMessage("Selected variable <%s> already fixed to [%g,%g] (solval: %.9f), diving aborted \n",
584 SCIPvarGetName(bestcand), SCIPvarGetLbLocal(bestcand), SCIPvarGetUbLocal(bestcand), bestcandsol);
585 cutoff = TRUE;
586 break;
587 }
588
589 /* round variable up */
590 SCIPdebugMessage(" dive %d/%d, LP iter %"SCIP_LONGINT_FORMAT"/%"SCIP_LONGINT_FORMAT", pricerounds %d/%d: var <%s>, round=%u, sol=%g, oldbounds=[%g,%g], newbounds=[%g,%g]\n",
591 divedepth, maxdivedepth, heurdata->nlpiterations, maxnlpiterations, totalpricerounds, heurdata->maxpricerounds,
592 SCIPvarGetName(bestcand), bestcandmayround,
593 bestcandsol, SCIPvarGetLbLocal(bestcand), SCIPvarGetUbLocal(bestcand),
594 SCIPfeasCeil(scip, bestcandsol), SCIPvarGetUbLocal(bestcand));
595 SCIP_CALL( SCIPchgVarLbProbing(scip, bestcand, SCIPfeasCeil(scip, bestcandsol)) );
596
597 backtracked = FALSE;
598 farkaspricing = FALSE;
599 do
600 {
601 /* apply domain propagation */
602 SCIP_CALL( SCIPpropagateProbing(scip, 0, &cutoff, NULL) );
603
604 if( !cutoff || backtracked || farkaspricing )
605 {
606 int npricerounds; /* pricing rounds performed in one single diving loop */
607
608 /* resolve the diving LP */
609 /* Errors in the LP solver should not kill the overall solving process, if the LP is just needed for a heuristic.
610 * Hence in optimized mode, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
611 */
612 nlpiterations = SCIPgetNLPIterations(scip);
613 npricerounds = SCIPgetNPriceRounds(scip);
615#ifdef NDEBUG
616 if( (!heurdata->usefarkasonly || farkaspricing )
617 && (heurdata->maxpricerounds == -1 || totalpricerounds < heurdata->maxpricerounds) )
618 retstat = SCIPsolveProbingLPWithPricing(scip, FALSE, TRUE, heurdata->maxpricerounds == -1 ? -1 : heurdata->maxpricerounds - totalpricerounds, &lperror, &cutoff);
619
620 else
621 retstat = SCIPsolveProbingLP(scip, MAX((int)(maxnlpiterations - heurdata->nlpiterations), MINLPITER), &lperror, &cutoff);
622 if( retstat != SCIP_OKAY )
623 {
624 SCIPwarningMessage(scip, "Error while solving LP in %s heuristic; LP solve terminated with code <%d>\n", SCIPheurGetName(heur), retstat);
625 }
626#else
627 if( (!heurdata->usefarkasonly || farkaspricing )
628 && (heurdata->maxpricerounds == -1 || totalpricerounds < heurdata->maxpricerounds) )
629 SCIP_CALL( SCIPsolveProbingLPWithPricing(scip, FALSE, TRUE, heurdata->maxpricerounds == -1 ? -1 : heurdata->maxpricerounds - totalpricerounds, &lperror, &cutoff) );
630 else
631 SCIP_CALL( SCIPsolveProbingLP(scip, MAX((int)(maxnlpiterations - heurdata->nlpiterations), MINLPITER), &lperror, &cutoff) );
632#endif
634
635 if( lperror )
636 break;
637
638 /* update iteration counts */
639 heurdata->nlpiterations += SCIPgetNLPIterations(scip) - nlpiterations;
640 heurdata->npricerounds += (SCIP_Longint) SCIPgetNPriceRounds(scip) - (SCIP_Longint) npricerounds;
641 totalpricerounds += SCIPgetNPriceRounds(scip) - npricerounds;
642 SCIPstatistic( totallpiters += SCIPgetNLPIterations(scip) - nlpiterations );
643
644 /* get LP solution status */
645 lpsolstat = SCIPgetLPSolstat(scip);
646 }
647
648 /* If infeasibility is encountered, perform Farkas pricing in order to reach feasibility again */
649 if( lpsolstat == SCIP_LPSOLSTAT_INFEASIBLE && heurdata->usefarkasonly
650 && !farkaspricing && (heurdata->maxpricerounds == -1 || totalpricerounds < heurdata->maxpricerounds)
651 && !backtracked )
652 {
653 SCIPdebugMessage(" *** infeasibility detected at level %d - perform Farkas pricing\n", SCIPgetProbingDepth(scip));
654#ifdef SCIP_STATISTIC
655 ++nfarkas;
656#endif
657 farkaspricing = TRUE;
658 }
659 else
660 farkaspricing = FALSE;
661
662 /* perform backtracking if a cutoff or an infeasibility was detected and if Farkas pricing did not help */
663 if( (lpsolstat == SCIP_LPSOLSTAT_INFEASIBLE || cutoff) && !backtracked && !farkaspricing )
664 {
665 /* Single backtracking (go back only one node) */
666 if( heurdata->backtrack && divedepth > heurdata->maxdiscdepth && discrepancy < heurdata->maxdiscrepancy )
667 {
668 SCIPdebugMessage(" *** cutoff or infeasibility detected at level %d - backtracking one node\n", SCIPgetProbingDepth(scip));
669
670 /* go back one depth in the search tree */
672 --divedepth;
673
674 tabulist[discrepancy] = bestcand;
675 ++discrepancy;
676
677#ifdef SCIP_STATISTIC
678 ++nbacktracks;
679#endif
680 backtracked = TRUE;
681 }
682 /* Limited discrepancy search: If single backtracking unsuccessful, backtrack further */
683 else if( heurdata->maxdiscdepth > 0 )
684 {
685 SCIPdebugMessage(" *** cutoff or infeasibility detected at level %d - performing discrepancy search\n", SCIPgetProbingDepth(scip));
686
687 /* go back until the search can differ from the previous search tree */
688 do
689 {
691 --divedepth;
692 }
693 while( divedepth > 0 &&
694 (divedepth >= heurdata->maxdiscdepth || discrepancies[divedepth] >= heurdata->maxdiscrepancy) );
695
696 assert(divedepth < heurdata->maxdiscdepth);
697
698 if( discrepancies[divedepth] < heurdata->maxdiscrepancy )
699 {
700 /* add variable selected previously at this depth to the tabu list */
701 tabulist[discrepancies[divedepth]] = selectedvars[divedepth];
702 ++discrepancies[divedepth];
703 discrepancy = discrepancies[divedepth];
704 for( i = discrepancy; i < heurdata->maxdiscrepancy; ++i )
705 tabulist[i] = NULL;
706 for( i = divedepth + 1; i < heurdata->maxdiscdepth; ++i )
707 discrepancies[i] = discrepancies[divedepth];
708
709#ifdef SCIP_STATISTIC
710 ++ndiscsearches;
711#endif
712 backtracked = TRUE;
713 }
714 else
715 {
716 assert(divedepth == 0);
717 }
718 }
719 }
720 else
721 backtracked = FALSE;
722 }
723 while( backtracked || farkaspricing );
724
725 if( !lperror && !cutoff && lpsolstat == SCIP_LPSOLSTAT_OPTIMAL )
726 {
727 /* get new objective value */
728 oldobjval = objval;
729 objval = SCIPgetLPObjval(scip);
730
731 /* update pseudo cost values */
732 if( SCIPisGT(scip, objval, oldobjval) )
733 {
734 SCIP_CALL( SCIPupdateVarPseudocost(scip, bestcand, 0.0-bestfrac,
735 objval - oldobjval, 1.0) );
736 }
737
738 /* get new number of fractional variables */
739 nlpcands = SCIPgetNLPBranchCands(scip);
740
741 if( GCGrelaxIsOrigSolFeasible(heurdata->gcg) )
742 {
743 SCIPdebugMessage(" -> LP solution is feasible in the original problem\n");
744 }
745 }
746 SCIPdebugMessage(" -> lpsolstat=%d, objval=%g/%g, nfrac=%d\n", lpsolstat, objval, searchbound, nlpcands);
747 }
748
749 /* check if a solution has been found */
750 if( nlpcands == 0 && !lperror && !cutoff && lpsolstat == SCIP_LPSOLSTAT_OPTIMAL )
751 {
752 SCIP_Bool success;
753
754 /* create solution from diving LP */
755 SCIP_CALL( SCIPlinkLPSol(scip, heurdata->sol) );
756 SCIPdebugMessage("%s found primal solution: obj=%g\n", SCIPheurGetName(heur), SCIPgetSolOrigObj(scip, heurdata->sol));
757
758 /* try to add solution to SCIP */
759 SCIP_CALL( SCIPtrySol(scip, heurdata->sol, FALSE, FALSE, FALSE, FALSE, FALSE, &success) );
760
761 /* check, if solution was feasible and good enough */
762 if( success )
763 {
764 SCIPdebugMessage(" -> solution was feasible and good enough\n");
765 *result = SCIP_FOUNDSOL;
766 }
767 }
768
769 /* end diving */
771
772 if( *result == SCIP_FOUNDSOL )
773 heurdata->nsuccess++;
774
775#ifdef SCIP_STATISTIC
776 eventhdlrdata->runningheur = NULL;
777 heurdata->ndivenodes += ndivenodes;
778 heurdata->nfarkas += nfarkas;
779 heurdata->nbacktracks += nbacktracks;
780 heurdata->ndiscsearches += ndiscsearches;
781
782 if( ndivenodes > 0 )
783 {
784 SCIPstatisticPrintf("Masterdiving statistic: %s at node %"SCIP_LONGINT_FORMAT" , %d dive nodes, max depth = %d, lptime = %6.1f sec, %"SCIP_LONGINT_FORMAT" lp iters, %d pricing rds, %d Farkas repairs, %d single backtracks, %d disc searches\n",
785 SCIPheurGetName(heur), SCIPgetNNodes(scip), ndivenodes, maxreacheddepth, SCIPgetClockTime(scip, lptime), totallpiters, totalpricerounds, nfarkas, nbacktracks, ndiscsearches);
786 }
787#endif
788
789 /* free memory */
790 if( heurdata->divingexitexec != NULL )
791 {
792 SCIP_CALL( heurdata->divingexitexec(heurdata->gcg, heur) );
793 }
795 SCIPfreeBufferArray(scip, &selectedvars);
796 SCIPfreeBufferArray(scip, &tabulist);
797 SCIPfreeBufferArray(scip, &discrepancies);
798
799 SCIPdebugMessage("%s heuristic finished\n", SCIPheurGetName(heur));
800
801 return SCIP_OKAY;
802}
803
804
805#ifdef SCIP_STATISTIC
806/** destructor of event handler to free user data (called when SCIP is exiting) */
807static
808SCIP_DECL_EVENTFREE(eventFreeMasterdiving)
809{ /*lint --e{715}*/
810 SCIP_EVENTHDLRDATA* eventhdlrdata;
811
812 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
813 assert(eventhdlrdata != NULL);
814
815 assert((eventhdlrdata->heurs == NULL) == (eventhdlrdata->nheurs == 0));
816 SCIPfreeMemoryArrayNull(scip, &eventhdlrdata->heurs);
817
818 SCIPfreeMemory(scip, &eventhdlrdata);
819
820 SCIPeventhdlrSetData(eventhdlr, NULL);
821
822 return SCIP_OKAY;
823}
824
825/** initialization method of event handler (called after problem was transformed) */
826static
827SCIP_DECL_EVENTINIT(eventInitMasterdiving)
828{ /*lint --e{715}*/
829 assert(eventhdlr != NULL);
830
831 /* notify GCG that this event should catch the SOLFOUND event */
832 SCIP_CALL( SCIPcatchEvent(scip, SCIP_EVENTTYPE_SOLFOUND, eventhdlr, NULL, NULL) );
833
834 return SCIP_OKAY;
835}
836
837/** deinitialization method of event handler (called before transformed problem is freed) */
838static
839SCIP_DECL_EVENTEXIT(eventExitMasterdiving)
840{ /*lint --e{715}*/
841 assert(eventhdlr != NULL);
842
843 /* notify GCG that this event should drop the SOLFOUND event */
844 SCIP_CALL( SCIPdropEvent(scip, SCIP_EVENTTYPE_SOLFOUND, eventhdlr, NULL, -1) );
845
846 return SCIP_OKAY;
847}
848
849/** solving process deinitialization method of event handler (called before branch and bound process data is freed) */
850static
851SCIP_DECL_EVENTEXITSOL(eventExitsolMasterdiving)
852{ /*lint --e{715}*/
853 SCIP_EVENTHDLRDATA* eventhdlrdata;
854 int i;
855
856 assert(eventhdlr != NULL);
857
858 /* get event handler data */
859 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
860 assert(eventhdlrdata != NULL);
861
862 /* print detailed statistics */
863 SCIPstatisticPrintf("Master Diving Heuristics : Calls Sols Improving DiveSols Improving RoundSols Improving Nodes LP iters Price rds max nFarkas Single bt Discsrch BestPrimal Rounded?\n");
864 for( i = 0; i < eventhdlrdata->nheurs; ++i )
865 {
866 SCIP_HEUR* heur;
867 SCIP_HEURDATA* heurdata;
868
869 heur = eventhdlrdata->heurs[i];
870
871 /* get heuristic data */
872 heurdata = SCIPheurGetData(heur);
873 assert(heurdata != NULL);
874
875 SCIPstatisticPrintf("%-17.17s : %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10d %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT" %10"SCIP_LONGINT_FORMAT,
876 SCIPheurGetName(heur), heurdata->ncalls, heurdata->nsols, heurdata->nimpsols, heurdata->ndivesols, heurdata->nimpdivesols, heurdata->nroundsols, heurdata->nimproundsols, heurdata->ndivenodes, heurdata->nlpiterations, heurdata->npricerounds, heurdata->maxpricerounds, heurdata->nfarkas, heurdata->nbacktracks, heurdata->ndiscsearches);
877 if( SCIPisInfinity(scip, heurdata->bestprimalbd) )
878 SCIPstatisticPrintf(" infinity");
879 else
880 SCIPstatisticPrintf(" %13.6e", heurdata->bestprimalbd);
881 SCIPstatisticPrintf(heurdata->bestsolrounded ? " yes\n" : " no\n");
882 }
883 SCIPstatisticPrintf("END\n");
885
886 return SCIP_OKAY;
887}
888
889
890/** execution method of event handler */
891static
892SCIP_DECL_EVENTEXEC(eventExecMasterdiving)
893{ /*lint --e{715}*/
894 SCIP_EVENTHDLRDATA* eventhdlrdata;
895 SCIP_HEUR* heur;
896 SCIP_HEURDATA* heurdata;
897 SCIP_SOL* sol;
898 SCIP_HEUR* solheur;
899 SCIP_Bool rounded;
900 SCIP_Bool improving;
901
902 assert(eventhdlr != NULL);
903
904 /* get event handler data */
905 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
906 assert(eventhdlrdata != NULL);
907
908 /* get the diving heuristic which is currently running;
909 * if no diving heuristic is currently running, abort
910 */
911 heur = eventhdlrdata->runningheur;
912 if( heur == NULL )
913 return SCIP_OKAY;
914 assert(heur != NULL);
915
916 /* get heuristic data */
917 heurdata = SCIPheurGetData(heur);
918 assert(heurdata != NULL);
919
920 /* get new primal solution */
921 sol = SCIPeventGetSol(event);
922 assert(sol != NULL);
923
924 /* get the heuristic that found the solution (might differ from the diving heuristic) */
925 solheur = SCIPgetSolHeur(scip, sol);
926
927 /* update solution statistics */
928 ++heurdata->nsols;
929
930 if( SCIPeventGetType(event) == SCIP_EVENTTYPE_BESTSOLFOUND )
931 {
932 ++heurdata->nimpsols;
933 improving = TRUE;
934 }
935 else
936 improving = FALSE;
937
938 rounded = FALSE;
939 if( solheur != NULL && strcmp(SCIPheurGetName(solheur), "simplerounding") == 0 )
940 {
941 rounded = TRUE;
942 ++heurdata->nroundsols;
943 if( improving )
944 ++heurdata->nimproundsols;
945 }
946 else if( solheur == heur )
947 {
948 ++heurdata->ndivesols;
949 if( improving )
950 ++heurdata->nimpdivesols;
951 }
952
953 if( SCIPgetSolTransObj(scip, sol) < heurdata->bestprimalbd )
954 {
955 heurdata->bestprimalbd = SCIPgetSolTransObj(scip, sol);
956 heurdata->bestsolrounded = rounded;
957 }
958
959 SCIPstatisticPrintf("Masterdiving statistic: %s found solution %13.6e , improving = %u , rounded = %u\n",
960 SCIPheurGetName(heur), SCIPgetSolTransObj(scip, sol), improving, rounded);
961
962 return SCIP_OKAY;
963}
964#endif
965
966
967/*
968 * heuristic specific interface methods
969 */
970
971/** gets diving rule specific data of a diving heuristic */
973 SCIP_HEUR* heur /**< primal heuristic */
974 )
975{
976 SCIP_HEURDATA* heurdata;
977
978 assert(heur != NULL);
979
980 /* get heuristic data */
981 heurdata = SCIPheurGetData(heur);
982 assert(heurdata != NULL);
983
984 return heurdata->divingdata;
985}
986
987/** sets diving rule specific data of a diving heuristic */
989 SCIP_HEUR* heur, /**< primal heuristic */
990 GCG_MASTER_DIVINGDATA* divingdata /**< diving rule specific data */
991 )
992{
993 SCIP_HEURDATA* heurdata;
994
995 assert(heur != NULL);
996
997 /* get heuristic data */
998 heurdata = SCIPheurGetData(heur);
999 assert(heurdata != NULL);
1000
1001 heurdata->divingdata = divingdata;
1002}
1003
1004/** creates a master diving heuristic and includes it in GCG */
1006 GCG* gcg, /**< GCG data structure */
1007 SCIP_HEUR** heur, /**< pointer to diving heuristic */
1008 const char* name, /**< name of primal heuristic */
1009 const char* desc, /**< description of primal heuristic */
1010 char dispchar, /**< display character of primal heuristic */
1011 int priority, /**< priority of the primal heuristic */
1012 int freq, /**< frequency for calling primal heuristic */
1013 int freqofs, /**< frequency offset for calling primal heuristic */
1014 int maxdepth, /**< maximal depth level to call heuristic at (-1: no limit) */
1015 GCG_DECL_MASTER_DIVINGFREE ((*divingfree)), /**< destructor of diving heuristic */
1016 GCG_DECL_MASTER_DIVINGINIT ((*divinginit)), /**< initialize diving heuristic */
1017 GCG_DECL_MASTER_DIVINGEXIT ((*divingexit)), /**< deinitialize diving heuristic */
1018 GCG_DECL_MASTER_DIVINGINITSOL ((*divinginitsol)), /**< solving process initialization method of diving heuristic */
1019 GCG_DECL_MASTER_DIVINGEXITSOL ((*divingexitsol)), /**< solving process deinitialization method of diving heuristic */
1020 GCG_DECL_MASTER_DIVINGINITEXEC ((*divinginitexec)), /**< execution initialization method of diving heuristic */
1021 GCG_DECL_MASTER_DIVINGEXITEXEC ((*divingexitexec)), /**< execution deinitialization method of diving heuristic */
1022 GCG_DECL_MASTER_DIVINGSELECTVAR ((*divingselectvar)), /**< variable selection method of diving heuristic */
1023 GCG_MASTER_DIVINGDATA* divingdata /**< diving rule specific data (or NULL) */
1024 )
1025{
1026#ifdef SCIP_STATISTIC
1027 SCIP_EVENTHDLRDATA* eventhdlrdata;
1028 SCIP_EVENTHDLR* eventhdlr;
1029#endif
1030 SCIP_HEURDATA* heurdata;
1031 char paramname[SCIP_MAXSTRLEN];
1032 SCIP* masterprob = GCGgetMasterprob(gcg);
1033
1034#ifdef SCIP_STATISTIC
1035 /* get masterdiving event handler and its data */
1036 eventhdlr = SCIPfindEventhdlr(masterprob, EVENTHDLR_NAME);
1037 assert(eventhdlr != NULL);
1038 eventhdlrdata = SCIPeventhdlrGetData(eventhdlr);
1039 assert(eventhdlrdata != NULL);
1040#endif
1041
1042 /* create Masterdiving primal heuristic data */
1043 SCIP_CALL( SCIPallocMemory(masterprob, &heurdata) );
1044 heurdata->gcg = gcg;
1045
1046 /* set diving rule callbacks and data */
1047 heurdata->divingfree = divingfree;
1048 heurdata->divinginit = divinginit;
1049 heurdata->divingexit = divingexit;
1050 heurdata->divinginitsol = divinginitsol;
1051 heurdata->divingexitsol = divingexitsol;
1052 heurdata->divinginitexec = divinginitexec;
1053 heurdata->divingexitexec = divingexitexec;
1054 heurdata->divingselectvar = divingselectvar;
1055 heurdata->divingdata = divingdata;
1056
1057 /* include primal heuristic */
1058 SCIP_CALL( SCIPincludeHeurBasic(masterprob, heur,
1059 name, desc, dispchar, priority, freq, freqofs,
1060 maxdepth, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecMasterdiving, heurdata) );
1061
1062 assert(*heur != NULL);
1063
1064 /* set non-NULL pointers to callback methods */
1065 SCIP_CALL( SCIPsetHeurFree(masterprob, *heur, heurFreeMasterdiving) );
1066 SCIP_CALL( SCIPsetHeurInit(masterprob, *heur, heurInitMasterdiving) );
1067 SCIP_CALL( SCIPsetHeurExit(masterprob, *heur, heurExitMasterdiving) );
1068 SCIP_CALL( SCIPsetHeurInitsol(masterprob, *heur, heurInitsolMasterdiving) );
1069 SCIP_CALL( SCIPsetHeurExitsol(masterprob, *heur, heurExitsolMasterdiving) );
1070
1071 /* masterdiving heuristic parameters */
1072 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/minreldepth", name);
1073 SCIP_CALL( SCIPaddRealParam(masterprob,
1074 paramname,
1075 "minimal relative depth to start diving",
1076 &heurdata->minreldepth, TRUE, DEFAULT_MINRELDEPTH, 0.0, 1.0, NULL, NULL) );
1077 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxreldepth", name);
1078 SCIP_CALL( SCIPaddRealParam(masterprob,
1079 paramname,
1080 "maximal relative depth to start diving",
1081 &heurdata->maxreldepth, TRUE, DEFAULT_MAXRELDEPTH, 0.0, 1.0, NULL, NULL) );
1082 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxlpiterquot", name);
1083 SCIP_CALL( SCIPaddRealParam(masterprob,
1084 paramname,
1085 "maximal fraction of diving LP iterations compared to node LP iterations",
1087 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxlpiterofs", name);
1088 SCIP_CALL( SCIPaddIntParam(masterprob,
1089 paramname,
1090 "additional number of allowed LP iterations",
1091 &heurdata->maxlpiterofs, FALSE, DEFAULT_MAXLPITEROFS, 0, INT_MAX, NULL, NULL) );
1092 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxpricerounds", name);
1093 SCIP_CALL( SCIPaddIntParam(masterprob,
1094 paramname,
1095 "maximal number of allowed pricing rounds (-1: no limit)",
1096 &heurdata->maxpricerounds, FALSE, DEFAULT_MAXPRICEROUNDS, -1, INT_MAX, NULL, NULL) );
1097 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/usefarkasonly", name);
1098 SCIP_CALL( SCIPaddBoolParam(masterprob,
1099 paramname,
1100 "perform pricing only if infeasibility is encountered",
1102 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxdiveubquot", name);
1103 SCIP_CALL( SCIPaddRealParam(masterprob,
1104 paramname,
1105 "maximal quotient (curlowerbound - lowerbound)/(cutoffbound - lowerbound) where diving is performed (0.0: no limit)",
1106 &heurdata->maxdiveubquot, TRUE, DEFAULT_MAXDIVEUBQUOT, 0.0, 1.0, NULL, NULL) );
1107 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxdiveavgquot", name);
1108 SCIP_CALL( SCIPaddRealParam(masterprob,
1109 paramname,
1110 "maximal quotient (curlowerbound - lowerbound)/(avglowerbound - lowerbound) where diving is performed (0.0: no limit)",
1112 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxdiveubquotnosol", name);
1113 SCIP_CALL( SCIPaddRealParam(masterprob,
1114 paramname,
1115 "maximal UBQUOT when no solution was found yet (0.0: no limit)",
1116 &heurdata->maxdiveubquotnosol, TRUE, DEFAULT_MAXDIVEUBQUOTNOSOL, 0.0, 1.0, NULL, NULL) );
1117 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxdiveavgquotnosol", name);
1118 SCIP_CALL( SCIPaddRealParam(masterprob,
1119 paramname,
1120 "maximal AVGQUOT when no solution was found yet (0.0: no limit)",
1122 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/backtrack", name);
1123 SCIP_CALL( SCIPaddBoolParam(masterprob,
1124 paramname,
1125 "single backtracking by choosing another variable in case of infeasibility",
1126 &heurdata->backtrack, TRUE, DEFAULT_BACKTRACK, NULL, NULL) );
1127 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxdiscrepancy", name);
1128 SCIP_CALL( SCIPaddIntParam(masterprob,
1129 paramname,
1130 "maximal discrepancy allowed in backtracking and limited discrepancy search",
1131 &heurdata->maxdiscrepancy, TRUE, DEFAULT_MAXDISCREPANCY, 0, INT_MAX, NULL, NULL) );
1132 (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "heuristics/%s/maxdiscdepth", name);
1133 SCIP_CALL( SCIPaddIntParam(masterprob,
1134 paramname,
1135 "maximal depth until which a limited discrepancy search is performed",
1136 &heurdata->maxdiscdepth, TRUE, DEFAULT_MAXDISCDEPTH, 0, INT_MAX, NULL, NULL) );
1137
1138#ifdef SCIP_STATISTIC
1139 /* register the diving heuristic to the masterdiving event handler */
1140 assert((eventhdlrdata->heurs == NULL) == (eventhdlrdata->nheurs == 0));
1141 if( eventhdlrdata->nheurs == 0 )
1142 {
1143 SCIP_CALL( SCIPallocMemoryArray(scip, &eventhdlrdata->heurs, 1) ); /*lint !e506*/
1144 }
1145 else
1146 {
1147 SCIP_CALL( SCIPreallocMemoryArray(scip, &eventhdlrdata->heurs, eventhdlrdata->nheurs+1) );
1148 }
1149 eventhdlrdata->heurs[eventhdlrdata->nheurs] = *heur;
1150 ++eventhdlrdata->nheurs;
1151#endif
1152
1153 return SCIP_OKAY;
1154}
1155
1156/** creates event handler for masterdiving event */
1158 GCG* gcg /**< GCG data structure */
1159 )
1160{
1161#ifdef SCIP_STATISTIC
1162 SCIP_EVENTHDLRDATA* eventhdlrdata;
1163 SCIP_EVENTHDLR* eventhdlr;
1165
1166 /* create master event handler data */
1167 SCIP_CALL( SCIPallocMemory(scip, &eventhdlrdata) );
1168 assert(eventhdlrdata != NULL);
1169
1170 eventhdlr = NULL;
1171
1172 /* include event handler into GCG */
1174 eventExecMasterdiving, eventhdlrdata) );
1175 assert(eventhdlr != NULL);
1176
1177 /* set non fundamental callbacks via setter functions */
1178 SCIP_CALL( SCIPsetEventhdlrFree(scip, eventhdlr, eventFreeMasterdiving) );
1179 SCIP_CALL( SCIPsetEventhdlrInit(scip, eventhdlr, eventInitMasterdiving) );
1180 SCIP_CALL( SCIPsetEventhdlrExit(scip, eventhdlr, eventExitMasterdiving) );
1181 SCIP_CALL( SCIPsetEventhdlrExitsol(scip, eventhdlr, eventExitsolMasterdiving) );
1182
1183 /* initialize masterdiving event handler data */
1184 eventhdlrdata->heurs = NULL;
1185 eventhdlrdata->nheurs = 0;
1186 eventhdlrdata->runningheur = NULL;
1187#endif
1188
1189 return SCIP_OKAY;
1190}
SCIP_DECL_EVENTEXEC(EventhdlrNewSol::scip_exec)
SCIP_DECL_EVENTINIT(EventhdlrNewSol::scip_init)
SCIP_DECL_EVENTEXIT(EventhdlrNewSol::scip_exit)
SCIP_DECL_EVENTEXITSOL(EventhdlrNewSol::scip_exitsol)
SCIP_DECL_EVENTFREE(EventhdlrNewSol::scip_free)
#define EVENTHDLR_DESC
#define EVENTHDLR_NAME
#define SCIP_MAXSTRLEN
#define SCIP_Longint
#define SCIP_REAL_MAX
#define SCIP_Bool
#define MIN(x, y)
#define SCIP_Real
#define MAX(x, y)
#define SCIP_LONGINT_FORMAT
#define SCIP_CALL(x)
#define TRUE
#define FALSE
SCIP * GCGgetMasterprob(GCG *gcg)
Definition: gcg.cpp:99
SCIP_Bool SCIPisStopped(SCIP *scip)
int SCIPgetNIntVars(SCIP *scip)
int SCIPgetNBinVars(SCIP *scip)
SCIP_Bool SCIPisObjIntegral(SCIP *scip)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
int SCIPgetNLPBranchCands(SCIP *scip)
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
SCIP_EVENTHDLR * SCIPfindEventhdlr(SCIP *scip, const char *name)
SCIP_EVENTHDLRDATA * SCIPeventhdlrGetData(SCIP_EVENTHDLR *eventhdlr)
SCIP_RETCODE SCIPsetEventhdlrExitsol(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTEXITSOL((*eventexitsol)))
void SCIPeventhdlrSetData(SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTHDLRDATA *eventhdlrdata)
SCIP_RETCODE SCIPsetEventhdlrFree(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTFREE((*eventfree)))
SCIP_RETCODE SCIPsetEventhdlrExit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTEXIT((*eventexit)))
SCIP_RETCODE SCIPsetEventhdlrInit(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_DECL_EVENTINIT((*eventinit)))
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
SCIP_SOL * SCIPeventGetSol(SCIP_EVENT *event)
SCIP_RETCODE SCIPcatchEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
SCIP_RETCODE SCIPdropEvent(SCIP *scip, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
SCIP_RETCODE SCIPsetHeurExitsol(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXITSOL((*heurexitsol)))
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
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)
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
SCIP_RETCODE SCIPsetHeurInitsol(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINITSOL((*heurinitsol)))
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
const char * SCIPheurGetName(SCIP_HEUR *heur)
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
SCIP_Longint SCIPgetLastDivenode(SCIP *scip)
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
SCIP_Real SCIPgetLPObjval(SCIP *scip)
SCIP_Bool SCIPisLPSolBasic(SCIP *scip)
#define SCIPfreeMemoryArrayNull(scip, ptr)
#define SCIPreallocMemoryArray(scip, ptr, newnum)
#define SCIPallocMemoryArray(scip, ptr, num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeBufferArray(scip, ptr)
#define SCIPfreeMemory(scip, ptr)
int SCIPgetProbingDepth(SCIP *scip)
SCIP_RETCODE SCIPchgVarLbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIP_RETCODE SCIPpropagateProbing(SCIP *scip, int maxproprounds, SCIP_Bool *cutoff, SCIP_Longint *ndomredsfound)
SCIP_RETCODE SCIPbacktrackProbing(SCIP *scip, int probingdepth)
SCIP_RETCODE SCIPstartProbing(SCIP *scip)
SCIP_RETCODE SCIPnewProbingNode(SCIP *scip)
SCIP_RETCODE SCIPsolveProbingLP(SCIP *scip, int itlim, SCIP_Bool *lperror, SCIP_Bool *cutoff)
SCIP_RETCODE SCIPendProbing(SCIP *scip)
SCIP_RETCODE SCIPsolveProbingLPWithPricing(SCIP *scip, SCIP_Bool pretendroot, SCIP_Bool displayinfo, int maxpricerounds, SCIP_Bool *lperror, SCIP_Bool *cutoff)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
SCIP_HEUR * SCIPgetSolHeur(SCIP *scip, SCIP_SOL *sol)
SCIP_RETCODE SCIProundSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *success)
SCIP_RETCODE SCIPtrySol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
SCIP_RETCODE SCIPlinkLPSol(SCIP *scip, SCIP_SOL *sol)
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
SCIP_Real SCIPretransformObj(SCIP *scip, SCIP_Real obj)
SCIP_Longint SCIPgetNSolsFound(SCIP *scip)
int SCIPgetMaxDepth(SCIP *scip)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_Real SCIPgetDualbound(SCIP *scip)
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_Real SCIPgetAvgLowerbound(SCIP *scip)
SCIP_Longint SCIPgetNNodeLPIterations(SCIP *scip)
int SCIPgetNPriceRounds(SCIP *scip)
SCIP_Real SCIPgetCutoffbound(SCIP *scip)
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
SCIP_RETCODE SCIPcreateClock(SCIP *scip, SCIP_CLOCK **clck)
SCIP_RETCODE SCIPstopClock(SCIP *scip, SCIP_CLOCK *clck)
SCIP_RETCODE SCIPfreeClock(SCIP *scip, SCIP_CLOCK **clck)
SCIP_Real SCIPgetClockTime(SCIP *scip, SCIP_CLOCK *clck)
SCIP_RETCODE SCIPstartClock(SCIP *scip, SCIP_CLOCK *clck)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPceil(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
int SCIPgetDepth(SCIP *scip)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
SCIP_RETCODE SCIPupdateVarPseudocost(SCIP *scip, SCIP_VAR *var, SCIP_Real solvaldelta, SCIP_Real objdelta, SCIP_Real weight)
void SCIPenableVarHistory(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
static SCIP_DECL_HEUREXEC(heurExecMasterdiving)
#define DEFAULT_MAXDIVEUBQUOT
SCIP_RETCODE GCGincludeEventHdlrMasterdiving(GCG *gcg)
#define DEFAULT_MAXPRICEROUNDS
#define HEUR_TIMING
#define DEFAULT_MAXDISCREPANCY
#define DEFAULT_MAXLPITERQUOT
static SCIP_DECL_HEURFREE(heurFreeMasterdiving)
#define MINLPITER
#define DEFAULT_MAXDIVEAVGQUOT
static SCIP_DECL_HEURINIT(heurInitMasterdiving)
void GCGheurSetDivingDataMaster(SCIP_HEUR *heur, GCG_MASTER_DIVINGDATA *divingdata)
#define DEFAULT_BACKTRACK
#define DEFAULT_USEFARKASONLY
#define DEFAULT_MAXDIVEUBQUOTNOSOL
#define DEFAULT_MAXRELDEPTH
#define DEFAULT_MAXLPITEROFS
static SCIP_DECL_HEURINITSOL(heurInitsolMasterdiving)
#define DEFAULT_MAXDIVEAVGQUOTNOSOL
GCG_MASTER_DIVINGDATA * GCGheurGetDivingDataMaster(SCIP_HEUR *heur)
static SCIP_DECL_HEUREXITSOL(heurExitsolMasterdiving)
static SCIP_DECL_HEUREXIT(heurExitMasterdiving)
SCIP_RETCODE GCGincludeDivingHeurMaster(GCG *gcg, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, GCG_DECL_MASTER_DIVINGFREE((*divingfree)), GCG_DECL_MASTER_DIVINGINIT((*divinginit)), GCG_DECL_MASTER_DIVINGEXIT((*divingexit)), GCG_DECL_MASTER_DIVINGINITSOL((*divinginitsol)), GCG_DECL_MASTER_DIVINGEXITSOL((*divingexitsol)), GCG_DECL_MASTER_DIVINGINITEXEC((*divinginitexec)), GCG_DECL_MASTER_DIVINGEXITEXEC((*divingexitexec)), GCG_DECL_MASTER_DIVINGSELECTVAR((*divingselectvar)), GCG_MASTER_DIVINGDATA *divingdata)
#define DEFAULT_MINRELDEPTH
#define DEFAULT_MAXDISCDEPTH
#define HEUR_USESSUBSCIP
primal heuristic interface for LP diving heuristics on the master variables
#define NULL
GCG variable pricer.
#define SCIPstatisticPrintf
#define SCIPdebugMessage
#define SCIPstatistic(x)
SCIP_Bool GCGrelaxIsOrigSolFeasible(GCG *gcg)
Definition: relax_gcg.c:4328
GCG relaxator.
Definition: struct_gcg.h:55
GCG_DECL_MASTER_DIVINGINITEXEC((*divinginitexec))
SCIP_Real maxdiveubquot
GCG_DECL_MASTER_DIVINGEXIT((*divingexit))
SCIP_Real maxlpiterquot
SCIP_Real maxdiveavgquotnosol
SCIP_Longint nlpiterations
GCG_DECL_MASTER_DIVINGEXITSOL((*divingexitsol))
SCIP_Real maxreldepth
SCIP_Bool usefarkasonly
SCIP_Longint npricerounds
GCG_DECL_MASTER_DIVINGINIT((*divinginit))
SCIP_Real maxdiveubquotnosol
GCG_DECL_MASTER_DIVINGINITSOL((*divinginitsol))
GCG_DECL_MASTER_DIVINGSELECTVAR((*divingselectvar))
GCG_DECL_MASTER_DIVINGFREE((*divingfree))
GCG_MASTER_DIVINGDATA * divingdata
GCG_DECL_MASTER_DIVINGEXITEXEC((*divingexitexec))
SCIP_Real maxdiveavgquot
SCIP_Real minreldepth
SCIP_SOL * sol
enum SCIP_LPSolStat SCIP_LPSOLSTAT
SCIP_LPSOLSTAT_OPTIMAL
SCIP_LPSOLSTAT_INFEASIBLE
#define GCG_DECL_MASTER_DIVINGINITEXEC(x)
struct GCG_Master_DivingData GCG_MASTER_DIVINGDATA
#define GCG_DECL_MASTER_DIVINGINITSOL(x)
#define GCG_DECL_MASTER_DIVINGSELECTVAR(x)
#define GCG_DECL_MASTER_DIVINGINIT(x)
#define GCG_DECL_MASTER_DIVINGFREE(x)
#define GCG_DECL_MASTER_DIVINGEXIT(x)
#define GCG_DECL_MASTER_DIVINGEXITEXEC(x)
#define GCG_DECL_MASTER_DIVINGEXITSOL(x)
SCIP_DIDNOTRUN
SCIP_DELAYED
SCIP_DIDNOTFIND
SCIP_FOUNDSOL
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE