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