GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
pricestore_gcg.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 pricestore_gcg.c
30 * @brief methods for storing priced cols (based on SCIP's separation storage)
31 * @author Jonas Witt
32 * @author Christian Puchert
33 * @author Erik Muehmer
34 */
35
36/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
37//#define SCIP_DEBUG
38#include <assert.h>
39
40#include "gcg/pub_gcgcol.h"
41#include "gcg/pub_gcgvar.h"
42#include "scip/def.h"
43#include "scip/set.h"
44#include "scip/stat.h"
45#include "scip/lp.h"
46#include "scip/var.h"
47#include "scip/tree.h"
48#include "scip/reopt.h"
49#include "scip/event.h"
50#include "scip/cons.h"
51#include "scip/debug.h"
52
53#include "gcg/gcg.h"
54#include "gcg/pricestore_gcg.h"
56#include "gcg/pricer_gcg.h"
57#include "gcg/struct_gcgcol.h"
58#include "gcg/struct_sepagcg.h"
59
60#ifdef _OPENMP
61#include "gcg/struct_locks.h"
62#endif
63
64/*
65 * dynamic memory arrays
66 */
67
68/** resizes cols and score arrays to be able to store at least num entries */
69static
71 GCG_PRICESTORE* pricestore, /**< price storage */
72 int arrayindex, /**< index of the arrays */
73 int num /**< minimal number of slots in array */
74 )
75{
76 int retcode;
77 assert(pricestore != NULL);
78 assert(pricestore->masterprob != NULL);
79
80 if( num > pricestore->colssize[arrayindex] )
81 {
82 int newsize;
83
84 newsize = SCIPcalcMemGrowSize(pricestore->masterprob, num);
85
86 GCG_SET_LOCK(&pricestore->locks->memorylock);
87 retcode = SCIPreallocBlockMemoryArray(pricestore->masterprob, &pricestore->cols[arrayindex], pricestore->colssize[arrayindex], newsize);
88 if( retcode == SCIP_OKAY )
89 retcode = SCIPreallocBlockMemoryArray(pricestore->masterprob, &pricestore->objparallelisms[arrayindex], pricestore->colssize[arrayindex], newsize);
90 if( retcode == SCIP_OKAY )
91 retcode = SCIPreallocBlockMemoryArray(pricestore->masterprob, &pricestore->orthogonalities[arrayindex], pricestore->colssize[arrayindex], newsize);
92 if( retcode == SCIP_OKAY )
93 retcode = SCIPreallocBlockMemoryArray(pricestore->masterprob, &pricestore->scores[arrayindex], pricestore->colssize[arrayindex], newsize);
94 GCG_UNSET_LOCK(&pricestore->locks->memorylock);
95
97 pricestore->colssize[arrayindex] = newsize;
98 }
99 assert(num <= pricestore->colssize[arrayindex]);
100
101 return SCIP_OKAY;
102}
103
104/** returns the index of the arrays that are used to store data of a column */
105static
107 GCG_PRICESTORE* pricestore, /**< price storage */
108 GCG_COL* col /**< column */
109 )
110{
111 assert(col != NULL);
112 assert(col->probnr < pricestore->narrays);
113 return col->probnr;
114}
115
116/** creates price storage */
118 GCG* gcg, /**< GCG data structure */
119 GCG_PRICESTORE** pricestore, /**< pointer to store price storage */
120 SCIP_Real efficiacyfac, /**< factor of -redcost/norm in score function */
121 SCIP_Real objparalfac, /**< factor of objective parallelism in score function */
122 SCIP_Real orthofac, /**< factor of orthogonalities in score function */
123 SCIP_Real mincolorth, /**< minimal orthogonality of columns to add
124 (with respect to columns added in the current round) */
125 GCG_EFFICIACYCHOICE efficiacychoice, /**< choice to base efficiacy on */
126 int hashtablesize /**< size of hashtable */
127 )
128{
129 int i;
131 assert(gcg != NULL);
132 assert(pricestore != NULL);
133
135
137
138 (*pricestore)->gcg = gcg;
139 (*pricestore)->masterprob = masterprob;
140 (*pricestore)->ncolstotal = 0;
141 (*pricestore)->ncolsfound = 0;
142 (*pricestore)->ncolsfoundround = 0;
143 (*pricestore)->ncolsapplied = 0;
144 (*pricestore)->narrays = GCGgetNPricingprobs(gcg);
145 (*pricestore)->infarkas = FALSE;
146 (*pricestore)->forcecols = FALSE;
147 (*pricestore)->efficiacyfac = efficiacyfac; /* factor of efficiacies in score function */
148 (*pricestore)->objparalfac = objparalfac; /* factor of objective parallelism in score function */
149 (*pricestore)->orthofac = orthofac; /* factor of orthogonalities in score function */
150 (*pricestore)->mincolorth = mincolorth; /* minimal orthogonality of columns to add
151 (with respect to columns added in the current round) */
152 (*pricestore)->efficiacychoice = efficiacychoice;
153
154#ifdef _OPENMP
155 (*pricestore)->locks = GCGgetLocks(gcg);
156#endif
157
158 SCIP_CALL( SCIPhashtableCreate(&(*pricestore)->hashtable, SCIPblkmem(masterprob),
159 hashtablesize, GCGhashGetKeyCol, GCGhashKeyEqCol, GCGhashKeyValCol, (void*)pricestore) );
160
161 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &(*pricestore)->cols, (*pricestore)->narrays) );
162 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &(*pricestore)->objparallelisms, (*pricestore)->narrays) );
163 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &(*pricestore)->orthogonalities, (*pricestore)->narrays) );
164 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &(*pricestore)->scores, (*pricestore)->narrays) );
165 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &(*pricestore)->colssize, (*pricestore)->narrays) );
166 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &(*pricestore)->ncols, (*pricestore)->narrays) );
167 SCIP_CALL( SCIPallocBlockMemoryArray(masterprob, &(*pricestore)->nforcedcols, (*pricestore)->narrays) );
168
169 for( i = 0; i < (*pricestore)->narrays; ++i )
170 {
171 (*pricestore)->cols[i] = NULL;
172 (*pricestore)->objparallelisms[i] = NULL;
173 (*pricestore)->orthogonalities[i] = NULL;
174 (*pricestore)->scores[i] = NULL;
175 (*pricestore)->colssize[i] = 0;
176 (*pricestore)->ncols[i] = 0;
177 (*pricestore)->nforcedcols[i] = 0;
178 }
179
180 return SCIP_OKAY;
181}
182
183/** frees price storage */
185 GCG_PRICESTORE** pricestore /**< pointer to store price storage */
186 )
187{
188 SCIP* scip;
189 int i;
190 assert(pricestore != NULL);
191 assert(*pricestore != NULL);
192 assert((*pricestore)->ncolstotal == 0);
193
194 scip = (*pricestore)->masterprob;
195
196 SCIPhashtableFree(&(*pricestore)->hashtable);
197
198 for( i = 0; i < (*pricestore)->narrays; ++i )
199 {
200 SCIPfreeBlockMemoryArrayNull(scip, &(*pricestore)->cols[i], (*pricestore)->colssize[i]);
201 SCIPfreeBlockMemoryArrayNull(scip, &(*pricestore)->objparallelisms[i], (*pricestore)->colssize[i]);
202 SCIPfreeBlockMemoryArrayNull(scip, &(*pricestore)->orthogonalities[i], (*pricestore)->colssize[i]);
203 SCIPfreeBlockMemoryArrayNull(scip, &(*pricestore)->scores[i], (*pricestore)->colssize[i]);
204 }
205 SCIPfreeBlockMemoryArray(scip, &(*pricestore)->cols, (*pricestore)->narrays);
206 SCIPfreeBlockMemoryArray(scip, &(*pricestore)->objparallelisms, (*pricestore)->narrays);
207 SCIPfreeBlockMemoryArray(scip, &(*pricestore)->orthogonalities, (*pricestore)->narrays);
208 SCIPfreeBlockMemoryArray(scip, &(*pricestore)->scores, (*pricestore)->narrays);
209 SCIPfreeBlockMemoryArray(scip, &(*pricestore)->colssize, (*pricestore)->narrays);
210 SCIPfreeBlockMemoryArray(scip, &(*pricestore)->ncols, (*pricestore)->narrays);
211 SCIPfreeBlockMemoryArray(scip, &(*pricestore)->nforcedcols, (*pricestore)->narrays);
212 SCIPfreeBlockMemory(scip, pricestore);
213
214 return SCIP_OKAY;
215}
216
217/** informs price storage, that Farkas pricing starts now */
219 GCG_PRICESTORE* pricestore /**< price storage */
220 )
221{
222 assert(pricestore != NULL);
223 assert(pricestore->ncolstotal == 0);
224
225 pricestore->infarkas = TRUE;
226}
227
228/** informs price storage, that Farkas pricing is now finished */
230 GCG_PRICESTORE* pricestore /**< price storage */
231 )
232{
233 assert(pricestore != NULL);
234 assert(pricestore->ncolstotal == 0);
235
236 pricestore->infarkas = FALSE;
237}
238
239/** informs price storage, that the following cols should be used in any case */
241 GCG_PRICESTORE* pricestore /**< price storage */
242 )
243{
244 assert(pricestore != NULL);
245 assert(!pricestore->forcecols);
246
247 pricestore->forcecols = TRUE;
248}
249
250/** informs price storage, that the following cols should no longer be used in any case */
252 GCG_PRICESTORE* pricestore /**< price storage */
253 )
254{
255 assert(pricestore != NULL);
256 assert(pricestore->forcecols);
257
258 pricestore->forcecols = FALSE;
259}
260
261/** removes a non-forced col from the price storage */
262static
264 GCG_PRICESTORE* pricestore, /**< price storage */
265 int arrayindex, /**< index of the arrays */
266 int pos, /**< position of col to delete */
267 SCIP_Bool freecol /**< should col be freed */
268 )
269{
270 assert(pricestore != NULL);
271 assert(pricestore->cols != NULL);
272 assert(pricestore->nforcedcols[arrayindex] <= pos && pos < pricestore->ncols[arrayindex]);
273
274 SCIPhashtableRemove(pricestore->hashtable, pricestore->cols[arrayindex][pos]);
275 pricestore->cols[arrayindex][pos]->pos = -1;
276
277 /* free the column */
278 if( freecol )
279 SCIP_CALL( GCGfreeGcgCol(&(pricestore->cols[arrayindex][pos])) );
280
281 pricestore->ncols[arrayindex]--;
282 if( pos != pricestore->ncols[arrayindex] )
283 {
284 /* move last col to the empty position */
285 pricestore->cols[arrayindex][pos] = pricestore->cols[arrayindex][pricestore->ncols[arrayindex]];
286 pricestore->objparallelisms[arrayindex][pos] = pricestore->objparallelisms[arrayindex][pricestore->ncols[arrayindex]];
287 pricestore->orthogonalities[arrayindex][pos] = pricestore->orthogonalities[arrayindex][pricestore->ncols[arrayindex]];
288 pricestore->scores[arrayindex][pos] = pricestore->scores[arrayindex][pricestore->ncols[arrayindex]];
289 pricestore->cols[arrayindex][pos]->pos = pos;
290 }
291 return SCIP_OKAY;
292}
293
294/** for a given column, check if an identical column already exists in the price storage;
295 * if one exists, return its position, otherwise, return -1
296 */
297static
299 GCG_PRICESTORE* pricestore, /**< price storage */
300 GCG_COL* col /**< column to be checked */
301 )
302{
303 GCG_COL* othercol = (GCG_COL*)SCIPhashtableRetrieve(pricestore->hashtable, (void*)col);
304
305 if( othercol != NULL )
306 return othercol->pos;
307 else
308 return -1;
309}
310
311/** adds col to price storage;
312 * if the col should be forced to enter the LP, an infinite score will be used
313 */
315 GCG_PRICESTORE* pricestore, /**< price storage */
316 GCG_COL* col, /**< priced col */
317 SCIP_Bool forcecol, /**< should the col be forced to enter the LP? */
318 SCIP_Bool fromcolpool, /**< is column from colpool */
319 SCIP_Bool* added
320 )
321{
322 SCIP_Real colobjparallelism;
323 SCIP_Real colscore;
324
325 int oldpos;
326 int pos;
327 int arrayindex;
328
329 assert(pricestore != NULL);
330 assert(col != NULL);
331 assert(col->pos == -1);
332 assert(added != NULL);
333
334 arrayindex = pricestoreGetArrayIndex(pricestore, col);
335 assert(pricestore->nforcedcols[arrayindex] <= pricestore->ncols[arrayindex]);
336
337 /* a col is forced to enter the LP if
338 * - we construct the initial LP, or
339 * - it has infinite score factor, or
340 * if it is a non-forced col and no cols should be added, abort
341 */
342 forcecol = forcecol || pricestore->forcecols;
343
344 SCIP_CALL( GCGcolComputeNorm(pricestore->gcg, col) );
345
346 if( forcecol )
347 {
348 colscore = SCIPinfinity(pricestore->masterprob);
349 colobjparallelism = 1.0;
350 }
351 else
352 {
353 /* initialize values to invalid (will be initialized during col filtering) */
354 colscore = SCIP_INVALID;
355
356 if( SCIPisPositive(pricestore->masterprob, pricestore->objparalfac) )
357 SCIP_CALL( GCGcolComputeDualObjPara(pricestore->gcg, col, &colobjparallelism) );
358 else
359 colobjparallelism = 0.0; /* no need to calculate it */
360 }
361
362 GCG_SET_LOCK(&pricestore->locks->pricestorelock);
363 oldpos = pricestoreFindEqualCol(pricestore, col);
364 GCG_UNSET_LOCK(&pricestore->locks->pricestorelock);
365
366 pos = -1;
367
368 /* If the column is no duplicate of an existing one, add it */
369 if( oldpos == -1 )
370 {
371#ifndef NDEBUG
372 int i;
373 SCIP_VAR* var;
374 SCIP_Real val;
375 SCIP_SOL* sol;
376 SCIP_Bool feasible;
378 {
380 SCIP_CALL( SCIPsetSolVals(col->pricingprob, sol, col->nvars, col->vars, col->vals) );
381 SCIP_CALL( SCIPcheckSolOrig(col->pricingprob, sol, &feasible, TRUE, TRUE) );
382 if( !feasible )
385 }
386 for( i = 0; i < col->nvars; ++i )
387 {
388 var = col->vars[i];
389 val = col->vals[i];
390
392 {
393 continue;
394 }
395
397
400 }
401#endif
402 /* get enough memory to store the col */
403 SCIP_CALL( pricestoreEnsureColsMem(pricestore, arrayindex, pricestore->ncols[arrayindex]+1) );
404 assert(pricestore->ncols[arrayindex] < pricestore->colssize[arrayindex]);
405
406 if( forcecol )
407 {
408 /* make room at the beginning of the array for forced col */
409 pos = pricestore->nforcedcols[arrayindex];
410 pricestore->cols[arrayindex][pricestore->ncols[arrayindex]] = pricestore->cols[arrayindex][pos];
411 pricestore->objparallelisms[arrayindex][pricestore->ncols[arrayindex]] = pricestore->objparallelisms[arrayindex][pos];
412 pricestore->orthogonalities[arrayindex][pricestore->ncols[arrayindex]] = pricestore->orthogonalities[arrayindex][pos];
413 pricestore->scores[arrayindex][pricestore->ncols[arrayindex]] = pricestore->scores[arrayindex][pos];
414 pricestore->cols[arrayindex][pricestore->ncols[arrayindex]]->pos = pricestore->ncols[arrayindex];
415 pricestore->nforcedcols[arrayindex]++;
416 }
417 else
418 pos = pricestore->ncols[arrayindex];
419
420 pricestore->ncols[arrayindex]++;
421 #pragma omp atomic update
422 pricestore->ncolstotal++;
423
424 /* update statistics of total number of found cols */
425 #pragma omp atomic update
426 pricestore->ncolsfound++;
427 #pragma omp atomic update
428 pricestore->ncolsfoundround++;
429 }
430 /* Otherwise, if the new column is forced and the duplicate one is not,
431 * remove the duplicate and replace it by the new column
432 */
433 else if( forcecol && oldpos >= pricestore->nforcedcols[arrayindex] )
434 {
435 assert(GCGcolIsEq(pricestore->cols[arrayindex][oldpos], col));
436 SCIP_CALL( GCGfreeGcgCol(&pricestore->cols[arrayindex][oldpos]) );
437 pricestore->cols[arrayindex][oldpos] = pricestore->cols[arrayindex][pricestore->nforcedcols[arrayindex]];
438 pricestore->objparallelisms[arrayindex][oldpos] = pricestore->objparallelisms[arrayindex][pricestore->nforcedcols[arrayindex]];
439 pricestore->orthogonalities[arrayindex][oldpos] = pricestore->orthogonalities[arrayindex][pricestore->nforcedcols[arrayindex]];
440 pricestore->scores[arrayindex][oldpos] = pricestore->scores[arrayindex][pricestore->nforcedcols[arrayindex]];
441
442 pos = pricestore->nforcedcols[arrayindex];
443 pricestore->nforcedcols[arrayindex]++;
444 }
445 /* The column already exists and is not forced, free it */
446 else
447 {
448 assert(GCGcolIsEq(pricestore->cols[arrayindex][oldpos], col));
449 /* @todo: This is a little dangerous */
450 assert(col->pos == -1);
451 SCIP_CALL( GCGfreeGcgCol(&col) );
452 }
453
454 if( pos > -1 )
455 {
456 SCIPdebugMessage("adding col %p to price storage of size %d (forcecol=%u)\n",
457 (void*)col, pricestore->ncolstotal, forcecol);
458
459 /* add col to arrays */
460 pricestore->cols[arrayindex][pos] = col;
461 pricestore->objparallelisms[arrayindex][pos] = colobjparallelism;
462 pricestore->orthogonalities[arrayindex][pos] = 1.0;
463 pricestore->scores[arrayindex][pos] = colscore;
464 assert(col->pos == -1);
465 col->pos = pos;
466
467 GCG_SET_LOCK(&pricestore->locks->pricestorelock);
468 GCG_SET_LOCK(&pricestore->locks->memorylock);
469 SCIPhashtableInsert(pricestore->hashtable, col);
470 GCG_UNSET_LOCK(&pricestore->locks->memorylock);
471 GCG_UNSET_LOCK(&pricestore->locks->pricestorelock);
472
473 *added = TRUE;
474 }
475 else
476 {
477 *added = FALSE;
478 }
479
480 return SCIP_OKAY;
481}
482
483/** updates the orthogonalities and scores of the non-forced cols after the given col was added to the LP */
484static
486 GCG_PRICESTORE* pricestore, /**< price storage */
487 GCG_COL* col, /**< col that was applied */
488 SCIP_Real mincolorthogonality /**< minimal orthogonality of cols to apply to LP */
489 )
490{
491 int pos;
492 int i;
493
494 assert(pricestore != NULL);
495
496 for( i = 0; i < pricestore->narrays; ++i)
497 {
498 pos = pricestore->nforcedcols[i];
499 while( pos < pricestore->ncols[i] )
500 {
501 SCIP_Real thisortho;
502
503 /* update orthogonality */
504 SCIP_CALL( GCGcolComputeOrth(pricestore->gcg, col, pricestore->cols[i][pos], &thisortho) );
505
506 if( thisortho < pricestore->orthogonalities[i][pos] )
507 {
508 if( thisortho < mincolorthogonality )
509 {
510 /* col is too parallel: delete the col */
511 SCIPdebugMessage(" -> deleting parallel col %p after adding %p (pos=%d, orthogonality=%g, score=%g)\n",
512 (void*) pricestore->cols[i][pos], (void*) col, pos, thisortho, pricestore->scores[i][pos]);
513 SCIP_CALL( pricestoreDelCol(pricestore, i, pos, TRUE) );
514 continue;
515 }
516 else
517 {
518 SCIP_Real colefficiacy;
519
520 /* calculate col's efficacy */
521 switch ( pricestore->efficiacychoice )
522 {
524 colefficiacy = -1.0 * GCGcolGetRedcost(pricestore->cols[i][pos]);
525 break;
527 colefficiacy = -1.0 * GCGcolGetRedcost(pricestore->cols[i][pos])/ GCGcolGetNorm(col);
528 break;
530 SCIPerrorMessage("Lambda pricing not yet implemented.\n");
531 return SCIP_INVALIDCALL;
532 default:
533 SCIPerrorMessage("Invalid efficiacy choice.\n");
534 return SCIP_INVALIDCALL;
535 }
536
537 /* recalculate score */
538 pricestore->orthogonalities[i][pos] = thisortho;
539 assert( pricestore->objparallelisms[i][pos] != SCIP_INVALID ); /*lint !e777*/
540 assert( pricestore->scores[i][pos] != SCIP_INVALID ); /*lint !e777*/
541
542
543 pricestore->scores[i][pos] = pricestore->efficiacyfac * colefficiacy
544 + pricestore->objparalfac * pricestore->objparallelisms[i][pos]
545 + pricestore->orthofac * thisortho;
546 }
547 }
548 pos++;
549 }
550 }
551 return SCIP_OKAY;
552}
553
554/** adds the given col to priced vars, updates the orthogonalities and scores of remaining cols, and frees non-forced cols */
555static
557 GCG_PRICESTORE* pricestore, /**< price storage */
558 GCG_COL* col, /**< col to apply to the LP */
559 SCIP_Bool force, /**< force column */
560 SCIP_Real mincolorthogonality,/**< minimal orthogonality of cols to apply to LP */
561 SCIP_Real score, /**< score of column (or -1.0 if not specified) */
562 SCIP_Bool* added /**< pointer to store whether the column was added */
563 )
564{
565 int arrayindex;
566 assert(pricestore != NULL);
567 assert(added != NULL);
568
569 arrayindex = pricestoreGetArrayIndex(pricestore, col);
570
571 SCIP_CALL( GCGcreateNewMasterVarFromGcgCol(pricestore->gcg, pricestore->infarkas, col, force, added, NULL, score) );
572 assert(*added);
573
574 if( !force )
575 {
576 assert(pricestore->cols[arrayindex][col->pos] == col);
577 SCIP_CALL( pricestoreDelCol(pricestore, arrayindex, col->pos, FALSE) );
578 }
579
580 /* update the orthogonalities if needed */
581 if( SCIPisGT(pricestore->masterprob, mincolorthogonality, SCIPepsilon(pricestore->masterprob)) || SCIPisPositive(pricestore->masterprob, pricestore->orthofac))
582 SCIP_CALL( pricestoreUpdateOrthogonalities(pricestore, col, mincolorthogonality) );
583
584 if( !force )
585 {
586 SCIP_CALL( GCGfreeGcgCol(&col) );
587 }
588
589 return SCIP_OKAY;
590}
591
592/** returns the position of the best non-forced col in the cols array */
593static
595 GCG_PRICESTORE* pricestore, /**< price storage */
596 int* ncolsapplied, /**< number of cols applied per array index */
597 int maxpricecolsprob /**< maximum number of cols allowed per array index */
598 )
599{
601 GCG_COL* bestcol;
602 int pos;
603 int i;
604
605 assert(pricestore != NULL);
606
608 bestcol = NULL;
609 for( i = 0; i < pricestore->narrays; ++i )
610 {
611 if( ncolsapplied[i] < maxpricecolsprob )
612 {
613 for( pos = pricestore->nforcedcols[i]; pos < pricestore->ncols[i]; pos++ )
614 {
615 /* check if col is current best col */
616 assert( pricestore->scores[i][pos] != SCIP_INVALID ); /*lint !e777*/
617 if( pricestore->scores[i][pos] > bestscore )
618 {
619 bestscore = pricestore->scores[i][pos];
620 bestcol = pricestore->cols[i][pos];
621 }
622 }
623 }
624 }
625
626 return bestcol;
627}
628
629/** computes score for dual solution and initialized orthogonalities */
630static
632 GCG_PRICESTORE* pricestore, /**< price storage */
633 int arrayindex, /**< index of the arrays */
634 int pos /**< position of col to handle */
635 )
636{
637 GCG_COL* col;
638 SCIP_Real colefficiacy;
639 SCIP_Real colscore;
640
641 col = pricestore->cols[arrayindex][pos];
642
643 /* calculate cut's efficacy */
644 switch ( pricestore->efficiacychoice )
645 {
647 colefficiacy = -1.0 * GCGcolGetRedcost(pricestore->cols[arrayindex][pos]);
648 break;
650 colefficiacy = -1.0 * GCGcolGetRedcost(pricestore->cols[arrayindex][pos])/ GCGcolGetNorm(col);
651 break;
653 SCIPerrorMessage("Lambda pricing not yet implemented.\n");
654 return SCIP_INVALIDCALL;
655 default:
656 SCIPerrorMessage("Invalid efficiacy choice.\n");
657 return SCIP_INVALIDCALL;
658 }
659
660 assert( pricestore->objparallelisms[arrayindex][pos] != SCIP_INVALID ); /*lint !e777*/
661 colscore = pricestore->efficiacyfac * colefficiacy
662 + pricestore->objparalfac * pricestore->objparallelisms[arrayindex][pos]
663 + pricestore->orthofac * 1.0;
664 assert( !SCIPisInfinity(pricestore->masterprob, colscore) );
665
666 pricestore->scores[arrayindex][pos] = colscore;
667
668 /* make sure that the orthogonalities are initialized to 1.0 */
669 pricestore->orthogonalities[arrayindex][pos] = 1.0;
670
671 return SCIP_OKAY;
672}
673
674/** adds cols to priced vars and clears price storage */
676 GCG_PRICESTORE* pricestore, /**< price storage */
677 GCG_COLPOOL* colpool, /**< GCG column pool */
678 SCIP_Bool usecolpool, /**< use column pool? */
679 int* nfoundvars /**< pointer to store number of variables that were added to the problem */
680 )
681{
683 SCIP_Bool added;
684 int* ncolsappliedprob;
685 SCIP_Real mincolorthogonality;
686 int maxpricecols;
687 int maxpricecolsprob;
688 int ncolsapplied;
689 int pos;
690 int i;
691
692 assert(pricestore != NULL);
693
694 masterprob = pricestore->masterprob;
695
696 SCIPdebugMessage("applying %d cols\n", pricestore->ncolstotal);
697
698 /* get maximal number of cols to add to the LP */
699 maxpricecols = GCGpricerGetMaxColsRound(pricestore->gcg);
700 maxpricecolsprob = GCGpricerGetMaxColsProb(pricestore->gcg);
701
702 ncolsapplied = 0;
703 SCIP_CALL( SCIPallocClearBufferArray(masterprob, &ncolsappliedprob, GCGgetNPricingprobs(pricestore->gcg)) );
704
705 /* set minimal col orthogonality */
706 mincolorthogonality = pricestore->mincolorth;
707 mincolorthogonality = MAX(mincolorthogonality, SCIPepsilon(masterprob)); /*lint !e666 */
708
709 /* Compute scores for all non-forced cols and initialize orthogonalities - make sure all cols are initialized again for the current dual solution */
710 for( i = 0; i < pricestore->narrays; ++i )
711 {
712 for( pos = pricestore->nforcedcols[i]; pos < pricestore->ncols[i]; pos++ )
713 {
714 SCIP_CALL( computeScore(pricestore, i, pos) );
715 }
716 }
717
718 /* apply all forced cols */
719 for( i = 0; i < pricestore->narrays; ++i )
720 {
721 for( pos = 0; pos < pricestore->nforcedcols[i]; pos++ )
722 {
723 GCG_COL* col;
724 int probnr;
725
726 col = pricestore->cols[i][pos];
727 assert(SCIPisInfinity(masterprob, pricestore->scores[i][pos]));
728
729 probnr = GCGcolGetProbNr(col);
730
731 /* add col to the priced vars and update orthogonalities */
732 SCIPdebugMessage(" -> applying forced col %p (probnr = %d)\n", (void*) col, probnr);
733
734 SCIP_CALL( pricestoreApplyCol(pricestore, col, TRUE, mincolorthogonality, pricestore->scores[i][pos], &added) );
735
736 if( added )
737 {
738 ++ncolsapplied;
739 ++ncolsappliedprob[probnr];
740 }
741 }
742 }
743
744 /* apply non-forced cols */
745 while( TRUE )
746 {
747 GCG_COL* col;
748 int bestpos;
749 SCIP_Real score;
750 int probnr;
751
752 /* get best non-forced col */
753 col = NULL;
754 if( ncolsapplied < maxpricecols )
755 {
756 col = pricestoreGetBestCol(pricestore, ncolsappliedprob, maxpricecolsprob);
757 }
758 else
759 {
760 for( i = 0; i < pricestore->narrays; ++i )
761 {
762 if( pricestore->nforcedcols[i] < pricestore->ncols[i] )
763 {
764 col = pricestore->cols[i][pricestore->nforcedcols[i]];
765 assert(col != NULL);
766 }
767 }
768 }
769 if( col == NULL )
770 break;
771 i = pricestoreGetArrayIndex(pricestore, col);
772 bestpos = col->pos;
773 assert(pricestore->nforcedcols[i] <= bestpos && bestpos < pricestore->ncols[i]);
774 assert(pricestore->scores[i][bestpos] != SCIP_INVALID ); /*lint !e777*/
775 score = pricestore->scores[i][bestpos];
776 assert(!SCIPisInfinity(masterprob, pricestore->scores[i][bestpos]));
777 probnr = GCGcolGetProbNr(col);
778
779 /* Do not add (non-forced) non-violated cols.
780 * Note: do not take SCIPsetIsEfficacious(), because constraint handlers often add cols w.r.t. SCIPsetIsFeasPositive().
781 * Note2: if pricerating/feastolfac != -1, constraint handlers may even add cols w.r.t. SCIPsetIsPositive(); those are currently rejected here
782 */
783 if( SCIPisDualfeasNegative(masterprob, GCGcolGetRedcost(col)) && ncolsapplied < maxpricecols )
784 {
785 assert(ncolsappliedprob[probnr] < maxpricecolsprob);
786 /* add col to the LP and update orthogonalities */
787 SCIP_CALL( pricestoreApplyCol(pricestore, col, FALSE, mincolorthogonality, score, &added) );
788 if( added )
789 {
790 SCIPdebugMessage(" -> applied col %p (pos=%d/%d, probnr=%d, efficacy=%g, objparallelism=%g, orthogonality=%g, score=%g)\n",
791 (void*) col, bestpos+1, pricestore->ncols[i], probnr, GCGcolGetRedcost(col), pricestore->objparallelisms[i][bestpos],
792 pricestore->orthogonalities[i][bestpos], pricestore->scores[i][bestpos]);
793
794 ++ncolsapplied;
795 ++ncolsappliedprob[probnr];
796 }
797 }
798 else if( usecolpool )
799 {
800 SCIP_CALL( pricestoreDelCol(pricestore, i, bestpos, FALSE) );
801 SCIP_CALL( GCGcolpoolAddCol(colpool, col, TRUE) );
802 }
803 else
804 {
805 SCIP_CALL( pricestoreDelCol(pricestore, i, bestpos, TRUE) );
806 }
807 }
808
809 *nfoundvars = ncolsapplied;
810
811 /* clear the price storage and reset statistics for price round */
812 SCIP_CALL( GCGpricestoreClearCols(pricestore) );
813
814 SCIPfreeBufferArray(masterprob, &ncolsappliedprob);
815
816 return SCIP_OKAY;
817}
818
819/** clears the price storage without adding the cols to the LP */
821 GCG_PRICESTORE* pricestore /**< price storage */
822 )
823{
824 int c;
825 int i;
826
827 assert(pricestore != NULL);
828
829 SCIPdebugMessage("clearing %d cols\n", pricestore->ncolstotal);
830
831 /* release cols */
832 for( i = 0; i < pricestore->narrays; ++i )
833 {
834 for( c = 0; c < pricestore->ncols[i]; ++c )
835 {
836 SCIP_CALL( GCGfreeGcgCol(&(pricestore->cols[i][c])) );
837 }
838 /* reset counters */
839 pricestore->ncols[i] = 0;
840 pricestore->nforcedcols[i] = 0;
841 }
842
844
845 /* reset counters */
846 pricestore->ncolstotal = 0;
847 pricestore->ncolsfoundround = 0;
848
849 /* if we have just finished the initial LP construction, free the (potentially large) cols array */
850 if( pricestore->infarkas )
851 {
852 for( i = 0; i < pricestore->narrays; ++i )
853 {
854 SCIPfreeBlockMemoryArrayNull(pricestore->masterprob, &pricestore->cols[i], pricestore->colssize[i]);
855 SCIPfreeBlockMemoryArrayNull(pricestore->masterprob, &pricestore->objparallelisms[i], pricestore->colssize[i]);
856 SCIPfreeBlockMemoryArrayNull(pricestore->masterprob, &pricestore->orthogonalities[i], pricestore->colssize[i]);
857 SCIPfreeBlockMemoryArrayNull(pricestore->masterprob, &pricestore->scores[i], pricestore->colssize[i]);
858
859 pricestore->colssize[i] = 0;
860 }
861 }
862 return SCIP_OKAY;
863}
864
865/** get cols in the price storage */
867 GCG_PRICESTORE* pricestore, /**< price storage */
868 int arrayindex /**< index of the arrays */
869 )
870{
871 assert(pricestore != NULL);
872
873 return pricestore->cols[arrayindex];
874}
875
876/** get number of cols in the price storage */
878 GCG_PRICESTORE* pricestore, /**< price storage */
879 int arrayindex /**< index of the arrays */
880 )
881{
882 assert(pricestore != NULL);
883
884 return pricestore->ncols[arrayindex];
885}
886
887/** get number of cols in the price storage */
889 GCG_PRICESTORE* pricestore /**< price storage */
890 )
891{
892 assert(pricestore != NULL);
893
894 return pricestore->ncolstotal;
895}
896
897/** get total number of cols found so far */
899 GCG_PRICESTORE* pricestore /**< price storage */
900 )
901{
902 assert(pricestore != NULL);
903
904 return pricestore->ncolsfound;
905}
906
907/** get number of cols found so far in current price round */
909 GCG_PRICESTORE* pricestore /**< price storage */
910 )
911{
912 assert(pricestore != NULL);
913
914 return pricestore->ncolsfoundround;
915}
916
917/** get total number of cols applied to the LPs */
919 GCG_PRICESTORE* pricestore /**< price storage */
920 )
921{
922 assert(pricestore != NULL);
923
924 return pricestore->ncolsapplied;
925}
#define SCIP_INVALID
#define SCIP_Bool
#define SCIP_Real
#define MAX(x, y)
#define SCIP_REAL_MIN
#define TRUE
#define FALSE
int GCGgetNActiveMastersepacuts(GCG *gcg)
GCG interface methods.
SCIP_VAR ** GCGpricingVarGetOrigvars(SCIP_VAR *var)
Definition gcgvar.c:1100
GCG_EXPORT SCIP_Bool GCGvarIsInferredPricing(SCIP_VAR *var)
Definition gcgvar.c:195
SCIP_RETCODE GCGcreateNewMasterVarFromGcgCol(GCG *gcg, SCIP_Bool infarkas, GCG_COL *gcgcol, SCIP_Bool force, SCIP_Bool *added, SCIP_VAR **addedvar, SCIP_Real score)
int GCGpricerGetMaxColsRound(GCG *gcg)
int GCGpricerGetMaxColsProb(GCG *gcg)
SCIP_RETCODE GCGcolpoolAddCol(GCG_COLPOOL *colpool, GCG_COL *col, SCIP_Bool freeduplicate)
Definition colpool.c:215
SCIP_RETCODE GCGcolComputeNorm(GCG *gcg, GCG_COL *gcgcol)
Definition gcgcol.c:562
SCIP_Real GCGcolGetNorm(GCG_COL *gcgcol)
Definition gcgcol.c:691
SCIP_RETCODE GCGfreeGcgCol(GCG_COL **gcgcol)
Definition gcgcol.c:231
SCIP_Real GCGcolGetRedcost(GCG_COL *gcgcol)
Definition gcgcol.c:475
SCIP_RETCODE GCGcolComputeDualObjPara(GCG *gcg, GCG_COL *gcgcol, SCIP_Real *para)
Definition gcgcol.c:825
SCIP_Bool GCGcolIsEq(GCG_COL *gcgcol1, GCG_COL *gcgcol2)
Definition gcgcol.c:371
int GCGcolGetProbNr(GCG_COL *gcgcol)
Definition gcgcol.c:427
SCIP_RETCODE GCGcolComputeOrth(GCG *gcg, GCG_COL *gcgcol1, GCG_COL *gcgcol2, SCIP_Real *orth)
Definition gcgcol.c:984
GCG_EXPORT int GCGgetNPricingprobs(GCG *gcg)
Definition relax_gcg.c:4113
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
SCIP_STAGE SCIPgetStage(SCIP *scip)
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
void * SCIPhashtableRetrieve(SCIP_HASHTABLE *hashtable, void *key)
void SCIPhashtableRemoveAll(SCIP_HASHTABLE *hashtable)
SCIP_RETCODE SCIPhashtableRemove(SCIP_HASHTABLE *hashtable, void *element)
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
#define SCIPallocClearBufferArray(scip, ptr, num)
int SCIPcalcMemGrowSize(SCIP *scip, int num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_RETCODE SCIPcheckSolOrig(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *feasible, SCIP_Bool printreason, SCIP_Bool completely)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
SCIP_RETCODE SCIPprintSol(SCIP *scip, SCIP_SOL *sol, FILE *file, SCIP_Bool printzeros)
SCIP_RETCODE SCIPcreateOrigSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisDualfeasNegative(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPepsilon(SCIP *scip)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
SCIP_Bool GCGvarIsPricing(SCIP_VAR *var)
Definition gcgvar.c:159
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP_VAR * var
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
SCIP_RETCODE retcode
int i
SCIPfreeBufferArray(scip, &cycles)
SCIP_Real bestscore
SCIP_SOL * sol
#define NULL
GCG variable pricer.
void GCGpricestoreEndFarkas(GCG_PRICESTORE *pricestore)
static GCG_COL * pricestoreGetBestCol(GCG_PRICESTORE *pricestore, int *ncolsapplied, int maxpricecolsprob)
SCIP_RETCODE GCGpricestoreApplyCols(GCG_PRICESTORE *pricestore, GCG_COLPOOL *colpool, SCIP_Bool usecolpool, int *nfoundvars)
static SCIP_RETCODE pricestoreUpdateOrthogonalities(GCG_PRICESTORE *pricestore, GCG_COL *col, SCIP_Real mincolorthogonality)
static SCIP_RETCODE pricestoreEnsureColsMem(GCG_PRICESTORE *pricestore, int arrayindex, int num)
SCIP_RETCODE GCGpricestoreFree(GCG_PRICESTORE **pricestore)
int GCGpricestoreGetNColsApplied(GCG_PRICESTORE *pricestore)
static SCIP_RETCODE computeScore(GCG_PRICESTORE *pricestore, int arrayindex, int pos)
int GCGpricestoreGetNColsTotal(GCG_PRICESTORE *pricestore)
int GCGpricestoreGetNCols(GCG_PRICESTORE *pricestore, int arrayindex)
void GCGpricestoreEndForceCols(GCG_PRICESTORE *pricestore)
int GCGpricestoreGetNColsFound(GCG_PRICESTORE *pricestore)
void GCGpricestoreStartFarkas(GCG_PRICESTORE *pricestore)
int GCGpricestoreGetNColsFoundRound(GCG_PRICESTORE *pricestore)
SCIP_RETCODE GCGpricestoreAddCol(GCG_PRICESTORE *pricestore, GCG_COL *col, SCIP_Bool forcecol, SCIP_Bool fromcolpool, SCIP_Bool *added)
GCG_COL ** GCGpricestoreGetCols(GCG_PRICESTORE *pricestore, int arrayindex)
static SCIP_RETCODE pricestoreDelCol(GCG_PRICESTORE *pricestore, int arrayindex, int pos, SCIP_Bool freecol)
static int pricestoreFindEqualCol(GCG_PRICESTORE *pricestore, GCG_COL *col)
static SCIP_RETCODE pricestoreApplyCol(GCG_PRICESTORE *pricestore, GCG_COL *col, SCIP_Bool force, SCIP_Real mincolorthogonality, SCIP_Real score, SCIP_Bool *added)
void GCGpricestoreStartForceCols(GCG_PRICESTORE *pricestore)
static int pricestoreGetArrayIndex(GCG_PRICESTORE *pricestore, GCG_COL *col)
SCIP_RETCODE GCGpricestoreClearCols(GCG_PRICESTORE *pricestore)
SCIP_RETCODE GCGpricestoreCreate(GCG *gcg, GCG_PRICESTORE **pricestore, SCIP_Real efficiacyfac, SCIP_Real objparalfac, SCIP_Real orthofac, SCIP_Real mincolorth, GCG_EFFICIACYCHOICE efficiacychoice, int hashtablesize)
methods for storing priced cols (based on SCIP's separation storage)
public methods for working with gcg columns
public methods for GCG variables
#define SCIPerrorMessage
SCIP * pricingprob
SCIP_Real * vals
SCIP_VAR ** vars
GCG_EFFICIACYCHOICE efficiacychoice
SCIP_Real ** objparallelisms
SCIP_HASHTABLE * hashtable
SCIP_Real ** orthogonalities
data structure to store columns (solutions from a pricing problem)
data structures for storing OpenMP locks
datastructures for storing priced cols
data structures for separators for master
struct GCG_Colpool GCG_COLPOOL
struct Gcg GCG
Definition type_gcg.h:44
struct GCG_Col GCG_COL
Definition type_gcgcol.h:44
#define GCG_SET_LOCK(lockname)
Definition type_locks.h:68
#define GCG_UNSET_LOCK(lockname)
Definition type_locks.h:70
@ GCG_EFFICIACYCHOICE_LAMBDA
@ GCG_EFFICIACYCHOICE_DANTZIG
@ GCG_EFFICIACYCHOICE_STEEPESTEDGE
enum GCG_Efficiacychoice GCG_EFFICIACYCHOICE
struct GCG_PriceStore GCG_PRICESTORE
SCIP_INVALIDCALL
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_PRESOLVING
struct SCIP_Sol SCIP_SOL
struct SCIP_Var SCIP_VAR