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