GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
heur_gcgrins.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_gcgrins.c
30 * @brief LNS heuristic that combines the incumbent with the LP optimum
31 * @author Timo Berthold
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
40#include "gcg/heur_gcgrins.h"
41#include "gcg/gcg.h"
42
43#include "scip/scipdefplugins.h"
44#include "scip/cons_linear.h"
45
46#define HEUR_NAME "gcgrins"
47#define HEUR_DESC "relaxation induced neighborhood search by Danna, Rothberg, and Le Pape"
48#define HEUR_DISPCHAR 'N'
49#define HEUR_PRIORITY -1101000
50#define HEUR_FREQ 20
51#define HEUR_FREQOFS 5
52#define HEUR_MAXDEPTH -1
53#define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
54#define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
55
56#define DEFAULT_NODESOFS 500 /**< number of nodes added to the contingent of the total nodes */
57#define DEFAULT_MAXNODES 5000 /**< maximum number of nodes to regard in the subproblem */
58#define DEFAULT_MINNODES 500 /**< minimum number of nodes to regard in the subproblem */
59#define DEFAULT_MINIMPROVE 0.01 /**< factor by which RINS should at least improve the incumbent */
60#define DEFAULT_MINFIXINGRATE 0.0 /**< minimum percentage of integer variables that have to be fixed */
61#define DEFAULT_NODESQUOT 0.1 /**< subproblem nodes in relation to nodes of the original problem */
62#define DEFAULT_NWAITINGNODES 200 /**< number of nodes without incumbent change that heuristic should wait */
63#define DEFAULT_USELPROWS FALSE /**< should subproblem be created out of the rows in the LP rows,
64 * otherwise, the copy constructors of the constraints handlers are used */
65#define DEFAULT_COPYCUTS TRUE /**< if DEFAULT_USELPROWS is FALSE, then should all active cuts from the cutpool
66 * of the original scip be copied to constraints of the subscip
67 */
68
69
70/*
71 * Data structures
72 */
73
74/** primal heuristic data */
75struct SCIP_HeurData
76{
77 GCG* gcg; /**< GCG data structure */
78 int nodesofs; /**< number of nodes added to the contingent of the total nodes */
79 int maxnodes; /**< maximum number of nodes to regard in the subproblem */
80 int minnodes; /**< minimum number of nodes to regard in the subproblem */
81 SCIP_Real minfixingrate; /**< minimum percentage of integer variables that have to be fixed */
82 int nwaitingnodes; /**< number of nodes without incumbent change that heuristic should wait */
83 SCIP_Real minimprove; /**< factor by which RINS should at least improve the incumbent */
84 SCIP_Longint usednodes; /**< nodes already used by RINS in earlier calls */
85 SCIP_Real nodesquot; /**< subproblem nodes in relation to nodes of the original problem */
86 SCIP_Bool uselprows; /**< should subproblem be created out of the rows in the LP rows? */
87 SCIP_Bool copycuts; /**< if uselprows == FALSE, should all active cuts from cutpool be copied
88 * to constraints in subproblem?
89 */
90#ifdef SCIP_STATISTIC
91 SCIP_Longint nfixfails; /**< number of abortions due to a bad fixing rate */
92 SCIP_Real avgfixrate; /**< average rate of variables that are fixed */
93 SCIP_Real avgzerorate; /**< average rate of fixed variables that are zero */
94 SCIP_Longint totalsols; /**< total number of subSCIP solutions (including those which have not
95 * been added)
96 */
97 SCIP_Real subsciptime; /**< total subSCIP solving time in seconds */
98 SCIP_Real bestprimalbd; /**< objective value of best solution found by this heuristic */
99#endif
100};
101
102/*
103 * Local methods
104 */
105
106/** creates a subproblem for subscip by fixing a number of variables */
107static
109 SCIP* scip, /**< original SCIP data structure */
110 SCIP* subscip, /**< SCIP data structure for the subproblem */
111 SCIP_VAR** subvars, /**< the variables of the subproblem */
112 SCIP_Real minfixingrate, /**< percentage of integer variables that have to be fixed */
113 SCIP_Bool uselprows, /**< should subproblem be created out of the rows in the LP rows? */
114 SCIP_Real* intfixingrate, /**< percentage of integers that get actually fixed */
115 SCIP_Real* zerofixingrate, /**< percentage of variables fixed to zero */
116 SCIP_Bool* success /**< pointer to store whether the problem was created successfully */
117 )
118{
119 SCIP_SOL* bestsol; /* incumbent solution of the original problem */
120 SCIP_VAR** vars; /* original scip variables */
121 SCIP_ROW** rows; /* original scip rows */
122
123 int nrows;
124 int nvars;
125 int nbinvars;
126 int nintvars;
127 int i;
128
129 int fixingcounter;
130 int zerocounter;
131
132 assert(scip != NULL);
133 assert(subscip != NULL);
134 assert(subvars != NULL);
135
136 assert(0.0 <= minfixingrate && minfixingrate <= 1.0);
137
138 /* get required data of the original problem */
140 bestsol = SCIPgetBestSol(scip);
141 assert(bestsol != NULL);
142
143 fixingcounter = 0;
144 zerocounter = 0;
145
146 /* change bounds of variables of the subproblem */
147 for( i = 0; i < nbinvars + nintvars; i++ )
148 {
149 SCIP_Real lpsolval;
151
152 /* get the current relaxation solution and the incumbent solution for each variable */
153 lpsolval = SCIPgetRelaxSolVal(scip, vars[i]);
154 solval = SCIPgetSolVal(scip, bestsol, vars[i]);
155
156 /* iff both solutions are equal, variable is fixed to that value in the subproblem, otherwise it is just copied */
157 if( SCIPisFeasEQ(scip, lpsolval, solval) )
158 {
159 /* perform the bound change */
160 SCIP_CALL( SCIPchgVarLbGlobal(subscip, subvars[i], solval) );
161 SCIP_CALL( SCIPchgVarUbGlobal(subscip, subvars[i], solval) );
162 fixingcounter++;
163 if( SCIPisZero(scip, solval) )
164 zerocounter++;
165 }
166 }
167
168 /* abort, if all variables were fixed */
169 if( fixingcounter == nbinvars + nintvars )
170 {
171 *intfixingrate = 1.0;
172 *zerofixingrate = 1.0;
173 *success = FALSE;
174 return SCIP_OKAY;
175 }
176 else
177 {
178 *intfixingrate = (SCIP_Real)fixingcounter / (SCIP_Real)(MAX(nbinvars + nintvars, 1));
179 *zerofixingrate = (SCIP_Real)zerocounter / MAX((SCIP_Real)fixingcounter, 1.0);
180 }
181
182 /* abort, if the amount of fixed variables is insufficient */
183 if( *intfixingrate < minfixingrate )
184 {
185 *success = FALSE;
186 SCIPstatisticPrintf("gcgrins statistic: fixed only %5.2f ( %5.2f zero) integer variables --> abort \n", *intfixingrate, *zerofixingrate);
187 return SCIP_OKAY;
188 }
189
190 if( uselprows )
191 {
192 /* get the rows and their number */
193 SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );
194
195 /* copy all rows to linear constraints */
196 for( i = 0; i < nrows; i++ )
197 {
198 SCIP_CONS* cons;
199 SCIP_VAR** consvars;
200 SCIP_COL** cols;
201 SCIP_Real constant;
202 SCIP_Real lhs;
203 SCIP_Real rhs;
204 SCIP_Real* vals;
205 int nnonz;
206 int j;
207
208 /* ignore rows that are only locally valid */
209 if( SCIProwIsLocal(rows[i]) )
210 continue;
211
212 /* get the row's data */
213 constant = SCIProwGetConstant(rows[i]);
214 lhs = SCIProwGetLhs(rows[i]) - constant;
215 rhs = SCIProwGetRhs(rows[i]) - constant;
216 vals = SCIProwGetVals(rows[i]);
217 nnonz = SCIProwGetNNonz(rows[i]);
218 cols = SCIProwGetCols(rows[i]);
219
220 assert( lhs <= rhs );
221
222 /* allocate memory array to be filled with the corresponding subproblem variables */
223 SCIP_CALL( SCIPallocBufferArray(scip, &consvars, nnonz) );
224 for( j = 0; j < nnonz; j++ )
225 consvars[j] = subvars[SCIPvarGetProbindex(SCIPcolGetVar(cols[j]))];
226
227 /* create a new linear constraint and add it to the subproblem */
228 SCIP_CALL( SCIPcreateConsLinear(subscip, &cons, SCIProwGetName(rows[i]), nnonz, consvars, vals, lhs, rhs,
230 SCIP_CALL( SCIPaddCons(subscip, cons) );
231 SCIP_CALL( SCIPreleaseCons(subscip, &cons) );
232
233 /* free temporary memory */
234 SCIPfreeBufferArray(scip, &consvars);
235 }
236 }
237
238 *success = TRUE;
239 return SCIP_OKAY;
240}
241
242
243/** creates a new solution for the original problem by copying the solution of the subproblem */
244static
246 SCIP* scip, /**< original SCIP data structure */
247 SCIP* subscip, /**< SCIP structure of the subproblem */
248 SCIP_VAR** subvars, /**< the variables of the subproblem */
249 SCIP_HEUR* heur, /**< RINS heuristic structure */
250 SCIP_SOL* subsol, /**< solution of the subproblem */
251 SCIP_Bool* success /**< used to store whether new solution was found or not */
252)
253{
254#ifdef SCIP_STATISTIC
256#endif
257 SCIP_VAR** vars; /* the original problem's variables */
258 int nvars;
259 SCIP_Real* subsolvals; /* solution values of the subproblem */
260 SCIP_SOL* newsol; /* solution to be created for the original problem */
261
262 assert(scip != NULL);
263 assert(subscip != NULL);
264 assert(subvars != NULL);
265 assert(subsol != NULL);
266
267#ifdef SCIP_STATISTIC
268 /* get heuristic data */
270 assert( heurdata != NULL );
271#endif
272
273 /* get variables' data */
275 /* sub-SCIP may have more variables than the number of active (transformed) variables in the main SCIP
276 * since constraint copying may have required the copy of variables that are fixed in the main SCIP
277 */
278 assert(nvars <= SCIPgetNOrigVars(subscip));
279
280 SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
281
282 /* copy the solution */
283 SCIP_CALL( SCIPgetSolVals(subscip, subsol, nvars, subvars, subsolvals) );
284
285 /* create new solution for the original problem */
286 SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
287 SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, subsolvals) );
288
289 /* try to add new solution to scip and free it immediately */
291
292#ifdef SCIP_STATISTIC
293 if( *success )
294 {
295 if( SCIPgetSolTransObj(scip, newsol) < heurdata->bestprimalbd )
296 heurdata->bestprimalbd = SCIPgetSolTransObj(scip, newsol);
297 }
298#endif
299
300 SCIP_CALL( SCIPfreeSol(scip, &newsol) );
301
302 SCIPfreeBufferArray(scip, &subsolvals);
303
304 return SCIP_OKAY;
305}
306
307/*
308 * Callback methods of primal heuristic
309 */
310
311/** destructor of primal heuristic to free user data (called when SCIP is exiting) */
312static
313SCIP_DECL_HEURFREE(heurFreeGcgrins)
314{ /*lint --e{715}*/
316
317 assert(heur != NULL);
318 assert(scip != NULL);
319
320 /* get heuristic data */
322 assert(heurdata != NULL);
323
324 /* free heuristic data */
326 SCIPheurSetData(heur, NULL);
327
328 return SCIP_OKAY;
329}
330
331
332/** initialization method of primal heuristic (called after problem was transformed) */
333static
334SCIP_DECL_HEURINIT(heurInitGcgrins)
335{ /*lint --e{715}*/
337
338 assert(heur != NULL);
339 assert(scip != NULL);
340
341 /* get heuristic data */
343 assert(heurdata != NULL);
344
345 /* initialize data */
346 heurdata->usednodes = 0;
347
348 return SCIP_OKAY;
349}
350
351#ifdef SCIP_STATISTIC
352/** solving process initialization method of primal heuristic (called when branch and bound process is about to begin) */
353static
354SCIP_DECL_HEURINITSOL(heurInitsolGcgrins)
355{ /*lint --e{715}*/
357
358 assert(heur != NULL);
359 assert(scip != NULL);
360
361 /* get heuristic data */
363 assert(heurdata != NULL);
364
365 /* initialize statistical data */
366 heurdata->avgfixrate = 0.0;
367 heurdata->avgzerorate = 0.0;
368 heurdata->totalsols = 0;
369 heurdata->subsciptime = 0.0;
370 heurdata->bestprimalbd = SCIPinfinity(scip);
371
372 return SCIP_OKAY;
373}
374
375/** solving process deinitialization method of primal heuristic (called before branch and bound process data is freed) */
376static
377SCIP_DECL_HEUREXITSOL(heurExitsolGcgrins)
378{ /*lint --e{715}*/
381
382 assert(heur != NULL);
383 assert(scip != NULL);
384
385 /* get heuristic data */
387 assert(heurdata != NULL);
388
390 heurdata->avgfixrate /= MAX((SCIP_Real)ncalls, 1.0);
391 heurdata->avgzerorate /= MAX((SCIP_Real)ncalls, 1.0);
392
393 /* print detailed statistics */
394 SCIPstatisticPrintf("LNS Statistics -- %s:\n", SCIPheurGetName(heur));
396 SCIPstatisticPrintf("Failed Fixings : %13"SCIP_LONGINT_FORMAT"\n", heurdata->nfixfails);
398 SCIPstatisticPrintf("Improving Sols : %13"SCIP_LONGINT_FORMAT"\n", SCIPheurGetNBestSolsFound(heur));
399 SCIPstatisticPrintf("Total Sols : %13"SCIP_LONGINT_FORMAT"\n", heurdata->totalsols);
400 SCIPstatisticPrintf("subSCIP time : %13.2f\n", heurdata->subsciptime);
401 SCIPstatisticPrintf("subSCIP nodes : %13"SCIP_LONGINT_FORMAT"\n", heurdata->usednodes);
402 SCIPstatisticPrintf("Avg. fixing rate : %13.2f\n", 100.0 * heurdata->avgfixrate);
403 SCIPstatisticPrintf("Avg. zero rate : %13.2f\n", 100.0 * heurdata->avgzerorate);
404 SCIPstatisticPrintf("Best primal bd. :");
405 if( SCIPisInfinity(scip, heurdata->bestprimalbd) )
406 SCIPstatisticPrintf(" infinity\n");
407 else
408 SCIPstatisticPrintf(" %13.6e\n", heurdata->bestprimalbd);
410
411 return SCIP_OKAY;
412}
413#endif
414
415
416/** execution method of primal heuristic */
417static
418SCIP_DECL_HEUREXEC(heurExecGcgrins)
419{ /*lint --e{715}*/
420 SCIP_Longint nstallnodes;
421
423 SCIP_HEURDATA* heurdata; /* heuristic's data */
424 SCIP* subscip; /* the subproblem created by RINS */
425 SCIP_VAR** vars; /* original problem's variables */
426 SCIP_VAR** subvars; /* subproblem's variables */
427 SCIP_HASHMAP* varmapfw; /* mapping of SCIP variables to sub-SCIP variables */
428
429 SCIP_Real timelimit; /* timelimit for the subproblem */
430 SCIP_Real memorylimit;
431 SCIP_Real cutoff; /* objective cutoff for the subproblem */
432 SCIP_Real upperbound;
433 SCIP_Real allfixingrate; /* percentage of all variables fixed */
434 SCIP_Real intfixingrate; /* percentage of integer variables fixed */
435 SCIP_Real zerofixingrate; /* percentage of variables fixed to zero */
436
437 int nvars;
438 int nbinvars;
439 int nintvars;
440 int i;
441
444
445 assert(heur != NULL);
446 assert(scip != NULL);
447 assert(result != NULL);
448
449 /* get heuristic data */
451 assert(heurdata != NULL);
452
453 /* get master problem */
456
458
459 /* do not execute the heuristic on invalid relaxation solutions
460 * (which is the case if the node has been cut off)
461 */
463 {
464 SCIPdebugMessage("skipping GCG RINS: invalid relaxation solution\n");
465 return SCIP_OKAY;
466 }
467
468 /* only call heuristic, if feasible solution is available */
469 if( SCIPgetNSols(scip) <= 0 )
470 return SCIP_OKAY;
471
472 /* only call heuristic, if an optimal LP solution is at hand */
474 return SCIP_OKAY;
475
476 /* only call heuristic, if the best solution comes from transformed problem */
479 return SCIP_OKAY;
480
481 /* only call heuristic, if enough nodes were processed since last incumbent */
483 return SCIP_OKAY;
484
486
487 /* check whether there is enough time and memory left */
488 timelimit = 0.0;
489 memorylimit = 0.0;
490 SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
491 if( !SCIPisInfinity(scip, timelimit) )
492 timelimit -= SCIPgetSolvingTime(scip);
493 SCIP_CALL( SCIPgetRealParam(scip, "limits/memory", &memorylimit) );
494
495 /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
496 if( !SCIPisInfinity(scip, memorylimit) )
497 {
498 memorylimit -= SCIPgetMemUsed(scip)/1048576.0;
499 memorylimit -= SCIPgetMemExternEstim(scip)/1048576.0;
500 }
501
502 /* abort if no time is left or not enough memory to create a copy of SCIP, including external memory usage */
503 if( timelimit <= 0.0 || memorylimit <= 2.0*SCIPgetMemExternEstim(scip)/1048576.0 )
504 return SCIP_OKAY;
505
506 /* calculate the maximal number of branching nodes until heuristic is aborted */
507 nstallnodes = (SCIP_Longint)(heurdata->nodesquot * SCIPgetNNodes(scip));
508
509 /* reward RINS if it succeeded often */
510 nstallnodes = (SCIP_Longint)(nstallnodes * 3.0 * (SCIPheurGetNBestSolsFound(heur)+1.0)/(SCIPheurGetNCalls(heur) + 1.0));
511 nstallnodes -= 100 * SCIPheurGetNCalls(heur); /* count the setup costs for the sub-MIP as 100 nodes */
512 nstallnodes += heurdata->nodesofs;
513
514 /* determine the node limit for the current process */
515 nstallnodes -= heurdata->usednodes;
516 nstallnodes = MIN(nstallnodes, heurdata->maxnodes);
517
518 /* check whether we have enough nodes left to call subproblem solving */
519 if( nstallnodes < heurdata->minnodes )
520 return SCIP_OKAY;
521
523
524 /* check whether discrete variables are available */
525 if( nbinvars == 0 && nintvars == 0 )
526 return SCIP_OKAY;
527
528 if( SCIPisStopped(scip) )
529 return SCIP_OKAY;
530
532
533 /* initializing the subproblem */
535 SCIP_CALL( SCIPcreate(&subscip) );
536
537 /* create the variable mapping hash map */
539
540 if( heurdata->uselprows )
541 {
542 char probname[SCIP_MAXSTRLEN];
543
544 /* copy all plugins */
546
547 /* get name of the original problem and add the string "_gcgrinssub" */
548 (void) SCIPsnprintf(probname, SCIP_MAXSTRLEN, "%s_gcgrinssub", SCIPgetProbName(scip));
549
550 /* create the subproblem */
551 SCIP_CALL( SCIPcreateProb(subscip, probname, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
552
553 /* copy all variables */
554 SCIP_CALL( SCIPcopyVars(scip, subscip, varmapfw, NULL, NULL, NULL, 0, TRUE) );
555 }
556 else
557 {
558 SCIP_Bool valid;
559 valid = FALSE;
560
561 SCIP_CALL( SCIPcopy(scip, subscip, varmapfw, NULL, "gcgrins", TRUE, FALSE, FALSE, TRUE, &valid) ); /** @todo check for thread safeness */
562
563 if( heurdata->copycuts )
564 {
565 /* copies all active cuts from cutpool of sourcescip to linear constraints in targetscip */
567 }
568
569 SCIPdebugMessage("Copying the SCIP instance was %s complete.\n", valid ? "" : "not ");
570 }
571
572 for( i = 0; i < nvars; i++ )
573 subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
574
575 /* free hash map */
577
578 success = FALSE;
579
580 SCIPstatisticPrintf("gcgrins statistic: called at node %"SCIP_LONGINT_FORMAT"\n", SCIPgetNNodes(scip));
581
582 /* create a new problem, which fixes variables with same value in bestsol and LP relaxation */
583 SCIP_CALL( createSubproblem(scip, subscip, subvars, heurdata->minfixingrate, heurdata->uselprows, &intfixingrate, &zerofixingrate, &success) );
584 SCIPdebugMessage("RINS subproblem: %d vars, %d cons, success=%u\n", SCIPgetNVars(subscip), SCIPgetNConss(subscip), success);
585
586#ifdef SCIP_STATISTIC
587 heurdata->avgfixrate += intfixingrate;
588 heurdata->avgzerorate += zerofixingrate;
589#endif
590
591 if( !success )
592 {
594#ifdef SCIP_STATISTIC
595 ++heurdata->nfixfails;
596#endif
597 goto TERMINATE;
598 }
599
600 /* disable output to console */
601 SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 0) );
602
603 /* set limits for the subproblem */
604 SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nstallnodes) );
605 SCIP_CALL( SCIPsetIntParam(subscip, "limits/bestsol", 3) );
606 SCIP_CALL( SCIPsetRealParam(subscip, "limits/time", timelimit) );
607 SCIP_CALL( SCIPsetRealParam(subscip, "limits/memory", memorylimit) );
608
609 /* forbid recursive call of heuristics and separators solving subMIPs */
610 SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) );
611
612 /* disable cutting plane separation */
614
615 /* disable expensive presolving */
617
618 /* use best estimate node selection */
619 if( SCIPfindNodesel(subscip, "estimate") != NULL && !SCIPisParamFixed(subscip, "nodeselection/estimate/stdpriority") )
620 {
621 SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/estimate/stdpriority", INT_MAX/4) );
622 }
623
624 /* use inference branching */
625 if( SCIPfindBranchrule(subscip, "inference") != NULL && !SCIPisParamFixed(subscip, "branching/inference/priority") )
626 {
627 SCIP_CALL( SCIPsetIntParam(subscip, "branching/inference/priority", INT_MAX/4) );
628 }
629
630 /* disable conflict analysis */
631 if( !SCIPisParamFixed(subscip, "conflict/enable") )
632 {
633 SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/enable", FALSE) );
634 }
635
636 /* add an objective cutoff */
638
639 upperbound = SCIPgetUpperbound(scip) - SCIPsumepsilon(scip);
641 {
643 }
644 else
645 {
646 if( SCIPgetUpperbound ( scip ) >= 0 )
648 else
650 }
651 cutoff = MIN(upperbound, cutoff );
652 SCIP_CALL( SCIPsetObjlimit(subscip, cutoff) );
653
654 /* presolve the subproblem */
655 retcode = SCIPpresolve(subscip);
656
657 /* errors in solving the subproblem should not kill the overall solving process;
658 * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
659 */
660 if( retcode != SCIP_OKAY )
661 {
662#ifndef NDEBUG
664#endif
665 SCIPwarningMessage(scip, "Error while presolving subproblem in GCG RINS heuristic; sub-SCIP terminated with code <%d>\n",retcode);
666 goto TERMINATE;
667 }
668
669 SCIPdebugMessage("GCG RINS presolved subproblem: %d vars, %d cons, success=%u\n", SCIPgetNVars(subscip), SCIPgetNConss(subscip), success);
670
671 allfixingrate = (SCIPgetNOrigVars(subscip) - SCIPgetNVars(subscip)) / (SCIP_Real)SCIPgetNOrigVars(subscip);
672
673 /* additional variables added in presolving may lead to the subSCIP having more variables than the original */
674 allfixingrate = MAX(allfixingrate, 0.0);
675
676 /* after presolving, we should have at least reached a certain fixing rate over ALL variables (including continuous)
677 * to ensure that not only the MIP but also the LP relaxation is easy enough
678 */
679 if( allfixingrate >= heurdata->minfixingrate / 2.0 )
680 {
681 SCIP_SOL** subsols;
682 int nsubsols;
683
684 /* solve the subproblem */
685 retcode = SCIPsolve(subscip);
686
687 /* Errors in solving the subproblem should not kill the overall solving process
688 * Hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
689 */
690 if( retcode != SCIP_OKAY )
691 {
692#ifndef NDEBUG
694#endif
695 SCIPwarningMessage(scip, "Error while solving subproblem in GCG RINS heuristic; sub-SCIP terminated with code <%d>\n",retcode);
696 }
697
698#ifdef SCIP_STATISTIC
699 heurdata->usednodes += SCIPgetNNodes(subscip);
700 heurdata->subsciptime += SCIPgetTotalTime(subscip);
701#endif
702
703 /* check, whether a solution was found;
704 * due to numerics, it might happen that not all solutions are feasible -> try all solutions until one was accepted
705 */
706 nsubsols = SCIPgetNSols(subscip);
707 subsols = SCIPgetSols(subscip);
708#ifdef SCIP_STATISTIC
709 heurdata->totalsols += nsubsols;
710#endif
711 success = FALSE;
712 for( i = 0; i < nsubsols && !success; ++i )
713 {
714 SCIP_CALL( createNewSol(scip, subscip, subvars, heur, subsols[i], &success) );
715 if( success )
717 }
718
719 SCIPstatisticPrintf("gcgrins statistic: fixed %6.3f integer variables ( %6.3f zero), %6.3f all variables, needed %6.1f sec (SCIP time: %6.1f sec), %"SCIP_LONGINT_FORMAT" nodes, found %d solutions, solution %10.4f found at node %"SCIP_LONGINT_FORMAT"\n",
720 intfixingrate, zerofixingrate, allfixingrate, SCIPgetSolvingTime(subscip), SCIPgetSolvingTime(scip), SCIPgetNNodes(subscip), nsubsols,
721 success ? SCIPgetPrimalbound(scip) : SCIPinfinity(scip), nsubsols > 0 ? SCIPsolGetNodenum(SCIPgetBestSol(subscip)) : -1 );
722 }
723 else
724 {
725 SCIPstatisticPrintf("gcgrins statistic: fixed only %6.3f integer variables ( %6.3f zero), %6.3f all variables --> abort \n", intfixingrate, zerofixingrate, allfixingrate);
726 }
727
728 TERMINATE:
729 /* free subproblem */
730 SCIPfreeBufferArray(scip, &subvars);
731 SCIP_CALL( SCIPfree(&subscip) );
732
733 return SCIP_OKAY;
734}
735
736/*
737 * primal heuristic specific interface methods
738 */
739
740/** creates the GCG RINS primal heuristic and includes it in SCIP */
742 GCG* gcg /**< GCG data structure */
743 )
744{
746 SCIP_HEUR* heur;
748
749 /* create GCG RINS primal heuristic data */
751 heurdata->gcg = gcg;
752
753 /* include primal heuristic */
756 HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecGcgrins, heurdata) );
757
758 assert(heur != NULL);
759
760 /* set non-NULL pointers to callback methods */
761 SCIP_CALL( SCIPsetHeurFree(origprob, heur, heurFreeGcgrins) );
762 SCIP_CALL( SCIPsetHeurInit(origprob, heur, heurInitGcgrins) );
763#ifdef SCIP_STATISTIC
764 SCIP_CALL( SCIPsetHeurInitsol(origprob, heur, heurInitsolGcgrins) );
765 SCIP_CALL( SCIPsetHeurExitsol(origprob, heur, heurExitsolGcgrins) );
766#endif
767
768 /* add RINS primal heuristic parameters */
769 SCIP_CALL( SCIPaddIntParam(origprob, "heuristics/"HEUR_NAME"/nodesofs",
770 "number of nodes added to the contingent of the total nodes",
771 &heurdata->nodesofs, FALSE, DEFAULT_NODESOFS, 0, INT_MAX, NULL, NULL) );
772
773 SCIP_CALL( SCIPaddIntParam(origprob, "heuristics/"HEUR_NAME"/maxnodes",
774 "maximum number of nodes to regard in the subproblem",
775 &heurdata->maxnodes, TRUE, DEFAULT_MAXNODES, 0, INT_MAX, NULL, NULL) );
776
777 SCIP_CALL( SCIPaddIntParam(origprob, "heuristics/"HEUR_NAME"/minnodes",
778 "minimum number of nodes required to start the subproblem",
779 &heurdata->minnodes, TRUE, DEFAULT_MINNODES, 0, INT_MAX, NULL, NULL) );
780
781 SCIP_CALL( SCIPaddRealParam(origprob, "heuristics/"HEUR_NAME"/nodesquot",
782 "contingent of sub problem nodes in relation to the number of nodes of the original problem",
784
785 SCIP_CALL( SCIPaddIntParam(origprob, "heuristics/"HEUR_NAME"/nwaitingnodes",
786 "number of nodes without incumbent change that heuristic should wait",
788
789 SCIP_CALL( SCIPaddRealParam(origprob, "heuristics/"HEUR_NAME"/minimprove",
790 "factor by which "HEUR_NAME" should at least improve the incumbent",
792
793 SCIP_CALL( SCIPaddRealParam(origprob, "heuristics/"HEUR_NAME"/minfixingrate",
794 "minimum percentage of integer variables that have to be fixed",
796
797 SCIP_CALL( SCIPaddBoolParam(origprob, "heuristics/"HEUR_NAME"/uselprows",
798 "should subproblem be created out of the rows in the LP rows?",
800
801 SCIP_CALL( SCIPaddBoolParam(origprob, "heuristics/"HEUR_NAME"/copycuts",
802 "if uselprows == FALSE, should all active cuts from cutpool be copied to constraints in subproblem?",
804
805 return SCIP_OKAY;
806}
SCIP_DECL_HEUREXITSOL(Heur2opt::scip_exitsol)
SCIP_DECL_HEURINIT(Heur2opt::scip_init)
SCIP_DECL_HEURINITSOL(Heur2opt::scip_initsol)
SCIP_DECL_HEURFREE(Heur2opt::scip_free)
SCIP_DECL_HEUREXEC(Heur2opt::scip_exec)
#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 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)
SCIP_STAGE SCIPgetStage(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_Bool SCIPisParamFixed(SCIP *scip, const char *name)
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 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_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_Longint SCIPheurGetNSolsFound(SCIP_HEUR *heur)
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_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(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_SOL * SCIPgetBestSol(SCIP *scip)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_SOLORIGIN SCIPsolGetOrigin(SCIP_SOL *sol)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
SCIP_Longint SCIPsolGetNodenum(SCIP_SOL *sol)
int SCIPgetNSols(SCIP *scip)
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_Longint SCIPgetSolNodenum(SCIP *scip, SCIP_SOL *sol)
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_SOL ** SCIPgetSols(SCIP *scip)
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_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
SCIP_RETCODE SCIPpresolve(SCIP *scip)
SCIP_RETCODE SCIPsolve(SCIP *scip)
SCIP_Real SCIPgetPrimalbound(SCIP *scip)
SCIP_Real SCIPgetUpperbound(SCIP *scip)
SCIP_Longint SCIPgetNNodes(SCIP *scip)
SCIP_Real SCIPgetLowerbound(SCIP *scip)
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
SCIP_Real SCIPgetTotalTime(SCIP *scip)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisZero(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_Real SCIPgetRelaxSolVal(SCIP *scip, SCIP_VAR *var)
SCIP_Bool SCIPisRelaxSolValid(SCIP *scip)
SCIP_RETCODE SCIPchgVarUbGlobal(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
int SCIPsnprintf(char *t, int len, const char *s,...)
SCIPfreeMemory(GCGgetOrigprob(gcg), &divingdata)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
#define HEUR_FREQOFS
#define HEUR_DESC
#define HEUR_DISPCHAR
#define HEUR_MAXDEPTH
#define HEUR_PRIORITY
#define HEUR_NAME
SCIP * origprob
#define HEUR_FREQ
#define DEFAULT_NODESQUOT
#define DEFAULT_NWAITINGNODES
#define DEFAULT_NODESOFS
#define DEFAULT_COPYCUTS
#define DEFAULT_MAXNODES
#define HEUR_TIMING
#define DEFAULT_MINNODES
static SCIP_RETCODE createSubproblem(SCIP *scip, SCIP *subscip, SCIP_VAR **vars, SCIP_VAR **subvars, int nbinvars, int nintvars, SCIP_Bool uselprows, int *fixingcounter, int *zerocounter)
#define DEFAULT_MINIMPROVE
#define DEFAULT_USELPROWS
#define HEUR_USESSUBSCIP
static SCIP_RETCODE createNewSol(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEUR *heur, SCIP_SOL *subsol, SCIP_Bool *success)
SCIP_HASHMAP * varmapfw
* result
SCIP_VAR ** vars
SCIP_Longint ncalls
int nbinvars
int j
int nintvars
SCIP_Bool success
SCIP_Real solval
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
SCIP_RETCODE retcode
int i
static SCIP_HEURDATA * heurdata
int nvars
SCIPfreeBufferArray(scip, &cycles)
#define DEFAULT_MINFIXINGRATE
SCIP_RETCODE GCGincludeHeurGcgrins(GCG *gcg)
LNS heuristic that combines the incumbent with the LP optimum.
SCIP_Bool cutoff
#define NULL
#define SCIPstatisticPrintf
SCIP_RETCODE SCIPincludeDefaultPlugins(SCIP *scip)
SCIP_Longint nodesofs
SCIP_Real nodesquot
SCIP_Longint nwaitingnodes
SCIP_Real minimprove
SCIP_Bool uselprows
SCIP_Bool copycuts
SCIP_Real minfixingrate
SCIP_Longint usednodes
SCIP_Longint maxnodes
SCIP_Longint minnodes
struct SCIP_Cons SCIP_CONS
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_HeurData SCIP_HEURDATA
struct SCIP_Heur SCIP_HEUR
struct SCIP_Row SCIP_ROW
struct SCIP_Col SCIP_COL
SCIP_LPSOLSTAT_OPTIMAL
struct SCIP_HashMap SCIP_HASHMAP
SCIP_PARAMSETTING_OFF
SCIP_PARAMSETTING_FAST
SCIP_DIDNOTRUN
SCIP_DELAYED
SCIP_DIDNOTFIND
SCIP_FOUNDSOL
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_SOLVING
struct SCIP_Sol SCIP_SOL
SCIP_SOLORIGIN_ORIGINAL
struct SCIP_Var SCIP_VAR