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