Scippy

SCIP

Solving Constraint Integer Programs

scip_presol.c
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-2020 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 scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_presol.c
17  * @ingroup OTHER_CFILES
18  * @brief public methods for presolving plugins
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Gerald Gamrath
22  * @author Leona Gottwald
23  * @author Stefan Heinz
24  * @author Gregor Hendel
25  * @author Thorsten Koch
26  * @author Alexander Martin
27  * @author Marc Pfetsch
28  * @author Michael Winkler
29  * @author Kati Wolter
30  *
31  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #include "scip/debug.h"
37 #include "scip/presol.h"
38 #include "scip/pub_message.h"
39 #include "scip/scip_presol.h"
40 #include "scip/set.h"
41 #include "scip/struct_mem.h"
42 #include "scip/struct_scip.h"
43 #include "scip/struct_set.h"
44 
45 /** creates a presolver and includes it in SCIP.
46  *
47  * @note method has all presolver callbacks as arguments and is thus changed every time a new
48  * callback is added
49  * in future releases; consider using SCIPincludePresolBasic() and setter functions
50  * if you seek for a method which is less likely to change in future releases
51  */
53  SCIP* scip, /**< SCIP data structure */
54  const char* name, /**< name of presolver */
55  const char* desc, /**< description of presolver */
56  int priority, /**< priority of the presolver (>= 0: before, < 0: after constraint handlers) */
57  int maxrounds, /**< maximal number of presolving rounds the presolver participates in (-1: no limit) */
58  SCIP_PRESOLTIMING timing, /**< timing mask of the presolver */
59  SCIP_DECL_PRESOLCOPY ((*presolcopy)), /**< copy method of presolver or NULL if you don't want to copy your plugin into sub-SCIPs */
60  SCIP_DECL_PRESOLFREE ((*presolfree)), /**< destructor of presolver to free user data (called when SCIP is exiting) */
61  SCIP_DECL_PRESOLINIT ((*presolinit)), /**< initialization method of presolver (called after problem was transformed) */
62  SCIP_DECL_PRESOLEXIT ((*presolexit)), /**< deinitialization method of presolver (called before transformed problem is freed) */
63  SCIP_DECL_PRESOLINITPRE((*presolinitpre)),/**< presolving initialization method of presolver (called when presolving is about to begin) */
64  SCIP_DECL_PRESOLEXITPRE((*presolexitpre)),/**< presolving deinitialization method of presolver (called after presolving has been finished) */
65  SCIP_DECL_PRESOLEXEC ((*presolexec)), /**< execution method of presolver */
66  SCIP_PRESOLDATA* presoldata /**< presolver data */
67  )
68 {
69  SCIP_PRESOL* presol;
70 
71  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludePresol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
72 
73  /* check whether presolver is already present */
74  if( SCIPfindPresol(scip, name) != NULL )
75  {
76  SCIPerrorMessage("presolver <%s> already included.\n", name);
77  return SCIP_INVALIDDATA;
78  }
79 
80  SCIP_CALL( SCIPpresolCreate(&presol, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority,
81  maxrounds, timing, presolcopy,
82  presolfree, presolinit, presolexit, presolinitpre, presolexitpre, presolexec, presoldata) );
83  SCIP_CALL( SCIPsetIncludePresol(scip->set, presol) );
84 
85  return SCIP_OKAY;
86 }
87 
88 /** creates a presolver and includes it in SCIP with its fundamental callback. All non-fundamental (or optional)
89  * callbacks as, e.g., init and exit callbacks, will be set to NULL. Optional callbacks can be set via specific setter
90  * functions. These are SCIPsetPresolCopy(), SCIPsetPresolFree(), SCIPsetPresolInit(), SCIPsetPresolExit(),
91  * SCIPsetPresolInitpre(), and SCIPsetPresolExitPre().
92  *
93  * @note if you want to set all callbacks with a single method call, consider using SCIPincludePresol() instead
94  */
96  SCIP* scip, /**< SCIP data structure */
97  SCIP_PRESOL** presolptr, /**< reference to presolver, or NULL */
98  const char* name, /**< name of presolver */
99  const char* desc, /**< description of presolver */
100  int priority, /**< priority of the presolver (>= 0: before, < 0: after constraint handlers) */
101  int maxrounds, /**< maximal number of presolving rounds the presolver participates in (-1: no limit) */
102  SCIP_PRESOLTIMING timing, /**< timing mask of the presolver */
103  SCIP_DECL_PRESOLEXEC ((*presolexec)), /**< execution method of presolver */
104  SCIP_PRESOLDATA* presoldata /**< presolver data */
105  )
106 {
107  SCIP_PRESOL* presol;
108 
109  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludePresolBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
110 
111  /* check whether presolver is already present */
112  if( SCIPfindPresol(scip, name) != NULL )
113  {
114  SCIPerrorMessage("presolver <%s> already included.\n", name);
115  return SCIP_INVALIDDATA;
116  }
117 
118  SCIP_CALL( SCIPpresolCreate(&presol, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority, maxrounds, timing,
119  NULL,
120  NULL, NULL, NULL, NULL, NULL, presolexec, presoldata) );
121  SCIP_CALL( SCIPsetIncludePresol(scip->set, presol) );
122 
123  if( presolptr != NULL )
124  *presolptr = presol;
125 
126  return SCIP_OKAY;
127 }
128 
129 /** sets copy method of presolver */
131  SCIP* scip, /**< SCIP data structure */
132  SCIP_PRESOL* presol, /**< presolver */
133  SCIP_DECL_PRESOLCOPY ((*presolcopy)) /**< copy method of presolver or NULL if you don't want to copy your plugin into sub-SCIPs */
134  )
135 {
136  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolCopy", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
137 
138  assert(presol != NULL);
139 
140  SCIPpresolSetCopy(presol, presolcopy);
141 
142  return SCIP_OKAY;
143 }
144 
145 /** sets destructor method of presolver */
147  SCIP* scip, /**< SCIP data structure */
148  SCIP_PRESOL* presol, /**< presolver */
149  SCIP_DECL_PRESOLFREE ((*presolfree)) /**< destructor of presolver */
150  )
151 {
152  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolFree", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
153 
154  assert(presol != NULL);
155 
156  SCIPpresolSetFree(presol, presolfree);
157 
158  return SCIP_OKAY;
159 }
160 
161 /** sets initialization method of presolver */
163  SCIP* scip, /**< SCIP data structure */
164  SCIP_PRESOL* presol, /**< presolver */
165  SCIP_DECL_PRESOLINIT ((*presolinit)) /**< initialize presolver */
166  )
167 {
168  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolInit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
169 
170  assert(presol != NULL);
171 
172  SCIPpresolSetInit(presol, presolinit);
173 
174  return SCIP_OKAY;
175 }
176 
177 /** sets deinitialization method of presolver */
179  SCIP* scip, /**< SCIP data structure */
180  SCIP_PRESOL* presol, /**< presolver */
181  SCIP_DECL_PRESOLEXIT ((*presolexit)) /**< deinitialize presolver */
182  )
183 {
184  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolExit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
185 
186  assert(presol != NULL);
187 
188  SCIPpresolSetExit(presol, presolexit);
189 
190  return SCIP_OKAY;
191 }
192 
193 /** sets solving process initialization method of presolver */
195  SCIP* scip, /**< SCIP data structure */
196  SCIP_PRESOL* presol, /**< presolver */
197  SCIP_DECL_PRESOLINITPRE ((*presolinitpre))/**< solving process initialization method of presolver */
198  )
199 {
200  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolInitpre", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
201 
202  assert(presol != NULL);
203 
204  SCIPpresolSetInitpre(presol, presolinitpre);
205 
206  return SCIP_OKAY;
207 }
208 
209 /** sets solving process deinitialization method of presolver */
211  SCIP* scip, /**< SCIP data structure */
212  SCIP_PRESOL* presol, /**< presolver */
213  SCIP_DECL_PRESOLEXITPRE ((*presolexitpre))/**< solving process deinitialization method of presolver */
214  )
215 {
216  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolExitpre", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
217 
218  assert(presol != NULL);
219 
220  SCIPpresolSetExitpre(presol, presolexitpre);
221 
222  return SCIP_OKAY;
223 }
224 
225 /** returns the presolver of the given name, or NULL if not existing */
227  SCIP* scip, /**< SCIP data structure */
228  const char* name /**< name of presolver */
229  )
230 {
231  assert(scip != NULL);
232  assert(scip->set != NULL);
233  assert(name != NULL);
234 
235  return SCIPsetFindPresol(scip->set, name);
236 }
237 
238 /** returns the array of currently available presolvers */
240  SCIP* scip /**< SCIP data structure */
241  )
242 {
243  assert(scip != NULL);
244  assert(scip->set != NULL);
245 
246  SCIPsetSortPresols(scip->set);
247 
248  return scip->set->presols;
249 }
250 
251 /** returns the number of currently available presolvers */
253  SCIP* scip /**< SCIP data structure */
254  )
255 {
256  assert(scip != NULL);
257  assert(scip->set != NULL);
258 
259  return scip->set->npresols;
260 }
261 
262 /** sets the priority of a presolver */
264  SCIP* scip, /**< SCIP data structure */
265  SCIP_PRESOL* presol, /**< presolver */
266  int priority /**< new priority of the presolver */
267  )
268 {
269  assert(scip != NULL);
270  assert(scip->set != NULL);
271 
272  SCIPpresolSetPriority(presol, scip->set, priority);
273 
274  return SCIP_OKAY;
275 }
SCIP_RETCODE SCIPsetIncludePresol(SCIP_SET *set, SCIP_PRESOL *presol)
Definition: set.c:4051
SCIP_RETCODE SCIPsetPresolInitpre(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLINITPRE((*presolinitpre)))
Definition: scip_presol.c:194
struct SCIP_PresolData SCIP_PRESOLDATA
Definition: type_presol.h:42
void SCIPpresolSetPriority(SCIP_PRESOL *presol, SCIP_SET *set, int priority)
Definition: presol.c:630
#define SCIP_DECL_PRESOLINITPRE(x)
Definition: type_presol.h:89
#define FALSE
Definition: def.h:73
#define SCIP_DECL_PRESOLCOPY(x)
Definition: type_presol.h:51
public methods for presolving plugins
SCIP_PRESOL * SCIPfindPresol(SCIP *scip, const char *name)
Definition: scip_presol.c:226
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_PRESOL * SCIPsetFindPresol(SCIP_SET *set, const char *name)
Definition: set.c:4074
SCIP_RETCODE SCIPsetPresolExit(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLEXIT((*presolexit)))
Definition: scip_presol.c:178
SCIP_PRESOL ** presols
Definition: struct_set.h:75
SCIP_RETCODE SCIPsetPresolPriority(SCIP *scip, SCIP_PRESOL *presol, int priority)
Definition: scip_presol.c:263
SCIP_PRESOL ** SCIPgetPresols(SCIP *scip)
Definition: scip_presol.c:239
SCIP_RETCODE SCIPpresolCreate(SCIP_PRESOL **presol, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, 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: presol.c:171
#define SCIP_DECL_PRESOLEXEC(x)
Definition: type_presol.h:158
SCIP_MEM * mem
Definition: struct_scip.h:62
#define SCIPerrorMessage
Definition: pub_message.h:55
#define SCIP_DECL_PRESOLFREE(x)
Definition: type_presol.h:59
#define SCIP_DECL_PRESOLEXIT(x)
Definition: type_presol.h:75
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:2025
internal methods for presolvers
#define NULL
Definition: lpi_spx1.cpp:155
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:364
unsigned int SCIP_PRESOLTIMING
Definition: type_timing.h:52
SCIP main data structure.
BMS_BLKMEM * setmem
Definition: struct_mem.h:39
void SCIPpresolSetInitpre(SCIP_PRESOL *presol, SCIP_DECL_PRESOLINITPRE((*presolinitpre)))
Definition: presol.c:568
SCIP_RETCODE SCIPsetPresolCopy(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLCOPY((*presolcopy)))
Definition: scip_presol.c:130
#define SCIP_DECL_PRESOLEXITPRE(x)
Definition: type_presol.h:107
void SCIPpresolSetFree(SCIP_PRESOL *presol, SCIP_DECL_PRESOLFREE((*presolfree)))
Definition: presol.c:535
SCIP_RETCODE SCIPsetPresolInit(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLINIT((*presolinit)))
Definition: scip_presol.c:162
#define SCIP_DECL_PRESOLINIT(x)
Definition: type_presol.h:67
methods for debugging
datastructures for block memory pools and memory buffers
void SCIPpresolSetInit(SCIP_PRESOL *presol, SCIP_DECL_PRESOLINIT((*presolinit)))
Definition: presol.c:546
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:52
void SCIPpresolSetExit(SCIP_PRESOL *presol, SCIP_DECL_PRESOLEXIT((*presolexit)))
Definition: presol.c:557
SCIP_RETCODE SCIPsetPresolFree(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLFREE((*presolfree)))
Definition: scip_presol.c:146
int SCIPgetNPresols(SCIP *scip)
Definition: scip_presol.c:252
void SCIPsetSortPresols(SCIP_SET *set)
Definition: set.c:4094
SCIP_SET * set
Definition: struct_scip.h:63
public methods for message output
void SCIPpresolSetCopy(SCIP_PRESOL *presol, SCIP_DECL_PRESOLCOPY((*presolcopy)))
Definition: presol.c:524
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:66
SCIP_RETCODE SCIPincludePresolBasic(SCIP *scip, SCIP_PRESOL **presolptr, const char *name, const char *desc, int priority, int maxrounds, SCIP_PRESOLTIMING timing, SCIP_DECL_PRESOLEXEC((*presolexec)), SCIP_PRESOLDATA *presoldata)
Definition: scip_presol.c:95
int npresols
Definition: struct_set.h:106
datastructures for global SCIP settings
SCIP_RETCODE SCIPsetPresolExitpre(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLEXITPRE((*presolexitpre)))
Definition: scip_presol.c:210
void SCIPpresolSetExitpre(SCIP_PRESOL *presol, SCIP_DECL_PRESOLEXITPRE((*presolexitpre)))
Definition: presol.c:579