Scippy

SCIP

Solving Constraint Integer Programs

objprop.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-2023 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 objprop.cpp
26  * @brief C++ wrapper for propagators
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 "objprop.h"
35 
36 
37 
38 
39 /*
40  * Data structures
41  */
42 
43 /** propagator data */
44 struct SCIP_PropData
45 {
46  scip::ObjProp* objprop; /**< propagator object */
47  SCIP_Bool deleteobject; /**< should the propagator object be deleted when propagator is freed? */
48 };
49 
50 
51 
52 
53 /*
54  * Callback methods of propagator
55  */
56 
57 extern "C"
58 {
59 
60 /** copy method for propagator plugins (called when SCIP copies plugins) */
61 static
62 SCIP_DECL_PROPCOPY(propCopyObj)
63 { /*lint --e{715}*/
64  SCIP_PROPDATA* propdata;
65 
66  assert(scip != NULL);
67 
68  propdata = SCIPpropGetData(prop);
69  assert(propdata != NULL);
70  assert(propdata->objprop != NULL);
71  assert(propdata->objprop->scip_ != scip);
72 
73  if( propdata->objprop->iscloneable() )
74  {
75  scip::ObjProp* newobjprop;
76  newobjprop = dynamic_cast<scip::ObjProp*> (propdata->objprop->clone(scip));
77 
78  /* call include method of propagator object */
79  SCIP_CALL( SCIPincludeObjProp(scip, newobjprop, TRUE) );
80  }
81 
82  return SCIP_OKAY;
83 }
84 
85 /** destructor of propagator to free user data (called when SCIP is exiting) */
86 static
87 SCIP_DECL_PROPFREE(propFreeObj)
88 { /*lint --e{715}*/
89  SCIP_PROPDATA* propdata;
90 
91  propdata = SCIPpropGetData(prop);
92  assert(propdata != NULL);
93  assert(propdata->objprop != NULL);
94  assert(propdata->objprop->scip_ == scip);
95 
96  /* call virtual method of prop object */
97  SCIP_CALL( propdata->objprop->scip_free(scip, prop) );
98 
99  /* free prop object */
100  if( propdata->deleteobject )
101  delete propdata->objprop;
102 
103  /* free prop data */
104  delete propdata;
105  SCIPpropSetData(prop, NULL); /*lint !e64*/
106 
107  return SCIP_OKAY;
108 }
109 
110 
111 /** initialization method of propagator (called after problem was transformed) */
112 static
113 SCIP_DECL_PROPINIT(propInitObj)
114 { /*lint --e{715}*/
115  SCIP_PROPDATA* propdata;
116 
117  propdata = SCIPpropGetData(prop);
118  assert(propdata != NULL);
119  assert(propdata->objprop != NULL);
120  assert(propdata->objprop->scip_ == scip);
121 
122  /* call virtual method of prop object */
123  SCIP_CALL( propdata->objprop->scip_init(scip, prop) );
124 
125  return SCIP_OKAY;
126 }
127 
128 
129 /** deinitialization method of propagator (called before transformed problem is freed) */
130 static
131 SCIP_DECL_PROPEXIT(propExitObj)
132 { /*lint --e{715}*/
133  SCIP_PROPDATA* propdata;
134 
135  propdata = SCIPpropGetData(prop);
136  assert(propdata != NULL);
137  assert(propdata->objprop != NULL);
138 
139  /* call virtual method of prop object */
140  SCIP_CALL( propdata->objprop->scip_exit(scip, prop) );
141 
142  return SCIP_OKAY;
143 }
144 
145 
146 /** presolving initialization method of propagator (called when presolving is about to begin) */
147 static
148 SCIP_DECL_PROPINITPRE(propInitpreObj)
149 { /*lint --e{715}*/
150  SCIP_PROPDATA* propdata;
151 
152  propdata = SCIPpropGetData(prop);
153  assert(propdata != NULL);
154  assert(propdata->objprop != NULL);
155 
156  /* call virtual method of prop object */
157  SCIP_CALL( propdata->objprop->scip_initpre(scip, prop) );
158 
159  return SCIP_OKAY;
160 }
161 
162 
163 /** presolving deinitialization method of propagator (called after presolving has been finished) */
164 static
165 SCIP_DECL_PROPEXITPRE(propExitpreObj)
166 { /*lint --e{715}*/
167  SCIP_PROPDATA* propdata;
168 
169  propdata = SCIPpropGetData(prop);
170  assert(propdata != NULL);
171  assert(propdata->objprop != NULL);
172 
173  /* call virtual method of prop object */
174  SCIP_CALL( propdata->objprop->scip_exitpre(scip, prop) );
175 
176  return SCIP_OKAY;
177 }
178 
179 
180 /** solving process initialization method of propagator (called when branch and bound process is about to begin) */
181 static
182 SCIP_DECL_PROPINITSOL(propInitsolObj)
183 { /*lint --e{715}*/
184  SCIP_PROPDATA* propdata;
185 
186  propdata = SCIPpropGetData(prop);
187  assert(propdata != NULL);
188  assert(propdata->objprop != NULL);
189 
190  /* call virtual method of prop object */
191  SCIP_CALL( propdata->objprop->scip_initsol(scip, prop) );
192 
193  return SCIP_OKAY;
194 }
195 
196 
197 /** solving process deinitialization method of propagator (called before branch and bound process data is freed) */
198 static
199 SCIP_DECL_PROPEXITSOL(propExitsolObj)
200 { /*lint --e{715}*/
201  SCIP_PROPDATA* propdata;
202 
203  propdata = SCIPpropGetData(prop);
204  assert(propdata != NULL);
205  assert(propdata->objprop != NULL);
206 
207  /* call virtual method of prop object */
208  SCIP_CALL( propdata->objprop->scip_exitsol(scip, prop, restart) );
209 
210  return SCIP_OKAY;
211 }
212 
213 
214 /** presolving method of propagator */
215 static
216 SCIP_DECL_PROPPRESOL(propPresolObj)
217 { /*lint --e{715}*/
218  SCIP_PROPDATA* propdata;
219 
220  propdata = SCIPpropGetData(prop);
221  assert(propdata != NULL);
222  assert(propdata->objprop != NULL);
223 
224  /* call virtual method of prop object */
225  SCIP_CALL( propdata->objprop->scip_presol(scip, prop, nrounds, presoltiming,
226  nnewfixedvars, nnewaggrvars, nnewchgvartypes, nnewchgbds, nnewholes,
227  nnewdelconss, nnewaddconss, nnewupgdconss, nnewchgcoefs, nnewchgsides,
228  nfixedvars, naggrvars, nchgvartypes, nchgbds, naddholes,
229  ndelconss, naddconss, nupgdconss, nchgcoefs, nchgsides, result) );
230 
231  return SCIP_OKAY;
232 }
233 
234 
235 /** execution method of propagator */
236 static
237 SCIP_DECL_PROPEXEC(propExecObj)
238 { /*lint --e{715}*/
239  SCIP_PROPDATA* propdata;
240 
241  propdata = SCIPpropGetData(prop);
242  assert(propdata != NULL);
243  assert(propdata->objprop != NULL);
244 
245  /* call virtual method of prop object */
246  SCIP_CALL( propdata->objprop->scip_exec(scip, prop, proptiming, result) );
247 
248  return SCIP_OKAY;
249 }
250 
251 
252 /** propagation conflict resolving method of propagator */
253 static
254 SCIP_DECL_PROPRESPROP(propRespropObj)
255 { /*lint --e{715}*/
256  SCIP_PROPDATA* propdata;
257 
258  propdata = SCIPpropGetData(prop);
259  assert(propdata != NULL);
260  assert(propdata->objprop != NULL);
261 
262  /* call virtual method of prop object */
263  SCIP_CALL( propdata->objprop->scip_resprop(scip, prop, infervar, inferinfo, boundtype, bdchgidx, relaxedbd, result) );
264 
265  return SCIP_OKAY;
266 }
267 }
268 
269 
270 
271 /*
272  * propagator specific interface methods
273  */
274 
275 /** creates the propagator for the given propagator object and includes it in SCIP */
277  SCIP* scip, /**< SCIP data structure */
278  scip::ObjProp* objprop, /**< propagator object */
279  SCIP_Bool deleteobject /**< should the propagator object be deleted when propagator is freed? */
280  )
281 {
282  SCIP_PROPDATA* propdata;
283 
284  assert(scip != NULL);
285  assert(objprop != NULL);
286 
287  /* create propagator data */
288  propdata = new SCIP_PROPDATA;
289  propdata->objprop = objprop;
290  propdata->deleteobject = deleteobject;
291 
292  /* include propagator */
293  SCIP_CALL( SCIPincludeProp(scip, objprop->scip_name_, objprop->scip_desc_,
294  objprop->scip_priority_, objprop->scip_freq_, objprop->scip_delay_,
296  propCopyObj, propFreeObj, propInitObj, propExitObj, propInitpreObj, propExitpreObj, propInitsolObj, propExitsolObj,
297  propPresolObj, propExecObj, propRespropObj,
298  propdata) ); /*lint !e429*/
299 
300  return SCIP_OKAY; /*lint !e429*/
301 }
302 
303 /** returns the prop object of the given name, or 0 if not existing */
305  SCIP* scip, /**< SCIP data structure */
306  const char* name /**< name of propagator */
307  )
308 {
309  SCIP_PROP* prop;
310  SCIP_PROPDATA* propdata;
311 
312  prop = SCIPfindProp(scip, name);
313  if( prop == NULL )
314  return 0;
315 
316  propdata = SCIPpropGetData(prop);
317  assert(propdata != NULL);
318 
319  return propdata->objprop;
320 }
321 
322 /** returns the prop object for the given propagator */
324  SCIP* scip, /**< SCIP data structure */
325  SCIP_PROP* prop /**< propagator */
326  )
327 {
328  SCIP_PROPDATA* propdata;
329 
330  assert(scip != NULL);
331  propdata = SCIPpropGetData(prop);
332  assert(propdata != NULL);
333 
334  return propdata->objprop;
335 }
const SCIP_PRESOLTIMING scip_presol_timing_
Definition: objprop.h:86
const SCIP_Bool scip_delay_
Definition: objprop.h:74
static SCIP_DECL_PROPRESPROP(propRespropObj)
Definition: objprop.cpp:254
C++ wrapper for propagators.
Definition: objprop.h:53
SCIP_PROP * SCIPfindProp(SCIP *scip, const char *name)
Definition: scip_prop.c:329
static SCIP_DECL_PROPEXITPRE(propExitpreObj)
Definition: objprop.cpp:165
char * scip_desc_
Definition: objprop.h:65
C++ wrapper for propagators.
static SCIP_DECL_PROPEXITSOL(propExitsolObj)
Definition: objprop.cpp:199
#define TRUE
Definition: def.h:95
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
static SCIP_DECL_PROPCOPY(propCopyObj)
Definition: objprop.cpp:62
const int scip_priority_
Definition: objprop.h:68
const int scip_freq_
Definition: objprop.h:71
char * scip_name_
Definition: objprop.h:62
#define NULL
Definition: lpi_spx1.cpp:164
const SCIP_PROPTIMING scip_timingmask_
Definition: objprop.h:77
static SCIP_DECL_PROPINITPRE(propInitpreObj)
Definition: objprop.cpp:148
scip::ObjProp * SCIPfindObjProp(SCIP *scip, const char *name)
Definition: objprop.cpp:304
#define SCIP_CALL(x)
Definition: def.h:394
SCIP_RETCODE SCIPincludeObjProp(SCIP *scip, scip::ObjProp *objprop, SCIP_Bool deleteobject)
Definition: objprop.cpp:276
#define SCIP_Bool
Definition: def.h:93
static SCIP_DECL_PROPFREE(propFreeObj)
Definition: objprop.cpp:87
const int scip_presol_maxrounds_
Definition: objprop.h:83
const int scip_presol_priority_
Definition: objprop.h:80
static SCIP_DECL_PROPPRESOL(propPresolObj)
Definition: objprop.cpp:216
static SCIP_DECL_PROPINITSOL(propInitsolObj)
Definition: objprop.cpp:182
static SCIP_DECL_PROPINIT(propInitObj)
Definition: objprop.cpp:113
static SCIP_DECL_PROPEXEC(propExecObj)
Definition: objprop.cpp:237
struct SCIP_PropData SCIP_PROPDATA
Definition: type_prop.h:52
SCIP_RETCODE SCIPincludeProp(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_Bool delay, SCIP_PROPTIMING timingmask, int presolpriority, int presolmaxrounds, SCIP_PRESOLTIMING presoltiming, SCIP_DECL_PROPCOPY((*propcopy)), SCIP_DECL_PROPFREE((*propfree)), SCIP_DECL_PROPINIT((*propinit)), SCIP_DECL_PROPEXIT((*propexit)), SCIP_DECL_PROPINITPRE((*propinitpre)), SCIP_DECL_PROPEXITPRE((*propexitpre)), SCIP_DECL_PROPINITSOL((*propinitsol)), SCIP_DECL_PROPEXITSOL((*propexitsol)), SCIP_DECL_PROPPRESOL((*proppresol)), SCIP_DECL_PROPEXEC((*propexec)), SCIP_DECL_PROPRESPROP((*propresprop)), SCIP_PROPDATA *propdata)
Definition: scip_prop.c:62
SCIP_PROPDATA * SCIPpropGetData(SCIP_PROP *prop)
Definition: prop.c:789
void SCIPpropSetData(SCIP_PROP *prop, SCIP_PROPDATA *propdata)
Definition: prop.c:799
scip::ObjProp * SCIPgetObjProp(SCIP *scip, SCIP_PROP *prop)
Definition: objprop.cpp:323
static SCIP_DECL_PROPEXIT(propExitObj)
Definition: objprop.cpp:131