Scippy

SCIP

Solving Constraint Integer Programs

objpricer.cpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2016 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License. */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file objpricer.cpp
17  * @brief C++ wrapper for variable pricers
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <cassert>
24 
25 #include "objpricer.h"
26 
27 
28 
29 
30 /*
31  * Data structures
32  */
33 
34 /** variable pricer data */
35 struct SCIP_PricerData
36 {
37  scip::ObjPricer* objpricer; /**< variable pricer object */
38  SCIP_Bool deleteobject; /**< should the pricer object be deleted when pricer is freed? */
39 };
40 
41 
42 
43 
44 /*
45  * Callback methods of variable pricer
46  */
47 
48 extern "C"
49 {
50 
51 /** copy method for pricer plugins (called when SCIP copies plugins) */
52 static
53 SCIP_DECL_PRICERCOPY(pricerCopyObj)
54 { /*lint --e{715}*/
55  SCIP_PRICERDATA* pricerdata;
56 
57  assert(scip != NULL);
58 
59  pricerdata = SCIPpricerGetData(pricer);
60  assert(pricerdata != NULL);
61  assert(pricerdata->objpricer != NULL);
62  assert(pricerdata->objpricer->scip_ != scip);
63 
64  if( pricerdata->objpricer->iscloneable() )
65  {
66  scip::ObjPricer* newobjpricer;
67  newobjpricer = dynamic_cast<scip::ObjPricer*> (pricerdata->objpricer->clone(scip, valid));
68 
69  /* call include method of pricer object */
70  SCIP_CALL( SCIPincludeObjPricer(scip, newobjpricer, TRUE) );
71  }
72 
73  return SCIP_OKAY;
74 }
75 
76 /** destructor of variable pricer to free user data (called when SCIP is exiting) */
77 static
78 SCIP_DECL_PRICERFREE(pricerFreeObj)
79 { /*lint --e{715}*/
80  SCIP_PRICERDATA* pricerdata;
81 
82  pricerdata = SCIPpricerGetData(pricer);
83  assert(pricerdata != NULL);
84  assert(pricerdata->objpricer != NULL);
85  assert(pricerdata->objpricer->scip_ == scip);
86 
87  /* call virtual method of pricer object */
88  SCIP_CALL( pricerdata->objpricer->scip_free(scip, pricer) );
89 
90  /* free pricer object */
91  if( pricerdata->deleteobject )
92  delete pricerdata->objpricer;
93 
94  /* free pricer data */
95  delete pricerdata;
96  SCIPpricerSetData(pricer, NULL); /*lint !e64*/
97 
98  return SCIP_OKAY;
99 }
100 
101 
102 /** initialization method of variable pricer (called after problem was transformed) */
103 static
104 SCIP_DECL_PRICERINIT(pricerInitObj)
105 { /*lint --e{715}*/
106  SCIP_PRICERDATA* pricerdata;
107 
108  pricerdata = SCIPpricerGetData(pricer);
109  assert(pricerdata != NULL);
110  assert(pricerdata->objpricer != NULL);
111  assert(pricerdata->objpricer->scip_ == scip);
112 
113  /* call virtual method of pricer object */
114  SCIP_CALL( pricerdata->objpricer->scip_init(scip, pricer) );
115 
116  return SCIP_OKAY;
117 }
118 
119 
120 /** deinitialization method of variable pricer (called before transformed problem is freed) */
121 static
122 SCIP_DECL_PRICEREXIT(pricerExitObj)
123 { /*lint --e{715}*/
124  SCIP_PRICERDATA* pricerdata;
125 
126  pricerdata = SCIPpricerGetData(pricer);
127  assert(pricerdata != NULL);
128  assert(pricerdata->objpricer != NULL);
129 
130  /* call virtual method of pricer object */
131  SCIP_CALL( pricerdata->objpricer->scip_exit(scip, pricer) );
132 
133  return SCIP_OKAY;
134 }
135 
136 
137 /** solving process initialization method of variable pricer (called when branch and bound process is about to begin) */
138 static
139 SCIP_DECL_PRICERINITSOL(pricerInitsolObj)
140 { /*lint --e{715}*/
141  SCIP_PRICERDATA* pricerdata;
142 
143  pricerdata = SCIPpricerGetData(pricer);
144  assert(pricerdata != NULL);
145  assert(pricerdata->objpricer != NULL);
146 
147  /* call virtual method of pricer object */
148  SCIP_CALL( pricerdata->objpricer->scip_initsol(scip, pricer) );
149 
150  return SCIP_OKAY;
151 }
152 
153 
154 /** solving process deinitialization method of variable pricer (called before branch and bound process data is freed) */
155 static
156 SCIP_DECL_PRICEREXITSOL(pricerExitsolObj)
157 { /*lint --e{715}*/
158  SCIP_PRICERDATA* pricerdata;
159 
160  pricerdata = SCIPpricerGetData(pricer);
161  assert(pricerdata != NULL);
162  assert(pricerdata->objpricer != NULL);
163 
164  /* call virtual method of pricer object */
165  SCIP_CALL( pricerdata->objpricer->scip_exitsol(scip, pricer) );
166 
167  return SCIP_OKAY;
168 }
169 
170 
171 /** reduced cost pricing method of variable pricer for feasible LPs */
172 static
173 SCIP_DECL_PRICERREDCOST(pricerRedcostObj)
174 { /*lint --e{715}*/
175  SCIP_PRICERDATA* pricerdata;
176 
177  pricerdata = SCIPpricerGetData(pricer);
178  assert(pricerdata != NULL);
179  assert(pricerdata->objpricer != NULL);
180 
181  /* call virtual method of pricer object */
182  SCIP_CALL( pricerdata->objpricer->scip_redcost(scip, pricer, lowerbound, stopearly, result) );
183 
184  return SCIP_OKAY;
185 }
186 
187 
188 /** farkas pricing method of variable pricer for infeasible LPs */
189 static
190 SCIP_DECL_PRICERFARKAS(pricerFarkasObj)
191 { /*lint --e{715}*/
192  SCIP_PRICERDATA* pricerdata;
193 
194  pricerdata = SCIPpricerGetData(pricer);
195  assert(pricerdata != NULL);
196  assert(pricerdata->objpricer != NULL);
197 
198  /* call virtual method of pricer object */
199  SCIP_CALL( pricerdata->objpricer->scip_farkas(scip, pricer, result) );
200 
201  return SCIP_OKAY;
202 }
203 }
204 
205 
206 
207 /*
208  * variable pricer specific interface methods
209  */
210 
211 /** creates the variable pricer for the given variable pricer object and includes it in SCIP */
213  SCIP* scip, /**< SCIP data structure */
214  scip::ObjPricer* objpricer, /**< variable pricer object */
215  SCIP_Bool deleteobject /**< should the pricer object be deleted when pricer is freed? */
216  )
217 {
218  SCIP_PRICERDATA* pricerdata;
219 
220  assert(scip != NULL);
221  assert(objpricer != NULL);
222 
223  /* create variable pricer data */
224  pricerdata = new SCIP_PRICERDATA;
225  pricerdata->objpricer = objpricer;
226  pricerdata->deleteobject = deleteobject;
227 
228  /* include variable pricer */
229  SCIP_CALL( SCIPincludePricer(scip, objpricer->scip_name_, objpricer->scip_desc_, objpricer->scip_priority_,
230  objpricer->scip_delay_,
231  pricerCopyObj,
232  pricerFreeObj, pricerInitObj, pricerExitObj,
233  pricerInitsolObj, pricerExitsolObj, pricerRedcostObj, pricerFarkasObj,
234  pricerdata) ); /*lint !e429*/
235 
236  return SCIP_OKAY; /*lint !e429*/
237 }
238 
239 /** returns the variable pricer object of the given name, or 0 if not existing */
241  SCIP* scip, /**< SCIP data structure */
242  const char* name /**< name of variable pricer */
243  )
244 {
245  SCIP_PRICER* pricer;
246  SCIP_PRICERDATA* pricerdata;
247 
248  pricer = SCIPfindPricer(scip, name);
249  if( pricer == NULL )
250  return 0;
251 
252  pricerdata = SCIPpricerGetData(pricer);
253  assert(pricerdata != NULL);
254 
255  return pricerdata->objpricer;
256 }
257 
258 /** returns the variable pricer object for the given pricer */
260  SCIP* scip, /**< SCIP data structure */
261  SCIP_PRICER* pricer /**< pricer */
262  )
263 {
264  SCIP_PRICERDATA* pricerdata;
265 
266  pricerdata = SCIPpricerGetData(pricer);
267  assert(pricerdata != NULL);
268 
269  return pricerdata->objpricer;
270 }
C++ wrapper for variable pricer.
Definition: objpricer.h:42
scip::ObjPricer * SCIPgetObjPricer(SCIP *scip, SCIP_PRICER *pricer)
Definition: objpricer.cpp:259
#define NULL
Definition: lpi_spx.cpp:130
static SCIP_DECL_PRICERINIT(pricerInitObj)
Definition: objpricer.cpp:104
#define TRUE
Definition: def.h:55
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIP_CALL(x)
Definition: def.h:266
SCIP_RETCODE SCIPincludeObjPricer(SCIP *scip, scip::ObjPricer *objpricer, SCIP_Bool deleteobject)
Definition: objpricer.cpp:212
static SCIP_DECL_PRICEREXIT(pricerExitObj)
Definition: objpricer.cpp:122
static SCIP_DECL_PRICEREXITSOL(pricerExitsolObj)
Definition: objpricer.cpp:156
static SCIP_DECL_PRICERREDCOST(pricerRedcostObj)
Definition: objpricer.cpp:173
void SCIPpricerSetData(SCIP_PRICER *pricer, SCIP_PRICERDATA *pricerdata)
Definition: pricer.c:473
SCIP_PRICER * SCIPfindPricer(SCIP *scip, const char *name)
Definition: scip.c:4980
char * scip_desc_
Definition: objpricer.h:54
static SCIP_DECL_PRICERINITSOL(pricerInitsolObj)
Definition: objpricer.cpp:139
SCIP_RETCODE SCIPincludePricer(SCIP *scip, const char *name, const char *desc, int priority, SCIP_Bool delay, SCIP_DECL_PRICERCOPY((*pricercopy)), SCIP_DECL_PRICERFREE((*pricerfree)), SCIP_DECL_PRICERINIT((*pricerinit)), SCIP_DECL_PRICEREXIT((*pricerexit)), SCIP_DECL_PRICERINITSOL((*pricerinitsol)), SCIP_DECL_PRICEREXITSOL((*pricerexitsol)), SCIP_DECL_PRICERREDCOST((*pricerredcost)), SCIP_DECL_PRICERFARKAS((*pricerfarkas)), SCIP_PRICERDATA *pricerdata)
Definition: scip.c:4738
#define SCIP_Bool
Definition: def.h:53
char * scip_name_
Definition: objpricer.h:51
static SCIP_DECL_PRICERFREE(pricerFreeObj)
Definition: objpricer.cpp:78
const SCIP_Bool scip_delay_
Definition: objpricer.h:62
static SCIP_DECL_PRICERCOPY(pricerCopyObj)
Definition: objpricer.cpp:53
scip::ObjPricer * SCIPfindObjPricer(SCIP *scip, const char *name)
Definition: objpricer.cpp:240
struct SCIP_PricerData SCIP_PRICERDATA
Definition: type_pricer.h:36
const int scip_priority_
Definition: objpricer.h:57
C++ wrapper for variable pricers.
static SCIP_DECL_PRICERFARKAS(pricerFarkasObj)
Definition: objpricer.cpp:190
SCIP_PRICERDATA * SCIPpricerGetData(SCIP_PRICER *pricer)
Definition: pricer.c:463