GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
heur_gcgfeaspump.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_gcgfeaspump.c
30 * @brief Objective Feasibility Pump 2.0
31 * @author Timo Berthold
32 * @author Domenico Salvagnin
33 * @author Christian Puchert
34 */
35
36/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
37
38#include <assert.h>
39#include <string.h>
40
42#include "gcg/gcg.h"
43
44#include "scip/scipdefplugins.h"
45#include "scip/cons_linear.h"
46#include "scip/misc.h"
47
48
49#define HEUR_NAME "gcgfeaspump"
50#define HEUR_DESC "objective feasibility pump 2.0"
51#define HEUR_DISPCHAR 'F'
52#define HEUR_PRIORITY -1000000
53#define HEUR_FREQ -1
54#define HEUR_FREQOFS 0
55#define HEUR_MAXDEPTH -1
56#define HEUR_TIMING SCIP_HEURTIMING_AFTERPLUNGE
57#define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
58
59#define DEFAULT_MAXLPITERQUOT 0.01 /**< maximal fraction of diving LP iterations compared to node LP iterations */
60#define DEFAULT_MAXLPITEROFS 1000 /**< additional number of allowed LP iterations */
61#define DEFAULT_MAXSOLS 10 /**< total number of feasible solutions found up to which heuristic is called
62 * (-1: no limit) */
63#define DEFAULT_MAXLOOPS 10000 /**< maximal number of pumping rounds (-1: no limit) */
64#define DEFAULT_MAXSTALLLOOPS 10 /**< maximal number of pumping rounds without fractionality improvement (-1: no limit) */
65#define DEFAULT_MINFLIPS 10 /**< minimum number of random variables to flip, if a 1-cycle is encountered */
66#define DEFAULT_CYCLELENGTH 3 /**< maximum length of cycles to be checked explicitly in each round */
67#define DEFAULT_PERTURBFREQ 100 /**< number of iterations until a random perturbation is forced */
68#define DEFAULT_OBJFACTOR 1.0 /**< factor by which the regard of the objective is decreased in each round,
69 * 1.0 for dynamic, depending on solutions already found */
70#define DEFAULT_ALPHADIFF 1.0 /**< threshold difference for the convex parameter to perform perturbation */
71#define DEFAULT_USEFP20 FALSE /**< should an iterative round-and-propagate scheme be used to find the integral points? */
72#define DEFAULT_PERTSOLFOUND TRUE /**< should a random perturbation be performed if a feasible solution was found? */
73#define DEFAULT_STAGE3 FALSE /**< should we solve a local branching sub-MIP if no solution could be found? */
74#define DEFAULT_NEIGHBORHOODSIZE 18 /**< radius of the neighborhood to be searched in stage 3 */
75#define DEFAULT_COPYCUTS TRUE /**< should all active cuts from the cutpool of the original SCIP be copied to
76 * constraints of the subscip
77 */
78
79#define MINLPITER 5000 /**< minimal number of LP iterations allowed in each LP solving call */
80
81#define DEFAULT_RANDSEED 13 /**< initial random seed */
82
83
84/** primal heuristic data */
85struct SCIP_HeurData
86{
87 GCG* gcg; /**< GCG data structure */
88 SCIP_SOL* sol; /**< working solution */
89 SCIP_SOL* roundedsol; /**< rounded solution */
90 SCIP_Longint nlpiterations; /**< number of LP iterations used in this heuristic */
91 SCIP_Real maxlpiterquot; /**< maximal fraction of diving LP iterations compared to node LP iterations */
92 SCIP_Real objfactor; /**< factor by which the regard of the objective is decreased in each round,
93 * 1.0 for dynamic, depending on solutions already found */
94 SCIP_Real alphadiff; /**< threshold difference for the convex parameter to perform perturbation */
95
96 int maxlpiterofs; /**< additional number of allowed LP iterations */
97 int maxsols; /**< total number of feasible solutions found up to which heuristic is called
98 * (-1: no limit) */
99 int maxloops; /**< maximum number of loops (-1: no limit) */
100 int maxstallloops; /**< maximal number of pumping rounds without fractionality improvement (-1: no limit) */
101 int minflips; /**< minimum number of random variables to flip, if a 1-cycle is encountered */
102 int cyclelength; /**< maximum length of cycles to be checked explicitly in each round */
103 int perturbfreq; /**< number of iterations until a random perturbation is forced */
104 int nsuccess; /**< number of runs that produced at least one feasible solution */
105 int neighborhoodsize; /**< radius of the neighborhood to be searched in stage 3 */
106
107 SCIP_RANDNUMGEN* randnumgen; /**< random number generator */
108 SCIP_Bool usefp20; /**< should an iterative round-and-propagate scheme be used to find the integral points? */
109 SCIP_Bool pertsolfound; /**< should a random perturbation be performed if a feasible solution was found? */
110 SCIP_Bool stage3; /**< should we solve a local branching sub-MIP if no solution could be found? */
111 SCIP_Bool copycuts; /**< should all active cuts from cutpool be copied to constraints in
112 * subproblem?
113 */
114};
115
116/** copies SCIP to diving SCIP and creates variable hashmap */
117static
119 SCIP* scip, /**< SCIP data structure */
120 SCIP** divingscip, /**< diving SCIP data structure */
121 SCIP_HASHMAP** varmapfw, /**< mapping of SCIP variables to sub-SCIP variables */
122 SCIP_Bool copycuts, /**< should all active cuts from cutpool of scip copied to constraints in probingscip */
123 SCIP_Bool* success /**< was copying successful? */
124 )
125{
126 SCIP_VAR** subvars;
127 SCIP_VAR** tmpsubvars;
128 int nsubvars;
129
130 int i;
131
132 /* initialize the subproblem */
134
135 /* create the variable mapping hash map */
137 *success = FALSE;
138
139 /* copy SCIP instance */
141
142 if( copycuts )
143 {
144 /* copies all active cuts from cutpool of sourcescip to linear constraints in targetscip */
146 }
147
148 /* change all variable types to 'continuous' */
149 SCIP_CALL( SCIPgetVarsData(*divingscip, &tmpsubvars, &nsubvars, NULL, NULL, NULL, NULL) );
150 SCIP_CALL( SCIPduplicateBufferArray(*divingscip, &subvars, tmpsubvars, nsubvars) );
151 for( i = 0; i < nsubvars; ++i )
152 {
153 SCIP_Bool infeasible;
154 SCIP_CALL( SCIPchgVarType(*divingscip, subvars[i], SCIP_VARTYPE_CONTINUOUS, &infeasible) );
155 assert(!infeasible);
156 }
158
159 /* do not abort subproblem on CTRL-C */
160 SCIP_CALL( SCIPsetBoolParam(*divingscip, "misc/catchctrlc", FALSE) );
161
162 /* disable output to console */
163 SCIP_CALL( SCIPsetIntParam(*divingscip, "display/verblevel", 0) );
164
165 /* disable cutting plane separation */
167
168 /* disable expensive presolving */
170
171 /* disable heuristics */
173
174 /* disable conflict analysis */
175 if( !SCIPisParamFixed(*divingscip, "conflict/enable") )
176 {
177 SCIP_CALL( SCIPsetBoolParam(*divingscip, "conflict/enable", FALSE) );
178 }
179
180 /* set the node limit to 1 (this is an LP, so we do not branch) */
181 SCIP_CALL( SCIPsetLongintParam(*divingscip, "limits/nodes", 1LL) );
182
183 return SCIP_OKAY;
184}
185
186/* get the solution of the diving LP */
187static
189 SCIP* scip, /**< SCIP data structure */
190 SCIP* divingscip, /**< diving SCIP data structure */
191 SCIP_HASHMAP* varmapfw, /**< mapping of SCIP variables to sub-SCIP variables */
192 SCIP_SOL* lpsol /**< data structure to store the solution */
193 )
194{
195 SCIP_SOL* subsol;
196 SCIP_VAR** vars;
197 int nvars;
198 int i;
199
200 assert(scip != NULL);
202 assert(varmapfw != NULL);
203 assert(lpsol != NULL);
204
205 /* get diving lp solution */
206 subsol = SCIPgetBestSol(divingscip);
207 assert(subsol != NULL);
208
209 /* get original SCIP variables */
211
212 /* set solution values */
213 for( i = 0; i < nvars; ++i )
214 {
215 SCIP_VAR* subvar;
216
218 assert(subvar != NULL);
219
220 SCIP_CALL( SCIPsetSolVal(scip, lpsol, vars[i], SCIPgetSolVal(divingscip, subsol, subvar)) );
221 }
222
223 return SCIP_OKAY;
224}
225
226/* get the number of fractional variables in the diving LP solution that should be integral */
227static
229 SCIP* scip, /**< SCIP data structure */
230 SCIP_SOL* lpsol, /**< data structure to store the solution */
231 int* nfracs /**< pointer to store number of fractional variables */
232 )
233{
234 SCIP_VAR** vars;
235 int nbinvars;
236 int nintvars;
237 int i;
238
239 assert(scip != NULL);
240 assert(lpsol != NULL);
241 assert(nfracs != NULL);
242
243 /* get original SCIP variables */
245
246 /* count number of fractionals that should be integral */
247 *nfracs = 0;
248 for( i = 0; i < nbinvars + nintvars; ++i )
250 ++(*nfracs);
251
252 return SCIP_OKAY;
253}
254
255/* copies SCIP to probing SCIP and creates variable hashmap */
256static
258 SCIP* scip, /**< SCIP data structure */
259 SCIP** probingscip, /**< sub-SCIP data structure */
260 SCIP_HASHMAP** varmapfw, /**< mapping of SCIP variables to sub-SCIP variables */
261 SCIP_Bool copycuts, /**< should all active cuts from cutpool of scip copied to constraints in probingscip */
262 SCIP_Bool* success /**< was copying successful? */
263 )
264{
265 /* initializing the subproblem */
267
268 /* create the variable mapping hash map */
270 *success = FALSE;
271
272 /* copy SCIP instance */
273 SCIP_CALL( SCIPcopy(scip, *probingscip, *varmapfw, NULL, "gcgfeaspump_probing", FALSE, FALSE, FALSE, TRUE, success) );
274
275 if( copycuts )
276 {
277 /* copies all active cuts from cutpool of sourcescip to linear constraints in targetscip */
279 }
280
281 return SCIP_OKAY;
282}
283
284/** checks whether a variable is one of the currently most fractional ones */
285static
287 SCIP_VAR** mostfracvars, /**< sorted array of the currently most fractional variables */
288 SCIP_Real* mostfracvals, /**< array of their fractionality, decreasingly sorted */
289 int* nflipcands, /**< number of fractional variables already labeled to be flipped*/
290 int maxnflipcands, /**< typically randomized number of maximum amount of variables to flip */
291 SCIP_VAR* var, /**< variable to be checked */
292 SCIP_Real frac /**< fractional value of the variable */
293 )
294{
295 int i;
296
300
301 /* instead of the fractional value use the fractionality */
302 if( frac > 0.5 )
303 frac = 1 - frac;
304
305 /* if there are already enough candidates and the variable is less fractional, return, else reserve the last entry */
306 if( *nflipcands >= maxnflipcands )
307 {
308 if( frac <= mostfracvals[*nflipcands-1] )
309 return;
310 else
311 (*nflipcands)--;
312 }
313
314 /* shifting var and frac through the (sorted) arrays */
315 for( i = *nflipcands; i > 0 && mostfracvals[i-1] < frac; i-- )
316 {
319 }
320 assert(0 <= i && i <= *nflipcands && *nflipcands < maxnflipcands);
321
322 /* insert the variable and its fractionality */
323 mostfracvars[i] = var;
325
326 /* we've found another candidate */
327 (*nflipcands)++;
328}
329
330/** flips the roundings of the most fractional variables, if a 1-cycle was found */
331static
333 SCIP* scip, /**< SCIP data structure */
334 SCIP* divingscip, /**< diving SCIP data structure */
335 SCIP_HASHMAP* varmapfw, /**< mapping of SCIP variables to sub-SCIP variables */
336 SCIP_HEURDATA* heurdata, /**< data of this special heuristic */
337 SCIP_VAR** mostfracvars, /**< sorted array of the currently most fractional variables */
338 int nflipcands, /**< number of variables to flip */
339 SCIP_Real alpha /**< factor how much the original objective is regarded */
340 )
341{
342 int i;
343
344 /* just flipping the objective coefficients from +1 to -1 and the rounding from floor to ceil */
345 for( i = 0; i < nflipcands; i++ )
346 {
347 SCIP_VAR* var;
348 SCIP_VAR* divingvar;
353
354 var = mostfracvars[i];
358
359 if( frac > 0.5 )
360 {
361 newobjcoeff = (1.0 - alpha) + alpha * orgobjcoeff;
363 }
364 else
365 {
366 newobjcoeff = - (1.0 - alpha) + alpha * orgobjcoeff;
368 }
369 /* updating the rounded solution and the objective */
371 divingvar = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, var);
373 }
374 return SCIP_OKAY;
375}
376
377/** flips the roundings of randomly chosen fractional variables, preferring highly fractional ones,
378 * if a longer cycle was found
379 */
380static
382 SCIP* scip, /**< SCIP data structure */
383 SCIP* divingscip, /**< diving SCIP data structure */
384 SCIP_HASHMAP* varmapfw, /**< mapping of SCIP variables to sub-SCIP variables */
385 SCIP_HEURDATA* heurdata, /**< data of this special heuristic */
386 SCIP_VAR** vars, /**< array of all variables */
387 int nbinandintvars, /**< number of general integer and 0-1 variables */
388 SCIP_Real alpha /**< factor how much the original objective is regarded */
389 )
390{
391 int i;
392
393 /* just flipping the objective coefficients from +1 to -1 and the rounding from floor to ceil */
394 for( i = 0; i < nbinandintvars; i++ )
395 {
396 SCIP_VAR* var;
400 SCIP_Real flipprob;
401
402 /* decide arbitrarily whether the variable will be flipped or not */
403 var = vars[i];
407 flipprob = -0.3 + SCIPrandomGetReal(heurdata->randnumgen, 0.0, 1.0);
408
409 /* flip, iff the sum of the randomized number and the fractionality is big enough */
410 if( MIN(frac, 1.0-frac) + MAX(flipprob, 0.0) > 0.5 )
411 {
413 SCIP_VAR* divingvar;
414
415 if( frac > 0.5 )
416 {
417 newobjcoeff = (1.0 - alpha) + alpha * orgobjcoeff;
419 }
420 else
421 {
422 newobjcoeff = - (1.0 - alpha) + alpha * orgobjcoeff;
424 }
426 divingvar = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, var);
428 }
429 }
430
431 return SCIP_OKAY;
432}
433
434/** create the extra constraint of local branching and add it to subscip */
435static
437 SCIP* scip, /**< SCIP data structure of the original problem */
438 SCIP* probingscip, /**< SCIP data structure of the subproblem */
439 SCIP_HASHMAP* varmapfw, /**< mapping of SCIP variables to sub-SCIP variables */
440 SCIP_SOL* bestsol, /**< SCIP solution */
441 SCIP_Real neighborhoodsize /**< rhs for LB constraint */
442 )
443{
444 SCIP_CONS* cons; /* local branching constraint to create */
445 SCIP_VAR** consvars;
446 SCIP_VAR** vars;
447
448 int nbinvars;
449 int i;
450 SCIP_Real lhs;
451 SCIP_Real rhs;
452 SCIP_Real* consvals;
453 char consname[SCIP_MAXSTRLEN];
454
455 (void) SCIPsnprintf(consname, SCIP_MAXSTRLEN, "%s_localbranchcons", SCIPgetProbName(scip));
456
457 /* get vars data */
459 /* memory allocation */
462
463 /* set initial left and right hand sides of local branching constraint */
464 lhs = 0.0;
465 rhs = neighborhoodsize;
466
467 /* create the distance (to incumbent) function of the binary variables */
468 for( i = 0; i < nbinvars; i++ )
469 {
471
472 solval = SCIPgetSolVal(scip, bestsol, vars[i]);
474
475 /* is variable i part of the binary support of closest sol? */
476 if( SCIPisFeasEQ(scip,solval,1.0) )
477 {
478 consvals[i] = -1.0;
479 rhs -= 1.0;
480 lhs -= 1.0;
481 }
482 else
483 consvals[i] = 1.0;
484 consvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
485 SCIP_CALL( SCIPchgVarObj(probingscip, consvars[i], consvals[i]) );
487 }
488
489 /* creates localbranching constraint and adds it to subscip */
490 SCIP_CALL( SCIPcreateConsLinear(probingscip, &cons, consname, nbinvars, consvars, consvals,
491 lhs, rhs, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
494
495 /* free local memory */
496 SCIPfreeBufferArray(scip, &consvals);
497 SCIPfreeBufferArray(scip, &consvars);
498
499 return SCIP_OKAY;
500}
501
502/** creates new solutions for the original problem by copying the solutions of the subproblem */
503static
505 SCIP* scip, /**< original SCIP data structure */
506 SCIP* subscip, /**< SCIP structure of the subproblem */
507 SCIP_HASHMAP* varmapfw, /**< mapping of SCIP variables to sub-SCIP variables */
508 SCIP_HEUR* heur, /**< heuristic structure */
509 SCIP_Bool* success /**< used to store whether new solution was found or not */
510 )
511{
512 SCIP_VAR** vars; /* the original problem's variables */
513 int nvars;
514 SCIP_SOL** subsols;
515 int nsubsols;
516 SCIP_VAR** subvars;
517 SCIP_Real* subsolvals; /* solution values of the subproblem */
518 SCIP_SOL* newsol; /* solution to be created for the original problem */
519 int i;
520
521 assert(scip != NULL);
522 assert(subscip != NULL);
523
524 /* get variables' data */
526
527 /* sub-SCIP may have more variables than the number of active (transformed) variables in the main SCIP
528 * since constraint copying may have required the copy of variables that are fixed in the main SCIP
529 */
530 assert(nvars <= SCIPgetNOrigVars(subscip));
531
532 /* for copying a solution we need an explicit mapping */
534 for( i = 0; i < nvars; i++ )
535 subvars[i] = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, vars[i]);
536
537 SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
538
539 nsubsols = SCIPgetNSols(subscip);
540 subsols = SCIPgetSols(subscip);
541 *success = FALSE;
542
543 for( i = 0; i < nsubsols && !(*success); ++i )
544 {
545 /* copy the solution */
546 SCIP_CALL( SCIPgetSolVals(subscip, subsols[i], nvars, subvars, subsolvals) );
547
548 /* create new solution for the original problem */
549 SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
550 SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, subsolvals) );
551
552 /* try to add new solution to scip and free it immediately */
554 }
555
556 SCIPfreeBufferArray(scip, &subvars);
557 SCIPfreeBufferArray(scip, &subsolvals);
558
559 return SCIP_OKAY;
560}
561
562/** destructor of primal heuristic to free user data (called when SCIP is exiting) */
563static
564SCIP_DECL_HEURFREE(heurFreeGcgfeaspump)
565{
567
568 assert(heur != NULL);
569 assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
570 assert(scip != NULL);
571
572 /* free heuristic data */
574 assert(heurdata != NULL);
576 SCIPheurSetData(heur, NULL);
577
578 return SCIP_OKAY;
579}
580
581
582/** initialization method of primal heuristic (called after problem was transformed) */
583static
584SCIP_DECL_HEURINIT(heurInitGcgfeaspump)
585{
587
588 assert(heur != NULL);
589 assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
590
591 /* get heuristic data */
593 assert(heurdata != NULL);
594
595 /* create working solution */
598
599 /* initialize data */
601 heurdata->nsuccess = 0;
602
603 /* create random number generator */
606
607 return SCIP_OKAY;
608}
609
610/** deinitialization method of primal heuristic (called before transformed problem is freed) */
611static
612SCIP_DECL_HEUREXIT(heurExitGcgfeaspump)
613{
615
616 assert(heur != NULL);
617 assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
618
619 /* get heuristic data */
621 assert(heurdata != NULL);
622
623 /* free random number generator */
625
626 /* free working solution */
629
630 return SCIP_OKAY;
631}
632
633
634/** calculates an adjusted maximal number of LP iterations */
635static
637 SCIP_Longint maxnlpiterations, /**< regular maximal number of LP iterations */
638 SCIP_Longint nsolsfound, /**< total number of solutions found so far by SCIP */
639 int nstallloops /**< current number of stalling rounds */
640 )
641{
642 if( nstallloops <= 1 )
643 {
644 if( nsolsfound == 0 )
645 return 4*maxnlpiterations;
646 else
647 return 2*maxnlpiterations;
648 }
649 else
650 return maxnlpiterations;
651}
652
653/** execution method of primal heuristic */
654static
655SCIP_DECL_HEUREXEC(heurExecGcgfeaspump) /*lint --e{715}*/
656{
659 SCIP_SOL* tmpsol; /* only used for swapping */
660 SCIP_SOL** lastroundedsols;/* solutions of the last pumping rounds (depending on heurdata->cyclelength) */
661 SCIP_SOL* closestsol; /* rounded solution closest to the LP relaxation: used for stage3 */
662 SCIP_Real* lastalphas; /* alpha values associated to solutions in lastroundedsols */
663
664 SCIP* divingscip; /* copied SCIP structure, used for solving diving LPs */
665 SCIP* probingscip; /* copied SCIP structure, used for round-and-propagate loop of feasibility pump 2.0 */
666 SCIP_HASHMAP* varmapfwdive; /* mapping of SCIP variables to diving SCIP variables */
667 SCIP_HASHMAP* varmapfw; /* mapping of SCIP variables to probing SCIP variables */
668
669
673 SCIP_VAR** mostfracvars; /* the 30 most fractional variables, needed to avoid 1-cycles */
675
676 SCIP_Real* mostfracvals; /* the values of the variables above */
677 SCIP_Real newobjcoeff; /* used for changing the objective */
678 SCIP_Real orgobjcoeff; /* used for regarding the original objective */
679 SCIP_Real oldsolval; /* one value of the last solution */
680 SCIP_Real solval; /* one value of the actual solution */
681 SCIP_Real frac; /* the fractional part of the value above */
682 SCIP_Real objfactor; /* factor by which the regard of the objective is decreased in each round, in [0,0.99] */
683 SCIP_Real alpha; /* factor how the original objective is regarded, used for convex combination of two functions */
684 SCIP_Real objnorm; /* Euclidean norm of the objective function, used for scaling */
685 SCIP_Real scalingfactor; /* factor to scale the original objective function with */
686 SCIP_Real mindistance; /* distance of the closest rounded solution from the LP relaxation: used for stage3 */
687
688 SCIP_Longint nlpiterations; /* number of LP iterations performed so far */
689 SCIP_Longint maxnlpiterations; /* maximum number of LP iterations for this heuristic */
690 SCIP_Longint nsolsfound; /* number of solutions found by this heuristic */
691 SCIP_Longint ncalls; /* number of calls of this heuristic */
692 SCIP_Longint nbestsolsfound; /* current total number of best solution updates in SCIP */
693
694 int nvars; /* number of variables */
695 int nbinvars; /* number of 0-1-variables */
696 int nintvars; /* number of integer variables */
697 int nfracs; /* number of fractional variables updated after each pumping round*/
698 int nflipcands; /* how many flipcands (most frac. var.) have been found */
700 int nloops; /* how many pumping rounds have been made */
701 int maxflips; /* maximum number of flips, if a 1-cycle is found (depending on heurdata->minflips) */
702 int maxloops; /* maximum number of pumping rounds */
703 int nstallloops; /* number of loops without reducing the current best number of factional variables */
704 int maxstallloops; /* maximal number of allowed stalling loops */
705 int bestnfracs; /* best number of fractional variables */
706 int i;
707 int j;
708
710 SCIP_Bool* cycles; /* are there short cycles */
711
713
714 assert(heur != NULL);
715 assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
718
719 /* get heuristic data */
722
723
724 /* get master problem */
727
729
730 /* do not execute the heuristic on invalid relaxation solutions
731 * (which is the case if the node has been cut off)
732 */
734 return SCIP_OKAY;
735
736 /* only call heuristic, if an optimal LP solution is at hand */
738 return SCIP_OKAY;
739
741
742 /* only call feaspump once at the root */
743 if( SCIPgetDepth(scip) == 0 && SCIPheurGetNCalls(heur) > 0 )
744 return SCIP_OKAY;
745
746 /* only apply heuristic, if only a few solutions have been found and no pricer exists */
748 return SCIP_OKAY;
749
750 /* get all variables of LP and number of fractional variables in LP solution that should be integral */
753 assert(0 <= nfracs && nfracs <= nbinvars + nintvars);
754 if( nfracs == 0 )
755 return SCIP_OKAY;
756
757 /* calculate the maximal number of LP iterations until heuristic is aborted */
763
764 /* don't try to dive, if we took too many LP iterations during diving */
766 return SCIP_OKAY;
767
768 /* at the first root call, allow more iterations if there is no feasible solution yet */
769 if( SCIPheurGetNCalls(heur) == 0 && SCIPgetNSolsFound(scip) == 0 && SCIPgetDepth(scip) == 0 )
771
772 /* allow at least a certain number of LP iterations in this dive */
774
775 /* calculate maximal number of flips and loops */
777 maxloops = (heurdata->maxloops == -1 ? INT_MAX : heurdata->maxloops);
779
780 SCIPdebugMessage("executing GCG feasibility pump heuristic, nlpiters=%"SCIP_LONGINT_FORMAT", maxnlpit:%"SCIP_LONGINT_FORMAT", maxflips:%d \n",
782
784
786 varmapfw = NULL;
787
788 if( heurdata->usefp20 )
789 {
791
792 if( success )
793 {
794 if( SCIPisParamFixed(probingscip, "heuristics/"HEUR_NAME"/freq") )
795 {
796 SCIPwarningMessage(scip, "unfixing parameter heuristics/"HEUR_NAME"/freq in probingscip of "HEUR_NAME" heuristic to avoid recursive calls\n");
797 SCIP_CALL( SCIPunfixParam(probingscip, "heuristics/"HEUR_NAME"/freq") );
798 }
799 SCIP_CALL( SCIPsetIntParam(probingscip, "heuristics/"HEUR_NAME"/freq", -1) );
800
801 /* do not abort subproblem on CTRL-C */
802 SCIP_CALL( SCIPsetBoolParam(probingscip, "misc/catchctrlc", FALSE) );
803
804#ifndef SCIP_DEBUG
805 /* disable output to console */
806 SCIP_CALL( SCIPsetIntParam(probingscip, "display/verblevel", 0) );
807#endif
808
809 /* do presolve and initialize solving */
810 SCIP_CALL( SCIPsetLongintParam(probingscip, "limits/nodes", 1LL) );
811 if( SCIPisParamFixed(probingscip, "lp/solvefreq") )
812 {
813 SCIPwarningMessage(scip, "unfixing parameter lp/solvefreq in probingscip of "HEUR_NAME" heuristic to avoid recursive calls\n");
814 SCIP_CALL( SCIPunfixParam(probingscip, "lp/solvefreq") );
815 }
816 SCIP_CALL( SCIPsetIntParam(probingscip, "lp/solvefreq", -1) );
817
818 /* disable expensive presolving */
821
822 /* errors in solving the subproblem should not kill the overall solving process;
823 * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop. */
824 if( retcode != SCIP_OKAY )
825 {
826#ifndef NDEBUG
828#endif
829 SCIPwarningMessage(scip, "Error while solving subproblem in feaspump heuristic; sub-SCIP terminated with code <%d>\n", retcode);
830
831 /* free hash map and copied SCIP */
834 return SCIP_OKAY;
835 }
836
838 {
839 SCIP_STATUS probingstatus = SCIPgetStatus(probingscip);
840
841 if( probingstatus == SCIP_STATUS_OPTIMAL )
842 {
845 if( success )
847 }
848
849 /* free hash map and copied SCIP */
852 return SCIP_OKAY;
853 }
854 SCIP_CALL( SCIPsetLongintParam(probingscip, "limits/nodes", 2LL) );
855
856 /* set SCIP into probing mode and create root node of the probing tree */
859
860 SCIPdebugMessage("successfully copied SCIP instance -> feasibility pump 2.0 can be used.\n");
861 }
862 }
863
864 /* memory allocation */
870
871 for( j = 0; j < heurdata->cyclelength; j++ )
872 {
874 }
875
878 {
880 }
881
882 /* setup the diving SCIP */
884
885 /* pumping rounds */
887 if( heurdata->objfactor == 1.0 )
888 objfactor = MIN(1.0 - 0.1 / (SCIP_Real)(1 + nsolsfound), 0.999);
889 else
891
892 /* scale distance function and original objective to the same norm */
894 objnorm = MAX(objnorm, 1.0);
896
897 /* data initialization */
898 alpha = 1.0;
899 nloops = 0;
900 nstallloops = 0;
902 bestnfracs = INT_MAX;
904
907
908 /* pumping loop */
909 while( nfracs > 0
912 && !SCIPisStopped(scip) )
913 {
914 int minimum;
915 SCIP_Real* pseudocandsfrac;
916 int maxnflipcands; /* maximal number of candidates to flip in the current pumping round */
917 SCIP_Longint nlpiterationsleft;
918 SCIP_Longint iterlimit;
919
920 /* decrease convex combination scalar */
921 nloops++;
922 alpha *= objfactor;
923
924 SCIPdebugMessage("feasibility pump loop %d: %d fractional variables (alpha: %.4f, stall: %d/%d)\n",
926
927 success = FALSE;
928
930
931 /* if the rounded solution is feasible and better, add it to SCIP */
932 if( success )
933 {
935 if( success )
937 }
938
939 /* randomly choose maximum number of variables to flip in current pumping round in case of a 1-cycle */
941 nflipcands = 0;
942
943 /* get all unfixed integer variables */
946
947 /* get array of all fractional variables and sort it w.r.t. their fractionalities */
948 if( heurdata->usefp20 )
949 {
950 SCIP_CALL( SCIPallocBufferArray(scip, &pseudocandsfrac, npseudocands) );
951
952 for( i = 0; i < npseudocands; i++ )
953 {
955 pseudocandsfrac[i] = MIN(frac, 1.0-frac); /* always a number between 0 and 0.5 */
957 pseudocandsfrac[i] -= 10.0; /* binaries always come first */
958 }
959 SCIPsortRealPtr(pseudocandsfrac, (void**)pseudocands, npseudocands);
960 SCIPfreeBufferArray(scip, &pseudocandsfrac);
961
962 SCIPdebugMessage("iteratively fix and propagate variables\n");
963 }
964
965 for( i = 0; i < npseudocands; i++ )
966 {
967 SCIP_VAR* divingvar;
968 SCIP_Bool infeasible;
969 SCIP_Longint ndomreds;
970
971 var = pseudocands[i];
973
974 /* round the LP solution */
977
978 solval = SCIPfloor(scip, solval+0.5);
979
980 /* ensure, that the fixing value is inside the local domains */
981 if( heurdata->usefp20 )
982 {
983 SCIP_VAR* probingvar;
984 SCIP_Real lb;
985 SCIP_Real ub;
986
987 probingvar = (SCIP_VAR*) SCIPhashmapGetImage(varmapfw, var);
988 lb = SCIPvarGetLbLocal(probingvar);
989 ub = SCIPvarGetUbLocal(probingvar);
990
991 solval = MAX(solval, lb);
992 solval = MIN(solval, ub);
993
994 /* fix the variable and propagate the domain change */
995 if( !SCIPisFeasEQ(probingscip, lb, ub) )
996 {
999
1001 SCIPdebugMessage("try to fix variable <%s> (domain [%f,%f] to %f\n",SCIPvarGetName(probingvar), lb, ub,
1002 solval);
1003 SCIP_CALL( SCIPpropagateProbing(probingscip, 3, &infeasible, &ndomreds) );
1004 SCIPdebugMessage(" -> reduced %"SCIP_LONGINT_FORMAT" domains\n", ndomreds);
1005
1006 if( infeasible )
1007 {
1008 SCIPdebugMessage(" -> infeasible!\n");
1010 }
1011 }
1012 else
1013 {
1014 SCIPdebugMessage("variable <%s> is already fixed to %f\n",SCIPvarGetName(probingvar), solval);
1015 }
1016 }
1017
1020
1021 /* variables which are already integral, are treated separately */
1022 if( SCIPisFeasZero(scip, frac) )
1023 {
1024 SCIP_Real lb;
1025 SCIP_Real ub;
1026
1027 /* variables at their bounds should be kept there */
1028 lb = SCIPvarGetLbLocal(var);
1029 ub = SCIPvarGetUbLocal(var);
1030 if( SCIPisFeasEQ(scip, solval, lb) )
1032 else if( SCIPisFeasEQ(scip, solval, ub) )
1034 else
1036 }
1037 else
1038 {
1039 /* check whether the variable is one of the most fractionals and label if so */
1041
1042 if( frac > 0.5 )
1044 else
1046 }
1047
1048 /* change one coefficient of the objective */
1051 }
1052
1053 if( heurdata->usefp20 )
1054 {
1056 }
1057
1058 /* change objective coefficients for continuous variables */
1059 for( i = nbinvars+nintvars; i < nvars; i++ )
1060 {
1061 SCIP_VAR* divingvar;
1064 }
1065
1067
1068 /* initialize cycle check */
1069 minimum = MIN(heurdata->cyclelength, nloops-1);
1070 for( j = 0; j < heurdata->cyclelength; j++ )
1071 cycles[j] = (nloops > j+1) && (REALABS(lastalphas[j] - alpha) < heurdata->alphadiff);
1072
1073 /* check for j-cycles */
1074 for( i = 0; i < nbinvars+nintvars; i++ )
1075 {
1077
1078 /* cycles exist, iff all solution values are equal */
1079 for( j = 0; j < minimum; j++ )
1080 {
1083 }
1084 }
1085
1086 /* force to flip variables at random after a couple of pumping rounds,
1087 * or if a new best solution in the current region has been found
1088 */
1091 {
1092 SCIPdebugMessage(" -> random perturbation\n");
1095 }
1096 else
1097 {
1098 minimum = MIN(heurdata->cyclelength, nloops-1);
1099
1100 for( j = 0; j < minimum; j++ )
1101 {
1102 /* if we got the same rounded solution as in some step before, we have to flip some variables */
1103 if( cycles[j] )
1104 {
1105 /* 1-cycles have a special flipping rule (flip most fractional variables) */
1106 if( j == 0 )
1107 {
1108 SCIPdebugMessage(" -> avoiding 1-cycle: flipping %d candidates\n", nflipcands);
1110 }
1111 else
1112 {
1113 SCIPdebugMessage(" -> avoiding %d-cycle by random flip\n", j+1);
1115 }
1116 break;
1117 }
1118 }
1119 }
1120
1121 /* the LP with the new (distance) objective is solved */
1123 iterlimit = MAX((int)nlpiterationsleft, MINLPITER);
1124 SCIP_CALL( SCIPsetLongintParam(divingscip, "lp/iterlim", iterlimit) );
1125 SCIPdebugMessage(" -> solve LP with iteration limit %"SCIP_LONGINT_FORMAT"\n", iterlimit);
1126
1127 if( heurdata->stage3 )
1128 {
1130 }
1131
1132 /* solve the subproblem */
1134
1135 /* errors in solving the subproblem should not kill the overall solving process;
1136 * hence, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
1137 */
1138 if( retcode != SCIP_OKAY )
1139 {
1140#ifndef NDEBUG
1141 SCIP_CALL( retcode );
1142#endif
1143 SCIPwarningMessage(scip, "Error while solving subproblem in Feasibility Pump heuristic; sub-SCIP terminated with code <%d>\n",retcode);;
1144 SCIPwarningMessage(scip, "This does not affect the remaining solution procedure --> continue\n");
1145 }
1146
1147 /* update iteration count */
1149 SCIPdebugMessage(" -> number of iterations: %"SCIP_LONGINT_FORMAT"/%"SCIP_LONGINT_FORMAT", status=%d\n",
1151
1152 /* check whether LP was solved to optimality */
1154 {
1155 SCIPdebugMessage(" -> solstat is %d\n", SCIPgetStatus(divingscip));
1156 SCIPdebugMessage(" -> diving LP was not solved to optimality --> abort heuristic\n");
1157 break;
1158 }
1159
1160 /* get diving LP solution */
1162
1163 if( heurdata->stage3 )
1164 {
1165 SCIP_Real distance; /* distance of the current rounded solution from the LP solution */
1166
1168
1169 /* calculate distance */
1170 distance = 0.0;
1171 for( i = 0; i < nbinvars+nintvars; i++ )
1172 {
1173 SCIP_Real roundedval;
1174 SCIP_Real lpval;
1175
1176 roundedval = SCIPgetSolVal(scip, heurdata->roundedsol, vars[i]);
1177 lpval = SCIPgetSolVal(scip, heurdata->sol, vars[i]);
1178 distance += REALABS(roundedval - lpval);
1179 }
1180
1181 /* copy solution and update minimum distance */
1182 if( SCIPisLT(scip, distance, mindistance) )
1183 {
1184 for( i = 0; i < nbinvars+nintvars; i++ )
1185 {
1188 }
1189 mindistance = distance;
1190 }
1191 }
1192
1193 /* swap the last solutions */
1195 for( j = heurdata->cyclelength-1; j > 0; j-- )
1196 {
1198 lastalphas[j] = lastalphas[j-1];
1199 }
1201 lastalphas[0] = alpha;
1203
1205
1206 /* check for improvement in number of fractionals */
1208 if( nfracs < bestnfracs )
1209 {
1211 nstallloops = 0;
1212 }
1213 else
1214 nstallloops++;
1215
1216 /* reset the diving subSCIP */
1218
1219 SCIPdebugMessage(" -> loop finished: %d fractional variables (stall: %d/%d, iterations: %"SCIP_LONGINT_FORMAT"/%"SCIP_LONGINT_FORMAT")\n",
1221 }
1222
1223 /* try final solution, if no more fractional variables are left */
1224 if( nfracs == 0 )
1225 {
1226 success = FALSE;
1227
1229 if( success )
1231 }
1232
1233 /* free diving SCIP instance */
1236
1237 /* end probing in order to be able to apply stage 3 */
1238 if( heurdata->usefp20 )
1239 {
1241 }
1242
1243 /* only do stage 3 if we have not found a solution yet */
1244 /* only do stage 3 if the distance of the closest infeasible solution to the polyhedron is below a certain threshold */
1246 {
1247 /* setup some parameters for the sub-SCIP */
1248 SCIP_Real timelimit;
1249 SCIP_Real memorylimit;
1250
1253
1254 /* if we do not use feasibility pump 2.0, we have not created a copied SCIP instance yet */
1255 if( heurdata->usefp20 )
1256 {
1259 }
1260 else
1261 {
1264 }
1265
1266 /* check whether there is enough time and memory left */
1267 SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
1268 if( !SCIPisInfinity(scip, timelimit) )
1269 timelimit -= SCIPgetSolvingTime(scip);
1270 SCIP_CALL( SCIPgetRealParam(scip, "limits/memory", &memorylimit) );
1271
1272 /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
1273 if( !SCIPisInfinity(scip, memorylimit) )
1274 {
1275 memorylimit -= SCIPgetMemUsed(scip)/1048576.0;
1276 memorylimit -= SCIPgetMemExternEstim(scip)/1048576.0;
1277 }
1278
1279 /* abort if no time is left or not enough memory to create a copy of SCIP, including external memory usage */
1280 if( timelimit > 0.0 && memorylimit > 2.0*SCIPgetMemExternEstim(scip)/1048576.0 )
1281 {
1282 /* do not abort subproblem on CTRL-C */
1283 SCIP_CALL( SCIPsetBoolParam(probingscip, "misc/catchctrlc", FALSE) );
1284
1285#ifndef SCIP_DEBUG
1286 /* disable output to console */
1287 SCIP_CALL( SCIPsetIntParam(probingscip, "display/verblevel", 0) );
1288#endif
1289 /* set limits for the subproblem */
1290 SCIP_CALL( SCIPsetLongintParam(probingscip, "limits/nodes", 1000LL) );
1291 SCIP_CALL( SCIPsetLongintParam(probingscip, "limits/stallnodes", 100LL) );
1292 SCIP_CALL( SCIPsetRealParam(probingscip, "limits/time", timelimit) );
1293 SCIP_CALL( SCIPsetRealParam(probingscip, "limits/memory", memorylimit) );
1294
1295 /* forbid recursive call of heuristics and separators solving sub-SCIPs */
1297 if( SCIPisParamFixed(probingscip, "heuristics/"HEUR_NAME"/freq") )
1298 {
1299 SCIPwarningMessage(scip,"unfixing parameter heuristics/"HEUR_NAME"/freq in probingscip of "HEUR_NAME" heuristic to avoid recursive calls\n");
1300 SCIP_CALL( SCIPunfixParam(probingscip, "heuristics/"HEUR_NAME"/freq") );
1301 }
1302 SCIP_CALL( SCIPsetIntParam(probingscip, "heuristics/feaspump/freq", -1) );
1303
1304 /* disable heuristics which aim to feasibility instead of optimality */
1305 if( !SCIPisParamFixed(probingscip, "heuristics/octane/freq") )
1306 {
1307 SCIP_CALL( SCIPsetIntParam(probingscip, "heuristics/octane/freq", -1) );
1308 }
1309 if( !SCIPisParamFixed(probingscip, "heuristics/objpscostdiving/freq") )
1310 {
1311 SCIP_CALL( SCIPsetIntParam(probingscip, "heuristics/objpscostdiving/freq", -1) );
1312 }
1313 if( !SCIPisParamFixed(probingscip, "heuristics/rootsoldiving/freq") )
1314 {
1315 SCIP_CALL( SCIPsetIntParam(probingscip, "heuristics/rootsoldiving/freq", -1) );
1316 }
1317
1318 /* disable cutting plane separation */
1320
1321 /* disable expensive presolving */
1323
1324 /* use best estimate node selection */
1325 if( SCIPfindNodesel(probingscip, "estimate") != NULL && !SCIPisParamFixed(probingscip, "nodeselection/estimate/stdpriority") )
1326 {
1327 SCIP_CALL( SCIPsetIntParam(probingscip, "nodeselection/estimate/stdpriority", INT_MAX/4) );
1328 }
1329
1330 /* use inference branching */
1331 if( SCIPfindBranchrule(probingscip, "inference") != NULL && !SCIPisParamFixed(probingscip, "branching/inference/priority") )
1332 {
1333 SCIP_CALL( SCIPsetIntParam(probingscip, "branching/inference/priority", INT_MAX/4) );
1334 }
1335
1336 /* disable conflict analysis */
1337 if( !SCIPisParamFixed(probingscip, "conflict/useprop") )
1338 {
1339 SCIP_CALL( SCIPsetBoolParam(probingscip, "conflict/useprop", FALSE) );
1340 }
1341 if( !SCIPisParamFixed(probingscip, "conflict/useinflp") )
1342 {
1343 SCIP_CALL( SCIPsetBoolParam(probingscip, "conflict/useinflp", FALSE) );
1344 }
1345 if( !SCIPisParamFixed(probingscip, "conflict/useboundlp") )
1346 {
1347 SCIP_CALL( SCIPsetBoolParam(probingscip, "conflict/useboundlp", FALSE) );
1348 }
1349 if( !SCIPisParamFixed(probingscip, "conflict/usesb") )
1350 {
1351 SCIP_CALL( SCIPsetBoolParam(probingscip, "conflict/usesb", FALSE) );
1352 }
1353 if( !SCIPisParamFixed(probingscip, "conflict/usepseudo") )
1354 {
1355 SCIP_CALL( SCIPsetBoolParam(probingscip, "conflict/usepseudo", FALSE) );
1356 }
1357
1358 /* the neighborhood size is double the distance plus another ten percent */
1360
1362
1363 /* Errors in the LP solver should not kill the overall solving process, if the LP is just needed for a heuristic.
1364 * Hence in optimized mode, the return code is caught and a warning is printed, only in debug mode, SCIP will stop.
1365 */
1366#ifdef NDEBUG
1368 if( retcode != SCIP_OKAY )
1369 {
1370 SCIPwarningMessage(scip, "Error while solving sub-SCIP in stage 3 of feasibility pump heuristic; sub-SCIP terminated with code <%d>\n",
1371 retcode);
1372 }
1373#else
1375#endif
1376 /* check, whether a solution was found */
1377 if( SCIPgetNSols(probingscip) > 0 )
1378 {
1379 success = FALSE;
1381 if( success )
1383 }
1384 }
1385 }
1386
1387 if( *result == SCIP_FOUNDSOL )
1389
1390 /* free hash map and copied SCIP */
1393
1394 if( probingscip != NULL )
1395 {
1397 }
1398
1399 if( heurdata->stage3 )
1400 {
1402 }
1403
1404 /* free memory */
1405 for( j = 0; j < heurdata->cyclelength; j++ )
1406 {
1408 }
1409
1415
1416 SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops);
1417
1419}
1420
1421
1422/*
1423 * primal heuristic specific interface methods
1424 */
1425
1426/** creates the gcgfeaspump primal heuristic and includes it in SCIP */
1428 GCG* gcg /**< GCG data structure */
1429 )
1430{
1432 SCIP_HEUR* heur;
1434
1435 /* create Gcgfeaspump primal heuristic data */
1437 heurdata->gcg = gcg;
1438
1439 /* include primal heuristic */
1442 HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecGcgfeaspump, heurdata) );
1443
1444 assert(heur != NULL);
1445
1446 /* set non-NULL pointers to callback methods */
1447 SCIP_CALL( SCIPsetHeurFree(origprob, heur, heurFreeGcgfeaspump) );
1448 SCIP_CALL( SCIPsetHeurInit(origprob, heur, heurInitGcgfeaspump) );
1449 SCIP_CALL( SCIPsetHeurExit(origprob, heur, heurExitGcgfeaspump) );
1450
1451 /* add feaspump primal heuristic parameters */
1453 "heuristics/"HEUR_NAME"/maxlpiterquot",
1454 "maximal fraction of diving LP iterations compared to node LP iterations",
1457 "heuristics/"HEUR_NAME"/objfactor",
1458 "factor by which the regard of the objective is decreased in each round, 1.0 for dynamic",
1461 "heuristics/"HEUR_NAME"/alphadiff",
1462 "threshold difference for the convex parameter to perform perturbation",
1465 "heuristics/"HEUR_NAME"/maxlpiterofs",
1466 "additional number of allowed LP iterations",
1469 "heuristics/"HEUR_NAME"/maxsols",
1470 "total number of feasible solutions found up to which heuristic is called (-1: no limit)",
1471 &heurdata->maxsols, TRUE, DEFAULT_MAXSOLS, -1, INT_MAX, NULL, NULL) );
1473 "heuristics/"HEUR_NAME"/maxloops",
1474 "maximal number of pumping loops (-1: no limit)",
1475 &heurdata->maxloops, TRUE, DEFAULT_MAXLOOPS, -1, INT_MAX, NULL, NULL) );
1477 "heuristics/"HEUR_NAME"/maxstallloops",
1478 "maximal number of pumping rounds without fractionality improvement (-1: no limit)",
1481 "heuristics/"HEUR_NAME"/minflips",
1482 "minimum number of random variables to flip, if a 1-cycle is encountered",
1483 &heurdata->minflips, TRUE, DEFAULT_MINFLIPS, 1, INT_MAX, NULL, NULL) );
1485 "heuristics/"HEUR_NAME"/cyclelength",
1486 "maximum length of cycles to be checked explicitly in each round",
1489 "heuristics/"HEUR_NAME"/perturbfreq",
1490 "number of iterations until a random perturbation is forced",
1492 SCIP_CALL( SCIPaddIntParam(origprob, "heuristics/"HEUR_NAME"/neighborhoodsize",
1493 "radius (using Manhattan metric) of the neighborhood to be searched in stage 3",
1496 "heuristics/"HEUR_NAME"/usefp20",
1497 "should an iterative round-and-propagate scheme be used to find the integral points?",
1500 "heuristics/"HEUR_NAME"/pertsolfound",
1501 "should a random perturbation be performed if a feasible solution was found?",
1504 "heuristics/"HEUR_NAME"/stage3",
1505 "should we solve a local branching sub-MIP if no solution could be found?",
1507 SCIP_CALL( SCIPaddBoolParam(origprob, "heuristics/"HEUR_NAME"/copycuts",
1508 "should all active cuts from cutpool be copied to constraints in subproblem?",
1510
1511 return SCIP_OKAY;
1512}
SCIP_DECL_HEUREXIT(Heur2opt::scip_exit)
SCIP_DECL_HEURINIT(Heur2opt::scip_init)
SCIP_DECL_HEURFREE(Heur2opt::scip_free)
SCIP_DECL_HEUREXEC(Heur2opt::scip_exec)
#define DEFAULT_RANDSEED
#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 REALABS(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 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_STATUS SCIPgetStatus(SCIP *scip)
SCIP_STAGE SCIPgetStage(SCIP *scip)
const char * SCIPgetProbName(SCIP *scip)
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)
SCIP_Real SCIPgetObjNorm(SCIP *scip)
int SCIPgetNOrigVars(SCIP *scip)
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 SCIPsetHeuristics(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
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 SCIPunfixParam(SCIP *scip, const char *name)
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)
int SCIPgetNExternBranchCands(SCIP *scip)
SCIP_RETCODE SCIPgetPseudoBranchCands(SCIP *scip, SCIP_VAR ***pseudocands, int *npseudocands, int *npriopseudocands)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
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 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_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)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
int SCIPgetNPricers(SCIP *scip)
int SCIPgetProbingDepth(SCIP *scip)
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 SCIPfixVarProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval)
SCIP_RETCODE SCIPendProbing(SCIP *scip)
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
int SCIPgetNSols(SCIP *scip)
SCIP_RETCODE SCIPunlinkSol(SCIP *scip, SCIP_SOL *sol)
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_RETCODE SCIProundSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *success)
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_SOL ** SCIPgetSols(SCIP *scip)
SCIP_RETCODE SCIPlinkRelaxSol(SCIP *scip, SCIP_SOL *sol)
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 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_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_RETCODE SCIPfreeTransform(SCIP *scip)
SCIP_RETCODE SCIPsolve(SCIP *scip)
SCIP_Longint SCIPgetNSolsFound(SCIP *scip)
SCIP_Longint SCIPgetNBestSolsFound(SCIP *scip)
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisIntegral(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPceil(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
int SCIPgetDepth(SCIP *scip)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Bool SCIPisRelaxSolValid(SCIP *scip)
SCIP_RETCODE SCIPchgVarType(SCIP *scip, SCIP_VAR *var, SCIP_VARTYPE vartype, SCIP_Bool *infeasible)
SCIP_Real SCIPvarGetLPSol(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
unsigned int SCIPinitializeRandomSeed(SCIP *scip, unsigned int initialseedvalue)
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
int SCIPrandomGetInt(SCIP_RANDNUMGEN *randnumgen, int minrandval, int maxrandval)
void SCIPsortRealPtr(SCIP_Real *realarray, void **ptrarray, int len)
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
static SCIP_RETCODE addLocalBranchingConstraint(SCIP *scip, SCIP *subscip, SCIP_VAR **subvars, SCIP_HEURDATA *heurdata, SCIP_Bool *fixed)
#define DEFAULT_COPYCUTS
#define HEUR_TIMING
#define DEFAULT_NEIGHBORHOODSIZE
#define HEUR_USESSUBSCIP
#define DEFAULT_STAGE3
SCIP_HASHMAP * varmapfw
int maxflips
SCIP_SOL * closestsol
#define DEFAULT_CYCLELENGTH
SCIP_Real * mostfracvals
* result
SCIP_VAR ** pseudocands
SCIP_Real objnorm
static SCIP_RETCODE setupProbingSCIP(SCIP *scip, SCIP **probingscip, SCIP_HASHMAP **varmapfw, SCIP_Bool copycuts, SCIP_Bool *success)
static SCIP_RETCODE setupDivingSCIP(SCIP *scip, SCIP **divingscip, SCIP_HASHMAP **varmapfw, SCIP_Bool copycuts, SCIP_Bool *success)
#define DEFAULT_MINFLIPS
SCIP_VAR * var
SCIP_VAR ** vars
int nfracs
SCIP_Longint ncalls
int nbinvars
int j
SCIP * probingscip
#define DEFAULT_ALPHADIFF
SCIP_Real mindistance
#define DEFAULT_MAXLPITERQUOT
SCIP_Real scalingfactor
SCIP_Longint nsolsfound
SCIP_VAR ** mostfracvars
SCIP_RETCODE GCGincludeHeurGcgfeaspump(GCG *gcg)
#define MINLPITER
SCIP_Longint nbestsolsfound
SCIP_Real alpha
SCIP_HASHMAP * varmapfwdive
SCIP_VAR ** tmppseudocands
int nintvars
static SCIP_RETCODE handle1Cycle(SCIP *scip, SCIP *divingscip, SCIP_HASHMAP *varmapfw, SCIP_HEURDATA *heurdata, SCIP_VAR **mostfracvars, int nflipcands, SCIP_Real alpha)
#define DEFAULT_USEFP20
int maxloops
SCIP_Real * lastalphas
int bestnfracs
#define DEFAULT_MAXLPITEROFS
static SCIP_RETCODE handleCycle(SCIP *scip, SCIP *divingscip, SCIP_HASHMAP *varmapfw, SCIP_HEURDATA *heurdata, SCIP_VAR **vars, int nbinandintvars, SCIP_Real alpha)
SCIP_Longint nlpiterations
SCIP_Real frac
SCIP_Bool success
SCIP_SOL * tmpsol
static SCIP_RETCODE getNFracs(SCIP *scip, SCIP_SOL *lpsol, int *nfracs)
#define DEFAULT_MAXSTALLLOOPS
#define DEFAULT_PERTURBFREQ
#define DEFAULT_PERTSOLFOUND
SCIP_Real solval
static void insertFlipCand(SCIP_VAR **mostfracvars, SCIP_Real *mostfracvals, int *nflipcands, int maxnflipcands, SCIP_VAR *var, SCIP_Real frac)
SCIP_Longint maxnlpiterations
static SCIP_RETCODE getDivingLPSol(SCIP *scip, SCIP *divingscip, SCIP_HASHMAP *varmapfw, SCIP_SOL *lpsol)
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int nflipcands
SCIP_RETCODE retcode
int maxstallloops
SCIP_Real orgobjcoeff
int i
static SCIP_Longint adjustedMaxNLPIterations(SCIP_Longint maxnlpiterations, SCIP_Longint nsolsfound, int nstallloops)
SCIP_Real objfactor
int npseudocands
#define DEFAULT_MAXSOLS
SCIP_Real newobjcoeff
int nstallloops
static SCIP_HEURDATA * heurdata
SCIP_Bool * cycles
int nvars
int nloops
SCIPfreeBufferArray(scip, &cycles)
#define DEFAULT_MAXLOOPS
SCIP_Real oldsolval
#define DEFAULT_OBJFACTOR
static SCIP_RETCODE createNewSols(SCIP *scip, SCIP *subscip, SCIP_HASHMAP *varmapfw, SCIP_HEUR *heur, SCIP_Bool *success)
SCIP_SOL ** lastroundedsols
SCIP * divingscip
Objective Feasibility Pump 2.0.
#define NULL
SCIP_Real maxlpiterquot
SCIP_Longint nlpiterations
SCIP_SOL * roundedsol
SCIP_RANDNUMGEN * randnumgen
SCIP_Bool pertsolfound
SCIP_Real objfactor
SCIP_Bool copycuts
SCIP_Real alphadiff
struct SCIP_Cons SCIP_CONS
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_HeurData SCIP_HEURDATA
struct SCIP_Heur SCIP_HEUR
SCIP_LPSOLSTAT_OPTIMAL
struct SCIP_HashMap SCIP_HASHMAP
struct SCIP_RandNumGen SCIP_RANDNUMGEN
SCIP_PARAMSETTING_OFF
SCIP_PARAMSETTING_FAST
SCIP_DIDNOTRUN
SCIP_DELAYED
SCIP_DIDNOTFIND
SCIP_FOUNDSOL
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_SOLVED
SCIP_STAGE_SOLVING
struct SCIP_Sol SCIP_SOL
SCIP_STATUS_OPTIMAL
enum SCIP_Status SCIP_STATUS
struct SCIP_Var SCIP_VAR
SCIP_VARTYPE_CONTINUOUS
SCIP_VARTYPE_BINARY