Scippy

SCIP

Solving Constraint Integer Programs

scip_sepa.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_sepa.c
17  * @brief public methods for separator 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/debug.h"
36 #include "scip/pub_message.h"
37 #include "scip/scip_sepa.h"
38 #include "scip/sepa.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 #include "scip/tree.h"
44 
45 /** creates a separator and includes it in SCIP.
46  *
47  * @note method has all separator callbacks as arguments and is thus changed every time a new
48  * callback is added
49  * in future releases; consider using SCIPincludeSepaBasic() and setter functions
50  * if you seek for a method which is less likely to change in future releases
51  */
53  SCIP* scip, /**< SCIP data structure */
54  const char* name, /**< name of separator */
55  const char* desc, /**< description of separator */
56  int priority, /**< priority of separator (>= 0: before, < 0: after constraint handlers) */
57  int freq, /**< frequency for calling separator */
58  SCIP_Real maxbounddist, /**< maximal relative distance from current node's dual bound to primal bound compared
59  * to best node's dual bound for applying separation */
60  SCIP_Bool usessubscip, /**< does the separator use a secondary SCIP instance? */
61  SCIP_Bool delay, /**< should separator be delayed, if other separators found cuts? */
62  SCIP_DECL_SEPACOPY ((*sepacopy)), /**< copy method of separator or NULL if you don't want to copy your plugin into sub-SCIPs */
63  SCIP_DECL_SEPAFREE ((*sepafree)), /**< destructor of separator */
64  SCIP_DECL_SEPAINIT ((*sepainit)), /**< initialize separator */
65  SCIP_DECL_SEPAEXIT ((*sepaexit)), /**< deinitialize separator */
66  SCIP_DECL_SEPAINITSOL ((*sepainitsol)), /**< solving process initialization method of separator */
67  SCIP_DECL_SEPAEXITSOL ((*sepaexitsol)), /**< solving process deinitialization method of separator */
68  SCIP_DECL_SEPAEXECLP ((*sepaexeclp)), /**< LP solution separation method of separator */
69  SCIP_DECL_SEPAEXECSOL ((*sepaexecsol)), /**< arbitrary primal solution separation method of separator */
70  SCIP_SEPADATA* sepadata /**< separator data */
71  )
72 {
73  SCIP_SEPA* sepa;
74 
75  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeSepa", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
76 
77  /* check whether separator is already present */
78  if( SCIPfindSepa(scip, name) != NULL )
79  {
80  SCIPerrorMessage("separator <%s> already included.\n", name);
81  return SCIP_INVALIDDATA;
82  }
83 
84  SCIP_CALL( SCIPsepaCreate(&sepa, scip->set, scip->messagehdlr, scip->mem->setmem,
85  name, desc, priority, freq, maxbounddist, usessubscip, delay,
86  sepacopy, sepafree, sepainit, sepaexit, sepainitsol, sepaexitsol, sepaexeclp, sepaexecsol, sepadata) );
87  SCIP_CALL( SCIPsetIncludeSepa(scip->set, sepa) );
88 
89  return SCIP_OKAY;
90 }
91 
92 /** creates a separator and includes it in SCIP with its most fundamental callbacks. All non-fundamental
93  * (or optional) callbacks as, e.g., init and exit callbacks, will be set to NULL.
94  * Optional callbacks can be set via specific setter functions, see SCIPsetSepaInit(), SCIPsetSepaFree(),
95  * SCIPsetSepaInitsol(), SCIPsetSepaExitsol(), SCIPsetSepaCopy(), SCIPsetExit().
96  *
97  * @note if you want to set all callbacks with a single method call, consider using SCIPincludeSepa() instead
98  */
100  SCIP* scip, /**< SCIP data structure */
101  SCIP_SEPA** sepa, /**< reference to a separator, or NULL */
102  const char* name, /**< name of separator */
103  const char* desc, /**< description of separator */
104  int priority, /**< priority of separator (>= 0: before, < 0: after constraint handlers) */
105  int freq, /**< frequency for calling separator */
106  SCIP_Real maxbounddist, /**< maximal relative distance from current node's dual bound to primal bound compared
107  * to best node's dual bound for applying separation */
108  SCIP_Bool usessubscip, /**< does the separator use a secondary SCIP instance? */
109  SCIP_Bool delay, /**< should separator be delayed, if other separators found cuts? */
110  SCIP_DECL_SEPAEXECLP ((*sepaexeclp)), /**< LP solution separation method of separator */
111  SCIP_DECL_SEPAEXECSOL ((*sepaexecsol)), /**< arbitrary primal solution separation method of separator */
112  SCIP_SEPADATA* sepadata /**< separator data */
113  )
114 {
115  SCIP_SEPA* sepaptr;
116 
117  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeSepaBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
118 
119  /* check whether separator is already present */
120  if( SCIPfindSepa(scip, name) != NULL )
121  {
122  SCIPerrorMessage("separator <%s> already included.\n", name);
123  return SCIP_INVALIDDATA;
124  }
125 
126  SCIP_CALL( SCIPsepaCreate(&sepaptr, scip->set, scip->messagehdlr, scip->mem->setmem,
127  name, desc, priority, freq, maxbounddist, usessubscip, delay,
128  NULL, NULL, NULL, NULL, NULL, NULL, sepaexeclp, sepaexecsol, sepadata) );
129 
130  assert(sepaptr != NULL);
131 
132  SCIP_CALL( SCIPsetIncludeSepa(scip->set, sepaptr) );
133 
134  if( sepa != NULL)
135  *sepa = sepaptr;
136 
137  return SCIP_OKAY;
138 }
139 
140 /** sets copy method of separator */
142  SCIP* scip, /**< SCIP data structure */
143  SCIP_SEPA* sepa, /**< separator */
144  SCIP_DECL_SEPACOPY ((*sepacopy)) /**< copy method of separator or NULL if you don't want to copy your plugin into sub-SCIPs */
145  )
146 {
147  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetSepaCopy", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
148 
149  assert(sepa != NULL);
150 
151  SCIPsepaSetCopy(sepa, sepacopy);
152 
153  return SCIP_OKAY;
154 }
155 
156 /** sets destructor method of separator */
158  SCIP* scip, /**< SCIP data structure */
159  SCIP_SEPA* sepa, /**< separator */
160  SCIP_DECL_SEPAFREE ((*sepafree)) /**< destructor of separator */
161  )
162 {
163  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetSepaFree", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
164 
165  assert(sepa != NULL);
166 
167  SCIPsepaSetFree(sepa, sepafree);
168 
169  return SCIP_OKAY;
170 }
171 
172 /** sets initialization method of separator */
174  SCIP* scip, /**< SCIP data structure */
175  SCIP_SEPA* sepa, /**< separator */
176  SCIP_DECL_SEPAINIT ((*sepainit)) /**< initialize separator */
177  )
178 {
179  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetSepaInit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
180 
181  assert(sepa != NULL);
182 
183  SCIPsepaSetInit(sepa, sepainit);
184 
185  return SCIP_OKAY;
186 }
187 
188 /** sets deinitialization method of separator */
190  SCIP* scip, /**< SCIP data structure */
191  SCIP_SEPA* sepa, /**< separator */
192  SCIP_DECL_SEPAEXIT ((*sepaexit)) /**< deinitialize separator */
193  )
194 {
195  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetSepaExit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
196 
197  assert(sepa != NULL);
198 
199  SCIPsepaSetExit(sepa, sepaexit);
200 
201  return SCIP_OKAY;
202 }
203 
204 /** sets solving process initialization method of separator */
206  SCIP* scip, /**< SCIP data structure */
207  SCIP_SEPA* sepa, /**< separator */
208  SCIP_DECL_SEPAINITSOL ((*sepainitsol)) /**< solving process initialization method of separator */
209  )
210 {
211  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetSepaInitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
212 
213  assert(sepa != NULL);
214 
215  SCIPsepaSetInitsol(sepa, sepainitsol);
216 
217  return SCIP_OKAY;
218 }
219 
220 /** sets solving process deinitialization method of separator */
222  SCIP* scip, /**< SCIP data structure */
223  SCIP_SEPA* sepa, /**< separator */
224  SCIP_DECL_SEPAEXITSOL ((*sepaexitsol)) /**< solving process deinitialization method of separator */
225  )
226 {
227  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetSepaExitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
228 
229  assert(sepa != NULL);
230 
231  SCIPsepaSetExitsol(sepa, sepaexitsol);
232 
233  return SCIP_OKAY;
234 }
235 
236 /** returns the separator of the given name, or NULL if not existing */
238  SCIP* scip, /**< SCIP data structure */
239  const char* name /**< name of separator */
240  )
241 {
242  assert(scip != NULL);
243  assert(scip->set != NULL);
244  assert(name != NULL);
245 
246  return SCIPsetFindSepa(scip->set, name);
247 }
248 
249 /** returns the array of currently available separators */
251  SCIP* scip /**< SCIP data structure */
252  )
253 {
254  assert(scip != NULL);
255  assert(scip->set != NULL);
256 
257  SCIPsetSortSepas(scip->set);
258 
259  return scip->set->sepas;
260 }
261 
262 /** returns the number of currently available separators */
264  SCIP* scip /**< SCIP data structure */
265  )
266 {
267  assert(scip != NULL);
268  assert(scip->set != NULL);
269 
270  return scip->set->nsepas;
271 }
272 
273 /** sets the priority of a separator */
275  SCIP* scip, /**< SCIP data structure */
276  SCIP_SEPA* sepa, /**< separator */
277  int priority /**< new priority of the separator */
278  )
279 {
280  assert(scip != NULL);
281  assert(scip->set != NULL);
282 
283  SCIPsepaSetPriority(sepa, scip->set, priority);
284 
285  return SCIP_OKAY;
286 }
287 
288 #undef SCIPgetSepaMinEfficacy
289 
290 /** gets value of minimal efficacy for a cut to enter the LP
291  *
292  * @pre This method can be called if @p scip is in one of the following stages:
293  * - \ref SCIP_STAGE_SOLVING
294  *
295  * @return value of "separating/minefficacyroot" if at root node, otherwise value of "separating/minefficacy"
296  */
298  SCIP* scip /**< SCIP data structure */
299  )
300 {
301  assert(scip != NULL);
302  assert(scip->tree != NULL);
303  assert(scip->set != NULL);
304 
305  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetSepaMinEfficacy", FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
306 
307  if( SCIPtreeGetCurrentDepth(scip->tree) != 0 )
308  return scip->set->sepa_minefficacyroot;
309  return scip->set->sepa_minefficacy;
310 }
void SCIPsepaSetFree(SCIP_SEPA *sepa, SCIP_DECL_SEPAFREE((*sepafree)))
Definition: sepa.c:641
internal methods for separators
SCIP_Real sepa_minefficacyroot
Definition: struct_set.h:497
#define NULL
Definition: def.h:253
SCIP_Real SCIPgetSepaMinEfficacy(SCIP *scip)
Definition: scip_sepa.c:297
internal methods for branch and bound tree
#define FALSE
Definition: def.h:73
SCIP_SEPA ** sepas
Definition: struct_set.h:77
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_Real sepa_minefficacy
Definition: struct_set.h:496
int SCIPtreeGetCurrentDepth(SCIP_TREE *tree)
Definition: tree.c:8307
void SCIPsepaSetExit(SCIP_SEPA *sepa, SCIP_DECL_SEPAEXIT((*sepaexit)))
Definition: sepa.c:663
SCIP_RETCODE SCIPsetSepaCopy(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPACOPY((*sepacopy)))
Definition: scip_sepa.c:141
SCIP_RETCODE SCIPsetSepaPriority(SCIP *scip, SCIP_SEPA *sepa, int priority)
Definition: scip_sepa.c:274
#define SCIP_DECL_SEPAEXECLP(x)
Definition: type_sepa.h:116
public methods for separator plugins
SCIP_RETCODE SCIPsetIncludeSepa(SCIP_SET *set, SCIP_SEPA *sepa)
Definition: set.c:4121
SCIP_RETCODE SCIPsetSepaInit(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAINIT((*sepainit)))
Definition: scip_sepa.c:173
#define SCIP_DECL_SEPACOPY(x)
Definition: type_sepa.h:47
SCIP_MEM * mem
Definition: struct_scip.h:61
SCIP_SEPA * SCIPfindSepa(SCIP *scip, const char *name)
Definition: scip_sepa.c:237
#define SCIPerrorMessage
Definition: pub_message.h:45
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
SCIP_SEPA * SCIPsetFindSepa(SCIP_SET *set, const char *name)
Definition: set.c:4145
void SCIPsepaSetExitsol(SCIP_SEPA *sepa, SCIP_DECL_SEPAEXITSOL((*sepaexitsol)))
Definition: sepa.c:685
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
SCIP_RETCODE SCIPsetSepaExit(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAEXIT((*sepaexit)))
Definition: scip_sepa.c:189
SCIP_RETCODE SCIPincludeSepa(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_Real maxbounddist, SCIP_Bool usessubscip, SCIP_Bool delay, SCIP_DECL_SEPACOPY((*sepacopy)), SCIP_DECL_SEPAFREE((*sepafree)), SCIP_DECL_SEPAINIT((*sepainit)), SCIP_DECL_SEPAEXIT((*sepaexit)), SCIP_DECL_SEPAINITSOL((*sepainitsol)), SCIP_DECL_SEPAEXITSOL((*sepaexitsol)), SCIP_DECL_SEPAEXECLP((*sepaexeclp)), SCIP_DECL_SEPAEXECSOL((*sepaexecsol)), SCIP_SEPADATA *sepadata)
Definition: scip_sepa.c:52
int nsepas
Definition: struct_set.h:110
int SCIPgetNSepas(SCIP *scip)
Definition: scip_sepa.c:263
void SCIPsepaSetCopy(SCIP_SEPA *sepa, SCIP_DECL_SEPACOPY((*sepacopy)))
Definition: sepa.c:630
void SCIPsepaSetInitsol(SCIP_SEPA *sepa, SCIP_DECL_SEPAINITSOL((*sepainitsol)))
Definition: sepa.c:674
#define SCIP_Bool
Definition: def.h:70
#define SCIP_DECL_SEPAINIT(x)
Definition: type_sepa.h:63
SCIP_RETCODE SCIPincludeSepaBasic(SCIP *scip, SCIP_SEPA **sepa, const char *name, const char *desc, int priority, int freq, SCIP_Real maxbounddist, SCIP_Bool usessubscip, SCIP_Bool delay, SCIP_DECL_SEPAEXECLP((*sepaexeclp)), SCIP_DECL_SEPAEXECSOL((*sepaexecsol)), SCIP_SEPADATA *sepadata)
Definition: scip_sepa.c:99
SCIP_SEPA ** SCIPgetSepas(SCIP *scip)
Definition: scip_sepa.c:250
methods for debugging
datastructures for block memory pools and memory buffers
SCIP_RETCODE SCIPsetSepaInitsol(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAINITSOL((*sepainitsol)))
Definition: scip_sepa.c:205
#define SCIP_DECL_SEPAEXITSOL(x)
Definition: type_sepa.h:93
#define SCIP_DECL_SEPAEXECSOL(x)
Definition: type_sepa.h:140
void SCIPsepaSetPriority(SCIP_SEPA *sepa, SCIP_SET *set, int priority)
Definition: sepa.c:726
#define SCIP_DECL_SEPAEXIT(x)
Definition: type_sepa.h:71
#define SCIP_DECL_SEPAINITSOL(x)
Definition: type_sepa.h:82
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:65
#define SCIP_Real
Definition: def.h:164
SCIP_TREE * tree
Definition: struct_scip.h:84
SCIP_RETCODE SCIPsetSepaExitsol(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAEXITSOL((*sepaexitsol)))
Definition: scip_sepa.c:221
void SCIPsepaSetInit(SCIP_SEPA *sepa, SCIP_DECL_SEPAINIT((*sepainit)))
Definition: sepa.c:652
SCIP_RETCODE SCIPsetSepaFree(SCIP *scip, SCIP_SEPA *sepa, SCIP_DECL_SEPAFREE((*sepafree)))
Definition: scip_sepa.c:157
#define SCIP_CALL_ABORT(x)
Definition: def.h:344
void SCIPsetSortSepas(SCIP_SET *set)
Definition: set.c:4165
datastructures for global SCIP settings
#define SCIP_DECL_SEPAFREE(x)
Definition: type_sepa.h:55
struct SCIP_SepaData SCIP_SEPADATA
Definition: type_sepa.h:38
SCIP_RETCODE SCIPsepaCreate(SCIP_SEPA **sepa, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, int priority, int freq, SCIP_Real maxbounddist, SCIP_Bool usessubscip, SCIP_Bool delay, SCIP_DECL_SEPACOPY((*sepacopy)), SCIP_DECL_SEPAFREE((*sepafree)), SCIP_DECL_SEPAINIT((*sepainit)), SCIP_DECL_SEPAEXIT((*sepaexit)), SCIP_DECL_SEPAINITSOL((*sepainitsol)), SCIP_DECL_SEPAEXITSOL((*sepaexitsol)), SCIP_DECL_SEPAEXECLP((*sepaexeclp)), SCIP_DECL_SEPAEXECSOL((*sepaexecsol)), SCIP_SEPADATA *sepadata)
Definition: sepa.c:187