Scippy

SCIP

Solving Constraint Integer Programs

objpresol.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 objpresol.cpp
17  * @brief C++ wrapper for presolvers
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 "objpresol.h"
26 
27 
28 
29 
30 /*
31  * Data structures
32  */
33 
34 /** presolver data */
35 struct SCIP_PresolData
36 {
37  scip::ObjPresol* objpresol; /**< presolver object */
38  SCIP_Bool deleteobject; /**< should the presolver object be deleted when presolver is freed? */
39 };
40 
41 
42 
43 
44 /*
45  * Callback methods of presolver
46  */
47 
48 extern "C"
49 {
50 
51 /** copy method for presolver plugins (called when SCIP copies plugins) */
52 static
53 SCIP_DECL_PRESOLCOPY(presolCopyObj)
54 { /*lint --e{715}*/
55  SCIP_PRESOLDATA* presoldata;
56 
57  assert(scip != NULL);
58 
59  presoldata = SCIPpresolGetData(presol);
60  assert(presoldata != NULL);
61  assert(presoldata->objpresol != NULL);
62  assert(presoldata->objpresol->scip_ != scip);
63 
64  if( presoldata->objpresol->iscloneable() )
65  {
66  scip::ObjPresol* newobjpresol;
67  newobjpresol = dynamic_cast<scip::ObjPresol*> (presoldata->objpresol->clone(scip));
68 
69  /* call include method of presolver object */
70  SCIP_CALL( SCIPincludeObjPresol(scip, newobjpresol, TRUE) );
71  }
72 
73  return SCIP_OKAY;
74 }
75 
76 /** destructor of presolver to free user data (called when SCIP is exiting) */
77 static
78 SCIP_DECL_PRESOLFREE(presolFreeObj)
79 { /*lint --e{715}*/
80  SCIP_PRESOLDATA* presoldata;
81 
82  presoldata = SCIPpresolGetData(presol);
83  assert(presoldata != NULL);
84  assert(presoldata->objpresol != NULL);
85  assert(presoldata->objpresol->scip_ == scip);
86 
87  /* call virtual method of presol object */
88  SCIP_CALL( presoldata->objpresol->scip_free(scip, presol) );
89 
90  /* free presol object */
91  if( presoldata->deleteobject )
92  delete presoldata->objpresol;
93 
94  /* free presol data */
95  delete presoldata;
96  SCIPpresolSetData(presol, NULL); /*lint !e64*/
97 
98  return SCIP_OKAY;
99 }
100 
101 
102 /** initialization method of presolver (called after problem was transformed) */
103 static
104 SCIP_DECL_PRESOLINIT(presolInitObj)
105 { /*lint --e{715}*/
106  SCIP_PRESOLDATA* presoldata;
107 
108  presoldata = SCIPpresolGetData(presol);
109  assert(presoldata != NULL);
110  assert(presoldata->objpresol != NULL);
111  assert(presoldata->objpresol->scip_ == scip);
112 
113  /* call virtual method of presol object */
114  SCIP_CALL( presoldata->objpresol->scip_init(scip, presol) );
115 
116  return SCIP_OKAY;
117 }
118 
119 
120 /** deinitialization method of presolver (called before transformed problem is freed) */
121 static
122 SCIP_DECL_PRESOLEXIT(presolExitObj)
123 { /*lint --e{715}*/
124  SCIP_PRESOLDATA* presoldata;
125 
126  presoldata = SCIPpresolGetData(presol);
127  assert(presoldata != NULL);
128  assert(presoldata->objpresol != NULL);
129 
130  /* call virtual method of presol object */
131  SCIP_CALL( presoldata->objpresol->scip_exit(scip, presol) );
132 
133  return SCIP_OKAY;
134 }
135 
136 
137 /** presolving initialization method of presolver (called when presolving is about to begin) */
138 static
139 SCIP_DECL_PRESOLINITPRE(presolInitpreObj)
140 { /*lint --e{715}*/
141  SCIP_PRESOLDATA* presoldata;
142 
143  presoldata = SCIPpresolGetData(presol);
144  assert(presoldata != NULL);
145  assert(presoldata->objpresol != NULL);
146 
147  /* call virtual method of presol object */
148  SCIP_CALL( presoldata->objpresol->scip_initpre(scip, presol) );
149 
150  return SCIP_OKAY;
151 }
152 
153 
154 /** presolving deinitialization method of presolver (called after presolving has been finished) */
155 static
156 SCIP_DECL_PRESOLEXITPRE(presolExitpreObj)
157 { /*lint --e{715}*/
158  SCIP_PRESOLDATA* presoldata;
159 
160  presoldata = SCIPpresolGetData(presol);
161  assert(presoldata != NULL);
162  assert(presoldata->objpresol != NULL);
163 
164  /* call virtual method of presol object */
165  SCIP_CALL( presoldata->objpresol->scip_exitpre(scip, presol) );
166 
167  return SCIP_OKAY;
168 }
169 
170 
171 /** execution method of presolver */
172 static
173 SCIP_DECL_PRESOLEXEC(presolExecObj)
174 { /*lint --e{715}*/
175  SCIP_PRESOLDATA* presoldata;
176 
177  presoldata = SCIPpresolGetData(presol);
178  assert(presoldata != NULL);
179  assert(presoldata->objpresol != NULL);
180 
181  /* call virtual method of presol object */
182  SCIP_CALL( presoldata->objpresol->scip_exec(scip, presol, nrounds, presoltiming,
183  nnewfixedvars, nnewaggrvars, nnewchgvartypes, nnewchgbds, nnewholes,
184  nnewdelconss, nnewaddconss, nnewupgdconss, nnewchgcoefs, nnewchgsides,
185  nfixedvars, naggrvars, nchgvartypes, nchgbds, naddholes,
186  ndelconss, naddconss, nupgdconss, nchgcoefs, nchgsides, result) );
187 
188  return SCIP_OKAY;
189 }
190 }
191 
192 
193 
194 /*
195  * presolver specific interface methods
196  */
197 
198 /** creates the presolver for the given presolver object and includes it in SCIP */
200  SCIP* scip, /**< SCIP data structure */
201  scip::ObjPresol* objpresol, /**< presolver object */
202  SCIP_Bool deleteobject /**< should the presolver object be deleted when presolver is freed? */
203  )
204 {
205  SCIP_PRESOLDATA* presoldata;
206 
207  assert(scip != NULL);
208  assert(objpresol != NULL);
209 
210  /* create presolver data */
211  presoldata = new SCIP_PRESOLDATA;
212  presoldata->objpresol = objpresol;
213  presoldata->deleteobject = deleteobject;
214 
215  /* include presolver */
216  SCIP_CALL( SCIPincludePresol(scip, objpresol->scip_name_, objpresol->scip_desc_,
217  objpresol->scip_priority_, objpresol->scip_maxrounds_, objpresol->scip_timing_,
218  presolCopyObj,
219  presolFreeObj, presolInitObj, presolExitObj,
220  presolInitpreObj, presolExitpreObj, presolExecObj,
221  presoldata) ); /*lint !e429*/
222 
223  return SCIP_OKAY; /*lint !e429*/
224 }
225 
226 /** returns the presol object of the given name, or 0 if not existing */
228  SCIP* scip, /**< SCIP data structure */
229  const char* name /**< name of presolver */
230  )
231 {
232  SCIP_PRESOL* presol;
233  SCIP_PRESOLDATA* presoldata;
234 
235  presol = SCIPfindPresol(scip, name);
236  if( presol == NULL )
237  return 0;
238 
239  presoldata = SCIPpresolGetData(presol);
240  assert(presoldata != NULL);
241 
242  return presoldata->objpresol;
243 }
244 
245 /** returns the presol object for the given presolver */
247  SCIP* scip, /**< SCIP data structure */
248  SCIP_PRESOL* presol /**< presolver */
249  )
250 {
251  SCIP_PRESOLDATA* presoldata;
252 
253  presoldata = SCIPpresolGetData(presol);
254  assert(presoldata != NULL);
255 
256  return presoldata->objpresol;
257 }
void SCIPpresolSetData(SCIP_PRESOL *presol, SCIP_PRESOLDATA *presoldata)
Definition: presol.c:476
static SCIP_DECL_PRESOLEXEC(presolExecObj)
Definition: objpresol.cpp:173
struct SCIP_PresolData SCIP_PRESOLDATA
Definition: type_presol.h:37
SCIP_RETCODE SCIPincludeObjPresol(SCIP *scip, scip::ObjPresol *objpresol, SCIP_Bool deleteobject)
Definition: objpresol.cpp:199
C++ wrapper for presolvers.
static SCIP_DECL_PRESOLFREE(presolFreeObj)
Definition: objpresol.cpp:78
#define NULL
Definition: lpi_spx.cpp:130
const int scip_priority_
Definition: objpresol.h:58
static SCIP_DECL_PRESOLEXIT(presolExitObj)
Definition: objpresol.cpp:122
C++ wrapper for presolvers.
Definition: objpresol.h:43
const unsigned int scip_timing_
Definition: objpresol.h:64
#define TRUE
Definition: def.h:55
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIP_CALL(x)
Definition: def.h:266
static SCIP_DECL_PRESOLEXITPRE(presolExitpreObj)
Definition: objpresol.cpp:156
char * scip_desc_
Definition: objpresol.h:55
char * scip_name_
Definition: objpresol.h:52
static SCIP_DECL_PRESOLINITPRE(presolInitpreObj)
Definition: objpresol.cpp:139
SCIP_PRESOLDATA * SCIPpresolGetData(SCIP_PRESOL *presol)
Definition: presol.c:466
scip::ObjPresol * SCIPfindObjPresol(SCIP *scip, const char *name)
Definition: objpresol.cpp:227
SCIP_RETCODE SCIPincludePresol(SCIP *scip, const char *name, const char *desc, int priority, int maxrounds, SCIP_PRESOLTIMING timing, SCIP_DECL_PRESOLCOPY((*presolcopy)), SCIP_DECL_PRESOLFREE((*presolfree)), SCIP_DECL_PRESOLINIT((*presolinit)), SCIP_DECL_PRESOLEXIT((*presolexit)), SCIP_DECL_PRESOLINITPRE((*presolinitpre)), SCIP_DECL_PRESOLEXITPRE((*presolexitpre)), SCIP_DECL_PRESOLEXEC((*presolexec)), SCIP_PRESOLDATA *presoldata)
Definition: scip.c:6148
SCIP_PRESOL * SCIPfindPresol(SCIP *scip, const char *name)
Definition: scip.c:6322
const int scip_maxrounds_
Definition: objpresol.h:61
#define SCIP_Bool
Definition: def.h:53
static SCIP_DECL_PRESOLINIT(presolInitObj)
Definition: objpresol.cpp:104
static SCIP_DECL_PRESOLCOPY(presolCopyObj)
Definition: objpresol.cpp:53
scip::ObjPresol * SCIPgetObjPresol(SCIP *scip, SCIP_PRESOL *presol)
Definition: objpresol.cpp:246