Scippy

GCG

Branch-and-Price & Column Generation for Everyone

heur_restmaster.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_restmaster.c
30 * @brief Restricted Master Heuristic
31 * @author Christian Puchert
32 * @author Jonas Witt
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37#include <assert.h>
38
39#include "gcg/heur_restmaster.h"
40#include "gcg/gcg.h"
41#include "gcg/pricer_gcg.h"
42
43#include "scip/scipdefplugins.h"
44
45
46#define HEUR_NAME "restmaster"
47#define HEUR_DESC "LNS heuristic for the master problem that fixes some master variables to zero"
48#define HEUR_DISPCHAR 'P'
49#define HEUR_PRIORITY 100
50#define HEUR_FREQ 30
51#define HEUR_FREQOFS 0
52#define HEUR_MAXDEPTH -1
53#define HEUR_TIMING SCIP_HEURTIMING_DURINGLPLOOP | SCIP_HEURTIMING_DURINGPRICINGLOOP
54#define HEUR_USESSUBSCIP TRUE
55
56#define DEFAULT_MAXNODES 5000LL /**< maximum number of nodes to regard in the subproblem */
57#define DEFAULT_MINFIXINGRATE 0.5 /**< minimum percentage of integer variables that have to be fixed */
58#define DEFAULT_MINIMPROVE 0.01 /**< factor by which restricted master should at least improve the incumbent */
59#define DEFAULT_MINNODES 500LL /**< minimum number of nodes to regard in the subproblem */
60#define DEFAULT_NODESOFS 500LL /**< number of nodes added to the contingent of the total nodes */
61#define DEFAULT_NODESQUOT 0.1 /**< subproblem nodes in relation to nodes of the original problem */
62#define DEFAULT_USELPROWS FALSE /**< should subproblem be created out of the rows in the LP rows,
63 * otherwise, the copy constructor of the constraints handlers are used*/
64#define DEFAULT_COPYCUTS TRUE /**< if DEFAULT_USELPROWS is FALSE, then should all active cuts from the cutpool
65 * of the original scip be copied to constraints of the subscip */
66
67#define DEFAULT_PBHEUR FALSE /**< default value for using the restricted master heuristic as
68 * price-and-branch heuristic?
69 * (this changes the HEUR_TIMING to SCIP_HEURTIMING_AFTERNODE,
70 * and it changes the HEUR_FREQ to 0. */
71
72/*
73 * Data structures
74 */
75
76/** primal heuristic data */
77struct SCIP_HeurData
78{
79 GCG* gcg; /**< GCG data structure */
80 SCIP_Longint maxnodes; /**< maximum number of nodes to regard in the subproblem */
81 SCIP_Longint minnodes; /**< minimum number of nodes to regard in the subproblem */
82 SCIP_Longint nodesofs; /**< number of nodes added to the contingent of the total nodes */
83 SCIP_Longint usednodes; /**< nodes already used by restricted master in earlier calls */
84 SCIP_Real minfixingrate; /**< minimum percentage of integer variables that have to be fixed */
85 SCIP_Real minimprove; /**< factor by which restricted master should at least improve the incumbent */
86 SCIP_Real nodesquot; /**< subproblem nodes in relation to nodes of the original problem */
87 SCIP_Bool uselprows; /**< should subproblem be created out of the rows in the LP rows? */
88 SCIP_Bool copycuts; /**< if uselprows == FALSE, should all active cuts from cutpool be copied
89 * to constraints in subproblem?
90 */
91 SCIP_Bool pbheur; /**< value for using the restricted master heuristic as
92 * price-and-branch heuristic?
93 * (this changes the HEUR_TIMING to SCIP_HEURTIMING_AFTERNODE,
94 * and it changes the HEUR_FREQ to 0. */
95};
96
97
98
99
100/*
101 * Local methods
102 */
103
104/** set up the restricted master problem by fixing master variables to zero */
105static
107 SCIP* scip, /**< SCIP data structure for master problem */
108 SCIP* restmaster, /**< SCIP data structure for restricted master problem */
109 SCIP_VAR** restmastervars, /**< the variables of the restricted */
110 SCIP_Real minfixingrate, /**< percentage of integer variables that have to be fixed */
111 SCIP_Bool uselprows, /**< should subproblem be created out of the rows in the LP rows? */
112 SCIP_Bool pbheur, /**< use heuristic as price-and-branch heuristic? */
113 SCIP_Bool* success /**< pointer to store whether the problem was created successfully */
114 )
115{
116 SCIP_VAR** mastervars;
117 int nmastervars;
118 SCIP_Real fixingrate;
119
120 int i;
121 int fixingcounter;
122
123 /* get variable data of the master problem */
124 SCIP_CALL( SCIPgetVarsData(scip, &mastervars, &nmastervars, NULL, NULL, NULL, NULL) );
125 assert(mastervars != NULL);
126 assert(nmastervars >= 0);
127
128 fixingcounter = 0;
129
130 /* fix zero variables in the restricted master problem */
131 for( i = 0; i < nmastervars && !pbheur; i++ )
132 {
133 SCIP_Real mastersolval;
134
135 mastersolval = SCIPgetSolVal(scip, NULL, mastervars[i]);
136
137 /* if LP solution value of master variable is zero, fix it to zero in restricted master */
138 if( SCIPisFeasZero(scip, mastersolval) )
139 {
140 SCIP_CALL( SCIPchgVarLbGlobal(restmaster, restmastervars[i], 0.0) );
141 SCIP_CALL( SCIPchgVarUbGlobal(restmaster, restmastervars[i], 0.0) );
142 fixingcounter++;
143 }
144 }
145
146 /* abort, if all variables were fixed (which should not happen) */
147 if( fixingcounter == nmastervars )
148 {
149 SCIPdebugMessage(" -> all master variables fixed, not solving problem.\n");
150 *success = FALSE;
151 return SCIP_OKAY;
152 }
153 else
154 fixingrate = fixingcounter / (SCIP_Real)(MAX(nmastervars, 1));
155
156 SCIPdebugMessage(" -> %d out of %d (%.2f percent) master variables fixed.\n", fixingcounter, nmastervars, fixingrate * 100.0);
157
158 /* abort, if the amount of fixed variables is insufficient */
159 if( fixingrate < minfixingrate && !pbheur)
160 {
161 SCIPdebugMessage(" -> not enough variables fixed.\n");
162 *success = FALSE;
163 return SCIP_OKAY;
164 }
165
166 if( uselprows )
167 {
168 SCIP_ROW** rows; /* original scip rows */
169 int nrows;
170
171 /* get the rows and their number */
172 SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
173
174 /* copy all rows to linear constraints */
175 for( i = 0; i < nrows; i++ )
176 {
177 SCIP_CONS* cons;
178 SCIP_VAR** consvars;
179 SCIP_COL** cols;
180 SCIP_Real constant;
181 SCIP_Real lhs;
182 SCIP_Real rhs;
183 SCIP_Real* vals;
184 int nnonz;
185 int j;
186
187 /* ignore rows that are only locally valid */
188 if( SCIProwIsLocal(rows[i]) )
189 continue;
190
191 /* get the row's data */
192 constant = SCIProwGetConstant(rows[i]);
193 lhs = SCIProwGetLhs(rows[i]) - constant;
194 rhs = SCIProwGetRhs(rows[i]) - constant;
195 vals = SCIProwGetVals(rows[i]);
196 nnonz = SCIProwGetNNonz(rows[i]);
197 cols = SCIProwGetCols(rows[i]);
198
199 assert(lhs <= rhs);
200
201 /* allocate memory array to be filled with the corresponding subproblem variables */
202 SCIP_CALL( SCIPallocBufferArray(restmaster, &consvars, nnonz) );
203 for( j = 0; j < nnonz; j++ )
204 consvars[j] = restmastervars[SCIPvarGetProbindex(SCIPcolGetVar(cols[j]))];
205
206 /* create a new linear constraint and add it to the subproblem */
207 SCIP_CALL( SCIPcreateConsLinear(restmaster, &cons, SCIProwGetName(rows[i]), nnonz, consvars, vals, lhs, rhs,
209 SCIP_CALL( SCIPaddCons(restmaster, cons) );
210 SCIP_CALL( SCIPreleaseCons(restmaster, &cons) );
211
212 /* free temporary memory */
213 SCIPfreeBufferArray(restmaster, &consvars);
214 }
215 }
216
217 *success = TRUE;
218 return SCIP_OKAY;
219}
220
221/** creates a new solution for the original problem by translating the solution of the restricted master problem */
222static
224 SCIP* origprob, /**< original SCIP data structure */
225 SCIP* scip, /**< SCIP data structure of master problem */
226 SCIP* restmaster, /**< SCIP structure of restricted master problem */
227 SCIP_VAR** restmastervars, /**< the variables of the restricted master problem */
228 SCIP_HEUR* heur, /**< Restricted Master heuristic structure */
229 SCIP_SOL* restmastersol, /**< solution of the restricted master problem */
230 SCIP_Bool* success /**< used to store whether new solution was found or not */
231 )
232{
233 SCIP_VAR** vars; /* the original problem's variables */
234 SCIP_VAR** mastervars; /* the master problem's variables */
235 int nvars;
236 int nmastervars;
237 SCIP_Real* restmastervals; /* solution values of the subproblem */
238 SCIP_SOL* newmastersol; /* solution for the master problem */
239
240 assert(origprob != NULL);
241 assert(scip != NULL);
242 assert(restmaster != NULL);
243 assert(restmastervars != NULL);
244 assert(restmastersol != NULL);
245
246 /* get variables' data */
247 SCIP_CALL( SCIPgetVarsData(origprob, &vars, &nvars, NULL, NULL, NULL, NULL) );
248 SCIP_CALL( SCIPgetVarsData(scip, &mastervars, &nmastervars, NULL, NULL, NULL, NULL) );
249 assert(nmastervars == SCIPgetNOrigVars(restmaster));
250
251 SCIP_CALL( SCIPallocBufferArray(scip, &restmastervals, nmastervars) );
252
253 /* copy the solution */
254 SCIP_CALL( SCIPgetSolVals(restmaster, restmastersol, nmastervars, restmastervars, restmastervals) );
255
256 /* create new solution for the master problem */
257 SCIP_CALL( SCIPcreateSol(scip, &newmastersol, heur) );
258 SCIP_CALL( SCIPsetSolVals(scip, newmastersol, nmastervars, mastervars, restmastervals) );
259
260#ifdef SCIP_DEBUG
261 SCIP_CALL( SCIPtrySolFree(scip, &newmastersol, TRUE, TRUE, TRUE, TRUE, TRUE, success) );
262#else
263 SCIP_CALL( SCIPtrySolFree(scip, &newmastersol, FALSE, FALSE, TRUE, TRUE, TRUE, success) );
264#endif
265
266 SCIPfreeBufferArray(scip, &restmastervals);
267
268 return SCIP_OKAY;
269}
270
271
272/*
273 * Callback methods of primal heuristic
274 */
275
276/** copy method for primal heuristic plugins (called when SCIP copies plugins) */
277#define heurCopyRestmaster NULL
278
279/** destructor of primal heuristic to free user data (called when SCIP is exiting) */
280static
281SCIP_DECL_HEURFREE(heurFreeRestmaster)
282{ /*lint --e{715}*/
283 SCIP_HEURDATA* heurdata;
284
285 assert(heur != NULL);
286 assert(scip != NULL);
287
288 /* get heuristic data */
289 heurdata = SCIPheurGetData(heur);
290 assert(heurdata != NULL);
291
292 /* free heuristic data */
293 SCIPfreeMemory(scip, &heurdata);
294 SCIPheurSetData(heur, NULL);
295
296 return SCIP_OKAY;
297}
298
299
300/** initialization method of primal heuristic (called after problem was transformed) */
301static
302SCIP_DECL_HEURINIT(heurInitRestmaster)
303{ /*lint --e{715}*/
304 SCIP_HEURDATA* heurdata;
305
306 assert(heur != NULL);
307 assert(scip != NULL);
308
309 /* get heuristic's data */
310 heurdata = SCIPheurGetData(heur);
311 assert(heurdata != NULL);
312
313 /* initialize data */
314 heurdata->usednodes = 0;
315
316 /* change timing to after node, call heuristic only at root and increase maxnodes for price-and-branch heuristic */
317 if( heurdata->pbheur )
318 {
319 heurdata->maxnodes = INT_MAX;
320
322 SCIPheurSetFreq(heur, 0);
323 }
324
325 return SCIP_OKAY;
326}
327
328
329/** deinitialization method of primal heuristic (called before transformed problem is freed) */
330#define heurExitRestmaster NULL
331
332
333/** solving process initialization method of primal heuristic (called when branch and bound process is about to begin) */
334#define heurInitsolRestmaster NULL
335
336
337/** solving process deinitialization method of primal heuristic (called before branch and bound process data is freed) */
338#define heurExitsolRestmaster NULL
339
340
341/** execution method of primal heuristic */
342static
343SCIP_DECL_HEUREXEC(heurExecRestmaster)
344{ /*lint --e{715}*/
345 SCIP* origprob; /* SCIP structure of original problem */
346 SCIP_HEURDATA* heurdata; /* heuristic's data */
347 SCIP_Real timelimit; /* timelimit for the subproblem */
348 SCIP_Real memorylimit;
349 SCIP_Bool discretization;
350 SCIP_Bool success;
351 SCIP_Longint nstallnodes; /* number of stalling nodes for the restricted master problem */
352
353 SCIP* restmaster; /* SCIP structure of the restricted master problem */
354 SCIP_HASHMAP* varmapfw; /* mapping of master variables to restricted master variables */
355 SCIP_VAR** mastervars;
356 SCIP_VAR** restmastervars;
357 int nmastervars;
358
359 int i;
360
361#ifdef NDEBUG
362 SCIP_RETCODE retstat;
363#endif
364
365 assert(heur != NULL);
366 assert(scip != NULL);
367 assert(result != NULL);
368 assert(SCIPhasCurrentNodeLP(scip));
369
370 /* get heuristic's data */
371 heurdata = SCIPheurGetData(heur);
372 assert(heurdata != NULL);
373
374 /* get original problem */
375 origprob = GCGgetOrigprob(heurdata->gcg);
376 assert(origprob != NULL);
377
378 *result = SCIP_DIDNOTRUN;
379
380 /* this heuristic works only for the discretization approach */
381 SCIP_CALL( SCIPgetBoolParam(origprob, "relaxing/gcg/discretization", &discretization) );
382 if( !discretization )
383 return SCIP_OKAY;
384
385 *result = SCIP_DELAYED;
386
387 /* only call heuristic, if an optimal LP solution is at hand */
389 return SCIP_OKAY;
390
391 *result = SCIP_DIDNOTRUN;
392
393 /* calculate the maximal number of branching nodes until heuristic is aborted */
394 nstallnodes = (SCIP_Longint)(heurdata->nodesquot * SCIPgetNNodes(origprob));
395
396 if( !heurdata->pbheur )
397 {
398 /* reward restricted master if it succeeded often */
399 nstallnodes = (SCIP_Longint)(nstallnodes * 3.0 * (SCIPheurGetNBestSolsFound(heur)+1.0)/(SCIPheurGetNCalls(heur) + 1.0));
400 nstallnodes -= 100 * SCIPheurGetNCalls(heur); /* count the setup costs for the sub-MIP as 100 nodes */
401 nstallnodes += heurdata->nodesofs;
402
403 /* determine the node limit for the current process */
404 nstallnodes -= heurdata->usednodes;
405 nstallnodes = MIN(nstallnodes, heurdata->maxnodes);
406
407
408 /* check whether we have enough nodes left to call subproblem solving */
409 if( nstallnodes < heurdata->minnodes )
410 {
411 /* SCIPdebugMessage("skipping Restricted Master Heuristic: nstallnodes=%"SCIP_LONGINT_FORMAT", minnodes=%"SCIP_LONGINT_FORMAT"\n", nstallnodes, heurdata->minnodes); */
412 return SCIP_OKAY;
413 }
414 }
415
416 /* check whether there is enough time and memory left */
417 SCIP_CALL( SCIPgetRealParam(origprob, "limits/time", &timelimit) );
418 if( !SCIPisInfinity(origprob, timelimit) )
419 timelimit -= SCIPgetSolvingTime(origprob);
420 SCIP_CALL( SCIPgetRealParam(origprob, "limits/memory", &memorylimit) );
421 if( !SCIPisInfinity(origprob, memorylimit) )
422 memorylimit -= SCIPgetMemUsed(origprob)/1048576.0;
423 if( timelimit < 10.0 || memorylimit <= 0.0 )
424 return SCIP_OKAY;
425
426 if( SCIPisStopped(scip) )
427 return SCIP_OKAY;
428
429 SCIPdebugMessage("Executing Restricted Master Heuristic ...\n");
430
431 *result = SCIP_DIDNOTFIND;
432
433 /* get variable data of the master problem */
434 SCIP_CALL( SCIPgetVarsData(scip, &mastervars, &nmastervars, NULL, NULL, NULL, NULL) );
435 assert(mastervars != NULL);
436 assert(nmastervars >= 0);
437
438 /* initializing the subproblem */
439 SCIP_CALL( SCIPcreate(&restmaster) );
440
441 /* create the variable mapping hash map */
442 SCIP_CALL( SCIPhashmapCreate(&varmapfw, SCIPblkmem(restmaster), nmastervars) );
443 SCIP_CALL( SCIPallocBufferArray(scip, &restmastervars, nmastervars) );
444
445 if( heurdata->uselprows )
446 {
447 char probname[SCIP_MAXSTRLEN];
448
449 /* copy all plugins */
451
452 /* get name of the original problem and add the string "_restricted" */
453 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN, "%s_restricted", SCIPgetProbName(scip));
454
455 /* create the subproblem */
456 SCIP_CALL( SCIPcreateProb(restmaster, probname, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
457
458 /* copy all variables */
459 SCIP_CALL( SCIPcopyVars(scip, restmaster, varmapfw, NULL, NULL, NULL, 0, TRUE) );
460 }
461 else
462 {
463 SCIP_Bool valid;
464
465 valid = FALSE;
466
467 SCIP_CALL( SCIPcopy(scip, restmaster, varmapfw, NULL, "restmaster", TRUE, FALSE, FALSE, TRUE, &valid) ); /** @todo check for thread safeness */
468
469 if( heurdata->copycuts )
470 {
471 /* copies all active cuts from cutpool of sourcescip to linear constraints in targetscip */
472 SCIP_CALL( SCIPcopyCuts(scip, restmaster, varmapfw, NULL, TRUE, NULL) );
473 }
474
475 SCIPdebugMessage("Copying the SCIP instance was %s complete.\n", valid ? "" : "not ");
476 }
477
478 for( i = 0; i < nmastervars; i++ )
479 restmastervars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, mastervars[i]);
480
481 /* free hash map */
482 SCIPhashmapFree(&varmapfw);
483
484 success = FALSE;
485
486 /* set up restricted master problem by fixing variables to zero */
487 SCIP_CALL( setupSubproblem(scip, restmaster, restmastervars, heurdata->minfixingrate, heurdata->uselprows, heurdata->pbheur, &success) );
488 SCIPdebugMessage("restricted master problem: %d vars, %d cons, success=%u\n", SCIPgetNVars(restmaster), SCIPgetNConss(restmaster), success);
489
490 /* do not abort subproblem on CTRL-C */
491 SCIP_CALL( SCIPsetBoolParam(restmaster, "misc/catchctrlc", FALSE) );
492
493 /* disable output to console */
494 SCIP_CALL( SCIPsetIntParam(restmaster, "display/verblevel", 0) );
495
496 /* if price-and-branch heuristic, set node limits according to original problem */
497 if( heurdata->pbheur )
498 nstallnodes = heurdata->maxnodes;
499
500 /* set limits for the subproblem */
501 SCIP_CALL( SCIPsetLongintParam(restmaster, "limits/stallnodes", nstallnodes) );
502 SCIP_CALL( SCIPsetLongintParam(restmaster, "limits/nodes", heurdata->maxnodes) );
503 SCIP_CALL( SCIPsetRealParam(restmaster, "limits/time", timelimit) );
504 SCIP_CALL( SCIPsetRealParam(restmaster, "limits/memory", memorylimit) );
505
506 /* set specific parameters only of price-and-branch is not used */
507 if( !heurdata->pbheur )
508 {
509 /* forbid recursive call of heuristics solving subMIPs */
510 SCIP_CALL( SCIPsetSubscipsOff(restmaster, TRUE) );
511 /* disable cutting plane separation */
513
514 /* disable expensive presolving */
516
517 /* use best estimate node selection */
518 if( SCIPfindNodesel(scip, "estimate") != NULL )
519 {
520 SCIP_CALL( SCIPsetIntParam(restmaster, "nodeselection/estimate/stdpriority", INT_MAX/4) );
521 }
522
523 /* use inference branching */
524 if( SCIPfindBranchrule(scip, "inference") != NULL )
525 {
526 SCIP_CALL( SCIPsetIntParam(restmaster, "branching/inference/priority", INT_MAX/4) );
527 }
528
529 /* disable conflict analysis */
530 if( !SCIPisParamFixed(restmaster, "conflict/enable") )
531 {
532 SCIP_CALL( SCIPsetBoolParam(restmaster, "conflict/enable", FALSE) );
533 }
534 }
535
536 /* if the subproblem could not be created, free memory and return */
537 if( !success )
538 {
539 SCIPdebugMessage("restricted master problem not created.\n");
540 *result = SCIP_DIDNOTRUN;
541 SCIPfreeBufferArray(scip, &restmastervars);
542 SCIP_CALL( SCIPfree(&restmaster) );
543 return SCIP_OKAY;
544 }
545
546 /* if there is already a solution, add an objective cutoff */
547 /* @todo origprob or scip? */
548 if( SCIPgetNSols(origprob) > 0 )
549 {
550 SCIP_Real cutoff; /* objective cutoff for the restricted master problem */
551 SCIP_Real upperbound;
552 assert(!SCIPisInfinity(origprob,SCIPgetUpperbound(origprob)));
553
554 upperbound = SCIPgetUpperbound(origprob) - SCIPsumepsilon(origprob);
555
556 if( !SCIPisInfinity(origprob,-1.0*SCIPgetLowerbound(origprob)) )
557 {
558 cutoff = (1-heurdata->minimprove)*SCIPgetUpperbound(origprob) + heurdata->minimprove*SCIPgetLowerbound(origprob);
559 }
560 else
561 {
562 if( SCIPgetUpperbound ( origprob ) >= 0 )
563 cutoff = ( 1 - heurdata->minimprove ) * SCIPgetUpperbound ( origprob );
564 else
565 cutoff = ( 1 + heurdata->minimprove ) * SCIPgetUpperbound ( origprob );
566 }
567 cutoff = MIN(upperbound, cutoff);
568 SCIP_CALL( SCIPsetObjlimit(restmaster, cutoff) );
569 }
570
571 /* solve the restricted master problem */
572 /* Errors in the LP solver should not kill the overall solving process, if the LP is just needed for a heuristic.
573 * Hence in optimized mode, the return code is catched and a warning is printed, only in debug mode, SCIP will stop.
574 */
575#ifdef NDEBUG
576 retstat = SCIPpresolve(restmaster);
577 if( retstat != SCIP_OKAY )
578 {
579 SCIPwarningMessage(scip, "Error while presolving subMIP in Restricted Master Heuristic; Restricted Master terminated with code <%d>\n",retstat);
580 }
581#else
582 SCIP_CALL( SCIPpresolve(restmaster) );
583#endif
584
585 SCIPdebugMessage("presolved restricted master problem: %d vars, %d cons, success=%u\n", SCIPgetNVars(restmaster), SCIPgetNConss(restmaster), success);
586
587 /* after presolving, we should have at least reached a certain fixing rate over ALL variables (including continuous)
588 * to ensure that not only the MIP but also the LP relaxation is easy enough
589 */
590 if( heurdata->pbheur || ( nmastervars - SCIPgetNVars(restmaster) ) / (SCIP_Real)nmastervars >= heurdata->minfixingrate / 2.0 )
591 {
592 SCIP_SOL** restmastersols;
593 int nrestmastersols;
594
595 SCIPdebugMessage("solving restricted master problem: nstallnodes=%"SCIP_LONGINT_FORMAT", maxnodes=%"SCIP_LONGINT_FORMAT"\n", nstallnodes, heurdata->maxnodes);
596
597#ifdef NDEBUG
598 retstat = SCIPsolve(restmaster);
599 if( retstat != SCIP_OKAY )
600 {
601 SCIPwarningMessage(scip, "Error while solving subMIP in Restricted Master Heuristic; Restricted Master terminated with code <%d>\n",retstat);
602 }
603#else
604 SCIP_CALL( SCIPsolve(restmaster) );
605#endif
606
607 SCIPdebugMessage(" -> %d feasible solution(s) found.\n", SCIPgetNSols(restmaster));
608
609 /* check, whether a solution was found;
610 * due to numerics, it might happen that not all solutions are feasible -> try all solutions until one was accepted
611 */
612 nrestmastersols = SCIPgetNSols(restmaster);
613 restmastersols = SCIPgetSols(restmaster);
614 success = FALSE;
615 for( i = 0; i < nrestmastersols && !success; ++i )
616 {
617 SCIP_CALL( createNewSol(origprob, scip, restmaster, restmastervars, heur, restmastersols[i], &success) );
618 }
619 if( success )
620 *result = SCIP_FOUNDSOL;
621 }
622
623 /* free subproblem */
624 SCIPfreeBufferArray(scip, &restmastervars);
625 SCIP_CALL( SCIPfree(&restmaster) );
626
627
628 return SCIP_OKAY;
629}
630
631
632
633
634/*
635 * primal heuristic specific interface methods
636 */
637
638/** creates the Restricted Master primal heuristic and includes it in SCIP */
640 GCG* gcg /**< GCG data structure */
641 )
642{
643 SCIP_HEURDATA* heurdata;
644 SCIP* masterprob = GCGgetMasterprob(gcg);
645
646 /* create Restricted Master primal heuristic data */
647 SCIP_CALL( SCIPallocMemory(masterprob, &heurdata) );
648 heurdata->gcg = gcg;
649
650 /* include primal heuristic */
653 heurCopyRestmaster, heurFreeRestmaster, heurInitRestmaster, heurExitRestmaster,
654 heurInitsolRestmaster, heurExitsolRestmaster, heurExecRestmaster, heurdata) );
655
656 /* add Restricted Master primal heuristic parameters */
657 SCIP_CALL( SCIPaddRealParam(masterprob, "heuristics/"HEUR_NAME"/minfixingrate",
658 "minimum percentage of integer variables that have to be fixable ",
659 &heurdata->minfixingrate, FALSE, DEFAULT_MINFIXINGRATE, 0.0, 1.0, NULL, NULL) );
660
661 SCIP_CALL( SCIPaddLongintParam(masterprob, "heuristics/"HEUR_NAME"/maxnodes",
662 "maximum number of nodes to regard in the subproblem",
664
665 SCIP_CALL( SCIPaddLongintParam(masterprob, "heuristics/"HEUR_NAME"/nodesofs",
666 "number of nodes added to the contingent of the total nodes",
668
669 SCIP_CALL( SCIPaddLongintParam(masterprob, "heuristics/"HEUR_NAME"/minnodes",
670 "minimum number of nodes required to start the subproblem",
671 &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0LL, SCIP_LONGINT_MAX, NULL, NULL) );
672
673 SCIP_CALL( SCIPaddRealParam(masterprob, "heuristics/"HEUR_NAME"/nodesquot",
674 "contingent of sub problem nodes in relation to the number of nodes of the original problem",
675 &heurdata->nodesquot, FALSE, DEFAULT_NODESQUOT, 0.0, 1.0, NULL, NULL) );
676
677 SCIP_CALL( SCIPaddRealParam(masterprob, "heuristics/"HEUR_NAME"/minimprove",
678 "factor by which restricted master should at least improve the incumbent ",
679 &heurdata->minimprove, TRUE, DEFAULT_MINIMPROVE, 0.0, 1.0, NULL, NULL) );
680
681 SCIP_CALL( SCIPaddBoolParam(masterprob, "heuristics/"HEUR_NAME"/uselprows",
682 "should subproblem be created out of the rows in the LP rows?",
683 &heurdata->uselprows, TRUE, DEFAULT_USELPROWS, NULL, NULL) );
684
685 SCIP_CALL( SCIPaddBoolParam(masterprob, "heuristics/"HEUR_NAME"/copycuts",
686 "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
687 &heurdata->copycuts, TRUE, DEFAULT_COPYCUTS, NULL, NULL) );
688
689 SCIP_CALL( SCIPaddBoolParam(masterprob, "heuristics/"HEUR_NAME"/pbheur",
690 "should the restricted master heuristic be used as price-and-branch heuristic?",
691 &heurdata->pbheur, FALSE, DEFAULT_PBHEUR, NULL, NULL) );
692
693 return SCIP_OKAY;
694}
#define SCIP_MAXSTRLEN
#define SCIP_Longint
#define SCIP_Bool
#define MIN(x, y)
#define SCIP_Real
#define MAX(x, y)
#define SCIP_LONGINT_FORMAT
#define SCIP_LONGINT_MAX
#define SCIP_CALL(x)
#define TRUE
#define FALSE
GCG interface methods.
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIP_RETCODE SCIPcopyVars(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Bool global)
SCIP_RETCODE SCIPcopy(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool threadsafe, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
SCIP_RETCODE SCIPcopyCuts(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, int *ncutsadded)
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
SCIP * GCGgetMasterprob(GCG *gcg)
Definition: gcg.cpp:99
SCIP_Bool SCIPisStopped(SCIP *scip)
SCIP_RETCODE SCIPfree(SCIP **scip)
SCIP_RETCODE SCIPcreate(SCIP **scip)
const char * SCIPgetProbName(SCIP *scip)
SCIP_RETCODE SCIPsetObjlimit(SCIP *scip, SCIP_Real objlimit)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
int SCIPgetNVars(SCIP *scip)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNConss(SCIP *scip)
int SCIPgetNOrigVars(SCIP *scip)
SCIP_RETCODE SCIPcreateProb(SCIP *scip, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
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 SCIPsetIntParam(SCIP *scip, const char *name, int value)
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
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)
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
SCIP_RETCODE SCIPincludeHeur(SCIP *scip, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEURCOPY((*heurcopy)), SCIP_DECL_HEURFREE((*heurfree)), SCIP_DECL_HEURINIT((*heurinit)), SCIP_DECL_HEUREXIT((*heurexit)), SCIP_DECL_HEURINITSOL((*heurinitsol)), SCIP_DECL_HEUREXITSOL((*heurexitsol)), SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
void SCIPheurSetFreq(SCIP_HEUR *heur, int freq)
void SCIPheurSetTimingmask(SCIP_HEUR *heur, SCIP_HEURTIMING timingmask)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
SCIP_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeBufferArray(scip, ptr)
#define SCIPfreeMemory(scip, ptr)
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
int SCIProwGetNNonz(SCIP_ROW *row)
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
const char * SCIProwGetName(SCIP_ROW *row)
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
int SCIPgetNSols(SCIP *scip)
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_SOL ** SCIPgetSols(SCIP *scip)
SCIP_RETCODE SCIPtrySolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_RETCODE SCIPpresolve(SCIP *scip)
SCIP_RETCODE SCIPsolve(SCIP *scip)
SCIP_Real SCIPgetUpperbound(SCIP *scip)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPsumepsilon(SCIP *scip)
int SCIPvarGetProbindex(SCIP_VAR *var)
SCIP_RETCODE SCIPchgVarLbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIP_RETCODE SCIPchgVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
int SCIPsnprintf(char *t, int len, const char *s,...)
#define DEFAULT_NODESQUOT
#define DEFAULT_NODESOFS
#define DEFAULT_COPYCUTS
#define DEFAULT_MAXNODES
#define HEUR_TIMING
#define DEFAULT_MINNODES
#define heurExitsolRestmaster
#define DEFAULT_PBHEUR
#define HEUR_FREQOFS
SCIP_RETCODE GCGincludeHeurRestmaster(GCG *gcg)
#define HEUR_DESC
#define heurExitRestmaster
static SCIP_RETCODE createNewSol(SCIP *origprob, SCIP *scip, SCIP *restmaster, SCIP_VAR **restmastervars, SCIP_HEUR *heur, SCIP_SOL *restmastersol, SCIP_Bool *success)
static SCIP_DECL_HEURFREE(heurFreeRestmaster)
#define DEFAULT_MINFIXINGRATE
static SCIP_DECL_HEUREXEC(heurExecRestmaster)
#define HEUR_DISPCHAR
#define HEUR_MAXDEPTH
#define HEUR_PRIORITY
#define heurCopyRestmaster
#define heurInitsolRestmaster
#define DEFAULT_MINIMPROVE
#define HEUR_NAME
static SCIP_DECL_HEURINIT(heurInitRestmaster)
#define DEFAULT_USELPROWS
#define HEUR_FREQ
#define HEUR_USESSUBSCIP
static SCIP_RETCODE setupSubproblem(SCIP *scip, SCIP *restmaster, SCIP_VAR **restmastervars, SCIP_Real minfixingrate, SCIP_Bool uselprows, SCIP_Bool pbheur, SCIP_Bool *success)
Restricted Master Heuristic.
#define NULL
GCG variable pricer.
#define SCIPdebugMessage
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
Definition: struct_gcg.h:55
SCIP_Longint nodesofs
Definition: heur_gcgdins.c:79
SCIP_Real nodesquot
Definition: heur_gcgdins.c:85
SCIP_Bool pbheur
SCIP_Real minimprove
Definition: heur_gcgdins.c:83
SCIP_Bool uselprows
Definition: heur_gcgdins.c:91
SCIP_Bool copycuts
Definition: heur_gcgdins.c:92
SCIP_Real minfixingrate
Definition: heur_gcgrens.c:86
SCIP_Longint usednodes
Definition: heur_gcgdins.c:84
SCIP_Longint maxnodes
Definition: heur_gcgdins.c:80
SCIP_Longint minnodes
Definition: heur_gcgdins.c:81
SCIP_LPSOLSTAT_OPTIMAL
SCIP_PARAMSETTING_OFF
SCIP_PARAMSETTING_FAST
SCIP_DIDNOTRUN
SCIP_DELAYED
SCIP_DIDNOTFIND
SCIP_FOUNDSOL
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE
#define SCIP_HEURTIMING_AFTERNODE