Scippy

SCIP

Solving Constraint Integer Programs

scip_cutsel.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-2022 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_cutsel.c
17  * @ingroup OTHER_CFILES
18  * @brief public methods for cut selector plugins
19  * @author Felipe Serrano
20  * @author Mark Turner
21  *
22  */
23 
24 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
25 
26 #include "scip/debug.h"
27 #include "scip/cutsel.h"
28 #include "scip/pub_message.h"
29 #include "scip/scip_cutsel.h"
30 #include "scip/set.h"
31 #include "scip/struct_mem.h"
32 #include "scip/struct_scip.h"
33 #include "scip/struct_set.h"
34 
35 /** creates a cut selector and includes it in SCIP
36  *
37  * @note this method has all cut selector callbacks as arguments and is thus changed every time a new
38  * callback is added in future releases; consider using SCIPincludeCutselBasic() and setter functions
39  * if you seek for a method which is less likely to change in future releases
40  */
42  SCIP* scip, /**< SCIP data structure */
43  const char* name, /**< name of cut selector */
44  const char* desc, /**< description of cut selector */
45  int priority, /**< priority of the cut selector */
46  SCIP_DECL_CUTSELCOPY ((*cutselcopy)), /**< copy method of cut selector or NULL if you don't want to copy your plugin into sub-SCIPs */
47  SCIP_DECL_CUTSELFREE ((*cutselfree)), /**< destructor of cut selector */
48  SCIP_DECL_CUTSELINIT ((*cutselinit)), /**< initialize cut selector */
49  SCIP_DECL_CUTSELEXIT ((*cutselexit)), /**< deinitialize cut selector */
50  SCIP_DECL_CUTSELINITSOL((*cutselinitsol)),/**< solving process initialization method of cut selector */
51  SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)),/**< solving process deinitialization method of cut selector */
52  SCIP_DECL_CUTSELSELECT((*cutselselect)), /**< cut selection method */
53  SCIP_CUTSELDATA* cutseldata /**< cut selector data */
54  )
55 {
56  SCIP_CUTSEL* cutsel;
57 
58  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeCutsel", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
59 
60  /* check whether cut selector is already present */
61  if( SCIPfindCutsel(scip, name) != NULL )
62  {
63  SCIPerrorMessage("cut selector <%s> already included.\n", name);
64  return SCIP_INVALIDDATA;
65  }
66 
67  SCIP_CALL( SCIPcutselCreate(&cutsel, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority,
68  cutselcopy, cutselfree, cutselinit, cutselexit, cutselinitsol, cutselexitsol,
69  cutselselect, cutseldata) );
70  SCIP_CALL( SCIPsetIncludeCutsel(scip->set, cutsel) );
71 
72  return SCIP_OKAY;
73 }
74 
75 /** Creates a cut selector and includes it in SCIP with its most fundamental callbacks.
76  *
77  * All non-fundamental (or optional) callbacks as, e.g., init and exit callbacks, will be set to NULL. Optional
78  * callbacks can be set via specific setter functions, see SCIPsetCutselCopy(), SCIPsetCutselFree(),
79  * SCIPsetCutselInit(), SCIPsetCutselExit(), SCIPsetCutselInitsol(), and SCIPsetCutselExitsol()
80  *
81  * @note if you want to set all callbacks with a single method call, consider using SCIPincludeCutsel() instead
82  */
84  SCIP* scip, /**< SCIP data structure */
85  SCIP_CUTSEL** cutsel, /**< reference to a cut selector, or NULL */
86  const char* name, /**< name of cut selector */
87  const char* desc, /**< description of cut selector */
88  int priority, /**< priority of the cut selector in standard mode */
89  SCIP_DECL_CUTSELSELECT((*cutselselect)), /**< cut selection method */
90  SCIP_CUTSELDATA* cutseldata /**< cut selector data */
91  )
92 {
93  SCIP_CUTSEL* cutselptr;
94 
95  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeCutselBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
96 
97  /* check whether cut selector is already present */
98  if( SCIPfindCutsel(scip, name) != NULL )
99  {
100  SCIPerrorMessage("cut selector <%s> already included.\n", name);
101  return SCIP_INVALIDDATA;
102  }
103 
104  SCIP_CALL( SCIPcutselCreate(&cutselptr, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority,
105  NULL, NULL, NULL, NULL, NULL, NULL,
106  cutselselect, cutseldata) );
107  SCIP_CALL( SCIPsetIncludeCutsel(scip->set, cutselptr) );
108 
109  if( cutsel != NULL )
110  *cutsel = cutselptr;
111 
112  return SCIP_OKAY;
113 }
114 
115 /** sets copy method of cut selector */
117  SCIP* scip, /**< SCIP data structure */
118  SCIP_CUTSEL* cutsel, /**< cut selector */
119  SCIP_DECL_CUTSELCOPY ((*cutselcopy)) /**< copy method of cut selector or NULL if you don't want to copy your plugin into sub-SCIPs */
120  )
121 {
122  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselCopy", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
123 
124  assert(cutsel != NULL);
125 
126  SCIPcutselSetCopy(cutsel, cutselcopy);
127 
128  return SCIP_OKAY;
129 }
130 
131 /** sets destructor method of cut selector */
133  SCIP* scip, /**< SCIP data structure */
134  SCIP_CUTSEL* cutsel, /**< cut selector */
135  SCIP_DECL_CUTSELFREE ((*cutselfree)) /**< destructor of cut selector */
136  )
137 {
138  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselFree", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
139 
140  assert(cutsel != NULL);
141 
142  SCIPcutselSetFree(cutsel, cutselfree);
143 
144  return SCIP_OKAY;
145 }
146 
147 /** sets initialization method of cut selector */
149  SCIP* scip, /**< SCIP data structure */
150  SCIP_CUTSEL* cutsel, /**< cut selector */
151  SCIP_DECL_CUTSELINIT ((*cutselinit)) /**< initialize cut selector */
152  )
153 {
154  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselInit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
155 
156  assert(cutsel != NULL);
157 
158  SCIPcutselSetInit(cutsel, cutselinit);
159 
160  return SCIP_OKAY;
161 }
162 
163 /** sets deinitialization method of cut selector */
165  SCIP* scip, /**< SCIP data structure */
166  SCIP_CUTSEL* cutsel, /**< cut selector */
167  SCIP_DECL_CUTSELEXIT ((*cutselexit)) /**< deinitialize cut selector */
168  )
169 {
170  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselExit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
171 
172  assert(cutsel != NULL);
173 
174  SCIPcutselSetExit(cutsel, cutselexit);
175 
176  return SCIP_OKAY;
177 }
178 
179 /** sets solving process initialization method of cut selector */
181  SCIP* scip, /**< SCIP data structure */
182  SCIP_CUTSEL* cutsel, /**< cut selector */
183  SCIP_DECL_CUTSELINITSOL ((*cutselinitsol))/**< solving process initialization method of cut selector */
184  )
185 {
186  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselInitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
187 
188  assert(cutsel != NULL);
189 
190  SCIPcutselSetInitsol(cutsel, cutselinitsol);
191 
192  return SCIP_OKAY;
193 }
194 
195 /** sets solving process deinitialization method of cut selector */
197  SCIP* scip, /**< SCIP data structure */
198  SCIP_CUTSEL* cutsel, /**< cut selector */
199  SCIP_DECL_CUTSELEXITSOL ((*cutselexitsol))/**< solving process deinitialization method of cut selector */
200  )
201 {
202  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselExitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
203 
204  assert(cutsel != NULL);
205 
206  SCIPcutselSetExitsol(cutsel, cutselexitsol);
207 
208  return SCIP_OKAY;
209 }
210 
211 /** returns the cut selector of the given name, or NULL if not existing */
213  SCIP* scip, /**< SCIP data structure */
214  const char* name /**< name of cut selector */
215  )
216 {
217  assert(scip != NULL);
218  assert(scip->set != NULL);
219  assert(name != NULL);
220 
221  return SCIPsetFindCutsel(scip->set, name);
222 }
223 
224 /** returns the array of currently available cut selectors */
226  SCIP* scip /**< SCIP data structure */
227  )
228 {
229  assert(scip != NULL);
230  assert(scip->set != NULL);
231 
232  SCIPsetSortCutsels(scip->set);
233 
234  return scip->set->cutsels;
235 }
236 
237 /** returns the number of currently available cut selectors */
239  SCIP* scip /**< SCIP data structure */
240  )
241 {
242  assert(scip != NULL);
243  assert(scip->set != NULL);
244 
245  return scip->set->ncutsels;
246 }
247 
248 /** sets the priority of a cut selector */
250  SCIP* scip, /**< SCIP data structure */
251  SCIP_CUTSEL* cutsel, /**< cut selector */
252  int priority /**< new priority of the separator */
253  )
254 {
255  assert(scip != NULL);
256  assert(scip->set != NULL);
257 
258  SCIPcutselSetPriority(cutsel, scip->set, priority);
259 
260  return SCIP_OKAY;
261 }
SCIP_RETCODE SCIPsetCutselExit(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELEXIT((*cutselexit)))
Definition: scip_cutsel.c:164
int SCIPgetNCutsels(SCIP *scip)
Definition: scip_cutsel.c:238
SCIP_CUTSEL ** cutsels
Definition: struct_set.h:80
SCIP_RETCODE SCIPsetCutselInitsol(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELINITSOL((*cutselinitsol)))
Definition: scip_cutsel.c:180
#define SCIP_DECL_CUTSELINITSOL(x)
Definition: type_cutsel.h:88
struct SCIP_CutselData SCIP_CUTSELDATA
Definition: type_cutsel.h:44
SCIP_RETCODE SCIPcutselCreate(SCIP_CUTSEL **cutsel, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, int priority, SCIP_DECL_CUTSELCOPY((*cutselcopy)), SCIP_DECL_CUTSELFREE((*cutselfree)), SCIP_DECL_CUTSELINIT((*cutselinit)), SCIP_DECL_CUTSELEXIT((*cutselexit)), SCIP_DECL_CUTSELINITSOL((*cutselinitsol)), SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)), SCIP_DECL_CUTSELSELECT((*cutselselect)), SCIP_CUTSELDATA *cutseldata)
Definition: cutsel.c:119
void SCIPcutselSetPriority(SCIP_CUTSEL *cutsel, SCIP_SET *set, int priority)
Definition: cutsel.c:521
#define FALSE
Definition: def.h:87
internal methods for cut selectors
void SCIPsetSortCutsels(SCIP_SET *set)
Definition: set.c:4365
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
#define SCIP_DECL_CUTSELEXIT(x)
Definition: type_cutsel.h:77
#define SCIP_DECL_CUTSELSELECT(x)
Definition: type_cutsel.h:123
int ncutsels
Definition: struct_set.h:121
SCIP_CUTSEL ** SCIPgetCutsels(SCIP *scip)
Definition: scip_cutsel.c:225
void SCIPcutselSetCopy(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELCOPY((*cutselcopy)))
Definition: cutsel.c:455
SCIP_MEM * mem
Definition: struct_scip.h:62
SCIP_RETCODE SCIPsetIncludeCutsel(SCIP_SET *set, SCIP_CUTSEL *cutsel)
Definition: set.c:4321
#define SCIPerrorMessage
Definition: pub_message.h:55
SCIP_CUTSEL * SCIPfindCutsel(SCIP *scip, const char *name)
Definition: scip_cutsel.c:212
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:2177
SCIP_RETCODE SCIPsetCutselCopy(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELCOPY((*cutselcopy)))
Definition: scip_cutsel.c:116
#define SCIP_DECL_CUTSELINIT(x)
Definition: type_cutsel.h:69
#define NULL
Definition: lpi_spx1.cpp:155
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:384
void SCIPcutselSetExitsol(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)))
Definition: cutsel.c:510
SCIP main data structure.
BMS_BLKMEM * setmem
Definition: struct_mem.h:39
#define SCIP_DECL_CUTSELCOPY(x)
Definition: type_cutsel.h:53
SCIP_CUTSEL * SCIPsetFindCutsel(SCIP_SET *set, const char *name)
Definition: set.c:4345
SCIP_RETCODE SCIPsetCutselInit(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELINIT((*cutselinit)))
Definition: scip_cutsel.c:148
public methods for cut selector plugins
methods for debugging
datastructures for block memory pools and memory buffers
SCIP_RETCODE SCIPsetCutselPriority(SCIP *scip, SCIP_CUTSEL *cutsel, int priority)
Definition: scip_cutsel.c:249
void SCIPcutselSetFree(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELFREE((*cutselfree)))
Definition: cutsel.c:466
void SCIPcutselSetExit(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELEXIT((*cutselexit)))
Definition: cutsel.c:488
SCIP_RETCODE SCIPincludeCutsel(SCIP *scip, const char *name, const char *desc, int priority, SCIP_DECL_CUTSELCOPY((*cutselcopy)), SCIP_DECL_CUTSELFREE((*cutselfree)), SCIP_DECL_CUTSELINIT((*cutselinit)), SCIP_DECL_CUTSELEXIT((*cutselexit)), SCIP_DECL_CUTSELINITSOL((*cutselinitsol)), SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)), SCIP_DECL_CUTSELSELECT((*cutselselect)), SCIP_CUTSELDATA *cutseldata)
Definition: scip_cutsel.c:41
SCIP_SET * set
Definition: struct_scip.h:63
public methods for message output
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:66
void SCIPcutselSetInit(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELINIT((*cutselinit)))
Definition: cutsel.c:477
#define SCIP_DECL_CUTSELFREE(x)
Definition: type_cutsel.h:61
SCIP_RETCODE SCIPsetCutselFree(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELFREE((*cutselfree)))
Definition: scip_cutsel.c:132
SCIP_RETCODE SCIPsetCutselExitsol(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)))
Definition: scip_cutsel.c:196
#define SCIP_DECL_CUTSELEXITSOL(x)
Definition: type_cutsel.h:99
datastructures for global SCIP settings
void SCIPcutselSetInitsol(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELINITSOL((*cutselinitsol)))
Definition: cutsel.c:499
SCIP_RETCODE SCIPincludeCutselBasic(SCIP *scip, SCIP_CUTSEL **cutsel, const char *name, const char *desc, int priority, SCIP_DECL_CUTSELSELECT((*cutselselect)), SCIP_CUTSELDATA *cutseldata)
Definition: scip_cutsel.c:83