GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
heur_greedycolsel.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_greedycolsel.c
30 * @brief greedy 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 "greedycolsel"
44#define HEUR_DESC "greedy column selection heuristic"
45#define HEUR_DISPCHAR 'e'
46#define HEUR_PRIORITY 0
47#define HEUR_FREQ 1
48#define HEUR_FREQOFS 0
49#define HEUR_MAXDEPTH -1
50/** @todo should heuristic be called during the pricing loop or only after solving a node relaxation? */
51#define HEUR_TIMING SCIP_HEURTIMING_DURINGLPLOOP | SCIP_HEURTIMING_DURINGPRICINGLOOP
52#define HEUR_USESSUBSCIP FALSE
53
54#define DEFAULT_MINCOLUMNS 200 /**< minimum number of columns to regard in the master problem */
55#define DEFAULT_USEOBJ FALSE /**< use objective coefficients as tie breakers */
56
57
58
59
60/*
61 * Data structures
62 */
63
64/** primal heuristic data */
65struct SCIP_HeurData
66{
67 GCG* gcg; /**< GCG data structure */
68 /* parameters */
69 int mincolumns; /**< minimum number of columns to regard in the master problem */
70 SCIP_Bool useobj; /**< use objective coefficients as tie breakers */
71
72 /* data */
73 SCIP_VAR** zerovars; /**< array of master variables corresponding to zero solutions */
74 int maxzerovars; /**< capacity of zerovars */
75 int lastncols; /**< number of columns in the last call of the heuristic */
76};
77
78
79
80
81/*
82 * Local methods
83 */
84
85
86/** how would the number of violated rows change if mastervar were increased? */
87static
89 SCIP* scip,
91 SCIP_VAR* mastervar
92 )
93{
94 SCIP_COL* col;
95 SCIP_ROW** colrows;
96 SCIP_Real* colvals;
97 int ncolrows;
98 int violchange;
99
100 int r;
101
102 /* get the rows in which the master variable appears (only these must be regarded) */
103 col = SCIPvarGetCol(mastervar);
104 colrows = SCIPcolGetRows(col);
105 colvals = SCIPcolGetVals(col);
106 ncolrows = SCIPcolGetNLPNonz(col);
107 assert(ncolrows == 0 || (colrows != NULL && colvals != NULL));
108
109 violchange = 0;
110 for( r = 0; r < ncolrows; r++ )
111 {
112 SCIP_ROW* row;
113 int rowpos;
114
115 row = colrows[r];
116 rowpos = SCIProwGetLPPos(row);
117 assert(-1 <= rowpos);
118
119 if( rowpos >= 0 && !SCIProwIsLocal(row) )
120 {
121 SCIP_Real oldactivity;
122 SCIP_Real newactivity;
123
124 oldactivity = activities[rowpos];
125 newactivity = oldactivity + colvals[r];
126
127 if( SCIPisFeasLT(scip, oldactivity, SCIProwGetLhs(row)) || SCIPisFeasGT(scip, oldactivity, SCIProwGetRhs(row)) )
128 {
129 if( SCIPisFeasGE(scip, newactivity, SCIProwGetLhs(row)) && SCIPisFeasLE(scip, oldactivity, SCIProwGetRhs(row)) )
130 violchange--;
131 }
132 else
133 {
134 if( SCIPisFeasLT(scip, newactivity, SCIProwGetLhs(row)) || SCIPisFeasGT(scip, newactivity, SCIProwGetRhs(row)) )
135 violchange++;
136 }
137 }
138 }
139
140 return violchange;
141}
142
143/** get the index of the "best" master variable w.r.t. pseudo costs */
144static
146 GCG* gcg,
147 SCIP_SOL* mastersol,
149 int* blocknr,
150 SCIP_Bool* ignored,
151 SCIP_Bool useobj,
152 int* index,
153 int* violchange
154 )
155{
157 int nmastervars;
158
159 int i;
160 int tmpviolchange;
161 SCIP_Real tmpobj;
162 SCIP_Real curobj;
164
165 /* get variable data of the master problem */
167 assert(nmastervars >= 0);
168
169 *index = -1;
170 *violchange = INT_MAX;
171 curobj = SCIPinfinity(masterprob);
172
173 for( i = nmastervars - 1; i >= 0; i-- )
174 {
175 SCIP_VAR* mastervar;
176 int block;
177
178 mastervar = mastervars[i];
179 assert(GCGvarIsMaster(mastervar));
180 block = GCGvarGetBlock(mastervar);
181
182 /** @todo handle copied original variables and linking variables */
183 if( block < 0 )
184 continue;
185
186 /** @todo handle rays */
187 if( GCGmasterVarIsRay(mastervar) )
188 continue;
189
190 /* ignore the master variable if the corresponding block is already full
191 * or which are fixed
192 */
193 if( blocknr[block] < GCGgetNIdenticalBlocks(gcg, block )
194 && !ignored[i]
195 && !SCIPisEQ(masterprob, SCIPvarGetLbLocal(mastervar), SCIPvarGetUbLocal(mastervar))
196 && SCIPisFeasGE(masterprob, SCIPgetSolVal(masterprob, mastersol, mastervar), SCIPvarGetUbLocal(mastervar)) )
197 {
198 tmpviolchange = getViolationChange(masterprob, activities, mastervar);
199 tmpobj = SCIPvarGetObj(mastervar);
200 if( tmpviolchange < *violchange ||
201 (tmpviolchange == *violchange && SCIPisLE(masterprob, tmpobj, curobj) && useobj) )
202 {
203 *index = i;
204 *violchange = tmpviolchange;
205 curobj = tmpobj;
206 }
207 }
208 }
209
210 return SCIP_OKAY;
211}
212
213/** update activities */
214static
216 SCIP* scip,
218 SCIP_VAR* mastervar
219 )
220{
221 SCIP_COL* col;
222 SCIP_ROW** colrows;
223 SCIP_Real* colvals;
224 int ncolrows;
225
226 int r;
227
229
230 col = SCIPvarGetCol(mastervar);
231 colrows = SCIPcolGetRows(col);
232 colvals = SCIPcolGetVals(col);
233 ncolrows = SCIPcolGetNLPNonz(col);
234 assert(ncolrows == 0 || (colrows != NULL && colvals != NULL));
235
236 for( r = 0; r < ncolrows; ++r )
237 {
238 SCIP_ROW* row = colrows[r];
239 int rowpos = SCIProwGetLPPos(row);
240
241 assert(-1 <= rowpos);
242
243 if( rowpos >= 0 && !SCIProwIsLocal(row) )
244 {
245 SCIP_Real oldactivity;
246 SCIP_Real newactivity;
247
248 assert(SCIProwIsInLP(row));
249
250 /* update row activity */
251 oldactivity = activities[rowpos];
252 newactivity = oldactivity + colvals[r];
253 if( SCIPisInfinity(scip, newactivity) )
254 newactivity = SCIPinfinity(scip);
255 else if( SCIPisInfinity(scip, -newactivity) )
256 newactivity = -SCIPinfinity(scip);
257 activities[rowpos] = newactivity;
258 }
259 }
260
261 return SCIP_OKAY;
262}
263
264/** for a given block, search if there is a master variable corresponding to the zero solution;
265 * @todo it would be more efficient to "mark" master variables as being trivial */
266static
268 SCIP* scip,
269 int block,
270 SCIP_VAR** zeromastervar
271 )
272{
274 int nmastervars;
275
276 int i;
277 int j;
278
279 /* get variable data of the master problem */
281
282 *zeromastervar = NULL;
283
284 /* go through all master variables */
285 for( i = 0; i < nmastervars && *zeromastervar == NULL; ++i )
286 {
287 SCIP_VAR* mastervar = mastervars[i];
288 int b = GCGvarGetBlock(mastervar);
289
290 /* only regard master variables belonging to the block we are searching for */
291 if( b == block )
292 {
293 SCIP_Real* origvals = GCGmasterVarGetOrigvals(mastervar);
294 int norigvars = GCGmasterVarGetNOrigvars(mastervar);
295
296 /* check if all original variables contained in the master variable have value zero */
297 for( j = 0; j < norigvars; ++j )
298 if( !SCIPisZero(scip, origvals[j]) )
299 break;
300
301 /* if so, we have found the right master variable */
302 if( j == norigvars )
303 *zeromastervar = mastervar;
304 }
305 }
306
307 return SCIP_OKAY;
308}
309
310/** for a given block, return the master variable corresponding to the zero solution,
311 * or NULL is there is no such variable available */
312static
314 SCIP* scip,
316 int block,
317 SCIP_VAR** zeromastervar
318 )
319{
320 /* if no zero solution is known for the block, look if a master variable has been added
321 * and remember the variable for future use */
322 if( heurdata->zerovars[block] == NULL )
323 SCIP_CALL( searchZeroMastervar(scip, block, zeromastervar) );
324 else
325 *zeromastervar = heurdata->zerovars[block];
326
327 return SCIP_OKAY;
328}
329
330
331
332
333/*
334 * Callback methods of primal heuristic
335 */
336
337
338/** copy method for primal heuristic plugins (called when SCIP copies plugins) */
339#define heurCopyGreedycolsel NULL
340
341/** destructor of primal heuristic to free user data (called when SCIP is exiting) */
342static
343SCIP_DECL_HEURFREE(heurFreeGreedycolsel)
344{ /*lint --e{715}*/
346
347 assert(heur != NULL);
348 assert(scip != NULL);
349
350 /* get heuristic data */
352 assert(heurdata != NULL);
353
354 /* free heuristic data */
356 SCIPheurSetData(heur, NULL);
357
358 return SCIP_OKAY;
359}
360
361
362/** initialization method of primal heuristic (called after problem was transformed) */
363static
364SCIP_DECL_HEURINIT(heurInitGreedycolsel)
365{ /*lint --e{715}*/
367 int nblocks;
368
369 int i;
370
371 assert(heur != NULL);
372 assert(scip != NULL);
373
374 /* get heuristic's data */
376 assert(heurdata != NULL);
377
378 /* get number of blocks */
379 nblocks = GCGgetNPricingprobs(heurdata->gcg);
380
381 heurdata->lastncols = 0;
382
383 /* allocate memory and initialize array with NULL pointers */
384 if( nblocks > 0 )
385 {
388 }
389
390 for( i = 0; i < nblocks; ++i )
392
393 return SCIP_OKAY;
394}
395
396
397/** deinitialization method of primal heuristic (called before transformed problem is freed) */
398static
399SCIP_DECL_HEUREXIT(heurExitGreedycolsel)
400{ /*lint --e{715}*/
402
403 assert(heur != NULL);
404 assert(scip != NULL);
405
406 /* get heuristic data */
408 assert(heurdata != NULL);
409
410 /* free memory */
412
413 return SCIP_OKAY;
414}
415
416
417/** solving process initialization method of primal heuristic (called when branch and bound process is about to begin) */
418#define heurInitsolGreedycolsel NULL
419
420
421/** solving process deinitialization method of primal heuristic (called before branch and bound process data is freed) */
422#define heurExitsolGreedycolsel NULL
423
424
425/** execution method of primal heuristic */
426static
427SCIP_DECL_HEUREXEC(heurExecGreedycolsel)
428{ /*lint --e{715}*/
429 SCIP* origprob; /* SCIP structure of original problem */
430 SCIP_HEURDATA* heurdata; /* heuristic's data */
431 SCIP_ROW** lprows; /* LP rows of master problem */
432 SCIP_SOL* mastersol; /* working master solution */
433 SCIP_SOL* origsol; /* working original solution */
435 SCIP_Real* activities; /* for each master LP row, activity of current master solution */
436 int* blocknr; /* for each pricing problem, block we are currently working in */
437 SCIP_Bool* ignored; /* for each master variable, store whether it has to be ignored */
438 SCIP_Bool allblocksfull; /* indicates if all blocks are full, i.e. all convexity constraints are satisfied */
439 SCIP_Bool masterfeas;
441 int minnewcols; /* minimum number of new columns necessary for calling the heuristic */
442 int nlprows;
443 int nmastervars;
444 int nblocks;
445 int nviolrows;
446 int violchange;
447
448 int i;
449 int j;
450 int k;
451 int index;
452
453 assert(heur != NULL);
454 assert(scip != NULL);
455 assert(result != NULL);
456
457 /* get heuristic's data */
459 assert(heurdata != NULL);
460
461 /* get original problem */
463 assert(origprob != NULL);
464
466
467 /* get variable data of the master problem */
469 assert(nmastervars >= 0);
470
471 /* calculate minimum number of new columns necessary for calling the heuristic;
472 * this number is influenced by how successful the heuristic was in the past */
473 minnewcols = heurdata->mincolumns * (int) (1.0 * ((1.0 + SCIPheurGetNCalls(heur)) / (1.0 + SCIPheurGetNBestSolsFound(heur))));
474
475 /* if there are not enough new columns since last call, abort heuristic */
476 if( nmastervars - heurdata->lastncols < minnewcols )
477 return SCIP_OKAY;
478
480
481 SCIPdebugMessage("Executing Greedy Column Selection heuristic (nmastervars = %d) ...\n", nmastervars);
482
483 /* get number of pricing problems */
484 nblocks = GCGgetNPricingprobs(heurdata->gcg);
485 assert(nblocks >= 0);
486
487 /* get master LP rows data */
489 assert(lprows != NULL);
490 assert(nlprows >= 0);
491
492 /* allocate memory */
493 SCIP_CALL( SCIPallocBufferArray(scip, &blocknr, nblocks) );
496
497 /* get memory for working solutions and row activities */
498 SCIP_CALL( SCIPcreateSol(scip, &mastersol, heur) );
499 SCIP_CALL( SCIPcreateSol(origprob, &origsol, heur) );
500
501 /* initialize block and master variable information */
502 BMSclearMemoryArray(blocknr, nblocks);
504 allblocksfull = FALSE;
505
506 /* initialize activities with zero and get number of violated rows of zero master solution */
507 nviolrows = 0;
508 for( i = 0; i < nlprows; i++ )
509 {
510 SCIP_ROW* row;
511
512 row = lprows[i];
513 assert(SCIProwGetLPPos(row) == i);
514
515 if( !SCIProwIsLocal(row) )
516 {
517 activities[i] = 0;
518 if( SCIPisFeasLT(scip, 0.0, SCIProwGetLhs(row)) || SCIPisFeasGT(scip, 0.0, SCIProwGetRhs(row)) )
519 nviolrows++;
520 }
521 }
522
523 SCIPdebugMessage(" -> %d master LP rows violated\n", nviolrows);
524
525 masterfeas = FALSE;
526 success = FALSE;
527
528 /* try to increase master variables until all blocks are full */
529 while( !allblocksfull && !success )
530 {
531 SCIP_VAR* mastervar;
532 SCIP_VAR** origvars;
533 SCIP_Real* origvals;
534 int norigvars;
535 int block;
536
537 SCIP_CALL( getBestMastervar(heurdata->gcg, mastersol, activities, blocknr, ignored, heurdata->useobj, &index, &violchange) );
538 assert(index >= -1 && index < nmastervars);
539
540 /* if no master variable could be selected, abort */
541 if( index == -1 )
542 {
543 assert(violchange == INT_MAX);
544 SCIPdebugMessage(" -> no master variable could be selected\n");
545 break;
546 }
547
548 /* get master variable */
549 mastervar = mastervars[index];
550 assert(GCGvarIsMaster(mastervar));
551 assert(GCGvarGetBlock(mastervar) >= 0);
552 assert(!GCGmasterVarIsRay(mastervar));
553
554 /* get blocknr and original variables */
555 block = GCGvarGetBlock(mastervar);
556 origvars = GCGmasterVarGetOrigvars(mastervar);
557 origvals = GCGmasterVarGetOrigvals(mastervar);
558 norigvars = GCGmasterVarGetNOrigvars(mastervar);
559
560 SCIPdebugMessage(" -> (block %d) selected master variable %s; violchange=%d\n",
561 block, SCIPvarGetName(mastervar), violchange);
562
563 /* increase master value by one and increase solution values in current original solution accordingly */
564 SCIP_CALL( SCIPincSolVal(scip, mastersol, mastervar, 1.0) );
565
566 /* update original solution accordingly */
567 for( i = 0; i < norigvars; i++ )
568 {
569 assert(GCGvarIsOriginal(origvars[i]));
570
571 /* linking variables are treated differently; if the variable already has been assigned a value,
572 * one must check whether the value for the current block is the same (otherwise, the resulting
573 * solution will be infeasible in any case) */
574 if( GCGoriginalVarIsLinking(origvars[i]) )
575 {
576 SCIP_VAR** linkingpricingvars;
577 SCIP_Bool hasvalue;
578
579 /* check whether linking variable has already been assigned a value */
580 linkingpricingvars = GCGlinkingVarGetPricingVars(origvars[i]);
581 hasvalue = FALSE;
582 for( j = 0; j < nblocks; j++ )
583 if( linkingpricingvars[j] != NULL )
584 if( blocknr[j] > 0 )
585 {
586 hasvalue = TRUE;
587 break;
588 }
589
590 /* if the linking variable has not been assigned a value yet, assign a value to
591 * the variable and the corresponding copy in the master problem */
592 if( !hasvalue )
593 {
594 SCIP_VAR* linkingmastervar;
595
596 linkingmastervar = GCGoriginalVarGetMastervars(origvars[i])[0];
597 assert(linkingmastervar != NULL);
598 SCIP_CALL( SCIPincSolVal(origprob, origsol, origvars[i], origvals[i]) );
599 SCIP_CALL( SCIPincSolVal(scip, mastersol, linkingmastervar, origvals[i]) );
600 }
601 /* otherwise, exclude the current master variable, if the point has a different value for it */
602 else
603 {
604 SCIP_Real value;
605 value = SCIPgetSolVal(origprob, origsol, origvars[i]);
606 if( !SCIPisEQ(origprob, value, origvals[i]) )
607 {
608 SCIPdebugMessage(" -> cannot use mastervar: origvar %s already has value %g in block %d, different to %g\n",
609 SCIPvarGetName(origvars[i]), value, j, origvals[i]);
610 ignored[index] = TRUE;
611 break;
612 }
613 }
614 }
615 else
616 {
617 SCIP_VAR* pricingvar;
618 SCIP_VAR** origpricingvars;
619#ifndef NDEBUG
620 int norigpricingvars;
621#endif
622
623 /* if the variable is zero, nothing happens */
624 if( SCIPisZero(scip, origvals[i]) )
625 continue;
626
627 pricingvar = GCGoriginalVarGetPricingVar(origvars[i]);
628 assert(pricingvar != NULL);
629 assert(GCGvarIsPricing(pricingvar));
630
631 origpricingvars = GCGpricingVarGetOrigvars(pricingvar);
632
633#ifndef NDEBUG
634 norigpricingvars = GCGpricingVarGetNOrigvars(pricingvar);
635 assert(blocknr[block] < norigpricingvars);
636#endif
637
638 /* increase the corresponding value */
639 SCIP_CALL( SCIPincSolVal(origprob, origsol, origpricingvars[blocknr[block]], origvals[i]) );
640 }
641 }
642
643 /* if the current master variable was set to be ignored, reset solution values and choose a new one */
644 if( ignored[index] )
645 {
646 SCIP_CALL( SCIPincSolVal(scip, mastersol, mastervar, -1.0) );
647 for( k = 0; k < i; k++ )
648 {
649 if( GCGoriginalVarIsLinking(origvars[k]) )
650 {
651 SCIP_VAR** linkingpricingvars;
652 SCIP_Bool hasvalue;
653
654 /* check whether linking variable has already been assigned a value */
655 linkingpricingvars = GCGlinkingVarGetPricingVars(origvars[k]);
656 hasvalue = FALSE;
657 for( j = 0; j < nblocks; j++ )
658 {
659 if( linkingpricingvars[j] != NULL )
660 {
661 if( blocknr[j] > 0 && j != block )
662 {
663 hasvalue = TRUE;
664 break;
665 }
666 }
667 }
668
669 /* if the linking variable has not had a value before, set it back to zero */
670 if( !hasvalue )
671 {
672 SCIP_VAR* linkingmastervar;
673
674 linkingmastervar = GCGoriginalVarGetMastervars(origvars[k])[0];
675 SCIP_CALL( SCIPincSolVal(origprob, origsol, origvars[k], -origvals[k]) );
676 SCIP_CALL( SCIPincSolVal(scip, mastersol, linkingmastervar, -origvals[k]) );
677 }
678 }
679 else
680 {
681 SCIP_VAR* pricingvar;
682 SCIP_VAR** origpricingvars;
683#ifndef NDEBUG
684 int norigpricingvars;
685#endif
686
687 pricingvar = GCGoriginalVarGetPricingVar(origvars[k]);
688 assert(pricingvar != NULL);
689 assert(GCGvarIsPricing(pricingvar));
690
691 origpricingvars = GCGpricingVarGetOrigvars(pricingvar);
692
693#ifndef NDEBUG
694 norigpricingvars = GCGpricingVarGetNOrigvars(pricingvar);
695 assert(blocknr[block] < norigpricingvars);
696#endif
697
698 /* decrease the corresponding value */
699 SCIP_CALL( SCIPincSolVal(origprob, origsol, origpricingvars[blocknr[block]], -origvals[k]) );
700 }
701 }
702 continue;
703 }
704
705 blocknr[block]++;
706
707 /* try to add the solution to (original) solution pool */
709
710 /* check if all blocks are full */
711 allblocksfull = TRUE;
712 for( i = 0; i < nblocks && allblocksfull; i++ )
713 {
714 int nidentblocks;
715
716 nidentblocks = GCGgetNIdenticalBlocks(heurdata->gcg, i);
717
718 /* in case the solution is feasible but the block is not full,
719 * we need a zero solution for this block in order to generate
720 * a corresponding master solution */
721 if( success && blocknr[i] < nidentblocks )
722 {
723 SCIP_VAR* zeromastervar;
724
725 /* fill the block with the zero solution */
726 zeromastervar = NULL;
727 SCIP_CALL( getZeroMastervar(scip, heurdata, i, &zeromastervar) );
728 if( zeromastervar != NULL )
729 {
730 SCIPdebugMessage(" -> (block %d) selected zero master variable %s (%d times)\n",
731 i, SCIPvarGetName(zeromastervar), nidentblocks - blocknr[i]);
732
733 SCIP_CALL( SCIPincSolVal(scip, mastersol, zeromastervar,
734 (SCIP_Real) nidentblocks - blocknr[i]) );
735 blocknr[i] = nidentblocks;
736 }
737 }
738
739 /** @todo >= should not happen, replace it by == ? */
740 if( !(blocknr[i] >= nidentblocks) )
741 allblocksfull = FALSE;
742 }
743
744 /* if we found a solution for the original instance,
745 * also add the corresponding master solution */
746 if( success && allblocksfull )
747 {
748#ifdef SCIP_DEBUG
749 SCIP_CALL( SCIPtrySol(scip, mastersol, TRUE, TRUE, TRUE, TRUE, TRUE, &masterfeas) );
750#else
751 SCIP_CALL( SCIPtrySol(scip, mastersol, FALSE, FALSE, TRUE, TRUE, TRUE, &masterfeas) );
752#endif
753 if( !masterfeas )
754 {
755 SCIPdebugMessage("WARNING: original solution feasible, but no solution has been added to master problem.\n");
756 }
757 }
758
759 /* update number of violated rows and activities array */
760 nviolrows += violchange;
762 }
763
764 if( success )
765 {
767 SCIPdebugMessage("heuristic successful - feasible solution found, obj=%g\n",
768 SCIPgetSolOrigObj(origprob, origsol));
769 }
770 else
771 {
772 SCIPdebugMessage("no feasible solution found or solution already known; %d constraints violated.\n", nviolrows);
773 }
774
775 SCIP_CALL( SCIPfreeSol(origprob, &origsol) );
776 SCIP_CALL( SCIPfreeSol(scip, &mastersol) );
778 SCIPfreeBufferArray(scip, &ignored);
779 SCIPfreeBufferArray(scip, &blocknr);
780
782
783 return SCIP_OKAY;
784}
785
786
787
788
789/*
790 * primal heuristic specific interface methods
791 */
792
793/** creates the greedy column selection primal heuristic and includes it in SCIP */
795 GCG* gcg /**< GCG data structure */
796 )
797{
800
801 /* create greedy column selection primal heuristic data */
803 heurdata->gcg = gcg;
804
807
808 /* include primal heuristic */
811 heurCopyGreedycolsel, heurFreeGreedycolsel, heurInitGreedycolsel, heurExitGreedycolsel,
813 heurdata) );
814
815 /* add greedy column selection primal heuristic parameters */
816 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/"HEUR_NAME"/mincolumns",
817 "minimum number of columns to regard in the master problem",
819 SCIP_CALL( SCIPaddBoolParam(masterprob, "heuristics/"HEUR_NAME"/useobj",
820 "use objective coefficients as tie breakers",
822
823 return SCIP_OKAY;
824}
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
SCIP_Real * r
#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
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_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_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_Real * SCIPcolGetVals(SCIP_COL *col)
SCIP_ROW ** SCIPcolGetRows(SCIP_COL *col)
int SCIPcolGetNLPNonz(SCIP_COL *col)
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_RETCODE SCIPgetLPRowsData(SCIP *scip, SCIP_ROW ***rows, int *nrows)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
int SCIProwGetLPPos(SCIP_ROW *row)
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
SCIP_Bool SCIProwIsInLP(SCIP_ROW *row)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
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_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
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_COL * SCIPvarGetCol(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
SCIP_Bool GCGvarIsPricing(SCIP_VAR *var)
Definition gcgvar.c:159
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_Bool success
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
static SCIP_HEURDATA * heurdata
SCIPfreeBufferArray(scip, &cycles)
int nlprows
static SCIP_RETCODE updateActivities(SCIP *scip, SCIP_Real *activities, SCIP_ROW **violrows, int *violrowpos, int *nviolrows, int nlprows, SCIP_VAR *var, SCIP_Real oldsolval, SCIP_Real newsolval)
SCIP_ROW ** lprows
SCIP_Real * activities
int nviolrows
SCIP_VAR ** mastervars
int nmastervars
static SCIP_RETCODE getBestMastervar(GCG *gcg, SCIP_SOL *mastersol, SCIP_Real *activities, int *blocknr, SCIP_Bool *ignored, SCIP_Bool useobj, int *index, int *violchange)
#define DEFAULT_USEOBJ
#define heurInitsolGreedycolsel
#define heurExitsolGreedycolsel
SCIP_RETCODE GCGincludeHeurGreedycolsel(GCG *gcg)
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
static int getViolationChange(SCIP *scip, SCIP_Real *activities, SCIP_VAR *mastervar)
#define heurCopyGreedycolsel
greedy 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
struct SCIP_Row SCIP_ROW
struct SCIP_Col SCIP_COL
SCIP_DELAYED
SCIP_DIDNOTFIND
SCIP_FOUNDSOL
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct SCIP_Sol SCIP_SOL
struct SCIP_Var SCIP_VAR