Scippy

GCG

Branch-and-Price & Column Generation for Everyone

pricingprob.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 pricingprob.c
30 * @brief methods for working with pricing problems
31 * @author Christian Puchert
32 *
33 * Various methods to work with pricing problems
34 *
35 */
36
37/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
38
39#include "gcg/pricingprob.h"
40#include "gcg/pub_pricingprob.h"
41
42#include "gcg/gcg.h"
43#include "gcg/pricestore_gcg.h"
44#include "gcg/pub_colpool.h"
45#include "gcg/pub_gcgcol.h"
46#include "gcg/pub_pricingjob.h"
47
48#include "scip/scip.h"
49
50
51/** create a pricing problem */
53 GCG* gcg, /**< GCG data structure (master problem) */
54 GCG_PRICINGPROB** pricingprob, /**< pricing problem to be created */
55 SCIP* pricingscip, /**< SCIP data structure of the corresponding pricing problem */
56 int probnr, /**< index of the corresponding pricing problem */
57 int nroundscol /**< number of previous pricing rounds for which the number of improving columns should be counted */
58)
59{
61 SCIP_CALL( SCIPallocBlockMemory(scip, pricingprob) );
62
63 (*pricingprob)->pricingscip = pricingscip;
64 (*pricingprob)->probnr = probnr;
65 (*pricingprob)->branchconss = NULL;
66 (*pricingprob)->branchduals = NULL;
67 (*pricingprob)->nbranchconss = 0;
68 (*pricingprob)->branchconsssize = 0;
69 (*pricingprob)->branchconsidx = 0;
70 (*pricingprob)->consisadded = TRUE;
71 (*pricingprob)->status = GCG_PRICINGSTATUS_UNKNOWN;
72 (*pricingprob)->lowerbound = -SCIPinfinity(scip);
73 (*pricingprob)->nimpcols = 0;
74 (*pricingprob)->nsolves = 0;
75 (*pricingprob)->maxcolsround = SCIPcalcMemGrowSize(scip, nroundscol);
76
77 SCIP_CALL( SCIPallocClearBlockMemoryArray(scip, &(*pricingprob)->ncolsround, (*pricingprob)->maxcolsround) );
78
79
80 return SCIP_OKAY;
81}
82
83/** free a pricing problem */
85 GCG* gcg, /**< GCG data structure (master problem) */
86 GCG_PRICINGPROB** pricingprob /**< pricing problem to be freed */
87)
88{
90 SCIPfreeBlockMemoryArrayNull(scip, &(*pricingprob)->branchduals, (*pricingprob)->branchconsssize);
91 SCIPfreeBlockMemoryArrayNull(scip, &(*pricingprob)->branchconss, (*pricingprob)->branchconsssize);
92 SCIPfreeBlockMemoryArray(scip, &(*pricingprob)->ncolsround, (*pricingprob)->maxcolsround);
93 SCIPfreeBlockMemory(scip, pricingprob);
94 *pricingprob = NULL;
95}
96
97/** initialize pricing problem at the beginning of the pricing round */
99 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
100 )
101{
102 assert(pricingprob->nimpcols == 0);
103
104 pricingprob->nbranchconss = 0;
105 pricingprob->branchconsidx = 0;
106 pricingprob->consisadded = TRUE;
107}
108
109/** uninitialize pricing problem at the beginning of the pricing round */
111 GCG_PRICINGPROB* pricingprob, /**< pricing problem structure */
112 int nroundscol /**< number of previous pricing rounds for which the number of improving columns should be counted */
113 )
114{
115 int i;
116
117 for( i = nroundscol-1; i > 0; --i )
118 pricingprob->ncolsround[i] = pricingprob->ncolsround[i-1];
119 pricingprob->ncolsround[0] = pricingprob->nimpcols;
120
121 pricingprob->nimpcols = 0;
122}
123
124/** add generic branching data (constraint and dual value) to the current pricing problem */
126 GCG* gcg, /**< GCG data structure (master problem) */
127 GCG_PRICINGPROB* pricingprob, /**< pricing problem structure */
128 SCIP_CONS* branchcons, /**< generic branching constraint */
129 SCIP_Real branchdual /**< corresponding dual solution value */
130 )
131{
133 /* allocate memory, if necessary */
134 if( pricingprob->branchconsssize == pricingprob->nbranchconss )
135 {
136 int newsize = SCIPcalcMemGrowSize(scip, pricingprob->branchconsssize+1);
137
138 assert((pricingprob->branchconsssize == 0) == (pricingprob->branchconss == NULL));
139 assert((pricingprob->branchconsssize == 0) == (pricingprob->branchduals == NULL));
140
141 if( pricingprob->branchconss == NULL )
142 {
143 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &pricingprob->branchconss, newsize) );
144 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &pricingprob->branchduals, newsize) );
145 }
146 else
147 {
148 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &pricingprob->branchconss, pricingprob->branchconsssize, newsize) );
149 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &pricingprob->branchduals, pricingprob->branchconsssize, newsize) );
150 }
151 pricingprob->branchconsssize = newsize;
152 }
153
154 /* add constraint and dual solution value */
155 pricingprob->branchconss[pricingprob->nbranchconss] = branchcons;
156 pricingprob->branchduals[pricingprob->nbranchconss] = branchdual;
157 ++pricingprob->nbranchconss;
158 ++pricingprob->branchconsidx;
159
160 return SCIP_OKAY;
161}
162
163/** reset the pricing problem statistics for the current pricing round */
165 GCG* gcg, /**< GCG data structure (master problem) */
166 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
167 )
168{
169 assert(pricingprob->nimpcols == 0);
170
171 pricingprob->branchconsidx = pricingprob->nbranchconss;
172 pricingprob->status = GCG_PRICINGSTATUS_UNKNOWN;
174 pricingprob->nsolves = 0;
175}
176
177/** update solution information of a pricing problem */
179 GCG* gcg, /**< GCG data structure (master problem) */
180 GCG_PRICINGPROB* pricingprob, /**< pricing problem structure */
181 GCG_PRICINGSTATUS status, /**< status of last pricing job */
182 SCIP_Real lowerbound, /**< new lower bound */
183 int nimpcols /**< number of new improving columns */
184 )
185{
186 /* if the solver was not applicable to the problem, there is nothing to be done */
187 if( status == GCG_PRICINGSTATUS_NOTAPPLICABLE )
188 return;
189
190 /* update status, lower bound and number of improving columns */
191 pricingprob->status = status;
192 if( SCIPisDualfeasGT(GCGgetMasterprob(gcg), lowerbound, pricingprob->lowerbound) )
193 pricingprob->lowerbound = lowerbound;
194 pricingprob->nimpcols += nimpcols;
195
196 ++pricingprob->nsolves;
197}
198
199/** get the SCIP instance corresponding to the pricing problem */
201 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
202 )
203{
204 return pricingprob->pricingscip;
205}
206
207/** get the index of the corresponding pricing problem */
209 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
210 )
211{
212 return pricingprob->probnr;
213}
214
215/** get generic branching data corresponding to the pricing problem */
217 GCG_PRICINGPROB* pricingprob, /**< pricing problem structure */
218 SCIP_CONS*** branchconss, /**< pointer to store branching constraints array, or NULL */
219 SCIP_Real** branchduals, /**< pointer to store array of corresponding dual values, or NULL */
220 int* nbranchconss /**< pointer to store number of generic branching constraints, or NULL */
221 )
222{
223 if( branchconss != NULL )
224 *branchconss = pricingprob->branchconss;
225 if( branchduals != NULL )
226 *branchduals = pricingprob->branchduals;
227 if( nbranchconss != NULL )
228 *nbranchconss = pricingprob->nbranchconss;
229}
230
231/** get the number of generic branching constraints corresponding to the pricing problem */
233 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
234 )
235{
236 return pricingprob->nbranchconss;
237}
238
239/** get index of current generic branching constraint considered the pricing problem */
241 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
242 )
243{
244 return pricingprob->branchconsidx;
245}
246
247/** check if the current generic branching constraint has already been added */
249 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
250 )
251{
252 return pricingprob->consisadded;
253}
254
255/** mark the current generic branching constraint to be added */
257 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
258 )
259{
260 pricingprob->consisadded = TRUE;
261}
262
263/** add the information that the next branching constraint must be added */
265 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
266 )
267{
268 assert(pricingprob->branchconsidx >= 1);
269 --pricingprob->branchconsidx;
270 pricingprob->consisadded = FALSE;
271 pricingprob->status = GCG_PRICINGSTATUS_UNKNOWN;
272}
273
274/** get the status of a pricing problem */
276 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
277 )
278{
279 return pricingprob->status;
280}
281
282/** get the lower bound of a pricing problem */
284 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
285 )
286{
287 return pricingprob->lowerbound;
288}
289
290/** get the number of improving columns found for this pricing problem */
292 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
293 )
294{
295 return pricingprob->nimpcols;
296}
297
298/** get the number of times the pricing problem was solved during the loop */
300 GCG_PRICINGPROB* pricingprob /**< pricing problem structure */
301 )
302{
303 return pricingprob->nsolves;
304}
305
306/** get the total number of improving columns found in the last pricing rounds */
308 GCG_PRICINGPROB* pricingprob, /**< pricing problem structure */
309 int nroundscol /**< number of previous pricing rounds for which the number of improving columns should be counted */
310 )
311{
312 int ncols;
313 int i;
314
315 ncols = 0;
316 for( i = 0; i < nroundscol; ++i )
317 ncols += pricingprob->ncolsround[i];
318
319 return ncols;
320}
#define SCIP_Bool
#define SCIP_Real
#define SCIP_CALL(x)
#define TRUE
#define FALSE
GCG interface methods.
SCIP * GCGgetMasterprob(GCG *gcg)
Definition: gcg.cpp:99
SCIP * GCGpricingprobGetPricingscip(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:200
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
#define SCIPallocClearBlockMemoryArray(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_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisDualfeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define NULL
methods for storing priced cols (based on SCIP's separation storage)
void GCGpricingprobUpdate(GCG *gcg, GCG_PRICINGPROB *pricingprob, GCG_PRICINGSTATUS status, SCIP_Real lowerbound, int nimpcols)
Definition: pricingprob.c:178
void GCGpricingprobNextBranchcons(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:264
void GCGpricingprobMarkBranchconsAdded(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:256
int GCGpricingprobGetBranchconsIdx(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:240
void GCGpricingprobInitPricing(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:98
SCIP_Real GCGpricingprobGetLowerbound(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:283
void GCGpricingprobGetGenericBranchData(GCG_PRICINGPROB *pricingprob, SCIP_CONS ***branchconss, SCIP_Real **branchduals, int *nbranchconss)
Definition: pricingprob.c:216
int GCGpricingprobGetNImpCols(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:291
void GCGpricingprobReset(GCG *gcg, GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:164
SCIP_Bool GCGpricingprobBranchconsIsAdded(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:248
void GCGpricingprobFree(GCG *gcg, GCG_PRICINGPROB **pricingprob)
Definition: pricingprob.c:84
SCIP_RETCODE GCGpricingprobAddGenericBranchData(GCG *gcg, GCG_PRICINGPROB *pricingprob, SCIP_CONS *branchcons, SCIP_Real branchdual)
Definition: pricingprob.c:125
GCG_PRICINGSTATUS GCGpricingprobGetStatus(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:275
int GCGpricingprobGetProbnr(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:208
int GCGpricingprobGetNGenericBranchconss(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:232
int GCGpricingprobGetNSolves(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:299
SCIP_RETCODE GCGpricingprobCreate(GCG *gcg, GCG_PRICINGPROB **pricingprob, SCIP *pricingscip, int probnr, int nroundscol)
Definition: pricingprob.c:52
int GCGpricingprobGetNColsLastRounds(GCG_PRICINGPROB *pricingprob, int nroundscol)
Definition: pricingprob.c:307
void GCGpricingprobExitPricing(GCG_PRICINGPROB *pricingprob, int nroundscol)
Definition: pricingprob.c:110
private methods for working with pricing problems, to be used by the pricing controller only
public methods for storing cols in a col pool
public methods for working with gcg columns
public methods for working with pricing jobs
public methods for working with pricing problems
GCG_PRICINGSTATUS status
SCIP_Real * branchduals
SCIP_CONS ** branchconss
Definition: struct_gcg.h:55
enum GCG_PricingStatus GCG_PRICINGSTATUS
@ GCG_PRICINGSTATUS_NOTAPPLICABLE
@ GCG_PRICINGSTATUS_UNKNOWN
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE