GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
pricingjob.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 pricingjob.c
30 * @brief methods for working with pricing jobs
31 * @author Christian Puchert
32 *
33 * Various methods to work with pricing jobs
34 *
35 */
36
37/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
38
39#include "gcg/pricingjob.h"
40#include "gcg/pub_gcgcol.h"
41#include "gcg/pub_pricingjob.h"
42
43#include "gcg/gcg.h"
44#include "gcg/pricer_gcg.h"
45#include "gcg/pub_pricingprob.h"
46#include "gcg/pub_solver.h"
47
48#include "scip/scip.h"
49
50
51/** create a pricing job */
53 GCG* gcg, /**< GCG data structure */
54 GCG_PRICINGJOB** pricingjob, /**< pricing job to be created */
55 GCG_PRICINGPROB* pricingprob, /**< data structure of the corresponding pricing problem */
56 GCG_SOLVER* solver, /**< pricing solver responsible for the pricing job */
57 int chunk /**< chunk that the pricing problem should belong to */
58)
59{
62
63 (*pricingjob)->pricingprob = pricingprob;
64 (*pricingjob)->solver = solver;
65 (*pricingjob)->chunk = chunk;
66 (*pricingjob)->score = 0.0;
67 (*pricingjob)->heuristic = FALSE;
68 (*pricingjob)->nheuriters = 0;
69 (*pricingjob)->solverchanged = TRUE;
70
71 return SCIP_OKAY;
72}
73
74/** free a pricing job */
76 GCG* gcg, /**< GCG data structure */
77 GCG_PRICINGJOB** pricingjob /**< pricing job to be freed */
78)
79{
82 *pricingjob = NULL;
83}
84
85/** setup a pricing job at the beginning of the pricing loop
86 *
87 * The solver in the pricing job is reset during this call. This is to ensure that a valid solver is available for the
88 * pricing job. In some cases, such as when columns could not be found from a particular solver, the solver could be
89 * set to NULL. As such, the highest priority solver is assigned to the pricing job in this function.
90 */
92 GCG* gcg, /**< GCG data structure */
93 GCG_PRICINGJOB* pricingjob, /**< pricing job */
94 SCIP_Bool heuristic, /**< is heuristic pricing still possible at the current solving stage */
95 int scoring, /**< scoring parameter */
96 int nroundscol, /**< number of previous pricing rounds for which the number of improving columns should be counted */
97 SCIP_Real dualsolconv, /**< dual solution value of corresponding convexity constraint */
98 int npointsprob, /**< total number of extreme points generated so far by the pricing problem */
99 int nraysprob /**< total number of extreme rays generated so far by the pricing problem */
100 )
101{
102 GCG_PRICINGPROB* pricingprob = GCGpricingjobGetPricingprob(pricingjob);
103 assert(pricingprob != NULL);
104
105 /* set the score; the larger, the better */
106 switch( scoring )
107 {
108 case 'i':
109 pricingjob->score = - (SCIP_Real) GCGpricingprobGetProbnr(pricingprob);
110 break;
111 case 'd':
112 pricingjob->score = dualsolconv;
113 break;
114 case 'r':
115 pricingjob->score = -(0.2 * npointsprob + nraysprob);
116 break;
117 case 'l':
118 pricingjob->score = (SCIP_Real) GCGpricingprobGetNColsLastRounds(pricingprob, nroundscol);
119 break;
120 default:
121 pricingjob->score = 0.0;
122 break;
123 }
124
125 GCGpricingjobResetSolver(gcg, pricingjob);
126 if( heuristic && pricingjob->solver != NULL && GCGsolverIsHeurEnabled(pricingjob->solver) )
127 GCGpricingjobResetHeuristic(pricingjob);
128 else
129 GCGpricingjobSetExact(pricingjob);
130
131 return SCIP_OKAY;
132}
133
134/** get the pricing problem structure associated with a pricing job */
136 GCG_PRICINGJOB* pricingjob /**< pricing job */
137 )
138{
139 return pricingjob->pricingprob;
140}
141/** get the pricing solver with which the pricing job is to be performed */
143 GCG_PRICINGJOB* pricingjob /**< pricing job */
144 )
145{
146 return pricingjob->solver;
147}
148
149/** reset the pricing solver to be used to the one with the highest priority */
151 GCG* gcg, /**< GCG data structure */
152 GCG_PRICINGJOB* pricingjob /**< pricing job */
153 )
154{
155 GCG_SOLVER** solvers;
156 int nsolvers;
157 int i;
158
159 solvers = GCGpricerGetSolvers(gcg);
160 nsolvers = GCGpricerGetNSolvers(gcg);
161
162 /* get first available solver;
163 * assumption: solvers are sorted by priority
164 */
165 pricingjob->solver = NULL;
166 for( i = 0; i < nsolvers; ++i )
167 {
168 if( GCGsolverIsHeurEnabled(solvers[i]) || GCGsolverIsExactEnabled(solvers[i]) )
169 {
170 pricingjob->solver = solvers[i];
171 break;
172 }
173 }
174 pricingjob->solverchanged = TRUE;
175
176 assert(pricingjob->solver != NULL);
177}
178
179/** get the next pricing solver to be used, or NULL of there is none */
181 GCG* gcg, /**< GCG data structure */
182 GCG_PRICINGJOB* pricingjob /**< pricing job */
183 )
184{
185 GCG_SOLVER** solvers;
186 int nsolvers;
187
188 int pos;
189 int i;
190
191 solvers = GCGpricerGetSolvers(gcg);
192 nsolvers = GCGpricerGetNSolvers(gcg);
193
194 /* get position of current solver */
195 for( pos = 0; pos < nsolvers; ++pos )
196 if( solvers[pos] == pricingjob->solver )
197 break;
198 assert(pos < nsolvers);
199
200 /* get next available solver;
201 * assumption: solvers are sorted by priority
202 */
203 pricingjob->solver = NULL;
204 for( i = pos + 1; i < nsolvers; ++i )
205 {
206 if( GCGsolverIsHeurEnabled(solvers[i]) || GCGsolverIsExactEnabled(solvers[i]) )
207 {
208 pricingjob->solver = solvers[i];
209 break;
210 }
211 }
212 pricingjob->solverchanged = TRUE;
213}
214
215/** returns TRUE iff the solver was changed after the last solver call */
217 GCG_PRICINGJOB* pricingjob /**< pricing job */
218 )
219{
220 return pricingjob->solverchanged;
221}
222
223/** inform the pricing job that the current solver was called */
225 GCG_PRICINGJOB* pricingjob /**< pricing job */
226 )
227{
228 pricingjob->solverchanged = FALSE;
229}
230
231/** get the chunk of a pricing job */
233 GCG_PRICINGJOB* pricingjob /**< pricing job */
234 )
235{
236 return pricingjob->chunk;
237}
238
239/** get the score of a pricing job */
241 GCG_PRICINGJOB* pricingjob /**< pricing job */
242 )
243{
244 return pricingjob->score;
245}
246
247/** return whether the pricing job is to be performed heuristically */
249 GCG_PRICINGJOB* pricingjob /**< pricing job */
250 )
251{
252 return pricingjob->heuristic;
253}
254
255/** set the pricing job to be performed exactly */
257 GCG_PRICINGJOB* pricingjob /**< pricing job */
258 )
259{
260 pricingjob->heuristic = FALSE;
261}
262
263/** reset number of heuristic pricing iterations of a pricing job */
265 GCG_PRICINGJOB* pricingjob /**< pricing job */
266 )
267{
268 if( pricingjob->solver != NULL && GCGsolverIsHeurEnabled(pricingjob->solver) )
269 pricingjob->heuristic = TRUE;
270 else
271 pricingjob->heuristic = FALSE;
272 pricingjob->nheuriters = 0;
273}
274
275/** update number of heuristic pricing iterations of a pricing job */
277 GCG_PRICINGJOB* pricingjob /**< pricing job */
278 )
279{
280 if( pricingjob->heuristic )
281 ++pricingjob->nheuriters;
282}
283
284/** get the number of heuristic pricing iterations of the pricing job */
286 GCG_PRICINGJOB* pricingjob /**< pricing job */
287 )
288{
289 return pricingjob->nheuriters;
290}
#define SCIP_Bool
#define SCIP_Real
#define TRUE
#define FALSE
GCG interface methods.
int GCGpricerGetNSolvers(GCG *gcg)
GCG_SOLVER ** GCGpricerGetSolvers(GCG *gcg)
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
GCG_PRICINGPROB * GCGpricingjobGetPricingprob(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:135
GCG_EXPORT SCIP_Bool GCGsolverIsHeurEnabled(GCG_SOLVER *solver)
Definition solver.c:451
GCG_EXPORT SCIP_Bool GCGsolverIsExactEnabled(GCG_SOLVER *solver)
Definition solver.c:461
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPallocBlockMemory(scip, ptr)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
int i
#define NULL
GCG variable pricer.
void GCGpricingjobSetExact(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:256
SCIP_Bool GCGpricingjobSolverChanged(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:216
void GCGpricingjobSolverCalled(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:224
SCIP_RETCODE GCGpricingjobSetup(GCG *gcg, GCG_PRICINGJOB *pricingjob, SCIP_Bool heuristic, int scoring, int nroundscol, SCIP_Real dualsolconv, int npointsprob, int nraysprob)
Definition pricingjob.c:91
GCG_SOLVER * GCGpricingjobGetSolver(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:142
SCIP_Real GCGpricingjobGetScore(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:240
void GCGpricingjobResetHeuristic(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:264
SCIP_Bool GCGpricingjobIsHeuristic(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:248
void GCGpricingjobNextSolver(GCG *gcg, GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:180
void GCGpricingjobFree(GCG *gcg, GCG_PRICINGJOB **pricingjob)
Definition pricingjob.c:75
int GCGpricingjobGetNHeurIters(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:285
SCIP_RETCODE GCGpricingjobCreate(GCG *gcg, GCG_PRICINGJOB **pricingjob, GCG_PRICINGPROB *pricingprob, GCG_SOLVER *solver, int chunk)
Definition pricingjob.c:52
SCIP_Real GCGpricingjobGetChunk(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:232
void GCGpricingjobResetSolver(GCG *gcg, GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:150
void GCGpricingjobIncreaseNHeurIters(GCG_PRICINGJOB *pricingjob)
Definition pricingjob.c:276
private methods for working with pricing jobs, to be used by the pricing controller only
int GCGpricingprobGetProbnr(GCG_PRICINGPROB *pricingprob)
int GCGpricingprobGetNColsLastRounds(GCG_PRICINGPROB *pricingprob, int nroundscol)
public methods for working with gcg columns
public methods for working with pricing jobs
public methods for working with pricing problems
GCG_PRICINGPROB * pricingprob
GCG_SOLVER * solver
SCIP_Bool solverchanged
struct Gcg GCG
Definition type_gcg.h:44
struct GCG_PricingJob GCG_PRICINGJOB
struct GCG_PricingProb GCG_PRICINGPROB
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct GCG_Solver GCG_SOLVER
Definition type_solver.h:51