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