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