Scippy

GCG

Branch-and-Price & Column Generation for Everyone

pricingjob.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program */
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-2021 Operations Research, RWTH Aachen University */
10 /* Zuse Institute Berlin (ZIB) */
11 /* */
12 /* This program is free software; you can redistribute it and/or */
13 /* modify it under the terms of the GNU Lesser General Public License */
14 /* as published by the Free Software Foundation; either version 3 */
15 /* of the License, or (at your option) any later version. */
16 /* */
17 /* This program is distributed in the hope that it will be useful, */
18 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
19 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
20 /* GNU Lesser General Public License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with this program; if not, write to the Free Software */
24 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
25 /* */
26 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27 
28 /**@file pricingjob.c
29  * @brief methods for working with pricing jobs
30  * @author Christian Puchert
31  *
32  * Various methods to work with pricing jobs
33  *
34  */
35 
36 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
37 
38 #include "pricingjob.h"
39 #include "pub_gcgcol.h"
40 #include "pub_pricingjob.h"
41 
42 #include "gcg.h"
43 #include "pricer_gcg.h"
44 #include "pub_pricingprob.h"
45 #include "pub_solver.h"
46 
47 #include "scip/scip.h"
48 
49 
50 /** create a pricing job */
51 SCIP_RETCODE GCGpricingjobCreate(
52  SCIP* scip, /**< SCIP data structure (master problem) */
53  GCG_PRICINGJOB** pricingjob, /**< pricing job to be created */
54  GCG_PRICINGPROB* pricingprob, /**< data structure of the corresponding pricing problem */
55  GCG_SOLVER* solver, /**< pricing solver responsible for the pricing job */
56  int chunk /**< chunk that the pricing problem should belong to */
57 )
58 {
59  SCIP_CALL( SCIPallocBlockMemory(scip, pricingjob) );
60 
61  (*pricingjob)->pricingprob = pricingprob;
62  (*pricingjob)->solver = solver;
63  (*pricingjob)->chunk = chunk;
64  (*pricingjob)->score = 0.0;
65  (*pricingjob)->heuristic = FALSE;
66  (*pricingjob)->nheuriters = 0;
67 
68  return SCIP_OKAY;
69 }
70 
71 /** free a pricing job */
73  SCIP* scip, /**< SCIP data structure (master problem) */
74  GCG_PRICINGJOB** pricingjob /**< pricing job to be freed */
75 )
76 {
77  SCIPfreeBlockMemory(scip, pricingjob);
78  *pricingjob = NULL;
79 }
80 
81 /** setup a pricing job at the beginning of the pricing loop */
82 SCIP_RETCODE GCGpricingjobSetup(
83  SCIP* scip, /**< SCIP data structure (master problem) */
84  GCG_PRICINGJOB* pricingjob, /**< pricing job */
85  SCIP_Bool heuristic, /**< shall the pricing job be performed heuristically? */
86  int scoring, /**< scoring parameter */
87  int nroundscol, /**< number of previous pricing rounds for which the number of improving columns should be counted */
88  SCIP_Real dualsolconv, /**< dual solution value of corresponding convexity constraint */
89  int npointsprob, /**< total number of extreme points generated so far by the pricing problem */
90  int nraysprob /**< total number of extreme rays generated so far by the pricing problem */
91  )
92 {
93  GCG_PRICINGPROB* pricingprob = GCGpricingjobGetPricingprob(pricingjob);
94  assert(pricingprob != NULL);
95 
96  /* set the score; the larger, the better */
97  switch( scoring )
98  {
99  case 'i':
100  pricingjob->score = - (SCIP_Real) GCGpricingprobGetProbnr(pricingprob);
101  break;
102  case 'd':
103  pricingjob->score = dualsolconv;
104  break;
105  case 'r':
106  pricingjob->score = -(0.2 * npointsprob + nraysprob);
107  break;
108  case 'l':
109  pricingjob->score = (SCIP_Real) GCGpricingprobGetNColsLastRounds(pricingprob, nroundscol);
110  break;
111  default:
112  pricingjob->score = 0.0;
113  break;
114  }
115 
116  GCGpricingjobResetSolver(scip, pricingjob);
117  if( heuristic )
118  GCGpricingjobResetHeuristic(pricingjob);
119  else
120  GCGpricingjobSetExact(pricingjob);
121 
122  return SCIP_OKAY;
123 }
124 
125 /** get the pricing problem structure associated with a pricing job */
127  GCG_PRICINGJOB* pricingjob /**< pricing job */
128  )
129 {
130  return pricingjob->pricingprob;
131 }
132 /** get the pricing solver with which the pricing job is to be performed */
134  GCG_PRICINGJOB* pricingjob /**< pricing job */
135  )
136 {
137  return pricingjob->solver;
138 }
139 
140 /** reset the pricing solver to be used to the one with the highest priority */
142  SCIP* scip, /**< SCIP data structure (master problem) */
143  GCG_PRICINGJOB* pricingjob /**< pricing job */
144  )
145 {
146  GCG_SOLVER** solvers;
147  int nsolvers;
148 
149  int i;
150 
151  solvers = GCGpricerGetSolvers(scip);
152  nsolvers = GCGpricerGetNSolvers(scip);
153 
154  /* get first available solver;
155  * assumption: solvers are sorted by priority
156  */
157  pricingjob->solver = NULL;
158  for( i = 0; i < nsolvers; ++i )
159  {
160  if( GCGsolverIsHeurEnabled(solvers[i]) || GCGsolverIsExactEnabled(solvers[i]) )
161  {
162  pricingjob->solver = solvers[i];
163  break;
164  }
165  }
166 
167  assert(pricingjob->solver != NULL);
168 }
169 
170 /** get the next pricing solver to be used, or NULL of there is none */
172  SCIP* scip, /**< SCIP data structure (master problem) */
173  GCG_PRICINGJOB* pricingjob /**< pricing job */
174  )
175 {
176  GCG_SOLVER** solvers;
177  int nsolvers;
178 
179  int pos;
180  int i;
181 
182  solvers = GCGpricerGetSolvers(scip);
183  nsolvers = GCGpricerGetNSolvers(scip);
184 
185  /* get position of current solver */
186  for( pos = 0; pos < nsolvers; ++pos )
187  if( solvers[pos] == pricingjob->solver )
188  break;
189  assert(pos < nsolvers);
190 
191  /* get next available solver;
192  * assumption: solvers are sorted by priority
193  */
194  pricingjob->solver = NULL;
195  for( i = pos + 1; i < nsolvers; ++i )
196  {
197  if( GCGsolverIsHeurEnabled(solvers[i]) || GCGsolverIsExactEnabled(solvers[i]) )
198  {
199  pricingjob->solver = solvers[i];
200  break;
201  }
202  }
203 }
204 
205 /** get the chunk of a pricing job */
207  GCG_PRICINGJOB* pricingjob /**< pricing job */
208  )
209 {
210  return pricingjob->chunk;
211 }
212 
213 /** get the score of a pricing job */
215  GCG_PRICINGJOB* pricingjob /**< pricing job */
216  )
217 {
218  return pricingjob->score;
219 }
220 
221 /** return whether the pricing job is to be performed heuristically */
223  GCG_PRICINGJOB* pricingjob /**< pricing job */
224  )
225 {
226  return pricingjob->heuristic;
227 }
228 
229 /** set the pricing job to be performed exactly */
231  GCG_PRICINGJOB* pricingjob /**< pricing job */
232  )
233 {
234  pricingjob->heuristic = FALSE;
235 }
236 
237 /** reset number of heuristic pricing iterations of a pricing job */
239  GCG_PRICINGJOB* pricingjob /**< pricing job */
240  )
241 {
242  if( GCGsolverIsHeurEnabled(pricingjob->solver) )
243  pricingjob->heuristic = TRUE;
244  else
245  pricingjob->heuristic = FALSE;
246  pricingjob->nheuriters = 0;
247 }
248 
249 /** update number of heuristic pricing iterations of a pricing job */
251  GCG_PRICINGJOB* pricingjob /**< pricing job */
252  )
253 {
254  if( pricingjob->heuristic )
255  ++pricingjob->nheuriters;
256 }
257 
258 /** get the number of heuristic pricing iterations of the pricing job */
260  GCG_PRICINGJOB* pricingjob /**< pricing job */
261  )
262 {
263  return pricingjob->nheuriters;
264 }
public methods for working with pricing problems
GCG interface methods.
public methods for working with pricing jobs
GCG_SOLVER * GCGpricingjobGetSolver(GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:133
public methods for working with gcg columns
int GCGpricingprobGetNColsLastRounds(GCG_PRICINGPROB *pricingprob, int nroundscol)
Definition: pricingprob.c:303
GCG_SOLVER ** GCGpricerGetSolvers(SCIP *scip)
SCIP_RETCODE GCGpricingjobSetup(SCIP *scip, GCG_PRICINGJOB *pricingjob, SCIP_Bool heuristic, int scoring, int nroundscol, SCIP_Real dualsolconv, int npointsprob, int nraysprob)
Definition: pricingjob.c:82
void GCGpricingjobResetHeuristic(GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:238
GCG variable pricer.
GCG_SOLVER * solver
GCG_PRICINGPROB * GCGpricingjobGetPricingprob(GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:126
private methods for working with pricing jobs, to be used by the pricing controller only
int GCGpricingjobGetNHeurIters(GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:259
void GCGpricingjobFree(SCIP *scip, GCG_PRICINGJOB **pricingjob)
Definition: pricingjob.c:72
void GCGpricingjobIncreaseNHeurIters(GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:250
SCIP_EXPORT SCIP_Bool GCGsolverIsExactEnabled(GCG_SOLVER *solver)
Definition: solver.c:438
void GCGpricingjobResetSolver(SCIP *scip, GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:141
void GCGpricingjobNextSolver(SCIP *scip, GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:171
SCIP_Bool GCGpricingjobIsHeuristic(GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:222
void GCGpricingjobSetExact(GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:230
SCIP_RETCODE GCGpricingjobCreate(SCIP *scip, GCG_PRICINGJOB **pricingjob, GCG_PRICINGPROB *pricingprob, GCG_SOLVER *solver, int chunk)
Definition: pricingjob.c:51
SCIP_Real GCGpricingjobGetChunk(GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:206
int GCGpricerGetNSolvers(SCIP *scip)
SCIP_EXPORT SCIP_Bool GCGsolverIsHeurEnabled(GCG_SOLVER *solver)
Definition: solver.c:428
int GCGpricingprobGetProbnr(GCG_PRICINGPROB *pricingprob)
Definition: pricingprob.c:204
GCG_PRICINGPROB * pricingprob
SCIP_Real GCGpricingjobGetScore(GCG_PRICINGJOB *pricingjob)
Definition: pricingjob.c:214