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