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