GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
heur_relaxcolsel.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_relaxcolsel.c
30 * @brief relaxation based column selection primal heuristic
31 * @author Christian Puchert
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36#include <assert.h>
37
39#include "gcg/gcg.h"
40#include "gcg/pricer_gcg.h"
41
42
43#define HEUR_NAME "relaxcolsel"
44#define HEUR_DESC "column selection heuristic that tries to round a master LP solution in promising directions"
45#define HEUR_DISPCHAR 'x'
46#define HEUR_PRIORITY -100
47#define HEUR_FREQ 1
48#define HEUR_FREQOFS 0
49#define HEUR_MAXDEPTH -1
50#define HEUR_TIMING SCIP_HEURTIMING_AFTERLPNODE
51#define HEUR_USESSUBSCIP FALSE
52
53#define DEFAULT_MINCOLUMNS 200 /**< minimum number of columns to regard in the master problem */
54
55
56
57
58/*
59 * Data structures
60 */
61
62/** primal heuristic data */
63struct SCIP_HeurData
64{
65 GCG* gcg; /**< GCG data structure */
66 /* parameters */
67 int mincolumns; /**< minimum number of columns to regard in the master problem */
68
69 /* data */
70 SCIP_VAR** zerovars; /**< array of master variables corresponding to zero solutions */
71 int maxzerovars; /**< capacity of zerovars */
72 int lastncols; /**< number of columns in the last call of the heuristic */
73};
74
75
76
77
78/*
79 * Local methods
80 */
81
82
83/**
84 * initialize working solution as the rounded down master LP solution (and its original counterpart)
85 * and the master variable candidates for rounding up
86 */
87static
89 GCG* gcg,
90 SCIP_SOL* mastersol,
91 SCIP_SOL* origsol,
92 int* blocknr,
93 int* mastercands,
94 SCIP_Real* candfracs,
95 int* nmastercands,
97 )
98{
100 SCIP* origprob;
102 SCIP_Real* mastervals;
103 int nmastervars;
104 int nblocks;
105
106 int i;
107 int j;
108 int k;
109
111
112 /* get original problem */
114 assert(origprob != NULL);
115
116 /* get variable data of the master problem */
118 assert(nmastervars >= 0);
119
120 /* get number of blocks */
121 nblocks = GCGgetNPricingprobs(gcg);
122 assert( nblocks >= 0 );
123
124 /* get master LP solution values */
127
128 *nmastercands = 0;
129 *success = TRUE;
130
131 /* loop over all given master variables */
132 for( i = 0; i < nmastervars && *success; ++i )
133 {
134 SCIP_VAR* mastervar;
135 SCIP_VARTYPE vartype;
137 SCIP_Real roundval;
139 int block;
140 SCIP_VAR** origvars;
141 SCIP_Real* origvals;
142 int norigvars;
143
144 /* get master variable */
145 mastervar = mastervars[i];
146 assert(GCGvarIsMaster(mastervar));
147 vartype = SCIPvarGetType(mastervar);
148
149 /* get solution value, its integer part and its fractionality */
150 solval = mastervals[i];
151 roundval = SCIPfeasFloor(masterprob, solval);
153
154 /* get blocknr and corresponding original variables */
155 block = GCGvarGetBlock(mastervar);
156 origvars = GCGmasterVarGetOrigvars(mastervar);
157 origvals = GCGmasterVarGetOrigvals(mastervar);
158 norigvars = GCGmasterVarGetNOrigvars(mastervar);
159
160 if( GCGmasterVarIsArtificial(mastervar) )
161 continue;
162
163 /* update master solution and original solution */
164
165 /* treat variables representing rays separately */
166 if( GCGmasterVarIsRay(mastervar) )
167 {
168 assert(block >= 0);
169
170 if( SCIPisFeasPositive(masterprob, roundval) )
171 {
172 SCIPdebugMessage(" -> (block %d) select ray master variable %s (%d times)\n",
173 block, SCIPvarGetName(mastervar), (int) roundval);
174
175 /* set master solution value to rounded down solution */
176 SCIP_CALL( SCIPsetSolVal(masterprob, mastersol, mastervar, roundval) );
177
178 /* loop over all original variables contained in the current master variable */
179 for( j = 0; j < norigvars; ++j )
180 {
181 SCIP_VAR* origvar;
182 SCIP_Real origval;
183
184 /* get original variable and its value in the master variable */
185 origvar = origvars[j];
186 origval = origvals[j];
187 assert(GCGvarIsOriginal(origvar));
188
189 if( SCIPisZero(masterprob, origval) )
190 continue;
191
192 assert(!SCIPisZero(masterprob, origval));
193
194 /* the original variable is a linking variable: just transfer the solution value of the direct copy (this is done later) */
195 if( GCGoriginalVarIsLinking(origvar) )
196 continue;
197
198 /* increase the corresponding value */
199 SCIP_CALL( SCIPincSolVal(masterprob, origsol, origvar, origval * roundval) );
200 }
201
202 /* if the master variable is fractional, add it as a candidate */
204 {
205 mastercands[*nmastercands] = i;
206 candfracs[*nmastercands] = frac;
207 ++(*nmastercands);
208 }
209 }
210
211 continue;
212 }
213
214 assert(!GCGmasterVarIsRay(mastervar));
215
216 /* treat variables directly transferred to the master problem (but not linking variables) */
217 if( block == -1 )
218 {
219 SCIP_VAR* origvar;
220 int origblock;
221
222 /* get original variable and the block it belongs to */
223 assert(norigvars == 1);
224 origvar = origvars[0];
225 assert(GCGvarIsOriginal(origvar));
226 assert(origvals[0] == 1.0);
227 origblock = GCGvarGetBlock(origvar);
228 assert(origblock == -2 || origblock == -1);
229
230 /* only increase solution value if the variable is not a linking variable
231 * (these are treated later) */
232 if( origblock == -2 )
233 continue;
234
235 /* if the variable should be integral but is not, add rounded down value;
236 * otherwise, add (possibly fractional) value */
237 if( (vartype == SCIP_VARTYPE_BINARY || vartype == SCIP_VARTYPE_INTEGER )
239 {
240 SCIP_CALL( SCIPsetSolVal(masterprob, mastersol, mastervar, roundval) );
241 SCIP_CALL( SCIPsetSolVal(origprob, origsol, origvar, roundval) );
242 mastercands[*nmastercands] = i;
243 candfracs[*nmastercands] = frac;
244 ++(*nmastercands);
245 }
246 else
247 {
248 SCIP_CALL( SCIPsetSolVal(masterprob, mastersol, mastervar, solval) );
249 SCIP_CALL( SCIPsetSolVal(origprob, origsol, origvar, solval) );
250 }
251 }
252
253 /* then, treat master variables representing extreme points and rays */
254 else
255 {
256 if( !SCIPisFeasZero(masterprob, roundval) )
257 {
258 /* set master solution value to rounded down solution */
259 SCIP_CALL( SCIPsetSolVal(masterprob, mastersol, mastervar, roundval) );
260
261 SCIPdebugMessage(" -> (block %d) select master variable %s (%d times)\n",
262 block, SCIPvarGetName(mastervar), (int) roundval);
263
264 for( j = 0; j < norigvars; ++j )
265 {
266 SCIP_VAR* origvar;
267 SCIP_Real origval;
268
269 /* get original variable and its value in the master variable */
270 origvar = origvars[j];
271 origval = origvals[j];
272 assert(GCGvarIsOriginal(origvar));
273
274 /* if the variable is zero, nothing happens */
275 if( SCIPisZero(masterprob, origval) )
276 continue;
277
278 /* linking variables are treated differently; if the variable already has been assigned a value,
279 * one must check whether the value for the current block is the same (otherwise, the resulting
280 * solution will be infeasible in any case) */
281 if( GCGoriginalVarIsLinking(origvar) )
282 {
283 SCIP_VAR** linkingpricingvars;
284 SCIP_Bool hasvalue;
285
286 /* check whether linking variable has already been assigned a value */
287 linkingpricingvars = GCGlinkingVarGetPricingVars(origvar);
288 hasvalue = FALSE;
289 for( k = 0; k < nblocks; ++k )
290 if( linkingpricingvars[k] != NULL )
291 if( blocknr[k] > 0 )
292 {
293 hasvalue = TRUE;
294 break;
295 }
296
297 /* if the linking variable has not been assigned a value yet, assign a value to
298 * the variable and the corresponding copy in the master problem */
299 if( !hasvalue )
300 {
301 SCIP_VAR* linkingmastervar;
302
303 linkingmastervar = GCGoriginalVarGetMastervars(origvar)[0];
304 assert(linkingmastervar != NULL);
305 SCIP_CALL( SCIPsetSolVal(origprob, origsol, origvar, origval) );
306 SCIP_CALL( SCIPsetSolVal(masterprob, mastersol, linkingmastervar, origval) );
307 }
308 /* otherwise, exclude the current master variable, if the point has a different value for it */
309 else
310 {
311 SCIP_Real value;
312 value = SCIPgetSolVal(origprob, origsol, origvar);
313 if( !SCIPisEQ(origprob, value, origval) )
314 {
315 SCIPdebugMessage(" -> cannot use mastervar: origvar %s already has value %g in block %d, different to %g\n",
316 SCIPvarGetName(origvar), value, j, origval);
317 *success = FALSE;
318 break;
319 }
320 }
321 }
322 else
323 {
324 SCIP_VAR* pricingvar;
325 SCIP_VAR** origpricingvars;
326#ifndef NDEBUG
327 int norigpricingvars;
328#endif
329
330 assert(GCGvarGetBlock(origvar) == block);
331
332 /* get the corresponding pricing variable */
333 pricingvar = GCGoriginalVarGetPricingVar(origvar);
334 assert(pricingvar != NULL);
335 assert(GCGvarIsPricing(pricingvar));
336
337 /* get original variables represented by origvar */
338 origpricingvars = GCGpricingVarGetOrigvars(pricingvar);
339#ifndef NDEBUG
340 norigpricingvars = GCGpricingVarGetNOrigvars(pricingvar);
341#endif
342
343 /* increase the corresponding value */
344 for( k = 0; k < (int) roundval; ++k )
345 {
346 int blockidx;
347 blockidx = blocknr[block] + k;
348#ifndef NDEBUG
349 assert(blockidx < norigpricingvars);
350#endif
351 SCIP_CALL( SCIPincSolVal(origprob, origsol, origpricingvars[blockidx], origval) );
352 }
353 }
354 }
355
356 /* blocks have been filled, so increase blocknr */
357 blocknr[block] += (int) roundval;
358 }
359
360 /* if the master variable is fractional, add it as a candidate */
362 {
363 mastercands[*nmastercands] = i;
364 candfracs[*nmastercands] = frac;
365 ++(*nmastercands);
366 }
367 }
368 }
369
370 SCIPfreeBufferArray(masterprob, &mastervals);
371
372 return SCIP_OKAY;
373}
374
375/** for a given block, search if there is a master variable corresponding to the zero solution;
376 * @todo it would be more efficient to "mark" master variables as being trivial */
377static
379 SCIP* scip,
380 int block,
381 SCIP_VAR** zeromastervar
382 )
383{
385 int nmastervars;
386
387 int i;
388 int j;
389
390 /* get variable data of the master problem */
392
393 *zeromastervar = NULL;
394
395 /* go through all master variables */
396 for( i = 0; i < nmastervars && *zeromastervar == NULL; ++i )
397 {
398 SCIP_VAR* mastervar;
399 int b;
400
401 mastervar = mastervars[i];
402 b = GCGvarGetBlock(mastervar);
403
404 /* only regard master variables belonging to the block we are searching for */
405 if( b == block )
406 {
407 SCIP_Real* origvals;
408 int norigvars;
409
410 origvals = GCGmasterVarGetOrigvals(mastervar);
411 norigvars = GCGmasterVarGetNOrigvars(mastervar);
412
413 /* check if all original variables contained in the master variable have value zero */
414 for( j = 0; j < norigvars; ++j )
415 if( !SCIPisZero(scip, origvals[j]) )
416 break;
417
418 /* if so, we have found the right master variable */
419 if( j == norigvars )
420 *zeromastervar = mastervar;
421 }
422 }
423
424 return SCIP_OKAY;
425}
426
427/** for a given block, return the master variable corresponding to the zero solution,
428 * or NULL is there is no such variable available */
429static
431 SCIP* scip,
433 int block,
434 SCIP_VAR** zeromastervar
435 )
436{
437 /* if no zero solution is known for the block, look if a master variable has been added
438 * and remember the variable for future use */
439 if( heurdata->zerovars[block] == NULL )
440 SCIP_CALL( searchZeroMastervar(scip, block, zeromastervar) );
441 else
442 *zeromastervar = heurdata->zerovars[block];
443
444 return SCIP_OKAY;
445}
446
447
448
449/*
450 * Callback methods of primal heuristic
451 */
452
453
454/** copy method for primal heuristic plugins (called when SCIP copies plugins) */
455#define heurCopyRelaxcolsel NULL
456
457/** destructor of primal heuristic to free user data (called when SCIP is exiting) */
458static
459SCIP_DECL_HEURFREE(heurFreeRelaxcolsel)
460{ /*lint --e{715}*/
462
463 assert(heur != NULL);
464 assert(scip != NULL);
465
466 /* get heuristic data */
468 assert(heurdata != NULL);
469
470 /* free heuristic data */
472 SCIPheurSetData(heur, NULL);
473
474 return SCIP_OKAY;
475}
476
477
478/** initialization method of primal heuristic (called after problem was transformed) */
479static
480SCIP_DECL_HEURINIT(heurInitRelaxcolsel)
481{ /*lint --e{715}*/
483 int nblocks;
484
485 int i;
486
487 assert(heur != NULL);
488 assert(scip != NULL);
489
490 /* get heuristic's data */
492 assert(heurdata != NULL);
493
494 /* get number of blocks */
495 nblocks = GCGgetNPricingprobs(heurdata->gcg);
496
497 heurdata->lastncols = 0;
498
499 /* allocate memory and initialize array with NULL pointers */
500 if( nblocks > 0 )
501 {
504 }
505
506 for( i = 0; i < nblocks; ++i )
508
509 return SCIP_OKAY;
510}
511
512
513/** deinitialization method of primal heuristic (called before transformed problem is freed) */
514static
515SCIP_DECL_HEUREXIT(heurExitRelaxcolsel)
516{ /*lint --e{715}*/
518
519 assert(heur != NULL);
520 assert(scip != NULL);
521
522 /* get heuristic data */
524 assert(heurdata != NULL);
525
526 /* free memory */
528
529 return SCIP_OKAY;
530}
531
532
533/** solving process initialization method of primal heuristic (called when branch and bound process is about to begin) */
534#define heurInitsolRelaxcolsel NULL
535
536
537/** solving process deinitialization method of primal heuristic (called before branch and bound process data is freed) */
538#define heurExitsolRelaxcolsel NULL
539
540
541/** execution method of primal heuristic */
542static
543SCIP_DECL_HEUREXEC(heurExecRelaxcolsel)
544{ /*lint --e{715}*/
545 SCIP* origprob; /* SCIP structure of original problem */
546 SCIP_HEURDATA* heurdata; /* heuristic's data */
547 SCIP_SOL* mastersol; /* working master solution */
548 SCIP_SOL* origsol; /* working original solution */
550 SCIP_Real* candfracs; /* fractionalities of candidate variables */
551 int* blocknr; /* for each pricing problem, block we are currently working in */
552 int* mastercands; /* master variables which are considered first for rounding up */
553 SCIP_Bool allblocksfull; /* indicates if all blocks are full, i.e. all convexity constraints are satisfied */
554 SCIP_Bool masterfeas;
556 int minnewcols; /* minimum number of new columns necessary for calling the heuristic */
557 int nmastervars;
558 int nmastercands;
559 int nblocks;
560
561 int i;
562 int j;
563 int k;
564
565 assert(heur != NULL);
566 assert(scip != NULL);
567 assert(result != NULL);
568
569 /* get heuristic's data */
571 assert(heurdata != NULL);
572
573 /* get original problem */
575 assert(origprob != NULL);
576
578
579 /* only call heuristic, if an optimal relaxation solution is at hand */
581 return SCIP_OKAY;
582
584
585 /* get variable data of the master problem */
588 assert(nmastervars >= 0);
589
590 /* calculate minimum number of new columns necessary for calling the heuristic;
591 * this number is influenced by how successful the heuristic was in the past */
592 minnewcols = heurdata->mincolumns * (int) (1.0 * ((1.0 + SCIPheurGetNCalls(heur)) / (1.0 + SCIPheurGetNBestSolsFound(heur))));
593
594 /* if there are not enough new columns since last call, abort heuristic */
595 if( nmastervars - heurdata->lastncols < minnewcols )
596 return SCIP_OKAY;
597
599
600 SCIPdebugMessage("Executing Relaxation Based Column Selection heuristic (nmastervars = %d) ...\n", nmastervars);
601
602 /* get number of blocks */
603 nblocks = GCGgetNPricingprobs(heurdata->gcg);
604 assert(nblocks >= 0);
605
606 /* allocate memory and create working solutions */
607 SCIP_CALL( SCIPcreateSol(scip, &mastersol, heur) );
608 SCIP_CALL( SCIPcreateSol(origprob, &origsol, heur) );
609 SCIP_CALL( SCIPallocBufferArray(scip, &blocknr, nblocks) );
612
613 /* initialize the block information */
614 BMSclearMemoryArray(blocknr, nblocks);
616 allblocksfull = FALSE;
617
618 /* initialize empty candidate list */
619 for( i = 0; i < nmastervars; ++i )
620 mastercands[i] = -1;
621
622 /* initialize working original solution as transformation of rounded down master LP solution
623 * and get the candidate master variables for rounding up */
624 SCIPdebugMessage("initializing starting solution...\n");
625 SCIP_CALL( initializeStartsol(heurdata->gcg, mastersol, origsol, blocknr,
626 mastercands, candfracs, &nmastercands, &success) );
627
628 if( !success )
629 {
630 SCIPdebugMessage(" -> not successful.\n");
631 goto TERMINATE;
632 }
633
634 masterfeas = FALSE;
635 success = FALSE;
636
637 SCIPdebugMessage("trying to round up...\n");
638
639 /* first, loop over all candidates for rounding up */
640 while( !allblocksfull && !success )
641 {
642 SCIP_VAR* mastervar;
643 int candidx;
645 SCIP_Bool compatible;
646
647 SCIP_VAR** origvars;
648 SCIP_Real* origvals;
649 int norigvars;
650 int block;
651
652 /* search the candidate list for a master variable that can be rounded up;
653 * take the variable with the highest fractionality */
654 mastervar = NULL;
655 candidx = -1;
656 frac = 0.0;
657 compatible = TRUE;
658 for( i = 0; i < nmastercands; ++i )
659 {
660 int idx;
661 SCIP_Real tmpfrac;
662
663 idx = mastercands[i];
664 tmpfrac = candfracs[i];
665 if( idx != -1 && SCIPisFeasGT(scip, tmpfrac, frac) )
666 {
667 SCIP_VAR* tmpvar;
668
669 tmpvar = mastervars[idx];
670 block = GCGvarGetBlock(tmpvar);
671
672 /* consider only variables whose block is not already full
673 * or copied master variables */
674 if( block == -1 || blocknr[block] < GCGgetNIdenticalBlocks(heurdata->gcg, block) )
675 {
676 mastervar = tmpvar;
677 candidx = i;
678 frac = tmpfrac;
679 }
680 }
681 }
682
683 /* if no variable could be found, abort */
684 if( candidx == -1 )
685 {
686 assert(mastervar == NULL);
687 break;
688 }
689
690 /* remove the chosen variable from the candidate list */
691 assert(candidx >= 0 && candidx < nmastercands);
692 mastercands[candidx] = -1;
693 candfracs[candidx] = 0.0;
694
695 assert(mastervar != NULL);
696 block = GCGvarGetBlock(mastervar);
697
698 SCIPdebugMessage(" -> (block %d) selected master variable %s; frac=%g\n",
699 block, SCIPvarGetName(mastervar), frac);
700
701 /* get original variables */
702 origvars = GCGmasterVarGetOrigvars(mastervar);
703 origvals = GCGmasterVarGetOrigvals(mastervar);
704 norigvars = GCGmasterVarGetNOrigvars(mastervar);
705
706 /* increase master value by one and increase solution values in current original solution accordingly */
707 SCIP_CALL( SCIPincSolVal(scip, mastersol, mastervar, 1.0) );
708
709 /* update original solution accordingly
710 * first, treat variables directly transferred to the master problem (but not linking variables) */
711 if( block == -1 )
712 {
713 SCIP_VAR* origvar;
714#ifndef NDEBUG
715 int origblock;
716#endif
717
718 /* get original variable and the block it belongs to;
719 * the variable should not be a linking variable
720 * as those have not been added to the candidate list */
721 assert(norigvars == 1);
722 origvar = origvars[0];
723 assert(GCGvarIsOriginal(origvar));
724 assert(origvals[0] == 1.0);
725#ifndef NDEBUG
726 origblock = GCGvarGetBlock(origvar);
727 assert(origblock == -1);
728#endif
729
730 /* set solution value to rounded up value */
731 SCIP_CALL( SCIPincSolVal(origprob, origsol, origvar, 1.0) );
732 }
733
734 /* then, treat master variables representing extreme points and rays */
735 else
736 {
737 for( i = 0; i < norigvars; ++i )
738 {
739 SCIP_VAR* origvar;
740 SCIP_Real origval;
741
742 origvar = origvars[i];
743 origval = origvals[i];
744
745 assert(GCGvarIsOriginal(origvar));
746
747 /* linking variables are treated differently; if the variable already has been assigned a value,
748 * one must check whether the value for the current block is the same (otherwise, the resulting
749 * solution will be infeasible in any case) */
750 if( GCGoriginalVarIsLinking(origvar) )
751 {
752 SCIP_VAR** linkingpricingvars;
753 SCIP_Bool hasvalue;
754
755 /* check whether linking variable has already been assigned a value */
756 linkingpricingvars = GCGlinkingVarGetPricingVars(origvar);
757 hasvalue = FALSE;
758 for( j = 0; j < nblocks; ++j )
759 if( linkingpricingvars[j] != NULL )
760 if( blocknr[j] > 0 )
761 {
762 hasvalue = TRUE;
763 break;
764 }
765
766 /* if the linking variable has not been assigned a value yet, assign a value to
767 * the variable and the corresponding copy in the master problem */
768 if( !hasvalue )
769 {
770 SCIP_VAR* linkingmastervar;
771
772 linkingmastervar = GCGoriginalVarGetMastervars(origvar)[0];
773 assert(linkingmastervar != NULL);
774 SCIP_CALL( SCIPincSolVal(origprob, origsol, origvar, origval) );
775 SCIP_CALL( SCIPincSolVal(scip, mastersol, linkingmastervar, origval) );
776 }
777 /* otherwise do not take this variable */
778 else
779 {
780 SCIP_Real value;
781 value = SCIPgetSolVal(origprob, origsol, origvar);
782 if( !SCIPisEQ(origprob, value, origval) )
783 {
784 SCIPdebugMessage(" -> cannot use mastervar: origvar %s already has value %g in block %d, different to %g\n",
785 SCIPvarGetName(origvar), value, j, origval);
786 compatible = FALSE;
787 break;
788 }
789 }
790 }
791 else
792 {
793 SCIP_VAR* pricingvar;
794 SCIP_VAR** origpricingvars;
795#ifndef NDEBUG
796 int norigpricingvars;
797#endif
798
799 /* if the variable is zero, nothing happens */
800 if( SCIPisZero(scip, origval) )
801 continue;
802
803 pricingvar = GCGoriginalVarGetPricingVar(origvar);
804 assert(pricingvar != NULL);
805 assert(GCGvarIsPricing(pricingvar));
806
807 origpricingvars = GCGpricingVarGetOrigvars(pricingvar);
808
809#ifndef NDEBUG
810 norigpricingvars = GCGpricingVarGetNOrigvars(pricingvar);
811 assert(blocknr[block] < norigpricingvars);
812#endif
813
814 /* increase the corresponding value */
815 SCIP_CALL( SCIPincSolVal(origprob, origsol, origpricingvars[blocknr[block]], origval) );
816 }
817 }
818
819 /* if the current master variable cannot be selected (due to conflicting linking variables),
820 * reset solution values and choose a new one */
821 if( !compatible )
822 {
823 SCIP_CALL( SCIPincSolVal(scip, mastersol, mastervar, -1.0) );
824 for( k = 0; k < i; ++k )
825 {
826 SCIP_VAR* origvar;
827 SCIP_Real origval;
828
829 origvar = origvars[k];
830 origval = origvals[k];
831
832 if( GCGoriginalVarIsLinking(origvar) )
833 {
834 SCIP_VAR** linkingpricingvars;
835 SCIP_Bool hasvalue;
836
837 /* check whether linking variable has already been assigned a value */
838 linkingpricingvars = GCGlinkingVarGetPricingVars(origvar);
839 hasvalue = FALSE;
840 for( j = 0; j < nblocks; ++j )
841 if( linkingpricingvars[j] != NULL )
842 if( blocknr[j] > 0 && j != block )
843 {
844 hasvalue = TRUE;
845 break;
846 }
847
848 /* if the linking variable has not had a value before, set it back to zero */
849 if( !hasvalue )
850 {
851 SCIP_VAR* linkingmastervar;
852
853 linkingmastervar = GCGoriginalVarGetMastervars(origvar)[0];
854 SCIP_CALL( SCIPincSolVal(origprob, origsol, origvar, -origval) );
855 SCIP_CALL( SCIPincSolVal(scip, mastersol, linkingmastervar, -origval) );
856 }
857 }
858 else
859 {
860 SCIP_VAR* pricingvar;
861 SCIP_VAR** origpricingvars;
862#ifndef NDEBUG
863 int norigpricingvars;
864#endif
865
866 pricingvar = GCGoriginalVarGetPricingVar(origvar);
867 assert(pricingvar != NULL);
868 assert(GCGvarIsPricing(pricingvar));
869
870 origpricingvars = GCGpricingVarGetOrigvars(pricingvar);
871
872#ifndef NDEBUG
873 norigpricingvars = GCGpricingVarGetNOrigvars(pricingvar);
874 assert(blocknr[block] < norigpricingvars);
875#endif
876
877 /* decrease the corresponding value */
878 SCIP_CALL( SCIPincSolVal(origprob, origsol, origpricingvars[blocknr[block]], -origval) );
879 }
880 }
881 continue;
882 }
883
884 blocknr[block]++;
885 }
886
887 /* try to add the solution to (original) solution pool */
889
890 /* check if all blocks are full */
891 allblocksfull = TRUE;
892 for( i = 0; i < nblocks && allblocksfull; ++i )
893 {
894 int nidentblocks;
895
896 nidentblocks = GCGgetNIdenticalBlocks(heurdata->gcg, i);
897
898 /* in case the solution is feasible but the block is not full,
899 * we need a zero solution for this block in order to generate
900 * a corresponding master solution */
901 if( success && blocknr[i] < nidentblocks )
902 {
903 SCIP_VAR* zeromastervar;
904
905 /* fill the block with the zero solution */
906 zeromastervar = NULL;
907 SCIP_CALL( getZeroMastervar(scip, heurdata, i, &zeromastervar) );
908 if( zeromastervar != NULL )
909 {
910 SCIPdebugMessage(" -> (block %d) selected zero master variable %s (%d times)\n",
911 i, SCIPvarGetName(zeromastervar), nidentblocks - blocknr[i]);
912
913 SCIP_CALL( SCIPincSolVal(scip, mastersol, zeromastervar,
914 (SCIP_Real) nidentblocks - blocknr[i]) );
915 blocknr[i] = nidentblocks;
916 }
917 }
918
919 /** @todo >= should not happen, replace it by == ? */
920 if( !(blocknr[i] >= nidentblocks) )
921 allblocksfull = FALSE;
922 }
923
924 /* if we found a solution for the original instance,
925 * also add the corresponding master solution */
926 if( success && allblocksfull )
927 {
928#ifdef SCIP_DEBUG
929 SCIP_CALL( SCIPtrySol(scip, mastersol, TRUE, TRUE, TRUE, TRUE, TRUE, &masterfeas) );
930#else
931 SCIP_CALL( SCIPtrySol(scip, mastersol, FALSE, FALSE, TRUE, TRUE, TRUE, &masterfeas) );
932#endif
933 if( !masterfeas )
934 {
935 SCIPdebugMessage("WARNING: original solution feasible, but no solution has been added to master problem.\n");
936 }
937 }
938 }
939
940 if( success )
941 {
943 SCIPdebugMessage(" -> heuristic successful - feasible solution found.\n");
944 }
945 else
946 {
947 SCIPdebugMessage(" -> no feasible solution found.\n");
948 }
949
950TERMINATE:
951 SCIP_CALL( SCIPfreeSol(origprob, &origsol) );
952 SCIP_CALL( SCIPfreeSol(scip, &mastersol) );
953 SCIPfreeBufferArray(scip, &candfracs);
954 SCIPfreeBufferArray(scip, &mastercands);
955 SCIPfreeBufferArray(scip, &blocknr);
956
958
959 return SCIP_OKAY;
960}
961
962
963
964
965/*
966 * primal heuristic specific interface methods
967 */
968
969/** creates the relaxation based column selection primal heuristic and includes it in SCIP */
971 GCG* gcg /**< GCG data structure */
972 )
973{
976
977 /* create relaxation based column selection primal heuristic data */
981 heurdata->gcg = gcg;
982
983 /* include primal heuristic */
986 heurCopyRelaxcolsel, heurFreeRelaxcolsel, heurInitRelaxcolsel, heurExitRelaxcolsel,
988 heurdata) );
989
990 /* add relaxation based column selection primal heuristic parameters */
991 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/relaxcolsel/mincolumns",
992 "minimum number of columns to regard in the master problem",
994
995 return SCIP_OKAY;
996}
SCIP_DECL_HEUREXIT(Heur2opt::scip_exit)
SCIP_DECL_HEURINIT(Heur2opt::scip_init)
SCIP_DECL_HEURFREE(Heur2opt::scip_free)
SCIP_DECL_HEUREXEC(Heur2opt::scip_exec)
SCIP_VAR ** b
#define SCIP_Bool
#define SCIP_Real
#define TRUE
#define FALSE
GCG interface methods.
SCIP_Bool GCGvarIsOriginal(SCIP_VAR *var)
Definition gcgvar.c:231
SCIP_VAR ** GCGlinkingVarGetPricingVars(SCIP_VAR *var)
Definition gcgvar.c:488
SCIP_Bool GCGmasterVarIsArtificial(SCIP_VAR *var)
Definition gcgvar.c:954
int GCGmasterVarGetNOrigvars(SCIP_VAR *var)
Definition gcgvar.c:971
SCIP_VAR ** GCGoriginalVarGetMastervars(SCIP_VAR *var)
Definition gcgvar.c:666
SCIP_VAR ** GCGpricingVarGetOrigvars(SCIP_VAR *var)
Definition gcgvar.c:1100
SCIP_Bool GCGoriginalVarIsLinking(SCIP_VAR *var)
Definition gcgvar.c:247
SCIP_VAR * GCGoriginalVarGetPricingVar(SCIP_VAR *var)
Definition gcgvar.c:281
SCIP_VAR ** GCGmasterVarGetOrigvars(SCIP_VAR *var)
Definition gcgvar.c:993
int GCGpricingVarGetNOrigvars(SCIP_VAR *var)
Definition gcgvar.c:1082
SCIP_Bool GCGvarIsMaster(SCIP_VAR *var)
Definition gcgvar.c:176
SCIP_Real * GCGmasterVarGetOrigvals(SCIP_VAR *var)
Definition gcgvar.c:1017
SCIP_Bool GCGmasterVarIsRay(SCIP_VAR *var)
Definition gcgvar.c:937
int GCGvarGetBlock(SCIP_VAR *var)
Definition gcgvar.c:1118
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
GCG_EXPORT int GCGgetNIdenticalBlocks(GCG *gcg, int pricingprobnr)
Definition relax_gcg.c:4185
GCG_EXPORT int GCGgetNPricingprobs(GCG *gcg)
Definition relax_gcg.c:4113
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
SCIP_STAGE SCIPgetStage(SCIP *scip)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
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_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
SCIP_RETCODE SCIPincludeHeur(SCIP *scip, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEURCOPY((*heurcopy)), SCIP_DECL_HEURFREE((*heurfree)), SCIP_DECL_HEURINIT((*heurinit)), SCIP_DECL_HEUREXIT((*heurexit)), SCIP_DECL_HEURINITSOL((*heurinitsol)), SCIP_DECL_HEUREXITSOL((*heurexitsol)), SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
SCIP_Longint SCIPheurGetNBestSolsFound(SCIP_HEUR *heur)
SCIP_Longint SCIPheurGetNCalls(SCIP_HEUR *heur)
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
SCIP_Bool SCIPhasCurrentNodeLP(SCIP *scip)
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
SCIP_RETCODE SCIPgetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_RETCODE SCIPincSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real incval)
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 SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_Bool SCIPisFeasFracIntegral(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFrac(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Bool GCGvarIsPricing(SCIP_VAR *var)
Definition gcgvar.c:159
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 HEUR_TIMING
#define HEUR_USESSUBSCIP
* result
int j
SCIP_Real frac
SCIP_Bool success
SCIP_Real solval
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
static SCIP_HEURDATA * heurdata
SCIPfreeBufferArray(scip, &cycles)
SCIP_VAR ** mastervars
int nmastervars
static SCIP_RETCODE getZeroMastervar(SCIP *scip, SCIP_HEURDATA *heurdata, int block, SCIP_VAR **zeromastervar)
static SCIP_RETCODE searchZeroMastervar(SCIP *scip, int block, SCIP_VAR **zeromastervar)
#define DEFAULT_MINCOLUMNS
#define heurCopyRelaxcolsel
SCIP_RETCODE GCGincludeHeurRelaxcolsel(GCG *gcg)
#define heurExitsolRelaxcolsel
static SCIP_RETCODE initializeStartsol(GCG *gcg, SCIP_SOL *mastersol, SCIP_SOL *origsol, int *blocknr, int *mastercands, SCIP_Real *candfracs, int *nmastercands, SCIP_Bool *success)
#define heurInitsolRelaxcolsel
relaxation based column selection primal heuristic
#define NULL
#define BMSclearMemoryArray(ptr, num)
GCG variable pricer.
SCIP_VAR ** zerovars
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_HeurData SCIP_HEURDATA
SCIP_LPSOLSTAT_OPTIMAL
SCIP_DELAYED
SCIP_DIDNOTFIND
SCIP_FOUNDSOL
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_SOLVING
struct SCIP_Sol SCIP_SOL
struct SCIP_Var SCIP_VAR
SCIP_VARTYPE_INTEGER
SCIP_VARTYPE_BINARY
enum SCIP_Vartype SCIP_VARTYPE