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-2022 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 #include "scip/struct_stat.h"
45 
46 /** creates a presolver and includes it in SCIP.
47  *
48  * @note method has all presolver callbacks as arguments and is thus changed every time a new
49  * callback is added
50  * in future releases; consider using SCIPincludePresolBasic() and setter functions
51  * if you seek for a method which is less likely to change in future releases
52  */
54  SCIP* scip, /**< SCIP data structure */
55  const char* name, /**< name of presolver */
56  const char* desc, /**< description of presolver */
57  int priority, /**< priority of the presolver (>= 0: before, < 0: after constraint handlers) */
58  int maxrounds, /**< maximal number of presolving rounds the presolver participates in (-1: no limit) */
59  SCIP_PRESOLTIMING timing, /**< timing mask of the presolver */
60  SCIP_DECL_PRESOLCOPY ((*presolcopy)), /**< copy method of presolver or NULL if you don't want to copy your plugin into sub-SCIPs */
61  SCIP_DECL_PRESOLFREE ((*presolfree)), /**< destructor of presolver to free user data (called when SCIP is exiting) */
62  SCIP_DECL_PRESOLINIT ((*presolinit)), /**< initialization method of presolver (called after problem was transformed) */
63  SCIP_DECL_PRESOLEXIT ((*presolexit)), /**< deinitialization method of presolver (called before transformed problem is freed) */
64  SCIP_DECL_PRESOLINITPRE((*presolinitpre)),/**< presolving initialization method of presolver (called when presolving is about to begin) */
65  SCIP_DECL_PRESOLEXITPRE((*presolexitpre)),/**< presolving deinitialization method of presolver (called after presolving has been finished) */
66  SCIP_DECL_PRESOLEXEC ((*presolexec)), /**< execution method of presolver */
67  SCIP_PRESOLDATA* presoldata /**< presolver data */
68  )
69 {
70  SCIP_PRESOL* presol;
71 
72  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludePresol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
73 
74  /* check whether presolver is already present */
75  if( SCIPfindPresol(scip, name) != NULL )
76  {
77  SCIPerrorMessage("presolver <%s> already included.\n", name);
78  return SCIP_INVALIDDATA;
79  }
80 
81  SCIP_CALL( SCIPpresolCreate(&presol, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority,
82  maxrounds, timing, presolcopy,
83  presolfree, presolinit, presolexit, presolinitpre, presolexitpre, presolexec, presoldata) );
84  SCIP_CALL( SCIPsetIncludePresol(scip->set, presol) );
85 
86  return SCIP_OKAY;
87 }
88 
89 /** creates a presolver and includes it in SCIP with its fundamental callback. All non-fundamental (or optional)
90  * callbacks as, e.g., init and exit callbacks, will be set to NULL. Optional callbacks can be set via specific setter
91  * functions. These are SCIPsetPresolCopy(), SCIPsetPresolFree(), SCIPsetPresolInit(), SCIPsetPresolExit(),
92  * SCIPsetPresolInitpre(), and SCIPsetPresolExitPre().
93  *
94  * @note if you want to set all callbacks with a single method call, consider using SCIPincludePresol() instead
95  */
97  SCIP* scip, /**< SCIP data structure */
98  SCIP_PRESOL** presolptr, /**< reference to presolver, or NULL */
99  const char* name, /**< name of presolver */
100  const char* desc, /**< description of presolver */
101  int priority, /**< priority of the presolver (>= 0: before, < 0: after constraint handlers) */
102  int maxrounds, /**< maximal number of presolving rounds the presolver participates in (-1: no limit) */
103  SCIP_PRESOLTIMING timing, /**< timing mask of the presolver */
104  SCIP_DECL_PRESOLEXEC ((*presolexec)), /**< execution method of presolver */
105  SCIP_PRESOLDATA* presoldata /**< presolver data */
106  )
107 {
108  SCIP_PRESOL* presol;
109 
110  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludePresolBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
111 
112  /* check whether presolver is already present */
113  if( SCIPfindPresol(scip, name) != NULL )
114  {
115  SCIPerrorMessage("presolver <%s> already included.\n", name);
116  return SCIP_INVALIDDATA;
117  }
118 
119  SCIP_CALL( SCIPpresolCreate(&presol, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority, maxrounds, timing,
120  NULL,
121  NULL, NULL, NULL, NULL, NULL, presolexec, presoldata) );
122  SCIP_CALL( SCIPsetIncludePresol(scip->set, presol) );
123 
124  if( presolptr != NULL )
125  *presolptr = presol;
126 
127  return SCIP_OKAY;
128 }
129 
130 /** sets copy method of presolver */
132  SCIP* scip, /**< SCIP data structure */
133  SCIP_PRESOL* presol, /**< presolver */
134  SCIP_DECL_PRESOLCOPY ((*presolcopy)) /**< copy method of presolver or NULL if you don't want to copy your plugin into sub-SCIPs */
135  )
136 {
137  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolCopy", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
138 
139  assert(presol != NULL);
140 
141  SCIPpresolSetCopy(presol, presolcopy);
142 
143  return SCIP_OKAY;
144 }
145 
146 /** sets destructor method of presolver */
148  SCIP* scip, /**< SCIP data structure */
149  SCIP_PRESOL* presol, /**< presolver */
150  SCIP_DECL_PRESOLFREE ((*presolfree)) /**< destructor of presolver */
151  )
152 {
153  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolFree", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
154 
155  assert(presol != NULL);
156 
157  SCIPpresolSetFree(presol, presolfree);
158 
159  return SCIP_OKAY;
160 }
161 
162 /** sets initialization method of presolver */
164  SCIP* scip, /**< SCIP data structure */
165  SCIP_PRESOL* presol, /**< presolver */
166  SCIP_DECL_PRESOLINIT ((*presolinit)) /**< initialize presolver */
167  )
168 {
169  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolInit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
170 
171  assert(presol != NULL);
172 
173  SCIPpresolSetInit(presol, presolinit);
174 
175  return SCIP_OKAY;
176 }
177 
178 /** sets deinitialization method of presolver */
180  SCIP* scip, /**< SCIP data structure */
181  SCIP_PRESOL* presol, /**< presolver */
182  SCIP_DECL_PRESOLEXIT ((*presolexit)) /**< deinitialize presolver */
183  )
184 {
185  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolExit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
186 
187  assert(presol != NULL);
188 
189  SCIPpresolSetExit(presol, presolexit);
190 
191  return SCIP_OKAY;
192 }
193 
194 /** sets solving process initialization method of presolver */
196  SCIP* scip, /**< SCIP data structure */
197  SCIP_PRESOL* presol, /**< presolver */
198  SCIP_DECL_PRESOLINITPRE ((*presolinitpre))/**< solving process initialization method of presolver */
199  )
200 {
201  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolInitpre", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
202 
203  assert(presol != NULL);
204 
205  SCIPpresolSetInitpre(presol, presolinitpre);
206 
207  return SCIP_OKAY;
208 }
209 
210 /** sets solving process deinitialization method of presolver */
212  SCIP* scip, /**< SCIP data structure */
213  SCIP_PRESOL* presol, /**< presolver */
214  SCIP_DECL_PRESOLEXITPRE ((*presolexitpre))/**< solving process deinitialization method of presolver */
215  )
216 {
217  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetPresolExitpre", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
218 
219  assert(presol != NULL);
220 
221  SCIPpresolSetExitpre(presol, presolexitpre);
222 
223  return SCIP_OKAY;
224 }
225 
226 /** returns the presolver of the given name, or NULL if not existing */
228  SCIP* scip, /**< SCIP data structure */
229  const char* name /**< name of presolver */
230  )
231 {
232  assert(scip != NULL);
233  assert(scip->set != NULL);
234  assert(name != NULL);
235 
236  return SCIPsetFindPresol(scip->set, name);
237 }
238 
239 /** returns the array of currently available presolvers */
241  SCIP* scip /**< SCIP data structure */
242  )
243 {
244  assert(scip != NULL);
245  assert(scip->set != NULL);
246 
247  SCIPsetSortPresols(scip->set);
248 
249  return scip->set->presols;
250 }
251 
252 /** returns the number of currently available presolvers */
254  SCIP* scip /**< SCIP data structure */
255  )
256 {
257  assert(scip != NULL);
258  assert(scip->set != NULL);
259 
260  return scip->set->npresols;
261 }
262 
263 /** sets the priority of a presolver */
265  SCIP* scip, /**< SCIP data structure */
266  SCIP_PRESOL* presol, /**< presolver */
267  int priority /**< new priority of the presolver */
268  )
269 {
270  assert(scip != NULL);
271  assert(scip->set != NULL);
272 
273  SCIPpresolSetPriority(presol, scip->set, priority);
274 
275  return SCIP_OKAY;
276 }
277 
278 /** returns the number of presolve rounds (current or last presolve) */
280  SCIP* scip /**< SCIP data structure */
281 )
282 {
283  assert(scip != NULL);
284  assert(scip->stat != NULL);
285 
286  return scip->stat->npresolrounds;
287 }
SCIP_RETCODE SCIPsetIncludePresol(SCIP_SET *set, SCIP_PRESOL *presol)
Definition: set.c:4094
SCIP_STAT * stat
Definition: struct_scip.h:70
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:96
struct SCIP_PresolData SCIP_PRESOLDATA
Definition: type_presol.h:42
SCIP_RETCODE SCIPsetPresolFree(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLFREE((*presolfree)))
Definition: scip_presol.c:147
SCIP_RETCODE SCIPsetPresolExit(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLEXIT((*presolexit)))
Definition: scip_presol.c:179
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:87
#define SCIP_DECL_PRESOLCOPY(x)
Definition: type_presol.h:51
public methods for presolving plugins
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_PRESOL * SCIPsetFindPresol(SCIP_SET *set, const char *name)
Definition: set.c:4117
int SCIPgetNPresols(SCIP *scip)
Definition: scip_presol.c:253
SCIP_PRESOL ** presols
Definition: struct_set.h:77
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:2177
internal methods for presolvers
SCIP_RETCODE SCIPsetPresolInit(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLINIT((*presolinit)))
Definition: scip_presol.c:163
SCIP_PRESOL * SCIPfindPresol(SCIP *scip, const char *name)
Definition: scip_presol.c: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_presol.c:53
#define NULL
Definition: lpi_spx1.cpp:155
SCIP_RETCODE SCIPsetPresolPriority(SCIP *scip, SCIP_PRESOL *presol, int priority)
Definition: scip_presol.c:264
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:384
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 SCIPsetPresolInitpre(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLINITPRE((*presolinitpre)))
Definition: scip_presol.c:195
#define SCIP_DECL_PRESOLEXITPRE(x)
Definition: type_presol.h:107
void SCIPpresolSetFree(SCIP_PRESOL *presol, SCIP_DECL_PRESOLFREE((*presolfree)))
Definition: presol.c:535
int npresolrounds
Definition: struct_stat.h:233
#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
void SCIPpresolSetExit(SCIP_PRESOL *presol, SCIP_DECL_PRESOLEXIT((*presolexit)))
Definition: presol.c:557
datastructures for problem statistics
int SCIPgetNPresolRounds(SCIP *scip)
Definition: scip_presol.c:279
SCIP_PRESOL ** SCIPgetPresols(SCIP *scip)
Definition: scip_presol.c:240
void SCIPsetSortPresols(SCIP_SET *set)
Definition: set.c:4137
SCIP_RETCODE SCIPsetPresolCopy(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLCOPY((*presolcopy)))
Definition: scip_presol.c:131
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
int npresols
Definition: struct_set.h:115
datastructures for global SCIP settings
SCIP_RETCODE SCIPsetPresolExitpre(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLEXITPRE((*presolexitpre)))
Definition: scip_presol.c:211
void SCIPpresolSetExitpre(SCIP_PRESOL *presol, SCIP_DECL_PRESOLEXITPRE((*presolexitpre)))
Definition: presol.c:579