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-2019 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 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, presolFreeObj, presolInitObj, presolExitObj,
219  presolInitpreObj, presolExitpreObj, presolExecObj,
220  presoldata) ); /*lint !e429*/
221 
222  return SCIP_OKAY; /*lint !e429*/
223 }
224 
225 /** returns the presol object of the given name, or 0 if not existing */
227  SCIP* scip, /**< SCIP data structure */
228  const char* name /**< name of presolver */
229  )
230 {
231  SCIP_PRESOL* presol;
232  SCIP_PRESOLDATA* presoldata;
233 
234  presol = SCIPfindPresol(scip, name);
235  if( presol == NULL )
236  return 0;
237 
238  presoldata = SCIPpresolGetData(presol);
239  assert(presoldata != NULL);
240 
241  return presoldata->objpresol;
242 }
243 
244 /** returns the presol object for the given presolver */
246  SCIP* scip, /**< SCIP data structure */
247  SCIP_PRESOL* presol /**< presolver */
248  )
249 {
250  SCIP_PRESOLDATA* presoldata;
251 
252  presoldata = SCIPpresolGetData(presol);
253  assert(presoldata != NULL);
254 
255  return presoldata->objpresol;
256 }
static SCIP_DECL_PRESOLEXEC(presolExecObj)
Definition: objpresol.cpp:173
struct SCIP_PresolData SCIP_PRESOLDATA
Definition: type_presol.h:37
#define NULL
Definition: def.h:246
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
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
#define TRUE
Definition: def.h:71
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_PRESOLDATA * SCIPpresolGetData(SCIP_PRESOL *presol)
Definition: presol.c:502
static SCIP_DECL_PRESOLEXITPRE(presolExitpreObj)
Definition: objpresol.cpp:156
const SCIP_PRESOLTIMING scip_timing_
Definition: objpresol.h:64
char * scip_desc_
Definition: objpresol.h:55
char * scip_name_
Definition: objpresol.h:52
static SCIP_DECL_PRESOLINITPRE(presolInitpreObj)
Definition: objpresol.cpp:139
scip::ObjPresol * SCIPfindObjPresol(SCIP *scip, const char *name)
Definition: objpresol.cpp:226
void SCIPpresolSetData(SCIP_PRESOL *presol, SCIP_PRESOLDATA *presoldata)
Definition: presol.c:512
SCIP_PRESOL * SCIPfindPresol(SCIP *scip, const char *name)
Definition: scip_presol.c:305
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_presol.c:131
const int scip_maxrounds_
Definition: objpresol.h:61
#define SCIP_CALL(x)
Definition: def.h:358
#define SCIP_Bool
Definition: def.h:69
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:245