GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
heur_setcover.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_setcover.c
30 * @brief set covering primal heuristic according to Caprara, Fischetti, and Toth (1999)
31 * @author Tobias Oelschlaegel
32 * @author Christian Puchert
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37#include <assert.h>
38#include <string.h>
39#include "gcg/gcg.h"
40#include "gcg/pricer_gcg.h"
41#include "scip/clock.h"
42#include "scip/cons_linear.h"
43#include "gcg/heur_setcover.h"
44
45
46#define HEUR_NAME "setcover"
47#define HEUR_DESC "set covering primal heuristic according to Caprara, Fischetti, and Toth (1999)"
48#define HEUR_DISPCHAR 'S'
49#define HEUR_PRIORITY 0
50#define HEUR_FREQ 0
51#define HEUR_FREQOFS 0
52#define HEUR_MAXDEPTH -1
53#define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
54#define HEUR_USESSUBSCIP FALSE /**< does the heuristic use a secondary SCIP instance? */
55
56#define DEF_CORE_TENT_SIZE 10 /**< number of columns covering each row that are added to the tentative core at the beginning */
57#define DEF_LAMBDA_ADJUSTMENTS TRUE /**< adjust step size during the subgradient phase */
58#define DEF_LAMBDA_P 50 /**< number of iterations after which lambda is adjusted */
59#define DEF_LAMBDA 0.1 /**< initial step size for the subgradient phase */
60#define DEF_STOP_CRIT_ITER 300 /**< number of iterations of the subgradient phase after which the stopping criterion is tested again */
61#define DEF_STOP_CRIT_DIFF 1.0 /**< stop if absolute difference between best lower and upper bound is less than SCP_STOP_CRIT_DIFF, and */
62#define DEF_STOP_CRIT_RATIO 0.99 /**< the relative ratio between best lower and upper bound is less than DEF_STOP_CRIT_RATIO */
63#define DEF_PI_MIN 0.3 /**< percentage of rows to be removed after fixing columns */
64#define DEF_PI_ALPHA 1.1 /**< increase of pi when no improvement was made, i.e. more columns will be fixed */
65#define DEF_BETA 1.025 /**< allowed gap between lowerbound and upper bound during the subgradient phase */
66#define DEF_MAX_ITER 2 /**< maximum number of iterations of three-phase */
67#define DEF_MAX_ITER_NO_IMP 1 /**< stop of no improvements during the last X iterations of three-phase */
68#define DEF_THREEPHASE_MAX_ITER 10 /**< maximum number of iterations inside three-phase */
69#define DEF_GREEDY_MAX_ITER 100 /**< number of multipliers that are used for computing greedy solutions during each iteration */
70#define DEF_MIN_PROB_SIZE 1000 /**< minimum number of variables the problem has to contain for the heuristic to start */
71#define DEFAULT_RANDSEED 19 /**< initial random seed */
72
73/*
74 * Data structures
75 */
76
77/** primal heuristic data */
78
79typedef struct
80{
81 int size; /**< actual number of elements stored in the queue */
82 int reserved; /**< number of elements for which memory is allocated */
83 SCIP_Real* keys; /**< array of keys */
84 int* data; /**< array of values */
85 int** positions; /**< array of pointers to save positions of elements */
86} PQUEUE;
87
88typedef struct
89{
90 SCIP_Bool* varsfixed; /**< boolean array that indicates which variables are fixed */
91 int nvarsfixed; /**< number of fixed variables */
92 SCIP_Bool* rowscovered; /**< boolean array that indicates which rows are covered by the fixed variables */
93 int nrowscovered; /**< number of rows that are covered by the fixed variables */
94 SCIP_Real costsfixed; /**< total costs of variables that are fixed */
96
97typedef struct
98{
99 SCIP_Bool* varincore; /**< boolean array that indicates whether a variable is in the core */
100 int* listcorevariables; /**< array of indices of core variables */
101 int ncorevariables; /**< number of core variables */
102 SCIP_HASHMAP* mapvariables; /**< maps variables-indices to [0, nvariables) in array 'variables' */
103 SCIP_VAR** variables; /**< all variables of the problem */
104 int* nvarconss; /**< array that contains for each variable the number of constraints it is part of */
105 int nvariables; /**< total number of variables */
106 SCIP_Bool columnsavailable; /**< if set then 'columns' contains the columns for all core variables */
107 int** columns; /**< columns of core variables, NULL if not a core variable */
108 SCIP_Bool rowsavailable; /**< if set then 'rows' contains all rows reduced to core variables */
109 int** rows; /**< rows that only contain core variables */
110 int* nrowvars; /**< number of core variables a row contains */
111 int nconss; /**< total number of constraints (including inactive ones) */
112 int nactiveconss; /**< total number of active constraints for which the variables can be retrieved */
113 int maxconstraintvariables; /**< greatest number of variables some constraint contains */
114 SCIP_CONS** conss; /**< all constraints of the problem */
115 int* constraintid; /**< unique id for each constraint */
116 SCIP_Real* delta; /**< delta values of variables */
120} SCP_CORE;
121
122typedef struct
123{
124 SCIP_Bool* xgreedylocal; /**< contains variables that are part of a greedy solution, this is not necessarily a global solution */
125 SCIP_Real* u; /**< lagrange multipliers for the rows */
127 SCIP_Real* lagrangiancostslocal; /**< lagrangian costs (for a certain instance) when only uncovered rows are considered */
128 SCIP_Real* lagrangiancostsglobal; /**< lagrangian costs for the whole instance when all rows and columns are considered */
129 SCIP_Real ubgreedylocal; /**< bound computed by the greedy set cover algorithm for the restricted instance */
130 SCIP_Real lblagrangelocal; /**< lower bound by lagrange relaxation for the restricted instance */
131 SCIP_Real lblagrangeglobal; /**< lower bound by lagrange relaxation for the unrestricted instance */
133
134struct SCIP_HeurData
135{
136 GCG* gcg; /** GCG data structure */
137 int param_core_tent_size; /**< number of columns covering each row that are added to the tentative core at the beginning */
138 SCIP_Bool param_lambda_adjustments; /**< adjust step size during the subgradient phase */
139 int param_lambda_p; /**< number of iterations after which lambda is adjusted */
140 SCIP_Real param_lambda; /**< initial step size for the subgradient phase */
141 int param_stop_crit_iter; /**< number of iterations of the subgradient phase after which the stopping criterion is tested again */
142 SCIP_Real param_stop_crit_diff; /**< stop if absolute difference between best lower and upper bound is less than SCP_STOP_CRIT_DIFF, and */
143 SCIP_Real param_stop_crit_ratio; /**< the relative gap between best lower and upper bound is less than (1 - SCP_STOP_CRIT_PER */
144 SCIP_Real param_pi_min; /**< percentage of rows to be removed after fixing columns */
145 SCIP_Real param_pi_alpha; /**< increase of pi when no improvement was made, i.e. more columns will be fixed */
146 SCIP_Real param_beta; /**< allowed a gap between lowerbound and upper bound during the subgradient phase */
147 int param_max_iter; /**< maximum number of iterations of three-phase */
148 int param_max_iter_no_imp; /**< stop of no improvements during the last X iterations of three-phase */
149 int param_threephase_max_iter; /**< maximum number of iterations inside three-phase */
150 int param_greedy_max_iter; /**< number of multipliers that are used for computing greedy solutions during each iteration */
151 int param_min_prob_size; /**< minimum number of variables the master problem needs to contain before the heuristic starts at all */
152
153 SCP_CORE core; /**< core (subcollection of columns) of the problem covering all rows */
154 SCP_INSTANCE inst; /**< reduced instance where some variables may be fixed and some rows be covered */
155 SCP_INSTANCE subinst; /**< reduced instance of 'inst', used during the three-phase */
156
157 SCP_Lagrange_Sol multbestlbtotal; /**< lagrange multiplier that gives the best lower bound for the complete problem */
158 SCP_Lagrange_Sol multbestlbinst; /**< best multiplier for instance 'inst' */
159 SCP_Lagrange_Sol multbestlbsubinst; /**< best multiplier for instance 'subinst' */
160
161 SCIP_Real bestub; /**< best upper bound that could be obtained so far */
162 SCIP_Bool* bestubsol; /**< actual solution that gives the best upper bound */
163 SCIP_Real bestubinst; /**< best upper bound for the reduced instance 'inst' (including fixed costs) */
164 SCIP_Bool* bestubinst_sol; /**< actual solution for the instance 'inst' (including fixed variables) */
165 SCIP_Real bestubsubinst; /**< best upper bound for the reduced instance 'subinst' (including fixed costs) */
166 SCIP_Bool* bestubsubinstsol; /**< actual solution for the instance 'subinst' (including fixed variables) */
167
168 /* local data that is used by (most) local procedures */
169 SCIP_VAR** vars; /**< used to iterate through the variables of a constraint */
170
171 /* memory that is used locally by 'threephase' */
172 SCP_Lagrange_Sol tpmultlbsubinst; /**< lagrange multiplier */
173 SCIP_Bool useinitialmultiplier; /**< compute an own initial lagrange multiplier instead of using the best known */
174
175 /* memory that is used locally by 'greedysetcover' */
176 PQUEUE greedyqueue; /**< priority queue used by the greedy algorithm */
177 int* greedycolpos; /**< stores position of a variable within the priority queue */
178 int* greedycolmu; /**< value mu for each variable */
179 SCIP_Real* greedycolgamma; /**< value gamma for each variable */
180 SCIP_Real* greedycolscore; /**< score of each variable */
181 SCP_INSTANCE greedyinst; /**< instance that is used to hold covered rows */
182
183 /* memory that is used locally by redefineCore */
184 int* rccols; /**< stores columns covering some row sorted by increasing costs */
185 SCIP_Real* rccoldelta; /**< delta values of the columns stored in 'rccols' */
186
187 /* memory that is used locally by subgradientOptimization */
188 SCIP_Real* sglastlb; /**< stores lower bounds of the last iterations */
189 SCIP_RANDNUMGEN* randnumgen; /**< random number generator */
190};
191
192/*
193 * Local methods
194 */
195
196/** initializes a priority queue */
197static
199 SCIP* scip, /**< master SCIP data structure */
200 PQUEUE* queue /**< priority queue instance */
201 )
202{
203 queue->size = 0;
204 queue->reserved = 32;
205
206 SCIP_CALL( SCIPallocBufferArray(scip, &queue->keys, queue->reserved) );
207 SCIP_CALL( SCIPallocBufferArray(scip, &queue->data, queue->reserved) );
209
210 return SCIP_OKAY;
211}
212
213/** removes all elements from a priority queue, but does not release any memory */
214static
216 SCIP* scip, /**< master SCIP data structure */
217 PQUEUE* queue /**< priority queue instance */
218 )
219{
220 queue->size = 0;
221}
222
223/** releases all memory that is used by the priority queue */
224static
226 SCIP* scip, /**< master SCIP data structure */
227 PQUEUE* queue /**< priority queue instance */
228 )
229{
233}
234
235/** inserts an element with key 'key' and value 'elem' into the queue.
236 * If 'position' is not NULL, the referenced memory location will always contain the internal position of the element
237 * */
238static
240 SCIP* scip, /**< master SCIP data structure */
241 PQUEUE* queue, /**< priority queue instance */
242 SCIP_Real key, /**< key of the new item */
243 int elem, /**< value of the new item */
244 int* position /**< address where the items position within the queue is stored */
245 )
246{
247 int pos;
248 int parent = 0;
249
250 if( queue->size == queue->reserved )
251 {
252 queue->reserved += 128;
256 }
257
258 pos = queue->size++;
259 queue->keys[pos] = key;
260 queue->data[pos] = elem;
261
262 if( pos > 0 )
263 parent = (pos - 1) / 2;
264
265 while( (pos > 0) && (key < queue->keys[parent]) )
266 {
267 /* swap element with parent */
268 queue->keys[pos] = queue->keys[parent];
269 queue->data[pos] = queue->data[parent];
270 queue->positions[pos] = queue->positions[parent];
271 /*queue->data[parent] = elem;*/
272
273 if( queue->positions[pos] != NULL )
274 *queue->positions[pos] = pos;
275
276 pos = (pos - 1) / 2;
277 parent = (pos - 1) / 2;
278 }
279
280 queue->keys[pos] = key;
281 queue->data[pos] = elem;
282 queue->positions[pos] = position;
283
284 if( position != NULL )
285 *position = pos;
286
287 return SCIP_OKAY;
288}
289
290/** decreases the key to 'key' of the element that is currently at position 'pos' */
291static
293 SCIP* scip, /**< master SCIP data structure */
294 PQUEUE* queue, /**< priority queue instance */
295 int pos, /**< position of the item within the queue that is to be changed */
296 SCIP_Real key /**< new key of the item, needs to be greater than the old key */
297 )
298{
299 int parent;
300 int* positionptr;
301 int elem;
302
303 if( pos >= queue->size )
304 return;
305
306 parent = (pos - 1) / 2;
307 positionptr = queue->positions[pos];
308 elem = queue->data[pos];
309
310 while( (pos > 0) && (key < queue->keys[parent]) )
311 {
312 /* swap element with parent */
313 queue->keys[pos] = queue->keys[parent];
314 queue->data[pos] = queue->data[parent];
315 queue->positions[pos] = queue->positions[parent];
316 queue->data[parent] = elem;
317
318 if( queue->positions[pos] != NULL )
319 *queue->positions[pos] = pos;
320
321 pos = (pos - 1) / 2;
322 parent = (pos - 1) / 2;
323 }
324
325 queue->keys[pos] = key;
326 queue->data[pos] = elem;
327 queue->positions[pos] = positionptr;
328
329 if( positionptr != NULL )
330 *positionptr = pos;
331}
332
333/** increases the key to 'key' of the element that is currently at position 'pos' */
334static
336 SCIP* scip, /**< master SCIP data structure */
337 PQUEUE* queue, /**< priority queue instance */
338 int pos, /**< position of the item within the queue that is to be changed */
339 SCIP_Real key /**< new key of the item, needs to be smaller than the old one */
340 )
341{
342 int elem;
343 int* positionptr;
344 int left;
345 int right;
346
347 left = 2 * pos + 1;
348 right = 2 * pos + 2;
349
350 if( pos >= queue->size )
351 return;
352
353 elem = queue->data[pos];
354 positionptr = queue->positions[pos];
355
356 while( left < queue->size )
357 {
358 if( right < queue->size )
359 {
360 /* both children exist, so swap with smallest child */
361 if( key <= queue->keys[left] )
362 {
363 /* left child is not smaller than element */
364 if( key <= queue->keys[right] )
365 break;
366 else
367 {
368 /* swap with right child */
369 queue->keys[pos] = queue->keys[right];
370 queue->data[pos] = queue->data[right];
371 queue->positions[pos] = queue->positions[right];
372
373 if( queue->positions[pos] != NULL )
374 *(queue->positions[pos]) = pos;
375
376 pos = right;
377 }
378 }
379 else
380 {
381 /* left child is smaller than the element */
382 if( queue->keys[left] <= queue->keys[right] )
383 {
384 /* left child is smaller than right child and smaller than the element */
385 queue->keys[pos] = queue->keys[left];
386 queue->data[pos] = queue->data[left];
387 queue->positions[pos] = queue->positions[left];
388
389 if( queue->positions[pos] != NULL )
390 *(queue->positions[pos]) = pos;
391
392 pos = left;
393 }
394 else
395 {
396 /* right child is smallest element */
397 queue->keys[pos] = queue->keys[right];
398 queue->data[pos] = queue->data[right];
399 queue->positions[pos] = queue->positions[right];
400
401 if( queue->positions[pos] != NULL )
402 *(queue->positions[pos]) = pos;
403
404 pos = right;
405 }
406 }
407 }
408 else
409 {
410 /* only left child exists */
411 if( key > queue->keys[left] )
412 {
413 /* left child is smaller than element, so swap them */
414 queue->keys[pos] = queue->keys[left];
415 queue->data[pos] = queue->data[left];
416 queue->positions[pos] = queue->positions[left];
417
418 if( queue->positions[pos] != NULL )
419 *(queue->positions[pos]) = pos;
420
421 pos = left;
422 }
423 else
424 break;
425 }
426
427 left = 2 * pos + 1;
428 right = 2 * pos + 2;
429 }
430
431 queue->keys[pos] = key;
432 queue->data[pos] = elem;
433 queue->positions[pos] = positionptr;
434
435 if( positionptr != NULL )
436 *positionptr = pos;
437}
438
439/** returns the value of a minimum element in 'elem'. Sets 'elem' to -1 if the queue is empty */
440static
442 SCIP* scip, /**< master SCIP data structure */
443 PQUEUE* queue, /**< priority queue instance */
444 int* elem /**< address where the value of a minimum key item will be stored */
445 )
446{
447 *elem = -1;
448
449 if( queue->size > 0 )
450 {
451 *elem = queue->data[0];
452
453 queue->size--;
454
455 /* copy last element to front and repair heap structure */
456 if( queue->size > 0 )
457 {
458 queue->keys[0] = queue->keys[queue->size];
459 queue->data[0] = queue->data[queue->size];
460 queue->positions[0] = queue->positions[queue->size];
461
462 if( queue->positions[0] != NULL )
463 *(queue->positions[0]) = 0;
464
465 pqueue_increase_key(scip, queue, 0, queue->keys[0]);
466 }
467 }
468}
469
470/** allocates memory for a lagrange multiplier and a set covering solution */
471static
473 SCIP* scip, /**< master SCIP data structure */
474 SCP_CORE* core, /**< core data structure */
475 SCP_Lagrange_Sol* mult /**< uninitialized solution data structure */
476 )
477{
478 int i;
479
480 SCIP_CALL( SCIPallocBufferArray(scip, &mult->u, core->nconss) );
485
486 for( i = 0; i < core->nvariables; i++ )
487 {
488 mult->lagrangiancostslocal[i] = 0.0;
489 mult->lagrangiancostsglobal[i] = 0.0;
490 }
491
492 for( i = 0; i < core->nconss; i++ )
493 {
494 mult->u[i] = 0.0;
495 mult->subgradient[i] = 0.0;
496 }
497
501
502 return SCIP_OKAY;
503}
504
505/** checks if 'var' is a core variable */
506static
508 SCP_CORE* core, /**< initialized core data structure */
509 SCIP_VAR* var /**< SCIP variable */
510 )
511{
512 int varidx;
513
514 assert(core != NULL);
515 assert(var != NULL);
516
517 varidx = SCIPvarGetProbindex(var);
518 assert(varidx != -1);
519
520 return core->varincore[varidx];
521}
522
523/** checks if 'var' is fixed within instance 'inst' */
524static
526 SCP_INSTANCE* inst, /**< instance of the set covering problem */
527 SCIP_VAR* var /**< SCIP variable */
528 )
529{
530 int varidx;
531
532 assert(inst != NULL);
533 assert(var != NULL);
534
535 varidx = SCIPvarGetProbindex(var);
536 assert(varidx != -1);
537
538 return inst->varsfixed[varidx];
539}
540
541/** checks if 'variable' is part of 'solution' */
542static
544 SCIP_Bool* solution, /**< SCIP hashtable that contains SCIP variables */
545 SCIP_VAR* var /**< SCIP variable */
546 )
547{
548 int varidx;
549
550 assert(solution != NULL);
551 assert(var != NULL);
552
553 varidx = SCIPvarGetProbindex(var);
554 assert(varidx != -1);
555
556 return solution[varidx];
557}
558
559/** adds a variable to the core */
560static
562 SCP_CORE* core, /**< initialized core data structure */
563 SCIP_VAR* var /**< SCIP variable */
564 )
565{
566 int varidx;
567
568 assert(core != NULL);
569 assert(var != NULL);
570
571 varidx = SCIPvarGetProbindex(var);
572 assert(varidx != -1);
573
574 if( !core->varincore[varidx] )
575 ++core->ncorevariables;
576 core->varincore[varidx] = TRUE;
577}
578
579/** fixes 'var' within instance 'inst' */
580static
582 SCP_INSTANCE* inst, /**< SCP instance where 'variable' is to be fixed */
583 SCIP_VAR* var /**< SCIP variable */
584 )
585{
586 int varidx;
587
588 assert(inst != NULL);
589 assert(var != NULL);
590
591 varidx = SCIPvarGetProbindex(var);
592 assert(varidx != -1);
593
594 if( !inst->varsfixed[varidx] )
595 ++inst->nvarsfixed;
596 inst->varsfixed[varidx] = TRUE;
597}
598
599/** adds variable 'var' to 'solution' */
600static
602 SCIP_Bool* solution, /**< solution represented as a boolean array */
603 SCIP_VAR* var /**< SCIP variable */
604 )
605{
606 int varidx;
607
608 assert(solution != NULL);
609 assert(var != NULL);
610
611 varidx = SCIPvarGetProbindex(var);
612 assert(varidx != -1);
613
614 /* no test whether the variable is already part of the solution */
615 solution[varidx] = TRUE;
616}
617
618/** removes all variables from the core */
619static
621 SCIP* scip, /**< SCIP data structure */
622 SCP_CORE* core /**< initialized core data structure */
623 )
624{
625 int i;
626
627 assert(core != NULL);
628
629 for( i = 0; i < SCIPgetNVars(scip); ++i )
630 core->varincore[i] = FALSE;
631 core->ncorevariables = 0;
632}
633
634/** removes a 'var' from 'solution' */
635static
637 SCIP_Bool* solution, /**< solution represented as a boolean array */
638 SCIP_VAR* var /**< SCIP variable */
639 )
640{
641 int varidx;
642
643 assert(solution != NULL);
644 assert(var != NULL);
645
646 varidx = SCIPvarGetProbindex(var);
647 assert(varidx != -1);
648
649 /* no test whether the variable is already part of the solution */
650 solution[varidx] = FALSE;
651}
652
653/** clears a solution */
654static
656 SCIP* scip, /**< SCIP data structure */
657 SCIP_Bool* solution /**< solution represented as a boolean array */
658 )
659{
660 int i;
661
662 assert(scip != NULL);
663 assert(solution != NULL);
664
665 for( i = 0; i < SCIPgetNVars(scip); ++i )
666 solution[i] = FALSE;
667}
668
669/** checks if the row at position 'rowpos' is covered by fixed variables of 'inst' */
670static
672 SCP_INSTANCE* inst, /**< SCP instance */
673 int rowpos /**< position of the row within 'core' */
674 )
675{
676 assert(inst != NULL);
677
678 return inst->rowscovered[rowpos];
679}
680
681/** marks the row at position 'rowpos' as covered within instance 'inst' */
682static
684 SCP_INSTANCE* inst, /**< SCP instance */
685 int rowpos /**< position of the row within 'core' */
686 )
687{
688 assert(inst != NULL);
689
690 if( !inst->rowscovered[rowpos] )
691 ++inst->nrowscovered;
692 inst->rowscovered[rowpos] = TRUE;
693}
694
695/** returns the position of 'variable' within the array core->variables */
696static
698 SCIP* scip, /**< master SCIP data structure */
699 SCP_CORE* core, /**< SCP core data structure */
700 SCIP_VAR* variable, /**< SCIP variable */
701 int* pos /**< address where the position is to be stored */
702 )
703{
704 int varidx;
705
706 assert(scip != NULL);
707 assert(core != NULL);
708 assert(variable != NULL);
709 assert(pos != NULL);
710
711 varidx = SCIPvarGetIndex(variable);
712 *pos = (int) (size_t) SCIPhashmapGetImage(core->mapvariables, (void *) ((size_t) (varidx + 1))); /*lint !e507*/
713
714 return SCIP_OKAY;
715}
716
717/** get all variables that are part of the constraint at position 'pos' (within SCIP) and saves them into 'vars' */
718static
720 SCIP* scip, /**< master SCIP data structure */
721 SCP_CORE* core, /**< SCP core data structure */
722 int pos, /**< position of the constraint within SCIP */
723 SCIP_VAR** vars, /**< allocated memory that can hold all variables */
724 int* nvars, /**< address where the number of variables will be stored */
725 SCIP_Bool* success /**< address where the result of the operation will be stored */
726 )
727{
728 *success = FALSE;
729
730 if( SCIPconsIsActive(core->conss[pos]) == FALSE )
731 return SCIP_OKAY;
732
734
735 if( *success == FALSE )
736 return SCIP_OKAY;
737
739
740 return SCIP_OKAY;
741}
742
743/** releases all memory of a lagrange multiplier */
744static
746 SCIP* scip, /**< master SCIP data structure */
747 SCP_Lagrange_Sol* mult /**< initialized SCP lagrange multiplier that is to be freed */
748 )
749{
754 SCIPfreeBufferArray(scip, &mult->u);
755}
756
757/** creates a set covering solution. Adds all fixed variables of 'inst' and all variables of 'source' to 'dest'.
758 * 'destcosts' contains the total costs of the solution.
759 */
760static
762 SCIP* scip, /**< master SCIP data structure */
763 SCP_CORE* core, /**< SCP core data structure */
764 SCP_INSTANCE* inst, /**< SCP instance */
765 SCIP_Bool* dest, /**< array where variables belonging to the solution are inserted */
766 SCIP_Real* destcosts, /**< address where the total costs of the solution will be stored */
767 SCIP_Bool* source /**< SCP solution to the (reduced) instance 'inst' */
768 )
769{
770 int i;
771 SCIP_Real costs = 0.0;
772
773 /* remove all entries from dest */
774 clearSolution(scip, dest);
775
776 /* iterate through all variables of the problem */
777 for( i = 0; i < core->nvariables; i++ )
778 {
779 if( isVarInSolution(source, core->variables[i]) || isFixedVariable(inst, core->variables[i]) )
780 {
781 /* add variable 'i' if it is in the solution 'source' or fixed in instance 'inst' */
782 costs += SCIPvarGetObj(core->variables[i]);
783 addVarToSolution(dest, core->variables[i]);
784 }
785 }
786
787 /* save total costs if required */
788 if( destcosts != NULL )
789 *destcosts = costs;
790}
791
792/** copies all data of the lagrange multiplier 'source' to the lagrange multiplier 'dest' */
793static
795 SCIP* scip, /**< master SCIP data structure */
796 SCP_CORE* core, /**< SCP core data structure */
797 SCP_Lagrange_Sol* dest, /**< SCP lagrange multiplier where data will be copied to */
798 SCP_Lagrange_Sol* source /**< SCP lagrange multiplier where data will be copied from */
799 )
800{
801 int i;
802
804
805 memcpy(dest->lagrangiancostslocal, source->lagrangiancostslocal, sizeof(*dest->lagrangiancostslocal) * core->nvariables);
806 memcpy(dest->lagrangiancostsglobal, source->lagrangiancostsglobal, sizeof(*dest->lagrangiancostsglobal) * core->nvariables);
807 memcpy(dest->u, source->u, sizeof(*dest->u) * core->nconss);
808 memcpy(dest->subgradient, source->subgradient, sizeof(*dest->subgradient) * core->nconss);
809
810 for( i = 0; i < core->nvariables; i++ )
811 {
812 if( isVarInSolution(source->xgreedylocal, core->variables[i]) )
814 }
815
816 dest->lblagrangeglobal = source->lblagrangeglobal;
817 dest->lblagrangelocal = source->lblagrangelocal;
818 dest->ubgreedylocal = source->ubgreedylocal;
819}
820
821/** initializes an instance where no variables are fixed and no rows are covered */
822static
824 SCIP* scip, /**< master SCIP data structure */
825 SCP_INSTANCE* inst /**< unitialized SCP instance */
826 )
827{
830 inst->nvarsfixed = 0;
831 inst->nrowscovered = 0;
832 inst->costsfixed = 0.0;
833
834 return SCIP_OKAY;
835}
836
837/** copies the fixed variables from 'source' to 'dest', but not the set of covered rows. this must be done separately. */
838static
840 SCIP* scip, /**< master SCIP data structure */
841 SCP_CORE* core, /**< SCP core data structure */
842 SCP_INSTANCE* dest, /**< initialized SCP instance */
843 SCP_INSTANCE* source /**< initialized SCP instance that is to be copied */
844 )
845{
846 int i;
847
848 for( i = 0; i < SCIPgetNVars(scip); ++i )
849 dest->varsfixed[i] = FALSE;
850 dest->nvarsfixed = 0;
851 for( i = 0; i < SCIPgetNConss(scip); ++i )
852 dest->rowscovered[i] = FALSE;
853 dest->nrowscovered = 0;
854 dest->costsfixed = 0.0;
855
856 for( i = 0; i < core->nvariables; i++ )
857 {
858 if( isFixedVariable(source, core->variables[i]) == TRUE )
859 {
860 fixVariable(dest, core->variables[i]);
861 dest->costsfixed += SCIPvarGetObj(core->variables[i]);
862 }
863 }
864}
865
866/** releases all memory used by an instance */
867static
869 SCIP* scip, /**< master SCIP data structure */
870 SCP_INSTANCE* inst /**< initialized SCP instance that is to be freed */
871 )
872{
875}
876
877/** initializes a tentative core: for each row the first few columns covering this row are added to the core */
878static
880 SCIP* scip, /**< master SCIP data structure */
881 SCP_CORE* core, /**< SCP core data structure */
882 SCIP_HEURDATA* heurdata /**< pointer to SCIP's heurdata */
883 )
884{
885 SCIP_VAR** vars;
887 int nvars;
888 int i;
889 int j;
890
891 assert(scip != NULL);
892 assert(core != NULL);
893
894 /* mapvariables is a mapping: SCIPvarGetIndex(core->variables[i]) -> i */
897
898 core->rowsavailable = FALSE;
899 core->rows = NULL;
900 core->nrowvars = NULL;
901 core->columnsavailable = FALSE;
902 core->columns = NULL;
904 core->variables = SCIPgetVars(scip);
905
909 core->nsolgreedy = 0;
910
912 for( i = 0; i< core->nvariables; i++ )
913 core->nvarconss[i] = 0;
914
915 /* construct mapping of variable-indices to array 'variables' */
916 for( i = 0; i < core->nvariables; i++ )
917 {
918 int varidx = SCIPvarGetIndex(core->variables[i]);
919 SCIP_CALL( SCIPhashmapInsert(core->mapvariables, (void *) ((size_t) (varidx + 1)), (void *) (size_t) i) );
920 }
921
922 core->nactiveconss = 0;
923 core->maxconstraintvariables = 0;
924 core->nconss = SCIPgetNConss(scip);
925 core->conss = SCIPgetConss(scip);
926 core->ncorevariables = 0;
927 core->listcorevariables = NULL;
929
931
932 for( i = 0; i < core->nconss; i++ )
933 {
934 core->constraintid[i] = i;
935 if( SCIPconsIsActive(core->conss[i]) == FALSE )
936 {
937 SCIPdebugMessage("constraint %i (%s) is inactive\n", i, SCIPconsGetName(core->conss[i]));
938 continue;
939 }
940
941 /* get all variables that are part of this constraint */
943 if( success == FALSE )
944 {
945 SCIPdebugMessage("constraint %i (%s): can't get number of variables\n", i, SCIPconsGetName(core->conss[i]));
946 continue;
947 }
948
950 if( success == FALSE )
951 {
952 SCIPdebugMessage("constraint %i (%s): can't get variables\n", i, SCIPconsGetName(core->conss[i]));
953 continue;
954 }
955
956 if( nvars > core->maxconstraintvariables )
958
959 for( j = 0; j < nvars; j++ )
960 {
961 int varpos;
962
963 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
964 if( j < heurdata->param_core_tent_size )
965 {
966 /* add this variable to the core if it's not already in there */
967 if( !isCoreVariable(core, core->variables[varpos]) )
968 addVarToCore(core, core->variables[varpos]);
969 }
970
971 /* increase the number of constraints this variable is part of */
972 core->nvarconss[varpos]++;
973 }
974
975 core->nactiveconss++;
976 }
977
979
980 /* create list of core variables, so it is easy to traverse them */
981 j = 0;
983 for( i = 0; i < core->nvariables; i++ )
984 {
985 if( isCoreVariable(core, core->variables[i]) )
986 core->listcorevariables[j++] = i;
987 }
988
989 SCIPdebugMessage("%d variables in the tentative core\n", core->ncorevariables);
990
991 return SCIP_OKAY;
992}
993
994/** adds all fixed variables of 'inst' to a set covering solution 'solution' */
995static
997 SCIP* scip, /**< master SCIP data structure */
998 SCP_CORE* core, /**< SCP core data structure */
999 SCP_INSTANCE* inst, /**< (reduced) SCP instance */
1000 SCIP_Bool* solution /**< SCP solution (a hashtable that contains SCIP variables) */
1001 )
1002{
1003 int i;
1004
1005 for( i = 0; i < core->nvariables; i++ )
1006 {
1007 if( !isFixedVariable(inst, core->variables[i]) )
1008 continue;
1009
1010 /* add fixed variable if it is not already part of the solution */
1011 if( !isVarInSolution(solution, core->variables[i]) )
1012 addVarToSolution(solution, core->variables[i]);
1013 }
1014}
1015
1016/** constructs rows of all constraints, but only includes core variables */
1017static
1019 SCIP* scip, /**< master SCIP data structure */
1020 SCP_CORE* core, /**< SCP core data structure */
1021 SCIP_HEURDATA* heurdata /**< pointer to the heuristics's data */
1022 )
1023{
1025 SCIP_VAR** vars;
1026 int i;
1027 int j;
1028 int ncorevars;
1029 int nvars;
1030
1031 assert(scip != NULL);
1032 assert(core != NULL);
1033 assert(heurdata != NULL);
1034
1035 /* don't compute again if already computed */
1036 if( core->rowsavailable )
1037 return SCIP_OKAY;
1038
1039 assert(core->rows == NULL);
1040
1041 SCIP_CALL( SCIPallocBufferArray(scip, &core->rows, core->nconss) );
1044
1045 /* iterate through list of constraints */
1046 for( i = 0; i < core->nconss; i++ )
1047 {
1048 core->rows[i] = NULL;
1049 core->nrowvars[i] = 0;
1050
1051 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
1052 if( success == FALSE )
1053 continue;
1054
1055 /* count number of core variables this constraint contains */
1056 ncorevars = 0;
1057 for( j = 0; j < nvars; j++ )
1058 {
1059 int varpos;
1060
1061 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
1062
1063 if( isCoreVariable(core, core->variables[varpos]) )
1064 ncorevars++;
1065 }
1066
1067 if( ncorevars > 0 )
1068 {
1069 /* create array of core variables of this constraint */
1070 core->nrowvars[i] = ncorevars;
1071 SCIP_CALL( SCIPallocBufferArray(scip, &(core->rows[i]), core->nrowvars[i]) ); /*lint !e866*/
1072 for( j = 0; j < nvars; j++ )
1073 {
1074 int varpos;
1075
1076 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
1077
1078 if( isCoreVariable(core, core->variables[varpos]) )
1079 {
1080 ncorevars--;
1081 core->rows[i][ncorevars] = varpos;
1082 }
1083 }
1084 }
1085 }
1086
1088 core->rowsavailable = TRUE;
1089 return SCIP_OKAY;
1090}
1091
1092/** constructs columns of core variables to provide faster access */
1093static
1095 SCIP* scip, /**< master SCIP data structure */
1096 SCP_CORE* core /**< SCP core data structure */
1097 )
1098{
1100 SCIP_VAR** vars;
1101 int i;
1102 int j;
1103 int k;
1104 int nvars;
1105
1106 assert(scip != NULL);
1107 assert(core != NULL);
1108
1109 /* don't compute columns again if already computed */
1110 if( core->columnsavailable )
1111 return SCIP_OKAY;
1112
1114 for( i = 0; i < core->nvariables; i++ )
1115 {
1116 /* columns[i] = NULL for all non-core variables */
1117 core->columns[i] = NULL;
1118
1119 /* check if variable is a core variable */
1120 if( !isCoreVariable(core, core->variables[i]) )
1121 continue;
1122
1123 /* only allocate memory of it is part of any constraints at all (this should always be the case for core variables) */
1124 if( core->nvarconss[i] == 0 )
1125 continue;
1126
1127 SCIP_CALL( SCIPallocBufferArray(scip, &(core->columns[i]), core->nvarconss[i]) ); /*lint !e866*/
1128
1129 for( j = 0; j < core->nvarconss[i]; j++ )
1130 core->columns[i][j] = -1;
1131 }
1132
1134
1135 for( i = 0; i < core->nconss; i++ )
1136 {
1137 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
1138 if( success == FALSE )
1139 continue;
1140
1141 for( j = 0; j < nvars; j++ )
1142 {
1143 int varpos;
1144
1145 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
1146
1147 if( !isCoreVariable(core, core->variables[varpos]) )
1148 continue;
1149
1150 /* add this constraint to the column of the variable */
1151 for( k = 0; k < core->nvarconss[varpos]; k++ )
1152 {
1153 /* find first position that is not used yet in column 'varpos' */
1154 if( core->columns[varpos][k] == -1 )
1155 {
1156 core->columns[varpos][k] = i;
1157 break;
1158 }
1159 }
1160 }
1161 }
1162
1164 core->columnsavailable = TRUE;
1165 return SCIP_OKAY;
1166}
1167
1168/** releases memory that is used by the core, including rows and columns, if they were computed */
1169static
1171 SCIP* scip, /**< master SCIP data structure */
1172 SCP_CORE* core /**< SCP core data structure that is to be freed */
1173 )
1174{
1175 assert(core != NULL);
1176 assert(core->varincore != NULL);
1177 assert(core->mapvariables != NULL);
1178 assert(core->nvarconss != NULL);
1179
1180 if( core->rowsavailable )
1181 {
1182 int i;
1183
1184 for( i = 0; i < core->nconss; i++ )
1185 if( core->rows[i] )
1186 SCIPfreeBufferArray(scip, &core->rows[i]);
1187
1189 SCIPfreeBufferArray(scip, &core->rows);
1190 }
1191
1192 if( core->columnsavailable )
1193 {
1194 int i;
1195
1196 for( i = 0; i < core->nvariables; i++ )
1197 if( core->columns[i] )
1199
1201 }
1202
1211}
1212
1213/** computes a new core based on the delta values of variables, see formula (9) in the paper */
1214static
1216 SCIP* scip, /**< master SCIP data structure */
1217 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data; this contains the SCP core */
1218 )
1219{
1220 SCIP_Bool recomputecolumns = FALSE;
1221 SCIP_Bool recomputerows = FALSE;
1222 SCP_CORE* core;
1223 int* deltaperm;
1224 int nvars;
1225 SCIP_VAR** vars;
1226
1227 int i;
1228 int j;
1229
1230 /* assumption: delta values were already computed and are sorted in increasing order, this happens in computeDelta */
1231
1232 core = &heurdata->core;
1233 vars = heurdata->vars;
1234
1235 SCIP_CALL( SCIPallocBufferArray(scip, &deltaperm, core->nvariables) );
1236
1237 /* construct mapping deltaperm: variables -> delta_pos */
1238 for( i = 0; i < core->nvariables; i++ )
1239 {
1240 deltaperm[core->delta_pos[i]] = i;
1241 }
1242
1243 /* release memory that is used for the core rows and columns. it will be allocated again later on */
1244 removeVarsFromCore(scip, core);
1245 if( core->columnsavailable )
1246 {
1247 recomputecolumns = TRUE;
1248
1249 for( i = 0; i < core->nvariables; i++ )
1250 {
1251 if( core->columns[i] != NULL )
1253 }
1254
1256 core->columns = NULL;
1257 core->columnsavailable = FALSE;
1258 }
1259
1260 if( core->rowsavailable )
1261 {
1262 recomputerows = TRUE;
1263
1264 for( i = 0; i < core->nconss; i++ )
1265 {
1266 if( core->rows[i] )
1267 SCIPfreeBufferArray(scip, &core->rows[i]);
1268 }
1269
1270 SCIPfreeBufferArray(scip, &core->rows);
1272
1273 core->rows = NULL;
1274 core->nrowvars = NULL;
1275 core->rowsavailable = FALSE;
1276 }
1277
1278 if( core->listcorevariables != NULL )
1279 {
1281 core->listcorevariables = NULL;
1282 }
1283
1284 /* pick the first 'SCP_CORE_TENT_SIZE'*m columns with lowest delta values to be in the core */
1285 for( i = 0; i < core->nvariables; i++ )
1286 {
1288 break;
1289
1290 addVarToCore(core, core->variables[core->delta_pos[i]]);
1291 }
1292
1293 /* then add the first 'SCP_CORE_TENT_SIZE' columns covering each row in increasing order of their delta values */
1294 for( i = 0; i < core->nconss; i++ )
1295 {
1297 int *cols = heurdata->rccols; /*[SCP_CORE_TENT_SIZE];*/
1298 SCIP_Real *coldelta = heurdata->rccoldelta; /*[SCP_CORE_TENT_SIZE];*/
1299
1300 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
1301 if( success == FALSE )
1302 continue;
1303
1304 for( j = 0; j < heurdata->param_core_tent_size; j++ )
1305 {
1306 cols[j] = 0;
1307 coldelta[j] = SCIP_REAL_MAX;
1308 }
1309
1310 /* iterate through list of variables that are part of this constraint, and find the 'param_core_tent_size' variables with lowest delta values */
1311 for( j = 0; j < nvars; j++ )
1312 {
1313 int varpos;
1314 int k;
1315 SCIP_Real value;
1316
1317 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
1318
1319 value = core->delta[deltaperm[varpos]];
1320
1321 if( j < heurdata->param_core_tent_size )
1322 k = j;
1323 else
1325
1326 if( (j < heurdata->param_core_tent_size) || (coldelta[k] > value) )
1327 {
1328 cols[k] = varpos;
1329 coldelta[k] = value;
1330
1331 /* insertion sort */
1332 while( (k > 0) && (coldelta[k] < coldelta[k - 1]) )
1333 {
1334 int tmp1 = cols[k - 1];
1335 SCIP_Real tmp2 = coldelta[k - 1];
1336
1337 cols[k - 1] = cols[k];
1338 coldelta[k - 1] = coldelta[k];
1339 cols[k] = tmp1;
1340 coldelta[k] = tmp2;
1341 k--;
1342 }
1343 }
1344 }
1345
1346 /* add the variables with lowest delta values to the core */
1347 for( j = 0; j < nvars; j++ )
1348 {
1350 break;
1351
1352 if( !isCoreVariable(core, core->variables[cols[j]]) )
1353 addVarToCore(core, core->variables[cols[j]]);
1354 }
1355 }
1356
1357 /* construct list of core variables */
1359 j = 0;
1360 for( i = 0; i < core->nvariables; i++ )
1361 {
1362 if( isCoreVariable(core, core->variables[i]) )
1363 core->listcorevariables[j++] = i;
1364 }
1365 assert(j == core->ncorevariables);
1366
1367 /* recompute core rows and columns if they were available before */
1368 if( recomputecolumns )
1370
1371 if( recomputerows )
1373
1374 SCIPfreeBufferArray(scip, &deltaperm);
1375
1376 SCIPdebugMessage("%d variables are in the refined core\n", core->ncorevariables);
1377 return SCIP_OKAY;
1378}
1379
1380/** for all rows that are covered by the variables in inst->varsfixed, this function adds their indices to inst->rowscovered */
1381static
1383 SCIP* scip, /**< master SCIP data structure */
1384 SCP_CORE* core, /**< SCP core data structure */
1385 SCP_INSTANCE* inst, /**< initialized SCP instance where some variables may be fixed */
1386 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
1387 )
1388{
1389 int i;
1390 int j;
1391
1392 for( i = 0; i < SCIPgetNConss(scip); ++i )
1393 inst->rowscovered[i] = FALSE;
1394 inst->nrowscovered = 0;
1395
1396 if( core->columnsavailable == TRUE )
1397 {
1398 /* iterate through list of core variables */
1399 for( i = 0; i < core->ncorevariables; i++ )
1400 {
1401 int corevar = core->listcorevariables[i];
1402
1403 if( !isFixedVariable(inst, core->variables[corevar]) )
1404 continue;
1405
1406 /* this variable is fixed, so mark its rows as covered */
1407 for( j = 0; j < core->nvarconss[corevar]; j++ )
1408 {
1409 int rowidx = core->columns[corevar][j];
1410
1411 if( !isRowCovered(inst, rowidx) )
1412 markRowAsCovered(inst, rowidx);
1413 }
1414 }
1415 }
1416 else
1417 {
1418 SCIP_VAR **vars;
1419 int nvars;
1420
1421 vars = heurdata->vars;
1422
1423 /* if the core columns are not available, iterate through list of constraints and test which conss are covered */
1424 for( i = 0; i < core->nconss; i++ )
1425 {
1427
1428 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
1429 if( success == FALSE )
1430 continue;
1431
1432 for( j = 0; j < nvars; j++ )
1433 {
1434 if( isFixedVariable(inst, vars[j]) )
1435 {
1436 if( !isRowCovered(inst, i) )
1437 markRowAsCovered(inst, i);
1438
1439 break;
1440 }
1441 }
1442 }
1443 }
1444
1445 return SCIP_OKAY;
1446}
1447
1448/** checks whether the given 'solution' is actually a set cover */
1449static
1451 SCIP* scip, /**< master SCIP data structure */
1452 SCP_CORE* core, /**< SCP core data structure */
1453 SCP_INSTANCE* inst, /**< SCP instance */
1454 SCIP_Bool* solution, /**< possible SCP solution */
1455 SCIP_Bool* issetcover, /**< address where TRUE will be stored if 'solution' is a set cover */
1456 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
1457 )
1458{
1460 SCIP_VAR** vars;
1461 int nvars;
1462 int i;
1463 int j;
1464 int varpos;
1465
1466 assert(scip != NULL);
1467 assert(core != NULL);
1468 assert(inst != NULL);
1469 assert(solution != NULL);
1470 assert(issetcover != NULL);
1471 assert(heurdata != NULL);
1472
1473 *issetcover = TRUE;
1474 vars = heurdata->vars;
1475
1476 /* iterate through all constraints and check whether each of them contains a variable that is part of the cover */
1477 for( i = 0; i < core->nconss; i++ )
1478 {
1479 SCIP_Bool rowcovered = FALSE;
1480
1481 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
1482 if( success == FALSE )
1483 continue;
1484
1485 for( j = 0; j < nvars; j++ )
1486 {
1487 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
1488
1489 if( isVarInSolution(solution, core->variables[varpos]) )
1490 {
1491 rowcovered = TRUE;
1492 break;
1493 }
1494 }
1495
1496 if( rowcovered == FALSE )
1497 {
1498 SCIPdebugMessage("check set cover: row %i is not covered by any column\n", i);
1499 *issetcover = FALSE;
1500 break;
1501 }
1502 }
1503
1504 return SCIP_OKAY;
1505}
1506
1507/** computes delta values for variables and fixes new variables within inst, see formula (9) of the paper */
1508static
1510 SCIP* scip, /**< master SCIP data structure */
1511 SCP_CORE* core, /**< SCP core data structure */
1512 SCP_INSTANCE* inst, /**< SCP instance */
1513 SCIP_Real* lagrangiancosts, /**< array with lagrangian costs of the rows */
1514 SCIP_Bool* solution, /**< valid solution to the global SCP instance */
1515 SCIP_Real pi, /**< percentage of rows that need be covered by new fixed variables */
1516 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
1517 )
1518{
1520 SCIP_Real delta_sum;
1521 SCIP_Real delta_max;
1522 int* nvarcovering;
1523 SCIP_VAR** vars;
1524 int nvars;
1525 int i;
1526 int j;
1527 int* delta_pos;
1528 SCIP_Real* delta;
1529
1530 delta = core->delta;
1531 delta_pos = core->delta_pos;
1532
1533 SCIP_CALL( SCIPallocBufferArray(scip, &nvarcovering, core->nconss) );
1534 vars = heurdata->vars;
1535
1536 /* compute nvarcovering[i] = 'number of columns covering row i' */
1537 if( core->rowsavailable )
1538 {
1539 for( i = 0; i < core->nconss; i++ )
1540 {
1541 nvarcovering[i] = 0;
1542
1543 if( !SCIPconsIsActive(core->conss[i]) )
1544 continue;
1545
1546 for( j = 0; j < core->nrowvars[i]; j++ )
1547 {
1548 int varpos = core->rows[i][j];
1549 if( isVarInSolution(solution, core->variables[varpos]) )
1550 nvarcovering[i]++;
1551 }
1552 }
1553 }
1554 else
1555 {
1556 for( i = 0; i < core->nconss; i++ )
1557 {
1558 nvarcovering[i] = 0;
1559
1560 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
1561 if( success == FALSE )
1562 continue;
1563
1564 for( j = 0; j < nvars; j++ )
1565 {
1566 int varpos;
1567
1568 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
1569
1570 if( isVarInSolution(solution, core->variables[varpos]) )
1571 nvarcovering[i]++;
1572 }
1573 }
1574 }
1575
1576 /* compute delta values of variables that are part of 'solution', see formula (9) */
1577 for( i = 0; i < core->nvariables; i++ )
1578 {
1579 delta[i] = SCIP_REAL_MAX;
1580 delta_pos[i] = i;
1581
1582 if( !isVarInSolution(solution, core->variables[i]) )
1583 continue;
1584
1585 delta[i] = lagrangiancosts[i];
1586 if( delta[i] < 0.0 )
1587 delta[i] = 0.0;
1588
1589 for( j = 0; j < core->nvarconss[i]; j++ )
1590 {
1591 int rowpos = core->columns[i][j];
1592
1593 if( isRowCovered(inst, rowpos) )
1594 continue;
1595
1596 delta[i] += lagrangiancosts[rowpos] * (nvarcovering[rowpos] - 1) / ((SCIP_Real) nvarcovering[rowpos]);
1597 }
1598 }
1599
1600 /* sort the variables in increasing order of their delta values, delta_pos is used to track the variables within the array */
1601 SCIPsortRealInt(delta, delta_pos, core->nvariables);
1602
1603 /* fix variables as long as the sum of their delta values is not greater than delta_max.
1604 * We assume that variables with small delta values are likely part of an optimal solution. */
1605 delta_sum = 0.0;
1606 delta_max = core->nactiveconss * pi;
1607
1608 for( i = 0; i < SCIPgetNVars(scip); ++i )
1609 inst->varsfixed[i] = FALSE;
1610 inst->nvarsfixed = 0;
1611
1612 inst->costsfixed = 0.0;
1613
1614 for( i = 0; i < core->nvariables; i++ )
1615 {
1616 int varpos = delta_pos[i];
1617
1618 if( !isVarInSolution(solution, core->variables[varpos]) )
1619 break;
1620
1621 inst->costsfixed += SCIPvarGetObj(core->variables[varpos]);
1622 delta_sum += delta[i];
1623
1624 /* fix variable delta_pos[i] */
1625 fixVariable(inst, core->variables[varpos]);
1626
1627 if( delta_sum >= delta_max )
1628 break;
1629 }
1630
1631 SCIPfreeBufferArray(scip, &nvarcovering);
1632 return SCIP_OKAY;
1633}
1634
1635/* removes redundant columns from 'solution' by removing them one by one (in the order of decreasing costs),
1636 * and checking whether all rows are still covered */
1637static
1639 SCIP* scip, /**< master SCIP data structure */
1640 SCIP_HEURDATA* heurdata, /**< pointer to the heuristic's data */
1641 SCIP_Bool* solution, /**< solution to the global SCP instance */
1642 SCIP_Real* solcosts /**< pointer to original costs of 'solution'; contains updated costs */
1643 )
1644{
1645 SCP_CORE* core;
1646 SCIP_Real* costs;
1647 int* varpos;
1648 int* nvarcovering;
1649 SCIP_VAR** vars;
1650 int nvars;
1652 int solsize;
1653
1654 int i;
1655 int j;
1656
1657 core = &heurdata->core;
1658
1659 if( core->columnsavailable == FALSE )
1660 {
1661 SCIPdebugMessage("can only remove redundant columns if all core columns are available\n");
1662 return SCIP_OKAY;
1663 }
1664
1665 SCIP_CALL( SCIPallocBufferArray(scip, &costs, core->nvariables) );
1666 SCIP_CALL( SCIPallocBufferArray(scip, &varpos, core->nvariables) );
1667 SCIP_CALL( SCIPallocBufferArray(scip, &nvarcovering, core->nconss) );
1668
1669 vars = heurdata->vars;
1670
1671 /* compute nvarcovering[i] = 'number of columns covering row i' */
1672 if( core->rowsavailable )
1673 {
1674 for( i = 0; i < core->nconss; i++ )
1675 {
1676 nvarcovering[i] = 0;
1677
1678 if( SCIPconsIsActive(core->conss[i]) == FALSE )
1679 continue;
1680
1681 if( core->nrowvars[i] == 0 )
1682 continue;
1683
1684 for( j = 0; j < core->nrowvars[i]; j++ )
1685 {
1686 int vpos = core->rows[i][j];
1687
1688 if( isVarInSolution(solution, core->variables[vpos]) )
1689 nvarcovering[i]++;
1690 }
1691 }
1692 }
1693 else
1694 {
1695 /* iterate through the constraints if the core rows are not available */
1696 for( i = 0; i < core->nconss; i++ )
1697 {
1698 nvarcovering[i] = 0;
1699
1700 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
1701 if( success == FALSE )
1702 continue;
1703
1704 for( j = 0; j < nvars; j++ )
1705 {
1706 int vpos;
1707
1708 SCIP_CALL( getVarIndex(scip, core, vars[j], &vpos) );
1709
1710 if( isVarInSolution(solution, core->variables[vpos]) )
1711 nvarcovering[i]++;
1712 }
1713 }
1714 }
1715
1716 /* construct array of costs of variables that are part of the solution.
1717 * If v_1, ..., v_solsize are the variables of the solution, then
1718 * costs[i] = -costs(v_i), and varpos[i] = i.
1719 * We use negative costs because we only sort them in increasing order and want to remove the ones with highest costs first.
1720 * The 'varpos' array is used to track which variable is where within the sorted array (it is permutated in the same way as 'costs') */
1721 solsize = 0;
1722 for( i = 0; i < core->nvariables; i++ )
1723 {
1724 if( isVarInSolution(solution, core->variables[i]) )
1725 {
1726 costs[solsize] = -SCIPvarGetObj(core->variables[i]);
1727 varpos[solsize] = i;
1728 solsize++;
1729 }
1730 }
1731
1732 /* sort variables by decreasing costs */
1733 SCIPsortRealInt(costs, varpos, solsize);
1734
1735 /* for each variable of the solution: try to remove it and check whether it is still a set cover */
1736 for( i = 0; i < solsize; i++ )
1737 {
1738 SCIP_Bool canremove = TRUE;
1739 int vpos = varpos[i];
1740
1741 /* we can only remove this variable if every column it covers is covered by another variable */
1742 for( j = 0; j < core->nvarconss[vpos]; j++ )
1743 {
1744 if( nvarcovering[core->columns[vpos][j]] == 1 )
1745 {
1746 canremove = FALSE;
1747 break;
1748 }
1749 }
1750
1751 if( canremove == TRUE )
1752 {
1753 removeVarFromSolution(solution, core->variables[vpos]);
1754 *solcosts -= SCIPvarGetObj(core->variables[vpos]);
1755
1756 for( j = 0; j < core->nvarconss[vpos]; j++ )
1757 {
1758 nvarcovering[core->columns[vpos][j]]--;
1759 }
1760 }
1761 }
1762
1763 SCIPfreeBufferArray(scip, &nvarcovering);
1764 SCIPfreeBufferArray(scip, &varpos);
1765 SCIPfreeBufferArray(scip, &costs);
1766
1767 return SCIP_OKAY;
1768}
1769
1770/** greedy set cover algorithm that uses lagrangian costs instead of original costs. */
1771static
1773 SCIP* scip, /**< master SCIP data structure */
1774 SCP_CORE* core, /**< SCP core data structure */
1775 SCP_INSTANCE* inst, /**< (reduced) SCP instance */
1776 SCP_Lagrange_Sol* mult, /**< lagrange multiplier that is used to compute lagrangian costs */
1777 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
1778 )
1779{
1780 SCP_INSTANCE* greedyinst;
1781 int nrowsuncovered = 0;
1783 int nvars;
1784 PQUEUE* prioqueue;
1785 int* colpos;
1786 int* colmu;
1787 SCIP_Real* colgamma;
1788 SCIP_Real* colscore;
1789 SCIP_VAR** vars;
1790
1791 int i;
1792 int j;
1793 int k;
1794
1795 core->nsolgreedy = 0;
1796 mult->ubgreedylocal = 0.0;
1798
1799 greedyinst = &heurdata->greedyinst;
1800 for( i = 0; i < SCIPgetNConss(scip); ++i )
1801 greedyinst->rowscovered[i] = FALSE;
1802 greedyinst->nrowscovered = 0;
1803
1804 /* count number of uncovered rows and add covered rows to 'greedyinst' */
1805 for( i = 0; i < core->nconss; i++ )
1806 {
1807 if( SCIPconsIsActive(core->conss[i]) == FALSE )
1808 continue;
1809
1810 /* this is actually necessary because there exist constraints where this fails, and we simply need to ignore them */
1812 if( success == FALSE )
1813 continue;
1814
1815 if( isRowCovered(inst, i) )
1816 markRowAsCovered(greedyinst, i);
1817 else
1818 nrowsuncovered++;
1819 }
1820
1821 if( core->columnsavailable == FALSE )
1822 {
1823 SCIPerrorMessage("greedy algorithm requires core columns to be available\n");
1824 SCIPABORT();
1825 }
1826
1827 /* compute scores of all (unfixed) variables and add them to the priority queue */
1828 colpos = heurdata->greedycolpos; /* this array contains the position of the element within the queue and is needed to update the costs */
1829 colmu = heurdata->greedycolmu; /* for each column this contains the number of uncovered rows that it covers */
1830 colgamma = heurdata->greedycolgamma; /* for each column this contains the lagrangian costs of uncovered rows that it covers */
1831 colscore = heurdata->greedycolscore; /* for each column this contains its score */
1832 vars = heurdata->vars;
1833
1834 prioqueue = &heurdata->greedyqueue;
1835 pqueue_clear(scip, prioqueue);
1836
1837 /* compute initial scores for all unfixed columns, see "3. Heuristic Phase" of the paper, and add them to the priority queue */
1838 for( i = 0; i < core->nvariables; i++ )
1839 {
1840 int varpos = i;
1841 int mu = 0;
1842 SCIP_Real gamma = SCIPvarGetObj(core->variables[varpos]);
1843
1844 colmu[i] = 0;
1845 colgamma[i] = 0;
1846 colpos[i] = 0;
1847 colscore[i] = 0.0;
1848
1849 if( !isCoreVariable(core, core->variables[varpos]) )
1850 continue;
1851 else if( isFixedVariable(inst, core->variables[varpos]) )
1852 continue;
1853
1854 for( j = 0; j < core->nvarconss[varpos]; j++ )
1855 {
1856 if( !isRowCovered(greedyinst, core->columns[varpos][j]) )
1857 {
1858 gamma -= mult->u[core->columns[varpos][j]];
1859 mu++;
1860 }
1861 }
1862
1863 /* skip columns that do not cover anything */
1864 if( mu > 0 )
1865 {
1866 SCIP_Real score = (gamma > 0) ? (gamma / ((SCIP_Real) mu)) : (gamma * mu);
1867 colmu[i] = mu;
1868 colgamma[i] = gamma;
1869 colscore[i] = score;
1870
1871 SCIP_CALL( pqueue_insert(scip, prioqueue, colscore[i], i, &(colpos[i])) );
1872 }
1873 }
1874
1875 /* main loop: add variables to the solution as long as there are uncovered rows */
1876 while( nrowsuncovered > 0 )
1877 {
1878 int mincolumn;
1879
1880 /* get variable with minimum score */
1881 pqueue_get_min(scip, prioqueue, &mincolumn);
1882
1883 /* add variable 'variables[mincolumn]' to the set cover */
1884 addVarToSolution(mult->xgreedylocal, core->variables[mincolumn]);
1885 mult->ubgreedylocal += SCIPvarGetObj(core->variables[mincolumn]);
1886 core->solgreedy[core->nsolgreedy++] = mincolumn;
1887
1888 /* mark this variable, so its score won't be updated in the future */
1889 colmu[mincolumn] = 0;
1890
1891 /* mark all rows covered by this variable as covered and update scores of variables that are affected by this */
1892 for( j = 0; j < core->nvarconss[mincolumn]; j++ )
1893 {
1894 int columnpos = core->columns[mincolumn][j];
1895
1896 if( !isRowCovered(greedyinst, columnpos) )
1897 {
1898 markRowAsCovered(greedyinst, columnpos);
1899 nrowsuncovered--;
1900
1901 /* update scores of columns covering this row */
1902 SCIP_CALL( getConsVars(scip, core, columnpos, vars, &nvars, &success) );
1903 if( success == FALSE )
1904 continue;
1905
1906 /* for each variable: subtract u[i] from the variable's costs */
1907 for( k = 0; k < nvars; k++ )
1908 {
1909 SCIP_Real score;
1910 int varpos;
1911
1912 SCIP_CALL( getVarIndex(scip, core, vars[k], &varpos) );
1913
1914 /* skip non-core variables */
1915 if( !isCoreVariable(core, core->variables[varpos]) )
1916 continue;
1917
1918 if( colmu[varpos] == 0 )
1919 continue;
1920
1921 score = colscore[varpos];
1922
1923 /* compute a new score for this variable */
1924 colscore[varpos] = SCIP_REAL_MAX;
1925 colmu[varpos]--;
1926 colgamma[varpos] += mult->u[columnpos];
1927
1928 if( colmu[varpos] > 0 )
1929 colscore[varpos] = (colgamma[varpos] > 0) ? (colgamma[varpos] / ((SCIP_Real) colmu[varpos])) : (colgamma[varpos] * colmu[varpos]);
1930
1931 /* either decrease or increase the key, depending on whether it decreased or increased */
1932 if( score > colscore[varpos] )
1933 pqueue_decrease_key(scip, prioqueue, colpos[varpos], colscore[varpos]);
1934 else
1935 pqueue_increase_key(scip, prioqueue, colpos[varpos], colscore[varpos]);
1936 }
1937 }
1938 }
1939 }
1940
1941 return SCIP_OKAY;
1942}
1943
1944/** computes lagrangian costs for all columns, only considering rows that are uncovered by fixed variables in 'inst' */
1945static
1947 SCIP* scip, /**< master SCIP data structure */
1948 SCP_CORE* core, /**< SCP core data structure */
1949 SCP_INSTANCE* inst, /**< (reduced) SCP instance */
1950 SCP_Lagrange_Sol* mult, /**< lagrange multiplier that is used to compute the lagrangian costs*/
1951 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
1952 )
1953{
1954 SCIP_VAR** vars;
1955 int nvars;
1956
1957 int i;
1958 int j;
1959
1960 /* set all lagrangian costs to objective values */
1961 for( i = 0; i < core->nvariables; i++ )
1963
1964 vars = heurdata->vars;
1965
1966 if( core->rowsavailable )
1967 {
1968 for( i = 0; i < core->nconss; i++ )
1969 {
1970 if( SCIPconsIsActive(core->conss[i]) == FALSE )
1971 continue;
1972
1973 if( isRowCovered(inst, i) )
1974 continue;
1975
1976 for( j = 0; j < core->nrowvars[i]; j++ )
1977 {
1978 int varpos = core->rows[i][j];
1979 mult->lagrangiancostslocal[varpos] -= mult->u[i];
1980 }
1981 }
1982 }
1983 else
1984 {
1985 for( i = 0; i < core->nconss; i++ )
1986 {
1988
1989 /* skip rows that are not part of the reduced instance */
1990 if( isRowCovered(inst, i) )
1991 continue;
1992
1993 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
1994 if( success == FALSE )
1995 continue;
1996
1997 /* for each core variable: subtract u[i] from the variable's costs */
1998 for( j = 0; j < nvars; j++ )
1999 {
2000 int varpos;
2001
2002 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
2003
2004 mult->lagrangiancostslocal[varpos] -= mult->u[i];
2005 }
2006 }
2007 }
2008
2009 return SCIP_OKAY;
2010}
2011
2012/** computes lagrangian costs for all columns of the unrestricted instance and a global lower bound. */
2013static
2015 SCIP* scip, /**< master SCIP data structure */
2016 SCP_CORE* core, /**< SCP core data structure */
2017 SCP_Lagrange_Sol* mult, /**< lagrange multiplier that is used to compute the lagrangian costs*/
2018 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
2019 )
2020{
2021 SCIP_VAR** vars;
2022 int nvars;
2023 int i;
2024 int j;
2025
2026 /* set all lagrangian costs to objective values */
2027 for( i = 0; i < core->nvariables; i++ )
2029
2030 vars = heurdata->vars;
2031
2032 for( i = 0; i < core->nconss; i++ )
2033 {
2035
2036 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
2037 if( success == FALSE )
2038 continue;
2039
2040 /* for each core variable: subtract u[i] from the variable's costs */
2041 for( j = 0; j < nvars; j++ )
2042 {
2043 int varpos;
2044
2045 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
2046
2047 mult->lagrangiancostsglobal[varpos] -= mult->u[i];
2048 }
2049
2050 mult->lblagrangeglobal += mult->u[i];
2051 }
2052
2053 /* compute global lower bound */
2054 for( i = 0; i < core->nvariables; i++ )
2055 {
2056 if( mult->lagrangiancostsglobal[i] < 0.0 )
2058 }
2059
2060 return SCIP_OKAY;
2061}
2062
2063/** computes an optimal solution to the lagrangian relaxation, see formulae (4), (5) in the paper */
2064static
2066 SCIP* scip, /**< master SCIP data structure */
2067 SCP_CORE* core, /**< SCP core data structure */
2068 SCP_INSTANCE* inst, /**< (reduced) SCP instance */
2069 SCP_Lagrange_Sol* mult, /**< lagrange multiplier */
2070 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
2071 )
2072{
2073 SCIP_VAR** vars;
2075 int nvars;
2076
2077 int i;
2078 int j;
2079
2080 mult->lblagrangelocal = 0.0;
2081 mult->lblagrangeglobal = 0.0;
2082
2083 /* compute lagrangian costs for the reduced instance */
2084 SCIP_CALL( computeLocalLagrangianCosts(scip, core, inst, mult, heurdata) );
2085
2086 /* also, compute costs for the unrestricted instance. This even computes mult->lblagrangeglobal */
2088
2089 /* compute an optimal solution for 'inst', but only save its costs in lblagrangelocal */
2090 for( i = 0; i < core->ncorevariables; i++ )
2091 {
2092 int varpos = core->listcorevariables[i];
2093
2094 if( mult->lagrangiancostslocal[varpos] < 0.0 )
2095 {
2096 if( !isFixedVariable(inst, core->variables[varpos]) )
2097 mult->lblagrangelocal = mult->lblagrangelocal + mult->lagrangiancostslocal[varpos];
2098 }
2099 }
2100
2101 /* the subgradient can be computed faster when the core rows are available */
2102 if( core->rowsavailable )
2103 {
2104 /* compute the subgradient */
2105 for( i = 0; i < core->nconss; i++ )
2106 {
2107 mult->subgradient[i] = 0.0;
2108
2109 if( SCIPconsIsActive(core->conss[i]) == FALSE )
2110 continue;
2111
2112 if( isRowCovered(inst, i) )
2113 continue;
2114
2115 if( core->nrowvars[i] == 0 )
2116 continue;
2117
2118 mult->subgradient[i] = 1.0;
2119
2120 for( j = 0; j < core->nrowvars[i]; j++ )
2121 {
2122 int varpos = core->rows[i][j];
2123
2124 if( mult->lagrangiancostslocal[varpos] < 0.0 )
2125 mult->subgradient[i] -= 1.0;
2126 }
2127
2128 /* to get a lower bound from the multiplier we still need to subtract sum_i u[i] from lblagrangelocal */
2129 mult->lblagrangelocal = mult->lblagrangelocal + mult->u[i];
2130 }
2131 }
2132 else
2133 {
2134 /* the core rows are NOT available, so we need to iterate through the constraints */
2135 vars = heurdata->vars;
2136
2137 for( i = 0; i < core->nconss; i++ )
2138 {
2139 mult->subgradient[i] = 0.0;
2140
2141 if( isRowCovered(inst, i) )
2142 continue;
2143
2144 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
2145 if( success == FALSE )
2146 continue;
2147
2148 mult->subgradient[i] = 1.0;
2149
2150 for( j = 0; j < nvars; j++ )
2151 {
2152 int varpos;
2153
2154 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
2155
2156 if( !isCoreVariable(core, core->variables[varpos]) )
2157 continue;
2158
2159 if( mult->lagrangiancostslocal[varpos] < 0.0 )
2160 mult->subgradient[i] -= 1.0;
2161 }
2162
2163 mult->lblagrangelocal = mult->lblagrangelocal + mult->u[i];
2164 }
2165 }
2166
2167 return SCIP_OKAY;
2168}
2169
2170/** subgradient method with Held-Karp update of subgradients */
2171static
2173 SCIP* scip, /**< master SCIP data structure */
2174 SCP_CORE* core, /**< SCP core data structure */
2175 SCP_INSTANCE* inst, /**< (reduced) SCP instance */
2176 SCP_Lagrange_Sol* best_mult_lb, /**< lagrange multiplier that gives the best lower bound for 'inst' */
2177 SCIP_Real bestub, /**< costs of the best known solution for 'inst' */
2178 SCIP_HEURDATA* heurdata /**< pointer the heuristic's data */
2179 )
2180{
2181 int max_iter;
2182 SCP_Lagrange_Sol last_mult;
2183 SCP_Lagrange_Sol next_mult;
2184 SCP_Lagrange_Sol tmp_mult;
2185 SCIP_Real norm;
2187 SCIP_Bool lambda_adjustments = heurdata->param_lambda_adjustments;
2188 SCIP_Real* last_lb = heurdata->sglastlb;
2189 SCIP_Real stop_crit_lb = 0.0;
2190 int iter;
2191 int last_data_pos = 0;
2192 int i;
2193
2194 SCIP_CALL( allocateMemoryForSolution(scip, core, &next_mult) );
2195 SCIP_CALL( allocateMemoryForSolution(scip, core, &last_mult) );
2196
2197 /* save data from best lower bound multiplier in last_mult */
2198 copySolution(scip, core, &last_mult, best_mult_lb);
2199
2200 /* permutate best u by multiplying each entry with a uniformly random value in the range [0.9, 1.1] */
2201 for( i = 0; i < core->nconss; i++ )
2202 {
2203 if( !isRowCovered(inst, i) )
2204 last_mult.u[i] = SCIPrandomGetReal(heurdata->randnumgen, 0.9, 1.1) * last_mult.u[i];
2205 else
2206 last_mult.u[i] = 0.0;
2207 }
2208
2209 /* bestub is an upper bound for the restricted instance, without the fixed costs */
2210 bestub -= inst->costsfixed;
2211
2212 /* maximum number of subgradient iterations */
2213 max_iter = 10 * core->nconss;
2214
2215 for( iter = 0; iter < max_iter; iter++ )
2216 {
2217 /* compute norm of the subgradient */
2218 norm = 0.0;
2219 for( i = 0; i < core->nconss; i++ )
2220 norm = norm + last_mult.subgradient[i] * last_mult.subgradient[i]; /* we have subgradient[i] = 0.0 if row i is not to be considered */
2221
2222 /* the norm is zero if an optimal solution (to the restricted instance) was found */
2223 if( SCIPisZero(scip, norm) )
2224 break;
2225
2226 /* Held-Karp update */
2227 for( i = 0; i < core->nconss; i++ )
2228 {
2229 SCIP_Real hk = last_mult.u[i] + lambda * (bestub - last_mult.lblagrangelocal) * last_mult.subgradient[i] / norm; /*lint !e795*/
2230 next_mult.u[i] = 0.0;
2231
2232 if( SCIPisPositive(scip, 0.0) )
2233 next_mult.u[i] = hk;
2234 }
2235
2236 /* for each multiplier compute an optimal solution to get a lower bound */
2237 SCIP_CALL( computeOptimalSolution(scip, core, inst, &next_mult, heurdata) );
2238
2239 /* save the best incumbent */
2240 if( SCIPisGT(scip, next_mult.lblagrangelocal, best_mult_lb->lblagrangelocal) )
2241 copySolution(scip, core, best_mult_lb, &next_mult);
2242
2244 {
2245 copySolution(scip, core, &heurdata->multbestlbtotal, &next_mult);
2246 }
2247
2248 /* adjust lambda, the step size, if necessary */
2249 if( lambda_adjustments )
2250 {
2251 /* save last 'p' lower and upper bounds */
2252 last_lb[last_data_pos++] = next_mult.lblagrangelocal;
2253
2254 /* lambda is adjusted after param_lambda_p iterations */
2255 if( last_data_pos >= heurdata->param_lambda_p )
2256 {
2257 SCIP_Real max_lb = last_lb[0];
2258 SCIP_Real min_lb = last_lb[0];
2259
2260 /* find best and worst bounds that occurred within the last lambda_p iterations */
2261 for( i = 1; i < heurdata->param_lambda_p; i++ )
2262 {
2263 if( SCIPisGT(scip, last_lb[i], max_lb) )
2264 max_lb = last_lb[i];
2265 if( SCIPisLT(scip, last_lb[i], min_lb) )
2266 min_lb = last_lb[i];
2267 }
2268
2269 /* if min_lb and max_lb differ by more than 1%, lambda is halved */
2270 if( SCIPisGT(scip, max_lb - min_lb, 0.01) )
2271 lambda = lambda / 2;
2272
2273 /* if min_lb and max_lb differ by less than 0.1%, lambda is multiplied by 1.5 */
2274 if( SCIPisLT(scip, max_lb - min_lb, 0.001) )
2275 lambda = lambda * 1.5;
2276 last_data_pos = 0;
2277 }
2278 }
2279
2280 /* swap next_mult and last_mult */
2281 tmp_mult = last_mult;
2282 last_mult = next_mult;
2283 next_mult = tmp_mult;
2284
2285 /* check stopping criteria after stop_crit_iter iterations */
2286 if( iter % heurdata->param_stop_crit_iter == 0 )
2287 {
2288 /* we test how the current best lower bound compares to the best lower bound that was known 'stop_crit_iter' iterations ago:
2289 * if the absolute difference is smaller than param_stop_crit_diff and
2290 * the ratio lb_now / lb_old is at least stop_crit_ration
2291 * then we stop */
2292 if( (iter > 0) && (best_mult_lb->lblagrangelocal - stop_crit_lb <= heurdata->param_stop_crit_diff )
2293 && (stop_crit_lb / best_mult_lb->lblagrangelocal >= heurdata->param_stop_crit_ratio) )
2294 {
2295 break;
2296 }
2297
2298 stop_crit_lb = best_mult_lb->lblagrangelocal;
2299 }
2300 }
2301
2302 freeMemoryForSolution(scip, &last_mult);
2303 freeMemoryForSolution(scip, &next_mult);
2304
2305 return SCIP_OKAY;
2306}
2307
2308/** computes an initial lagrange multiplier, see formula (8) in the paper */
2309static
2311 SCIP* scip, /**< master SCIP data structure */
2312 SCP_CORE* core, /**< SCP core data structure */
2313 SCP_INSTANCE* inst, /**< (reduced) SCP instance */
2314 SCP_Lagrange_Sol* mult, /**< initialized lagrange multiplier were the new one will be stored */
2315 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
2316 )
2317{
2318 int i;
2319 int j;
2320
2321 if( core->columnsavailable == TRUE )
2322 {
2323 for( i = 0; i < core->nconss; i++ )
2324 mult->u[i] = SCIP_REAL_MAX;
2325
2326 for( i = 0; i < core->nvariables; i++ )
2327 {
2328 int nuncovered = 0;
2329
2330 if( !isCoreVariable(core, core->variables[i]) )
2331 continue;
2332
2333 if( isFixedVariable(inst, core->variables[i]) )
2334 continue;
2335
2336 /* count how many uncovered, active rows this column covers */
2337 for( j = 0; j < core->nvarconss[i]; j++ )
2338 {
2339 int colpos = core->columns[i][j];
2340
2341 /* skip inactive constraints */
2342 if( SCIPconsIsActive(core->conss[colpos]) == FALSE )
2343 continue;
2344
2345 /* skip covered rows */
2346 if( isRowCovered(inst, colpos) )
2347 continue;
2348
2349 nuncovered++;
2350 }
2351
2352 /* if this column covers any rows, update their cost if necessary */
2353 if( nuncovered > 0 )
2354 {
2355 SCIP_Real costs = SCIPvarGetObj(core->variables[i]) / ((SCIP_Real) nuncovered);
2356 int nvars;
2357
2358 for( j = 0; j < core->nvarconss[i]; j++ )
2359 {
2360 int colpos = core->columns[i][j];
2362
2363 if( isRowCovered(inst, colpos) )
2364 continue;
2365
2366 if( SCIPconsIsActive(core->conss[colpos]) == FALSE )
2367 continue;
2368
2369 SCIP_CALL( SCIPgetConsNVars(scip, core->conss[colpos], &nvars, &success) );
2370 if( success == FALSE )
2371 continue;
2372
2373 if( costs < mult->u[colpos] )
2374 mult->u[colpos] = costs;
2375 }
2376 }
2377 }
2378 }
2379 else
2380 {
2381 SCIP_VAR **vars;
2382 int nvars;
2383 int *nuncoveredactive;
2384
2385 vars = heurdata->vars;
2386 SCIP_CALL( SCIPallocBufferArray(scip, &nuncoveredactive, core->nvariables) );
2387
2388 for( i = 0; i < core->nvariables; i++ )
2389 nuncoveredactive[i] = 0;
2390
2391 for( i = 0; i < core->nconss; i++ )
2392 {
2394
2395 if( isRowCovered(inst, i) )
2396 continue;
2397
2398 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
2399 if( success == FALSE )
2400 continue;
2401
2402 for( j = 0; j < nvars; j++ )
2403 {
2404 int varpos;
2405
2406 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
2407
2408 if( !isCoreVariable(core, vars[j]) )
2409 continue;
2410 else
2411 nuncoveredactive[varpos]++;
2412 }
2413 }
2414
2415 for( i = 0; i < core->nconss; i++ )
2416 {
2417 SCIP_Bool found = FALSE;
2419
2420 if( isRowCovered(inst, i) )
2421 {
2422 mult->u[i] = 0.0;
2423 continue;
2424 }
2425
2426 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
2427 if( success == FALSE )
2428 continue;
2429
2430 for( j = 0; j < nvars; j++ )
2431 {
2432 if( !isCoreVariable(core, vars[j]) )
2433 continue;
2434 else
2435 {
2436 int varpos;
2437 SCIP_Real costs = SCIP_REAL_MAX;
2438
2439 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
2440
2441 if( nuncoveredactive[varpos] > 0 )
2442 costs = SCIPvarGetObj(core->variables[varpos]) / ((SCIP_Real) nuncoveredactive[varpos]);
2443
2444 if( (found == FALSE) || (costs < mult->u[i]) )
2445 {
2446 found = TRUE;
2447 mult->u[i] = costs;
2448 }
2449 }
2450 }
2451 }
2452
2453 SCIPfreeBufferArray(scip, &nuncoveredactive);
2454 }
2455
2456 return SCIP_OKAY;
2457}
2458
2459/* Explores a neighborhood of lagrange multipliers around 'startmult',
2460 * and calls the greedy algorithm for each multiplier. The neighborhood is
2461 * simply computed by doing the Held-Karp subgradient updates. The best solutions
2462 * are extended to solutions of the unrestricted instance.
2463 */
2464static
2466 SCIP* scip, /**< master SCIP data structure */
2467 SCP_Lagrange_Sol* startmult, /**< lagrange multiplier where the search is started */
2468 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
2469 )
2470{
2471 SCP_CORE* core;
2472 SCP_INSTANCE* subinst;
2473 SCP_Lagrange_Sol mult;
2474 SCIP_VAR** vars;
2476 SCIP_Real bestub;
2477 SCIP_Real norm;
2478 SCIP_Real costs;
2479 int nvars;
2480 int iter;
2481 int i;
2482 int j;
2483
2484 core = &heurdata->core;
2485 subinst = &heurdata->subinst;
2486 vars = heurdata->vars;
2487 bestub = heurdata->bestub - subinst->costsfixed;
2488
2490 copySolution(scip, core, &mult, startmult);
2491
2492 /* perform 'param_greedy_max_iter' subgradient iterations */
2493 for( iter = 0; iter < heurdata->param_greedy_max_iter; iter++ )
2494 {
2495 /* compute subgradient for 'mult' */
2496 if( core->rowsavailable )
2497 {
2498 for( i = 0; i < core->nconss; i++ )
2499 {
2500 mult.subgradient[i] = 0.0;
2501
2502 if( SCIPconsIsActive(core->conss[i]) == FALSE )
2503 continue;
2504
2505 if( isRowCovered(subinst, i) )
2506 continue;
2507
2508 if( core->nrowvars[i] == 0 )
2509 continue;
2510
2511 mult.subgradient[i] = 1.0;
2512
2513 for( j = 0; j < core->nrowvars[i]; j++ )
2514 {
2515 int varpos = core->rows[i][j];
2516
2517 if( mult.lagrangiancostslocal[varpos] < 0.0 )
2518 mult.subgradient[i] -= 1.0;
2519 }
2520 }
2521 }
2522 else
2523 {
2524 for( i = 0; i < core->nconss; i++ )
2525 {
2526 mult.subgradient[i] = 0.0;
2527
2528 if( isRowCovered(subinst, i) )
2529 continue;
2530
2531 SCIP_CALL( getConsVars(scip, core, i, vars, &nvars, &success) );
2532 if( success == FALSE )
2533 continue;
2534
2535 mult.subgradient[i] = 1.0;
2536
2537 for( j = 0; j < nvars; j++ )
2538 {
2539 int varpos;
2540
2541 SCIP_CALL( getVarIndex(scip, core, vars[j], &varpos) );
2542
2543 if( !isCoreVariable(core, core->variables[varpos]) )
2544 continue;
2545
2546 if( mult.lagrangiancostslocal[varpos] < 0.0 )
2547 mult.subgradient[i] -= 1.0;
2548 }
2549 }
2550 }
2551
2552 /* compute norm of subgradient */
2553 norm = 0.0;
2554 for( i = 0; i < core->nconss; i++ )
2555 norm = norm + mult.subgradient[i] * mult.subgradient[i];
2556
2557 /* the norm is zero if an optimal solution (to the restricted instance) was found */
2558 if( SCIPisZero(scip, norm) )
2559 break;
2560
2561 /* Held-Karp update */
2562 for( i = 0; i < core->nconss; i++ )
2563 {
2564 SCIP_Real hk = mult.u[i] + heurdata->param_lambda * (bestub - mult.lblagrangelocal) * mult.subgradient[i] / norm; /*lint !e795*/
2565 mult.u[i] = 0.0;
2566
2567 if( hk > 0.0 )
2568 mult.u[i] = hk;
2569 }
2570
2571 /* first, compute lagrangian costs */
2572 SCIP_CALL( computeOptimalSolution(scip, core, subinst, &mult, heurdata) );
2573
2574 /* save this multiplier if it gives a better local lower bound than the one known */
2577
2578 /* save this multiplier if it gives a better global lower bound */
2580 copySolution(scip, core, &heurdata->multbestlbtotal, &mult);
2581
2582 /* apply the greedy algorithm and extend it to a solution of the unrestricted instance by adding fixed variables */
2583 SCIP_CALL( greedySetCover(scip, core, subinst, &mult, heurdata) );
2584 extendSolution(scip, core, subinst, mult.xgreedylocal);
2585
2586 costs = subinst->costsfixed + mult.ubgreedylocal;
2588
2589 /* save solution if it is better */
2590 if( costs < heurdata->bestubsubinst )
2592 }
2593
2595
2596 return SCIP_OKAY;
2597}
2598
2599/* reports a solution to SCIP */
2600static
2602 SCIP* scip, /**< master SCIP data structure */
2603 SCP_INSTANCE* inst, /**< (reduced) SCP instance */
2604 SCIP_Bool* solution, /**< solution for 'inst'; will be extended to global solution */
2605 SCIP_HEUR* heur /**< pointer to the heuristic's data */
2606 )
2607{
2608 SCIP_VAR** solvars;
2609 SCIP_Real* solvals;
2610 int nsolvars;
2611 int i;
2612 SCIP_SOL* newsol;
2614 SCIP_Bool foundsol = FALSE;
2615 SCIP_CONS** conss;
2616 int nconss;
2617
2618 SCIP_CALL( SCIPgetVarsData(scip, &solvars, &nsolvars, NULL, NULL, NULL, NULL) );
2619 SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
2620 SCIP_CALL( SCIPallocBufferArray(scip, &solvals, nsolvars) );
2621
2622 for( i = 0; i < nsolvars; i++ )
2623 {
2624 if( isVarInSolution(solution, solvars[i]) )
2625 solvals[i] = 1.0;
2626 else if( (isFixedVariable(inst, solvars[i]) == TRUE) && (SCIPisZero(scip, SCIPvarGetObj(solvars[i])) == FALSE) )
2627 solvals[i] = 1.0;
2628 else
2629 solvals[i] = 0.0;
2630 }
2631
2632 SCIP_CALL( SCIPsetSolVals(scip, newsol, nsolvars, solvars, solvals) );
2633
2634 /* test all constraints and check if the activity is correct, adjust some free variable if necessary */
2635 conss = SCIPgetConss(scip);
2636 nconss = SCIPgetNConss(scip);
2637 for( i = 0; (i < nconss) && (foundsol == FALSE); i++ )
2638 {
2639 SCIP_Real lhs = 0.0, activity = 0.0;
2640 SCIP_Real *vals = NULL;
2641 SCIP_Bool valuesallones = FALSE;
2642
2643 if( !strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[i])), "linear") )
2644 {
2645 lhs = SCIPgetLhsLinear(scip, conss[i]);
2646 activity = SCIPgetActivityLinear(scip, conss[i], newsol);
2647 vals = SCIPgetValsLinear(scip, conss[i]);
2648 }
2649 else if( !strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[i])), "logicor") )
2650 {
2651 valuesallones = TRUE;
2652 }
2653 else if( !strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[i])), "masterbranch") )
2654 {
2655 /* do nothing */
2656 SCIPdebugMessage("constraint %i is a masterbranch\n", SCIPconsGetPos(conss[i]));
2657 continue;
2658 }
2659 else
2660 {
2661 SCIPerrorMessage("constraint is '%s', can't handle this\n", SCIPconshdlrGetName(SCIPconsGetHdlr(conss[i])));
2662 SCIPABORT();
2663 }
2664
2665 if( lhs > activity )
2666 {
2667 int j;
2668 int nvars;
2669 SCIP_Bool changed = FALSE;
2670 SCIP_VAR **vars;
2671
2672
2673 /*SCIPdebugMessage("constraint %i: left hand side is violated by %f\n", i, lhs - activity);*/
2674 SCIP_CALL( SCIPgetConsNVars(scip, conss[i], &nvars, &success) );
2677
2678 for( j = 0; (changed == FALSE) && (j < nvars); j++ )
2679 {
2680 SCIP_Bool costszero = SCIPisZero(scip, SCIPvarGetObj(vars[j]));
2681 if( costszero == TRUE )
2682 {
2683 assert(valuesallones || vals != NULL);
2684
2685 /* constraint is "logicor" */
2686 if( valuesallones )
2687 SCIP_CALL( SCIPincSolVal(scip, newsol, vars[j], lhs - activity) );
2688 /* constraint is "linear" */
2689 else
2690 {
2691 assert(vals != NULL);
2692 if( !SCIPisZero(scip, vals[j]) )
2693 SCIP_CALL( SCIPincSolVal(scip, newsol, vars[j], (lhs - activity) / vals[j]) );
2694 else
2695 SCIPdebugMessage("could not adjust activity\n");
2696 }
2697
2698 SCIP_CALL( SCIPtrySol(scip, newsol, FALSE, FALSE, TRUE, TRUE, TRUE, &foundsol) );
2699 changed = TRUE;
2700 }
2701 }
2702
2703 if( changed == FALSE )
2704 SCIPdebugMessage("could not find variable with zero costs\n");
2705
2707 }
2708
2709 if( !strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[i])), "linear") )
2710 {
2711 if( SCIPgetLhsLinear(scip, conss[i]) > SCIPgetActivityLinear(scip, conss[i], newsol) )
2712 SCIPdebugMessage("activity is still smaller than lhs\n");
2713 }
2714 /* take care of the case rhs < activity. Question: can this occur?
2715 * YES it can, but only the convexity constraint can be violated (is this really true?).
2716 * We simply ignore this issue. SCIP will not accept the solution if it is not good enough.
2717 */
2718 }
2719
2721 SCIPfreeBufferArray(scip, &solvals);
2722
2723 if( success == TRUE )
2724 SCIPdebugMessage("new solution found by set covering heuristic\n");
2725
2726 return SCIP_OKAY;
2727}
2728
2729/** the three-phase procedure from the paper. It tries to find near-optimal lagrange multipliers and
2730 * reduces the size of an instance by fixing variables that are likely to be in an optimal solution. */
2731static
2733 SCIP* scip, /**< master SCIP data structure */
2734 SCIP_HEUR* heur, /**< master SCIP heur data structure */
2735 SCIP_HEURDATA* heurdata /**< pointer to the heuristic's data */
2736 )
2737{
2738 SCP_Lagrange_Sol* mult_lb_subinst;
2739 int i;
2741 SCP_CORE* core;
2742 SCP_INSTANCE* inst;
2743 SCP_INSTANCE* subinst;
2744 int niter;
2745
2746 core = &heurdata->core;
2747 inst = &heurdata->inst;
2748 subinst = &heurdata->subinst;
2749 mult_lb_subinst = &heurdata->tpmultlbsubinst;
2750
2751 /* we first create our own copy of the instance, as we need to mark variables as fixed until all variables are fixed */
2752 copyInstance(scip, core, subinst, inst);
2754
2755 /* if this function is called for the first time, no multiplier is available and we need to compute one to start with */
2757 {
2758 /* next, compute initial lagrange multipliers and find a first lower bound */
2759 SCIP_CALL( computeInitialLagrangeMultiplier(scip, core, subinst, mult_lb_subinst, heurdata) );
2761 }
2762 else
2763 {
2764 /* take the best lagrange multiplier of the unrestricted instance as starting point */
2765 copySolution(scip, core, mult_lb_subinst, &heurdata->multbestlbtotal);
2766 }
2767
2768 /* computeOptimalSolution computes an optimal solution to the lagrange relaxation. Also, it computes the subgradient */
2769 SCIP_CALL( computeOptimalSolution(scip, core, subinst, mult_lb_subinst, heurdata) );
2770 SCIP_CALL( greedySetCover(scip, core, subinst, mult_lb_subinst, heurdata) );
2771
2772 /* we now have a lower and upper bound in mult_lb_local for the instance 'inst' and take these as our starting values */
2775 copySolution(scip, core, &heurdata->multbestlbinst, mult_lb_subinst);
2776
2777 /* check whether 'bestubinst_sol' is a solution of the reduced instance 'subinst' */
2779 if( !success )
2780 {
2781 SCIPerrorMessage("three-phase: initial solution is not a valid set cover\n");
2782 SCIPABORT();
2783 }
2784
2785 /* in the first call of this proceduce there is no best upper bound for the unrestricted instance */
2787 {
2789 SCIPdebugMessage("new upper bound: %f\n", heurdata->bestub);
2791 }
2792
2793 if( core->nactiveconss <= subinst->nrowscovered )
2794 {
2795 SCIPdebugMessage("threephase: all rows are already covered\n");
2796 }
2797
2798 /* The next loop works as follows:
2799 * 1. Derive the subinstance 'subinst' by marking all rows as covered that are covered by fixed variables of 'subinst'. If all rows are covered by fixed variables, stop.
2800 * 2. Perform subgradient optimization to find a lagrange multiplier that gives a better lower bound for 'subinst'.
2801 * 3. Explore the neighborhood of this best multiplier by doing additional subgradient steps and calling the greedy algorithm with each multiplier as argument.
2802 * 4. Check whether any of these local solutions can be extended to better global solutions.
2803 * 5. Fix several variables to reduce the size of 'subinst'.
2804 */
2805
2806 /* stop if all rows are covered by fixed variables or a maximum number of iterations has been reached */
2807 for( niter = 0; niter < heurdata->param_threephase_max_iter && core->nactiveconss > subinst->nrowscovered; ++niter )
2808 {
2809 /* we mark all rows covered by fixed variables, in addition to the ones that were already covered */
2811 SCIP_CALL( subgradientOptimization(scip, core, subinst, mult_lb_subinst, heurdata->bestubsubinst, heurdata) );
2812
2813 /* explore neighborhood of the best lower bound multiplier by applying the held-karp update again.
2814 * this updates all upper bounds (and sometimes also lower bounds) in 'heurdata' */
2815 SCIP_CALL( exploreNeighborhood(scip, mult_lb_subinst, heurdata) );
2816
2817 /* extend a solution of 'subinst' to one of 'inst' if it gives a better upper bound */
2819 {
2821
2822 /* extend a solution of 'inst' to a solution of the whole instance and check whether this gives a better global upper bound */
2824 {
2826
2828 SCIPdebugMessage("new upper bound: %f\n", heurdata->bestub);
2830 }
2831 }
2832
2833 /* stop if any solution can not be better than the best known solution */
2834 if( subinst->costsfixed + mult_lb_subinst->lblagrangelocal >= heurdata->bestub )
2835 break;
2836
2837 /* At each step we fix new variables: fix the first max(1, nconstraints / 200) variables
2838 * that were picked by the greedy solution (in the order they were picked) */
2839 for( i = 0; i < core->nsolgreedy && i <= core->nconss / 200; i++ )
2840 {
2841 fixVariable(subinst, core->variables[core->solgreedy[i]]);
2842 subinst->costsfixed += SCIPvarGetObj(core->variables[core->solgreedy[i]]);
2843 }
2844 }
2845
2847 if( !success )
2848 {
2849 SCIPdebugMessage("three-phase: final solution is not a valid set cover\n");
2850 }
2851
2852 return SCIP_OKAY;
2853}
2854
2855/** driver for the three-phase procedure */
2856static
2858 SCIP* scip, /**< master SCIP data structure */
2859 SCIP_HEUR* heur /**< original SCIP heuristic data structure */
2860 )
2861{
2863 SCIP_Bool stopcft = FALSE;
2864 int niter = 0; /* total number of iterations of the three-phase loop */
2865 int nitercore = 0; /* total number of iterations on the current core */
2866 int niternoimp = 0; /* number of iterations for how long no improvement on the upper bound was made */
2867 int coret = 10; /* compute new core after this number of iterations */
2868 SCIP_Real pi; /* percentage of rows that need to be covered in each fixing phase */
2869 SCIP_Real corelb = 0.0;
2870 SCP_CORE* core;
2871 SCP_INSTANCE* inst;
2873
2874 int i;
2875
2876 heurdata = SCIPheurGetData(heur);
2877 assert(heurdata != NULL);
2878
2879 /* allocate memory that is used locally by redefineCore */
2882
2883 /* allocate memory that is used locally by subgradientOptimization */
2885
2886 /* we always consider core variables (columns) only to cover rows, so we need to define the first core.
2887 * This is done by choosing for each row the first five columns covering it and adding them to the core. */
2889
2890 /* allocate memory that is used to get all variables that are part of some constraint.
2891 * 'maxconstraintvariables' is the maximum number of variables any constraint of the problem contains. */
2893
2894 /* after defining the core, we compute all core columns and core rows */
2897
2898 /* set up basic instance. so far no variables are fixed */
2901
2902 core = &heurdata->core;
2903 inst = &heurdata->inst;
2904 pi = heurdata->param_pi_min;
2905
2906 /* allocate memory that is used by the greedy algorithm locally */
2913
2918
2922
2926
2927 while( stopcft == FALSE )
2928 {
2929 SCIP_Bool redefine = FALSE;
2930 SCIP_Real currentub = heurdata->bestub;
2931
2932
2933 /* derive the reduced subinstance by marking rows covered by fixed variables */
2934 for( i = 0; i < SCIPgetNConss(scip); ++i )
2935 inst->rowscovered[i] = FALSE;
2936 inst->nrowscovered = 0;
2938
2939 /* call three-phase as long as 'inst' contains uncovered rows */
2940 if( core->nactiveconss > inst->nrowscovered )
2941 {
2942 SCIPdebugMessage("%d variables are fixed, %d rows are covered\n", inst->nvarsfixed, inst->nrowscovered);
2943
2944 /* apply procedure three-phase to find an near optimal lagrange multiplier */
2945 SCIP_CALL( threePhase(scip, heur, heurdata) );
2946 }
2947 else
2948 {
2949 /* compute new core when all of its rows are covered by fixed variables */
2950 redefine = TRUE;
2951 }
2952
2953 /* stop if maximum number of iterations is reached */
2954 if( niter++ >= heurdata->param_max_iter )
2955 stopcft = TRUE;
2956
2957 /* set pi to PI_MIN if the current best solution was found in this iteration */
2958 if( heurdata->bestub < currentub )
2959 {
2960 niternoimp = 0;
2961 pi = heurdata->param_pi_min;
2962 }
2963 else
2964 {
2965 /* increase pi if no better solution was found, i.e. fix more variables in order to cover more rows */
2966 pi = pi * heurdata->param_pi_alpha;
2967 niternoimp++;
2968 }
2969
2970 /* stop if there was no improvement during the last 'SCP_MAX_ITER_NO_IMP' iterations */
2971 if( niternoimp >= heurdata->param_max_iter_no_imp )
2972 stopcft = TRUE;
2973
2974 /* stop if UB <= beta * LB */
2976 stopcft = TRUE;
2977
2978 /* redefine core if the current core was worked on for 'coret' iterations */
2979 if( nitercore++ == coret )
2980 redefine = TRUE;
2981
2982 if( stopcft )
2983 break;
2984
2985 /* compute delta fixes variables of 'bestubsol' within the core that are likely to be part of an optimal solution */
2988
2989 if( redefine == TRUE )
2990 {
2991 /* stop if the last core did not lead to any improvements */
2993 stopcft = TRUE;
2994 else
2995 {
2997 for( i = 0; i < SCIPgetNVars(scip); ++i )
2998 inst->varsfixed[i] = FALSE;
2999 inst->nvarsfixed = 0;
3000 inst->costsfixed = 0.0;
3001 pi = heurdata->param_pi_min;
3002 nitercore = 0;
3004 }
3005 }
3006
3007 SCIPdebugMessage("iteration %i: best lower bound: %f, best upper bound: %f\n", niter, heurdata->multbestlbtotal.lblagrangeglobal, heurdata->bestub);
3008 }
3009
3010 for( i = 0; i < SCIPgetNVars(scip); ++i )
3011 inst->varsfixed[i] = FALSE;
3012 inst->nvarsfixed = 0;
3013
3015 if( success == FALSE )
3016 SCIPdebugMessage("final solution is not a valid set cover\n");
3017 else
3018 SCIPdebugMessage("final solution has costs %f\n", heurdata->bestub);
3019
3020 /* report the final solution to SCIP */
3022
3023 /* release all memory that was allocated before */
3027
3032
3038
3040
3043
3045
3047
3049
3052
3053 return SCIP_OKAY;
3054}
3055
3056/*
3057 * Callback methods of primal heuristic
3058 */
3059
3060/** destructor of primal heuristic to free user data (called when SCIP is exiting) */
3061static
3062SCIP_DECL_HEURFREE(heurFreeSetcover)
3063{ /*lint --e{715}*/
3065
3066 assert(heur != NULL);
3067 assert(scip != NULL);
3068
3069 /* get heuristic data */
3070 heurdata = SCIPheurGetData(heur);
3071 assert(heurdata != NULL);
3072
3073 /* free heuristic data */
3075 SCIPheurSetData(heur, NULL);
3076
3077 return SCIP_OKAY;
3078}
3079
3080/** initialization method of primal heuristic (called after problem was transformed) */
3081static
3082SCIP_DECL_HEURINIT(heurInitSetcover)
3083{ /*lint --e{715}*/
3085
3086 assert(heur != NULL);
3087 assert(scip != NULL);
3088
3089 /* get heuristic data */
3090 heurdata = SCIPheurGetData(heur);
3091 assert(heurdata != NULL);
3092
3093 /* create random number generator */
3096
3097 return SCIP_OKAY;
3098}
3099
3100/** deinitialization method of primal heuristic (called before transformed problem is freed) */
3101static
3102SCIP_DECL_HEUREXIT(heurExitSetcover)
3103{ /*lint --e{715}*/
3105
3106 assert(heur != NULL);
3107 assert(scip != NULL);
3108
3109 /* get heuristic data */
3110 heurdata = SCIPheurGetData(heur);
3111 assert(heurdata != NULL);
3112
3113 /* free random number generator */
3115
3116 return SCIP_OKAY;
3117}
3118
3119
3120/** execution method of primal heuristic */
3121static
3122SCIP_DECL_HEUREXEC(heurExecSetcover)
3123{ /*lint --e{715}*/
3125
3126 assert(heur != NULL);
3127 assert(scip != NULL);
3128 assert(result != NULL);
3129
3130 heurdata = SCIPheurGetData(heur);
3131 assert(heurdata != NULL);
3132
3134
3135 /* the heuristic is only executed on problems with many variables */
3137 {
3138 SCIPdebugMessage("not running set covering heuristic because instance is too small (only %i variables)\n", SCIPgetNVars(scip));
3139 return SCIP_OKAY;
3140 }
3141
3142 /* only run on set covering problems */
3144 return SCIP_OKAY;
3145
3146 if( SCIPgetNVars(scip) == 0 )
3147 return SCIP_OKAY;
3148
3150
3152 return SCIP_OKAY;
3153}
3154
3155
3156/*
3157 * primal heuristic specific interface methods
3158 */
3159
3160/** creates the setcover primal heuristic and includes it in SCIP */
3162 GCG* gcg /**< GCG data structure */
3163 )
3164{
3166 SCIP_HEUR* heur;
3168
3169 heur = NULL;
3171 heurdata->gcg = gcg;
3172
3173 /* include primal heuristic */
3174
3177 HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecSetcover, heurdata) );
3178
3179 assert(heur != NULL);
3180
3181 /* set non fundamental callbacks via setter functions */
3182 SCIP_CALL( SCIPsetHeurFree(masterprob, heur, heurFreeSetcover) );
3183 SCIP_CALL( SCIPsetHeurInit(masterprob, heur, heurInitSetcover) );
3184 SCIP_CALL( SCIPsetHeurExit(masterprob, heur, heurExitSetcover) );
3185
3186 /* add setcover primal heuristic parameters */
3187
3188 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/"HEUR_NAME"/tentcoresize",
3189 "how many columns are added to the tentative core for each row",
3191
3192 SCIP_CALL( SCIPaddBoolParam(masterprob, "heuristics/"HEUR_NAME"/lambdaadjustments",
3193 "should the step size during the subgradient phase be adjusted?",
3195
3196 SCIP_CALL( SCIPaddRealParam(masterprob, "heuristics/"HEUR_NAME"/lambda",
3197 "default step size",
3199
3200 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/"HEUR_NAME"/lambdap",
3201 "number of iterations after which lambda is adjusted",
3202 &heurdata->param_lambda_p, FALSE, DEF_LAMBDA_P, 1, INT_MAX, NULL, NULL) );
3203
3204 SCIP_CALL( SCIPaddRealParam(masterprob, "heuristics/"HEUR_NAME"/beta",
3205 "greatest gap between lower and upper bounds that is allowed",
3207
3208 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/"HEUR_NAME"/sciter",
3209 "number of subgradient iterations after which the stopping criterion is tested again",
3211
3212 SCIP_CALL( SCIPaddRealParam(masterprob, "heuristics/"HEUR_NAME"/scdiff",
3213 "maximum absolute difference between lower and upper bound that is allowed for the stopping criterion",
3215
3216 SCIP_CALL( SCIPaddRealParam(masterprob, "heuristics/"HEUR_NAME"/scratio",
3217 "minimum ratio between lower and upper bound that is allowed that is allowed for the stopping criterion",
3219
3220 SCIP_CALL( SCIPaddRealParam(masterprob, "heuristics/"HEUR_NAME"/pimin",
3221 "percentage of rows to be removed after column fixing",
3222 &heurdata->param_pi_min, FALSE, DEF_PI_MIN, 0.0, 1.0, NULL, NULL) );
3223
3224 SCIP_CALL( SCIPaddRealParam(masterprob, "heuristics/"HEUR_NAME"/pialpha",
3225 "increase of pi when no improvement was made",
3227
3228 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/"HEUR_NAME"/tpmaxiter",
3229 "maximum iterations of the three-phase procedure",
3230 &heurdata->param_max_iter, FALSE, DEF_MAX_ITER, 1, INT_MAX, NULL, NULL) );
3231
3232 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/"HEUR_NAME"/tpmaxiternoimp",
3233 "maximum allowed number of iterations of the three-phase procedure without improvements",
3235
3236 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/"HEUR_NAME"/threephasemaxiter",
3237 "maximum number of iterations inside three-phase",
3239
3240 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/"HEUR_NAME"/greedymaxiter",
3241 "maximum number of iterations of the greedy algorithm",
3243
3244 SCIP_CALL( SCIPaddIntParam(masterprob, "heuristics/"HEUR_NAME"/minprobsize",
3245 "minimum number of variables in the problem for the heuristic to start",
3247
3248 return SCIP_OKAY;
3249}
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_REAL_MAX
#define SCIP_Bool
#define SCIP_Real
#define SCIPABORT()
#define SCIP_REAL_MIN
#define TRUE
#define FALSE
GCG interface methods.
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetActivityLinear(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol)
GCG_EXPORT SCIP_Bool GCGisMasterSetCovering(GCG *gcg)
Definition relax_gcg.c:4347
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_CONS ** SCIPgetConss(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
int SCIPgetNConss(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
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 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 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)
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
SCIP_RETCODE SCIPgetConsNVars(SCIP *scip, SCIP_CONS *cons, int *nvars, SCIP_Bool *success)
int SCIPconsGetPos(SCIP_CONS *cons)
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
SCIP_RETCODE SCIPgetConsVars(SCIP *scip, SCIP_CONS *cons, SCIP_VAR **vars, int varssize, SCIP_Bool *success)
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
const char * SCIPconsGetName(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_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
#define SCIPallocClearBufferArray(scip, ptr, num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPreallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeBufferArrayNull(scip, ptr)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPincSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real incval)
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
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_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisGT(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 SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
int SCIPvarGetIndex(SCIP_VAR *var)
int SCIPvarGetProbindex(SCIP_VAR *var)
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)
void SCIPsortRealInt(SCIP_Real *realarray, int *intarray, int len)
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
#define HEUR_FREQ
#define HEUR_TIMING
#define HEUR_USESSUBSCIP
* result
SCIP_VAR * var
SCIP_VAR ** vars
int j
SCIP_Bool success
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
static SCIP_HEURDATA * heurdata
int nvars
SCIPfreeBufferArray(scip, &cycles)
#define DEF_STOP_CRIT_ITER
#define DEF_THREEPHASE_MAX_ITER
static SCIP_RETCODE allocateMemoryForSolution(SCIP *scip, SCP_CORE *core, SCP_Lagrange_Sol *mult)
static void removeVarsFromCore(SCIP *scip, SCP_CORE *core)
#define DEF_LAMBDA
static SCIP_Bool isCoreVariable(SCP_CORE *core, SCIP_VAR *var)
static SCIP_RETCODE computeOptimalSolution(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCP_Lagrange_Sol *mult, SCIP_HEURDATA *heurdata)
static SCIP_RETCODE computeDelta(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCIP_Real *lagrangiancosts, SCIP_Bool *solution, SCIP_Real pi, SCIP_HEURDATA *heurdata)
static void copySolution(SCIP *scip, SCP_CORE *core, SCP_Lagrange_Sol *dest, SCP_Lagrange_Sol *source)
static void addVarToSolution(SCIP_Bool *solution, SCIP_VAR *var)
#define DEF_CORE_TENT_SIZE
static SCIP_Bool isRowCovered(SCP_INSTANCE *inst, int rowpos)
SCIP_RETCODE GCGincludeHeurSetcover(GCG *gcg)
static SCIP_RETCODE exploreNeighborhood(SCIP *scip, SCP_Lagrange_Sol *startmult, SCIP_HEURDATA *heurdata)
#define DEF_PI_MIN
#define DEF_PI_ALPHA
#define DEF_LAMBDA_ADJUSTMENTS
static void addVarToCore(SCP_CORE *core, SCIP_VAR *var)
static SCIP_RETCODE pqueue_insert(SCIP *scip, PQUEUE *queue, SCIP_Real key, int elem, int *position)
static SCIP_RETCODE computeInitialLagrangeMultiplier(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCP_Lagrange_Sol *mult, SCIP_HEURDATA *heurdata)
static SCIP_RETCODE computeCoreRows(SCIP *scip, SCP_CORE *core, SCIP_HEURDATA *heurdata)
static void pqueue_get_min(SCIP *scip, PQUEUE *queue, int *elem)
#define DEF_STOP_CRIT_DIFF
static void freeMemoryForSolution(SCIP *scip, SCP_Lagrange_Sol *mult)
static SCIP_RETCODE pqueue_init(SCIP *scip, PQUEUE *queue)
static void freeCore(SCIP *scip, SCP_CORE *core)
static void markRowAsCovered(SCP_INSTANCE *inst, int rowpos)
#define DEF_MIN_PROB_SIZE
static SCIP_RETCODE computeCoreColumns(SCIP *scip, SCP_CORE *core)
static SCIP_RETCODE getConsVars(SCIP *scip, SCP_CORE *core, int pos, SCIP_VAR **vars, int *nvars, SCIP_Bool *success)
static void freeInstance(SCIP *scip, SCP_INSTANCE *inst)
static SCIP_RETCODE markRowsCoveredByFixedVariables(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCIP_HEURDATA *heurdata)
static SCIP_RETCODE subgradientOptimization(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCP_Lagrange_Sol *best_mult_lb, SCIP_Real bestub, SCIP_HEURDATA *heurdata)
static SCIP_RETCODE computeGlobalLagrangianCosts(SCIP *scip, SCP_CORE *core, SCP_Lagrange_Sol *mult, SCIP_HEURDATA *heurdata)
#define DEF_MAX_ITER
static void pqueue_decrease_key(SCIP *scip, PQUEUE *queue, int pos, SCIP_Real key)
static SCIP_RETCODE checkSetCover(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCIP_Bool *solution, SCIP_Bool *issetcover, SCIP_HEURDATA *heurdata)
#define DEF_STOP_CRIT_RATIO
static SCIP_RETCODE reportSolution(SCIP *scip, SCP_INSTANCE *inst, SCIP_Bool *solution, SCIP_HEUR *heur)
static SCIP_RETCODE getVarIndex(SCIP *scip, SCP_CORE *core, SCIP_VAR *variable, int *pos)
static void pqueue_increase_key(SCIP *scip, PQUEUE *queue, int pos, SCIP_Real key)
static void copySetCoverSolution(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCIP_Bool *dest, SCIP_Real *destcosts, SCIP_Bool *source)
static SCIP_RETCODE initInstance(SCIP *scip, SCP_INSTANCE *inst)
static void fixVariable(SCP_INSTANCE *inst, SCIP_VAR *var)
static void removeVarFromSolution(SCIP_Bool *solution, SCIP_VAR *var)
static SCIP_RETCODE greedySetCover(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCP_Lagrange_Sol *mult, SCIP_HEURDATA *heurdata)
static void pqueue_clear(SCIP *scip, PQUEUE *queue)
static SCIP_RETCODE removeRedundantColumns(SCIP *scip, SCIP_HEURDATA *heurdata, SCIP_Bool *solution, SCIP_Real *solcosts)
#define DEF_GREEDY_MAX_ITER
static void copyInstance(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *dest, SCP_INSTANCE *source)
static SCIP_RETCODE redefineCore(SCIP *scip, SCIP_HEURDATA *heurdata)
static void clearSolution(SCIP *scip, SCIP_Bool *solution)
#define DEF_LAMBDA_P
static void extendSolution(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCIP_Bool *solution)
static SCIP_RETCODE initTentativeCore(SCIP *scip, SCP_CORE *core, SCIP_HEURDATA *heurdata)
#define DEF_MAX_ITER_NO_IMP
static SCIP_RETCODE computeLocalLagrangianCosts(SCIP *scip, SCP_CORE *core, SCP_INSTANCE *inst, SCP_Lagrange_Sol *mult, SCIP_HEURDATA *heurdata)
static SCIP_RETCODE threePhase(SCIP *scip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
#define DEF_BETA
static SCIP_RETCODE setCoveringHeuristic(SCIP *scip, SCIP_HEUR *heur)
static SCIP_Bool isVarInSolution(SCIP_Bool *solution, SCIP_VAR *var)
static SCIP_Bool isFixedVariable(SCP_INSTANCE *inst, SCIP_VAR *var)
static void pqueue_destroy(SCIP *scip, PQUEUE *queue)
set covering primal heuristic according to Caprara, Fischetti, and Toth (1999)
#define NULL
GCG variable pricer.
#define SCIPerrorMessage
int reserved
SCIP_Real * keys
int * data
int ** positions
SCIP_Real * rccoldelta
SCIP_Bool param_lambda_adjustments
SCIP_Real bestubinst
int param_threephase_max_iter
SCP_Lagrange_Sol multbestlbsubinst
SCP_Lagrange_Sol multbestlbinst
SCP_INSTANCE inst
SCIP_Real param_beta
SCIP_Real param_lambda
SCP_INSTANCE greedyinst
SCP_Lagrange_Sol multbestlbtotal
SCIP_Real param_pi_min
SCIP_Real * greedycolscore
SCP_Lagrange_Sol tpmultlbsubinst
SCP_INSTANCE subinst
SCIP_RANDNUMGEN * randnumgen
SCIP_Real param_stop_crit_ratio
SCIP_Bool * bestubsol
SCIP_Bool * bestubinst_sol
SCIP_Bool useinitialmultiplier
SCIP_Bool * bestubsubinstsol
SCIP_VAR ** vars
SCIP_Real param_stop_crit_diff
SCIP_Real * sglastlb
SCIP_Real * greedycolgamma
SCIP_Real bestub
SCIP_Real param_pi_alpha
SCIP_Real bestubsubinst
int * nvarconss
int maxconstraintvariables
int ** columns
SCIP_Bool * varincore
SCIP_HASHMAP * mapvariables
int ncorevariables
int * solgreedy
SCIP_Bool columnsavailable
SCIP_Bool rowsavailable
SCIP_VAR ** variables
int ** rows
int * listcorevariables
int * nrowvars
SCIP_Real * delta
int * constraintid
int * delta_pos
SCIP_CONS ** conss
SCIP_Real costsfixed
SCIP_Bool * rowscovered
SCIP_Bool * varsfixed
SCIP_Real * lagrangiancostsglobal
SCIP_Real ubgreedylocal
SCIP_Real * lagrangiancostslocal
SCIP_Bool * xgreedylocal
SCIP_Real lblagrangeglobal
SCIP_Real lblagrangelocal
SCIP_Real * subgradient
struct SCIP_Cons SCIP_CONS
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_HeurData SCIP_HEURDATA
struct SCIP_Heur SCIP_HEUR
struct SCIP_HashMap SCIP_HASHMAP
struct SCIP_RandNumGen SCIP_RANDNUMGEN
SCIP_DIDNOTRUN
SCIP_FOUNDSOL
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct SCIP_Sol SCIP_SOL
struct SCIP_Var SCIP_VAR