Scippy

GCG

Branch-and-Price & Column Generation for Everyone

class_pricingtype.cpp
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 class_pricingtype.cpp
29  * @brief abstraction for SCIP pricing types
30  * @author Martin Bergner
31  * @author Christian Puchert
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "scip/scip.h"
37 #include "class_pricingtype.h"
38 #include "scip/cons_linear.h"
39 #include "pub_gcgvar.h"
40 #include "scip/pub_lp.h"
41 #include "scip/clock.h"
42 #include "scip_misc.h"
43 
44 #include <exception>
45 
46 #define DEFAULT_MAXROUNDSREDCOST INT_MAX /**< maximal number of reduced cost pricing rounds */
47 #define DEFAULT_MAXCOLSROUNDREDCOSTROOT 100 /**< maximal number of columns per reduced cost pricing round at root node */
48 #define DEFAULT_MAXCOLSROUNDREDCOST 100 /**< maximal number of columns per reduced cost pricing round */
49 #define DEFAULT_MAXCOLSPROBREDCOSTROOT 10 /**< maximal number of columns per problem to be generated during red. cost pricing at root node */
50 #define DEFAULT_MAXCOLSPROBREDCOST 10 /**< maximal number of columns per problem to be generated during red. cost pricing */
51 #define DEFAULT_MAXSUCCESSFULPROBSREDCOST INT_MAX /**< maximal number of successfully solved red. cost pricing problems until pricing loop is aborted */
52 #define DEFAULT_RELMAXPROBSREDCOSTROOT 1.0 /**< maximal percentage of red. cost pricing problems that are solved at root node if variables have already been found */
53 #define DEFAULT_RELMAXPROBSREDCOST 1.0 /**< maximal percentage of red. cost pricing problems that are solved if variables have already been found */
54 #define DEFAULT_RELMAXSUCCESSFULPROBSREDCOST 1.0 /**< maximal percentage of successfully solved red. cost pricing problems until pricing loop is aborted */
55 
56 #define DEFAULT_MAXCOLSROUNDFARKAS 10 /**< maximal number of columns per Farkas pricing round */
57 #define DEFAULT_MAXCOLSPROBFARKAS 10 /**< maximal number of columns per problem to be generated during Farkas pricing */
58 #define DEFAULT_RELMAXPROBSFARKAS 1.0 /**< maximal percentage of Farkas pricing problems that are solved if variables have already been found */
59 
60 
61 #define SCIP_CALL_EXC(x) do \
62  { \
63  SCIP_RETCODE _restat_; \
64  if( (_restat_ = (x)) != SCIP_OKAY ) \
65  { \
66  SCIPerrorMessage("Error <%d> in function call\n", _restat_); \
67  throw std::exception(); \
68  } \
69  } \
70  while( FALSE )
71 
73  SCIP* scip
74  )
75 {
76  scip_ = scip; /* SCIP instance (master problem) */
77  type = GCG_PRICETYPE_UNKNOWN; /* type of pricing */
78 
79  /* statistical values */
80  calls = 0; /* number of times this type of pricing was called */
81 
82  /* parameters */
83  maxrounds = INT_MAX; /* maximal number of pricing rounds */
84  maxcolsroundroot = INT_MAX; /* maximal number of columns per pricing round at root node */
85  maxcolsround = INT_MAX; /* maximal number of columns per pricing round */
86  maxcolsprobroot = INT_MAX; /* maximal number of columns per problem to be generated at root node */
87  maxcolsprob = INT_MAX; /* maximal number of columns per problem to be generated */
88  maxsuccessfulprobs = INT_MAX; /* maximal number of successfully solved pricing problems until pricing loop is aborted */
89  relmaxprobsroot = 1.0; /* maximal percentage of pricing problems that are solved at root node if variables have already been found */
90  relmaxprobs = 1.0; /* maximal percentage of pricing problems that are solved if variables have already been found */
91  relmaxsuccessfulprobs = 1.0; /* maximal percentage of successfully solved pricing problems until pricing loop is aborted */
92 
93  SCIP_CALL_EXC( SCIPcreateCPUClock(scip, &(clock)) );
94 }
95 
97 {
98  SCIP_CALL_ABORT( SCIPfreeClock(scip_, &(clock)) );
99 
100  scip_ = (SCIP*) NULL;
101 }
102 
104 {
105  SCIP_CALL( SCIPstartClock(scip_, clock) );
106  return SCIP_OKAY;
107 }
108 
110 {
111  SCIP_CALL( SCIPstopClock(scip_, clock) );
112  return SCIP_OKAY;
113 }
114 
115 SCIP_Real PricingType::getClockTime() const
116 {
117  return SCIPgetClockTime(scip_, clock);
118 }
119 
121  SCIP* scip
122  ) : PricingType(scip)
123 {
125 }
126 
128  SCIP* scip,
129  SCIP_CONS* cons
130  ) const
131 {
132  return SCIPgetDualfarkasLinear(scip, cons);
133 }
134 
136  SCIP_ROW* row
137  ) const
138 {
139  return SCIProwGetDualfarkas(row);
140 }
141 
143  SCIP_VAR* var
144  ) const
145 {
146  assert(var != NULL);
147  return 0.0;
148 }
149 
150 /** returns the maximal number of columns per pricing round */
152 {
153  return maxcolsround;
154 }
155 
156 /** returns the maximal number of columns per problem to be generated during pricing */
158 {
159  return maxcolsprob;
160 }
161 
162 /** returns the maximal percentage of pricing problems that are solved if variables have already been found */
164 {
165  return relmaxprobs;
166 }
167 
169 {
170  SCIP* origprob = GCGmasterGetOrigprob(scip_);
171 
172  SCIP_CALL( SCIPaddIntParam(origprob, "pricing/masterpricer/maxcolsroundfarkas",
173  "maximal number of columns per Farkas pricing round",
174  &maxcolsround, FALSE, DEFAULT_MAXCOLSROUNDFARKAS, 1, INT_MAX, NULL, (SCIP_PARAMDATA*) NULL) );
175 
176  SCIP_CALL( SCIPaddIntParam(origprob, "pricing/masterpricer/maxcolsprobfarkas",
177  "maximal number of columns per problem to be generated during Farkas pricing",
178  &maxcolsprob, FALSE, DEFAULT_MAXCOLSPROBFARKAS, 1, INT_MAX, NULL, (SCIP_PARAMDATA*) NULL) );
179 
180  SCIP_CALL( SCIPaddRealParam(origprob, "pricing/masterpricer/relmaxprobsfarkas",
181  "maximal percentage of Farkas pricing problems that are solved if variables have already been found",
182  &relmaxprobs, FALSE, DEFAULT_RELMAXPROBSFARKAS, 0.0, 1.0, NULL, (SCIP_PARAMDATA*) NULL) );
183 
184  return SCIP_OKAY;
185 }
186 
188  SCIP* scip,
189  SCIP_CONS* cons
190  ) const
191 {
192  return SCIPgetDualsolLinear(scip, cons);
193 }
194 
196  SCIP_ROW* row
197  ) const
198 {
199  return SCIProwGetDualsol(row);
200 }
201 
203  SCIP* p_scip
204  ) : PricingType(p_scip)
205 {
207 }
208 
210  SCIP_VAR* var
211  ) const
212 {
213  SCIP_VAR* origvar;
214  assert(var != NULL);
215 
216  origvar = GCGpricingVarGetOrigvars(var)[0];
217 
218  if( GCGoriginalVarIsLinking(origvar) )
219  return 0.0;
220  else
221  return SCIPvarGetObj(origvar);
222 }
223 
224 /** returns the maximal number of columns per pricing round */
226 {
228 }
229 
230 /** returns the maximal number of columns per problem to be generated during pricing */
232 {
234 }
235 
236 /** returns the maximal percentage of pricing problems that are solved if variables have already been found */
238 {
240 }
241 
243 {
244  SCIP* origprob = GCGmasterGetOrigprob(scip_);
245 
246  SCIP_CALL( SCIPaddIntParam(origprob, "pricing/masterpricer/maxroundsredcost",
247  "maximal number of pricing rounds per node after the root node",
248  &maxrounds, FALSE, DEFAULT_MAXROUNDSREDCOST, 0, INT_MAX, NULL, (SCIP_PARAMDATA*) NULL) );
249 
250  SCIP_CALL( SCIPaddIntParam(origprob, "pricing/masterpricer/maxcolsroundredcostroot",
251  "maximal number of columns per reduced cost pricing round at root node",
253  NULL, (SCIP_PARAMDATA*) NULL) );
254 
255  SCIP_CALL( SCIPaddIntParam(origprob, "pricing/masterpricer/maxcolsroundredcost",
256  "maximal number of columns per reduced cost pricing round",
257  &maxcolsround, FALSE, DEFAULT_MAXCOLSROUNDREDCOST, 0, INT_MAX,
258  NULL, (SCIP_PARAMDATA*) NULL) );
259 
260  SCIP_CALL( SCIPaddIntParam(origprob, "pricing/masterpricer/maxcolsprobredcostroot",
261  "maximal number of columns per problem to be generated during red. cost pricing at root node",
262  &maxcolsprobroot, FALSE, DEFAULT_MAXCOLSPROBREDCOSTROOT, 0, INT_MAX,
263  NULL, (SCIP_PARAMDATA*) NULL) );
264 
265  SCIP_CALL( SCIPaddIntParam(origprob, "pricing/masterpricer/maxcolsprobredcost",
266  "maximal number of columns per problem to be generated during red. cost pricing",
267  &maxcolsprob, FALSE, DEFAULT_MAXCOLSPROBREDCOST, 0, INT_MAX,
268  NULL, (SCIP_PARAMDATA*) NULL) );
269 
270  SCIP_CALL( SCIPaddIntParam(origprob, "pricing/masterpricer/maxsuccessfulprobsredcost",
271  "maximal number of successfully solved red. cost pricing problems until pricing loop is aborted",
272  &maxsuccessfulprobs, FALSE, DEFAULT_MAXSUCCESSFULPROBSREDCOST, 1, INT_MAX, NULL, (SCIP_PARAMDATA*) NULL) );
273 
274  SCIP_CALL( SCIPaddRealParam(origprob, "pricing/masterpricer/relmaxprobsredcostroot",
275  "maximal percentage of red. cost pricing problems that are solved at root node if variables have already been found",
276  &relmaxprobsroot, FALSE, DEFAULT_RELMAXPROBSREDCOSTROOT, 0.0, 1.0, NULL, (SCIP_PARAMDATA*) NULL) );
277 
278  SCIP_CALL( SCIPaddRealParam(origprob, "pricing/masterpricer/relmaxprobsredcost",
279  "maximal percentage of red. cost pricing problems that are solved if variables have already been found",
280  &relmaxprobs, FALSE, DEFAULT_RELMAXPROBSREDCOST, 0.0, 1.0, NULL, (SCIP_PARAMDATA*) NULL) );
281 
282  SCIP_CALL( SCIPaddRealParam(origprob, "pricing/masterpricer/relmaxsuccessfulprobsredcost",
283  "maximal percentage of successfully solved red. cost pricing problems until pricing loop is aborted",
284  &relmaxsuccessfulprobs, FALSE, DEFAULT_RELMAXSUCCESSFULPROBSREDCOST, 0.0, 1.0, NULL, NULL) );
285 
286  return SCIP_OKAY;
287 }
virtual ~PricingType()
virtual int getMaxcolsprob() const
#define DEFAULT_RELMAXSUCCESSFULPROBSREDCOST
virtual SCIP_RETCODE stopClock()
SCIP_Real relmaxsuccessfulprobs
virtual int getMaxcolsround() const
virtual int getMaxcolsround() const
#define DEFAULT_MAXCOLSPROBREDCOST
virtual SCIP_Real varGetObj(SCIP_VAR *var) const
virtual SCIP_Real rowGetDual(SCIP_ROW *row) const
#define DEFAULT_MAXCOLSPROBREDCOSTROOT
@ GCG_PRICETYPE_UNKNOWN
Definition: pricer_gcg.h:54
#define DEFAULT_MAXCOLSROUNDREDCOST
various SCIP helper methods
virtual SCIP_Real getRelmaxprobs() const
virtual SCIP_Real varGetObj(SCIP_VAR *var) const
virtual SCIP_RETCODE addParameters()
virtual SCIP_RETCODE startClock()
virtual SCIP_RETCODE addParameters()
@ GCG_PRICETYPE_FARKAS
Definition: pricer_gcg.h:56
virtual SCIP_Real getRelmaxprobs() const
#define DEFAULT_MAXCOLSROUNDREDCOSTROOT
SCIP * GCGmasterGetOrigprob(SCIP *scip)
virtual int getMaxcolsprob() const
@ GCG_PRICETYPE_REDCOST
Definition: pricer_gcg.h:57
virtual SCIP_Real consGetDual(SCIP *scip, SCIP_CONS *cons) const
SCIP_CLOCK * clock
SCIP_Bool GCGisRootNode(SCIP *scip)
Definition: scip_misc.c:921
#define DEFAULT_MAXSUCCESSFULPROBSREDCOST
SCIP_VAR ** GCGpricingVarGetOrigvars(SCIP_VAR *var)
Definition: gcgvar.c:1015
virtual SCIP_Real getClockTime() const
virtual SCIP_Real consGetDual(SCIP *scip, SCIP_CONS *cons) const
#define DEFAULT_RELMAXPROBSREDCOSTROOT
#define SCIP_CALL_EXC(x)
virtual SCIP_Real rowGetDual(SCIP_ROW *row) const
SCIP_Bool GCGoriginalVarIsLinking(SCIP_VAR *var)
Definition: gcgvar.c:182
SCIP_Real relmaxprobs
SCIP_Real relmaxprobsroot
abstraction for SCIP pricing types
#define DEFAULT_RELMAXPROBSREDCOST
public methods for GCG variables
GCG_PRICETYPE type
#define DEFAULT_MAXCOLSPROBFARKAS
#define DEFAULT_RELMAXPROBSFARKAS
#define DEFAULT_MAXROUNDSREDCOST
#define DEFAULT_MAXCOLSROUNDFARKAS