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