Scippy

SCIP

Solving Constraint Integer Programs

scip_compr.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-2025 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_compr.c
26 * @ingroup OTHER_CFILES
27 * @brief public methods for compression 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/compr.h"
46#include "scip/debug.h"
47#include "scip/pub_message.h"
48#include "scip/scip_compr.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
54/** creates a tree compression and includes it in SCIP.
55 *
56 * @pre This method can be called if SCIP is in one of the following stages:
57 * - \ref SCIP_STAGE_INIT
58 * - \ref SCIP_STAGE_PROBLEM
59 *
60 * @note method has all compression callbacks as arguments and is thus changed every time a new
61 * callback is added in future releases; consider using SCIPincludeComprBasic() and setter functions
62 * if you seek for a method which is less likely to change in future releases
63 */
65 SCIP* scip, /**< SCIP data structure */
66 const char* name, /**< name of tree compression */
67 const char* desc, /**< description of tree compression */
68 int priority, /**< priority of the tree compression */
69 int minnnodes, /**< minimal number of nodes to call compression */
70 SCIP_DECL_COMPRCOPY ((*comprcopy)), /**< copy method of tree compression or NULL if you don't want to copy your plugin into sub-SCIPs */
71 SCIP_DECL_COMPRFREE ((*comprfree)), /**< destructor of tree compression */
72 SCIP_DECL_COMPRINIT ((*comprinit)), /**< initialize tree compression */
73 SCIP_DECL_COMPREXIT ((*comprexit)), /**< deinitialize tree compression */
74 SCIP_DECL_COMPRINITSOL ((*comprinitsol)), /**< solving process initialization method of tree compression */
75 SCIP_DECL_COMPREXITSOL ((*comprexitsol)), /**< solving process deinitialization method of tree compression */
76 SCIP_DECL_COMPREXEC ((*comprexec)), /**< execution method of tree compression */
77 SCIP_COMPRDATA* comprdata /**< tree compression data */
78 )
79{
80 SCIP_COMPR* compr;
81
83
84 /* check whether compression is already present */
85 if( SCIPfindCompr(scip, name) != NULL )
86 {
87 SCIPerrorMessage("compression <%s> already included.\n", name);
88 return SCIP_INVALIDDATA;
89 }
90
91 SCIP_CALL( SCIPcomprCreate(&compr, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority, minnnodes,
92 comprcopy, comprfree, comprinit, comprexit, comprinitsol, comprexitsol, comprexec, comprdata) );
93
94 SCIP_CALL( SCIPsetIncludeCompr(scip->set, compr) );
95
96 return SCIP_OKAY;
97}
98
99/** creates a tree compression and includes it in SCIP with its most fundamental callbacks.
100 * All non-fundamental (or optional) callbacks
101 * as, e. g., init and exit callbacks, will be set to NULL.
102 * Optional callbacks can be set via specific setter functions, see SCIPsetComprCopy(), SCIPsetComprFree(),
103 * SCIPsetComprInit(), SCIPsetComprExit(), SCIPsetComprInitsol(), and SCIPsetComprExitsol()
104 *
105 * @pre This method can be called if SCIP is in one of the following stages:
106 * - \ref SCIP_STAGE_INIT
107 * - \ref SCIP_STAGE_PROBLEM
108 *
109 * @note if you want to set all callbacks with a single method call, consider using SCIPincludeCompr() instead
110 */
112 SCIP* scip, /**< SCIP data structure */
113 SCIP_COMPR** compr, /**< pointer to tree compression */
114 const char* name, /**< name of tree compression */
115 const char* desc, /**< description of tree compression */
116 int priority, /**< priority of the tree compression */
117 int minnnodes, /**< minimal number of nodes to call the compression */
118 SCIP_DECL_COMPREXEC ((*comprexec)), /**< execution method of tree compression */
119 SCIP_COMPRDATA* comprdata /**< tree compression data */
120 )
121{
122 SCIP_COMPR* comprptr;
123
124 SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeComprBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
125
126 /* check whether heuristic is already present */
127 if( SCIPfindCompr(scip, name) != NULL )
128 {
129 SCIPerrorMessage("tree compression <%s> already included.\n", name);
130 return SCIP_INVALIDDATA;
131 }
132
133 SCIP_CALL( SCIPcomprCreate(&comprptr, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority,
134 minnnodes, NULL, NULL, NULL, NULL, NULL, NULL, comprexec, comprdata) );
135
136 assert(comprptr != NULL);
137
138 SCIP_CALL( SCIPsetIncludeCompr(scip->set, comprptr) );
139
140 if( compr != NULL )
141 *compr = comprptr;
142
143 return SCIP_OKAY;
144}
145
146/* new callback/method setter methods */
147
148/** sets copy method of tree compression */
150 SCIP* scip, /**< SCIP data structure */
151 SCIP_COMPR* compr, /**< tree compression */
152 SCIP_DECL_COMPRCOPY ((*comprcopy)) /**< copy method of tree compression or NULL if you don't want to copy your plugin into sub-SCIPs */
153 )
154{
156
157 assert(compr != NULL);
158
159 SCIPcomprSetCopy(compr, comprcopy);
160
161 return SCIP_OKAY;
162}
163
164/** sets destructor method of tree compression */
166 SCIP* scip, /**< SCIP data structure */
167 SCIP_COMPR* compr, /**< tree compression */
168 SCIP_DECL_COMPRFREE ((*comprfree)) /**< destructor of tree compression */
169 )
170{
172
173 assert(compr != NULL);
174
175 SCIPcomprSetFree(compr, comprfree);
176
177 return SCIP_OKAY;
178}
179
180/** sets initialization method of tree compression */
182 SCIP* scip, /**< SCIP data structure */
183 SCIP_COMPR* compr, /**< tree compression */
184 SCIP_DECL_COMPRINIT ((*comprinit)) /**< initialize tree compression */
185 )
186{
188
189 assert(compr != NULL);
190
191 SCIPcomprSetInit(compr, comprinit);
192
193 return SCIP_OKAY;
194}
195
196/** sets deinitialization method of tree compression */
198 SCIP* scip, /**< SCIP data structure */
199 SCIP_COMPR* compr, /**< tree compression */
200 SCIP_DECL_COMPREXIT ((*comprexit)) /**< deinitialize tree compression */
201 )
202{
204
205 assert(compr != NULL);
206
207 SCIPcomprSetExit(compr, comprexit);
208
209 return SCIP_OKAY;
210}
211
212/** sets solving process initialization method of tree compression */
214 SCIP* scip, /**< SCIP data structure */
215 SCIP_COMPR* compr, /**< tree compression */
216 SCIP_DECL_COMPRINITSOL ((*comprinitsol)) /**< solving process initialization method of tree compression */
217 )
218{
220
221 assert(compr != NULL);
222
223 SCIPcomprSetInitsol(compr, comprinitsol);
224
225 return SCIP_OKAY;
226}
227
228/** sets solving process deinitialization method of tree compression */
230 SCIP* scip, /**< SCIP data structure */
231 SCIP_COMPR* compr, /**< tree compression */
232 SCIP_DECL_COMPREXITSOL ((*comprexitsol)) /**< solving process deinitialization method of tree compression */
233 )
234{
236
237 assert(compr != NULL);
238
239 SCIPcomprSetExitsol(compr, comprexitsol);
240
241 return SCIP_OKAY;
242}
243
244/** returns the tree compression of the given name, or NULL if not existing */
246 SCIP* scip, /**< SCIP data structure */
247 const char* name /**< name of tree compression */
248 )
249{
250 assert(scip != NULL);
251 assert(scip->set != NULL);
252 assert(name != NULL);
253
254 return SCIPsetFindCompr(scip->set, name);
255}
256
257/** returns the array of currently available tree compression */
259 SCIP* scip /**< SCIP data structure */
260 )
261{
262 assert(scip != NULL);
263 assert(scip->set != NULL);
264
266
267 return scip->set->comprs;
268}
269
270/** returns the number of currently available tree compression */
272 SCIP* scip /**< SCIP data structure */
273 )
274{
275 assert(scip != NULL);
276 assert(scip->set != NULL);
277
278 return scip->set->ncomprs;
279}
280
281/** set the priority of a tree compression method */
283 SCIP* scip, /**< SCIP data structure */
284 SCIP_COMPR* compr, /**< compression */
285 int priority /**< new priority of the tree compression */
286 )
287{
288 assert(scip != NULL);
289 assert(scip->set != NULL);
290
291 SCIPcomprSetPriority(compr, scip->set, priority);
292
293 return SCIP_OKAY;
294}
void SCIPcomprSetExitsol(SCIP_COMPR *compr, SCIP_DECL_COMPREXITSOL((*comprexitsol)))
Definition: compr.c:431
void SCIPcomprSetCopy(SCIP_COMPR *compr, SCIP_DECL_COMPRCOPY((*comprcopy)))
Definition: compr.c:376
void SCIPcomprSetPriority(SCIP_COMPR *compr, SCIP_SET *set, int priority)
Definition: compr.c:486
void SCIPcomprSetInitsol(SCIP_COMPR *compr, SCIP_DECL_COMPRINITSOL((*comprinitsol)))
Definition: compr.c:420
void SCIPcomprSetFree(SCIP_COMPR *compr, SCIP_DECL_COMPRFREE((*comprfree)))
Definition: compr.c:387
void SCIPcomprSetInit(SCIP_COMPR *compr, SCIP_DECL_COMPRINIT((*comprinit)))
Definition: compr.c:398
SCIP_RETCODE SCIPcomprCreate(SCIP_COMPR **compr, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, int priority, int minnnodes, SCIP_DECL_COMPRCOPY((*comprcopy)), SCIP_DECL_COMPRFREE((*comprfree)), SCIP_DECL_COMPRINIT((*comprinit)), SCIP_DECL_COMPREXIT((*comprexit)), SCIP_DECL_COMPRINITSOL((*comprinitsol)), SCIP_DECL_COMPREXITSOL((*comprexitsol)), SCIP_DECL_COMPREXEC((*comprexec)), SCIP_COMPRDATA *comprdata)
Definition: compr.c:170
void SCIPcomprSetExit(SCIP_COMPR *compr, SCIP_DECL_COMPREXIT((*comprexit)))
Definition: compr.c:409
internal methods for tree compressions
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:2203
methods for debugging
#define NULL
Definition: def.h:266
#define TRUE
Definition: def.h:93
#define FALSE
Definition: def.h:94
#define SCIP_CALL(x)
Definition: def.h:373
SCIP_RETCODE SCIPsetComprExit(SCIP *scip, SCIP_COMPR *compr, SCIP_DECL_COMPREXIT((*comprexit)))
Definition: scip_compr.c:197
SCIP_RETCODE SCIPsetComprExitsol(SCIP *scip, SCIP_COMPR *compr, SCIP_DECL_COMPREXITSOL((*comprexitsol)))
Definition: scip_compr.c:229
SCIP_RETCODE SCIPsetComprCopy(SCIP *scip, SCIP_COMPR *compr, SCIP_DECL_COMPRCOPY((*comprcopy)))
Definition: scip_compr.c:149
SCIP_RETCODE SCIPsetComprInitsol(SCIP *scip, SCIP_COMPR *compr, SCIP_DECL_COMPRINITSOL((*comprinitsol)))
Definition: scip_compr.c:213
SCIP_RETCODE SCIPsetComprFree(SCIP *scip, SCIP_COMPR *compr, SCIP_DECL_COMPRFREE((*comprfree)))
Definition: scip_compr.c:165
SCIP_RETCODE SCIPsetComprPriority(SCIP *scip, SCIP_COMPR *compr, int priority)
Definition: scip_compr.c:282
SCIP_RETCODE SCIPincludeCompr(SCIP *scip, const char *name, const char *desc, int priority, int minnnodes, SCIP_DECL_COMPRCOPY((*comprcopy)), SCIP_DECL_COMPRFREE((*comprfree)), SCIP_DECL_COMPRINIT((*comprinit)), SCIP_DECL_COMPREXIT((*comprexit)), SCIP_DECL_COMPRINITSOL((*comprinitsol)), SCIP_DECL_COMPREXITSOL((*comprexitsol)), SCIP_DECL_COMPREXEC((*comprexec)), SCIP_COMPRDATA *comprdata)
Definition: scip_compr.c:64
SCIP_RETCODE SCIPincludeComprBasic(SCIP *scip, SCIP_COMPR **compr, const char *name, const char *desc, int priority, int minnnodes, SCIP_DECL_COMPREXEC((*comprexec)), SCIP_COMPRDATA *comprdata)
Definition: scip_compr.c:111
int SCIPgetNCompr(SCIP *scip)
Definition: scip_compr.c:271
SCIP_COMPR * SCIPfindCompr(SCIP *scip, const char *name)
Definition: scip_compr.c:245
SCIP_RETCODE SCIPsetComprInit(SCIP *scip, SCIP_COMPR *compr, SCIP_DECL_COMPRINIT((*comprinit)))
Definition: scip_compr.c:181
SCIP_COMPR ** SCIPgetComprs(SCIP *scip)
Definition: scip_compr.c:258
public methods for message output
#define SCIPerrorMessage
Definition: pub_message.h:64
public methods for compression plugins
SCIP_COMPR * SCIPsetFindCompr(SCIP_SET *set, const char *name)
Definition: set.c:4679
void SCIPsetSortComprs(SCIP_SET *set)
Definition: set.c:4699
SCIP_RETCODE SCIPsetIncludeCompr(SCIP_SET *set, SCIP_COMPR *compr)
Definition: set.c:4655
internal methods for global SCIP settings
datastructures for block memory pools and memory buffers
SCIP main data structure.
datastructures for global SCIP settings
#define SCIP_DECL_COMPREXITSOL(x)
Definition: type_compr.h:104
struct SCIP_ComprData SCIP_COMPRDATA
Definition: type_compr.h:49
#define SCIP_DECL_COMPRFREE(x)
Definition: type_compr.h:66
#define SCIP_DECL_COMPREXEC(x)
Definition: type_compr.h:120
#define SCIP_DECL_COMPREXIT(x)
Definition: type_compr.h:82
#define SCIP_DECL_COMPRINIT(x)
Definition: type_compr.h:74
#define SCIP_DECL_COMPRINITSOL(x)
Definition: type_compr.h:93
#define SCIP_DECL_COMPRCOPY(x)
Definition: type_compr.h:58
@ SCIP_INVALIDDATA
Definition: type_retcode.h:52
@ SCIP_OKAY
Definition: type_retcode.h:42
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63