Scippy

SCIP

Solving Constraint Integer Programs

scip_relax.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_relax.c
17  * @brief public methods for relaxator 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/relax.h"
38 #include "scip/scip_relax.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 relaxation handler and includes it in SCIP
45  *
46  * @note method has all relaxation handler callbacks as arguments and is thus changed every time a new
47  * callback is added
48  * in future releases; consider using SCIPincludeRelaxBasic() 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 relaxation handler */
54  const char* desc, /**< description of relaxation handler */
55  int priority, /**< priority of the relaxation handler (negative: after LP, non-negative: before LP) */
56  int freq, /**< frequency for calling relaxation handler */
57  SCIP_DECL_RELAXCOPY ((*relaxcopy)), /**< copy method of relaxation handler or NULL if you don't want to copy your plugin into sub-SCIPs */
58  SCIP_DECL_RELAXFREE ((*relaxfree)), /**< destructor of relaxation handler */
59  SCIP_DECL_RELAXINIT ((*relaxinit)), /**< initialize relaxation handler */
60  SCIP_DECL_RELAXEXIT ((*relaxexit)), /**< deinitialize relaxation handler */
61  SCIP_DECL_RELAXINITSOL((*relaxinitsol)), /**< solving process initialization method of relaxation handler */
62  SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), /**< solving process deinitialization method of relaxation handler */
63  SCIP_DECL_RELAXEXEC ((*relaxexec)), /**< execution method of relaxation handler */
64  SCIP_RELAXDATA* relaxdata /**< relaxation handler data */
65  )
66 {
67  SCIP_RELAX* relax;
68 
69  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeRelax", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
70 
71  /* check whether relaxation handler is already present */
72  if( SCIPfindRelax(scip, name) != NULL )
73  {
74  SCIPerrorMessage("relaxation handler <%s> already included.\n", name);
75  return SCIP_INVALIDDATA;
76  }
77 
78  SCIP_CALL( SCIPrelaxCreate(&relax, scip->set, scip->messagehdlr, scip->mem->setmem,
79  name, desc, priority, freq, relaxcopy,
80  relaxfree, relaxinit, relaxexit, relaxinitsol, relaxexitsol, relaxexec, relaxdata) );
81  SCIP_CALL( SCIPsetIncludeRelax(scip->set, relax) );
82 
83  return SCIP_OKAY;
84 }
85 
86 /** creates a relaxation handler and includes it in SCIP. All non fundamental
87  * (or optional) callbacks as, e.g., init and exit callbacks, will be set to NULL.
88  * Optional callbacks can be set via specific setter functions, see SCIPsetRelaxInit(), SCIPsetRelaxExit(),
89  * SCIPsetRelaxCopy(), SCIPsetRelaxFree(), SCIPsetRelaxInitsol(), and SCIPsetRelaxExitsol()
90  *
91  * @note if you want to set all callbacks with a single method call, consider using SCIPincludeRelax() instead
92  */
94  SCIP* scip, /**< SCIP data structure */
95  SCIP_RELAX** relaxptr, /**< reference to relaxation pointer, or NULL */
96  const char* name, /**< name of relaxation handler */
97  const char* desc, /**< description of relaxation handler */
98  int priority, /**< priority of the relaxation handler (negative: after LP, non-negative: before LP) */
99  int freq, /**< frequency for calling relaxation handler */
100  SCIP_DECL_RELAXEXEC ((*relaxexec)), /**< execution method of relaxation handler */
101  SCIP_RELAXDATA* relaxdata /**< relaxation handler data */
102  )
103 {
104  SCIP_RELAX* relax;
105 
106  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeRelaxBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
107 
108  /* check whether relaxation handler is already present */
109  if( SCIPfindRelax(scip, name) != NULL )
110  {
111  SCIPerrorMessage("relaxation handler <%s> already included.\n", name);
112  return SCIP_INVALIDDATA;
113  }
114 
115  SCIP_CALL( SCIPrelaxCreate(&relax, scip->set, scip->messagehdlr, scip->mem->setmem,
116  name, desc, priority, freq,
117  NULL, NULL, NULL, NULL, NULL, NULL, relaxexec, relaxdata) );
118  SCIP_CALL( SCIPsetIncludeRelax(scip->set, relax) );
119 
120  if( relaxptr != NULL )
121  *relaxptr = relax;
122 
123  return SCIP_OKAY;
124 }
125 
126 /** sets copy method of relaxation handler */
128  SCIP* scip, /**< SCIP data structure */
129  SCIP_RELAX* relax, /**< relaxation handler */
130  SCIP_DECL_RELAXCOPY ((*relaxcopy)) /**< copy method of relaxation handler or NULL if you don't want to copy your plugin into sub-SCIPs */
131  )
132 {
133  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxCopy", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
134 
135  assert(relax != NULL);
136 
137  SCIPrelaxSetCopy(relax, relaxcopy);
138 
139  return SCIP_OKAY;
140 }
141 
142 /** sets destructor method of relaxation handler */
144  SCIP* scip, /**< SCIP data structure */
145  SCIP_RELAX* relax, /**< relaxation handler */
146  SCIP_DECL_RELAXFREE ((*relaxfree)) /**< destructor of relaxation handler */
147  )
148 {
149  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxFree", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
150 
151  assert(relax != NULL);
152 
153  SCIPrelaxSetFree(relax, relaxfree);
154 
155  return SCIP_OKAY;
156 }
157 
158 /** sets initialization method of relaxation handler */
160  SCIP* scip, /**< SCIP data structure */
161  SCIP_RELAX* relax, /**< relaxation handler */
162  SCIP_DECL_RELAXINIT ((*relaxinit)) /**< initialize relaxation handler */
163  )
164 {
165  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxInit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
166 
167  assert(relax != NULL);
168 
169  SCIPrelaxSetInit(relax, relaxinit);
170 
171  return SCIP_OKAY;
172 }
173 
174 /** sets deinitialization method of relaxation handler */
176  SCIP* scip, /**< SCIP data structure */
177  SCIP_RELAX* relax, /**< relaxation handler */
178  SCIP_DECL_RELAXEXIT ((*relaxexit)) /**< deinitialize relaxation handler */
179  )
180 {
181  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxExit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
182 
183  assert(relax != NULL);
184 
185  SCIPrelaxSetExit(relax, relaxexit);
186 
187  return SCIP_OKAY;
188 }
189 
190 /** sets solving process initialization method of relaxation handler */
192  SCIP* scip, /**< SCIP data structure */
193  SCIP_RELAX* relax, /**< relaxation handler */
194  SCIP_DECL_RELAXINITSOL((*relaxinitsol)) /**< solving process initialization method of relaxation handler */
195  )
196 {
197  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxInitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
198 
199  assert(relax != NULL);
200 
201  SCIPrelaxSetInitsol(relax, relaxinitsol);
202 
203  return SCIP_OKAY;
204 }
205 
206 /** sets solving process deinitialization method of relaxation handler */
208  SCIP* scip, /**< SCIP data structure */
209  SCIP_RELAX* relax, /**< relaxation handler */
210  SCIP_DECL_RELAXEXITSOL((*relaxexitsol)) /**< solving process deinitialization method of relaxation handler */
211  )
212 {
213  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetRelaxExitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
214 
215  assert(relax != NULL);
216 
217  SCIPrelaxSetExitsol(relax, relaxexitsol);
218 
219  return SCIP_OKAY;
220 }
221 
222 
223 /** returns the relaxation handler of the given name, or NULL if not existing */
225  SCIP* scip, /**< SCIP data structure */
226  const char* name /**< name of relaxation handler */
227  )
228 {
229  assert(scip != NULL);
230  assert(scip->set != NULL);
231  assert(name != NULL);
232 
233  return SCIPsetFindRelax(scip->set, name);
234 }
235 
236 /** returns the array of currently available relaxation handlers */
238  SCIP* scip /**< SCIP data structure */
239  )
240 {
241  assert(scip != NULL);
242  assert(scip->set != NULL);
243 
244  SCIPsetSortRelaxs(scip->set);
245 
246  return scip->set->relaxs;
247 }
248 
249 /** returns the number of currently available relaxation handlers */
251  SCIP* scip /**< SCIP data structure */
252  )
253 {
254  assert(scip != NULL);
255  assert(scip->set != NULL);
256 
257  return scip->set->nrelaxs;
258 }
259 
260 /** sets the priority of a relaxation handler */
262  SCIP* scip, /**< SCIP data structure */
263  SCIP_RELAX* relax, /**< relaxation handler */
264  int priority /**< new priority of the relaxation handler */
265  )
266 {
267  assert(scip != NULL);
268  assert(scip->set != NULL);
269 
270  SCIPrelaxSetPriority(relax, scip->set, priority);
271 
272  return SCIP_OKAY;
273 }
#define SCIP_DECL_RELAXFREE(x)
Definition: type_relax.h:55
#define NULL
Definition: def.h:253
public methods for relaxator plugins
SCIP_RETCODE SCIPsetIncludeRelax(SCIP_SET *set, SCIP_RELAX *relax)
Definition: set.c:4047
void SCIPrelaxSetPriority(SCIP_RELAX *relax, SCIP_SET *set, int priority)
Definition: relax.c:510
#define FALSE
Definition: def.h:73
#define SCIP_DECL_RELAXINIT(x)
Definition: type_relax.h:63
#define SCIP_DECL_RELAXINITSOL(x)
Definition: type_relax.h:82
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
void SCIPrelaxSetCopy(SCIP_RELAX *relax, SCIP_DECL_RELAXCOPY((*relaxcopy)))
Definition: relax.c:414
SCIP_RELAX ** relaxs
Definition: struct_set.h:76
SCIP_RELAX * SCIPfindRelax(SCIP *scip, const char *name)
Definition: scip_relax.c:224
SCIP_MEM * mem
Definition: struct_scip.h:61
#define SCIP_DECL_RELAXEXIT(x)
Definition: type_relax.h:71
void SCIPrelaxSetFree(SCIP_RELAX *relax, SCIP_DECL_RELAXFREE((*relaxfree)))
Definition: relax.c:425
SCIP_RETCODE SCIPrelaxCreate(SCIP_RELAX **relax, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXCOPY((*relaxcopy)), SCIP_DECL_RELAXFREE((*relaxfree)), SCIP_DECL_RELAXINIT((*relaxinit)), SCIP_DECL_RELAXEXIT((*relaxexit)), SCIP_DECL_RELAXINITSOL((*relaxinitsol)), SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
Definition: relax.c:154
SCIP_RETCODE SCIPsetRelaxExitsol(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXEXITSOL((*relaxexitsol)))
Definition: scip_relax.c:207
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_RETCODE SCIPsetRelaxExit(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXEXIT((*relaxexit)))
Definition: scip_relax.c:175
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_RELAX * SCIPsetFindRelax(SCIP_SET *set, const char *name)
Definition: set.c:4071
SCIP_RETCODE SCIPincludeRelax(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXCOPY((*relaxcopy)), SCIP_DECL_RELAXFREE((*relaxfree)), SCIP_DECL_RELAXINIT((*relaxinit)), SCIP_DECL_RELAXEXIT((*relaxexit)), SCIP_DECL_RELAXINITSOL((*relaxinitsol)), SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
Definition: scip_relax.c:51
#define SCIP_DECL_RELAXCOPY(x)
Definition: type_relax.h:47
int nrelaxs
Definition: struct_set.h:108
void SCIPrelaxSetInitsol(SCIP_RELAX *relax, SCIP_DECL_RELAXINITSOL((*relaxinitsol)))
Definition: relax.c:458
void SCIPrelaxSetExitsol(SCIP_RELAX *relax, SCIP_DECL_RELAXEXITSOL((*relaxexitsol)))
Definition: relax.c:469
SCIP_RETCODE SCIPsetRelaxCopy(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXCOPY((*relaxcopy)))
Definition: scip_relax.c:127
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 SCIPsetRelaxPriority(SCIP *scip, SCIP_RELAX *relax, int priority)
Definition: scip_relax.c:261
internal methods for relaxators
void SCIPsetSortRelaxs(SCIP_SET *set)
Definition: set.c:4091
SCIP_RETCODE SCIPsetRelaxInit(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXINIT((*relaxinit)))
Definition: scip_relax.c:159
SCIP_RELAX ** SCIPgetRelaxs(SCIP *scip)
Definition: scip_relax.c:237
SCIP_RETCODE SCIPincludeRelaxBasic(SCIP *scip, SCIP_RELAX **relaxptr, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
Definition: scip_relax.c:93
SCIP_RETCODE SCIPsetRelaxFree(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXFREE((*relaxfree)))
Definition: scip_relax.c:143
methods for debugging
datastructures for block memory pools and memory buffers
int SCIPgetNRelaxs(SCIP *scip)
Definition: scip_relax.c:250
struct SCIP_RelaxData SCIP_RELAXDATA
Definition: type_relax.h:38
#define SCIP_DECL_RELAXEXEC(x)
Definition: type_relax.h:118
SCIP_RETCODE SCIPsetRelaxInitsol(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXINITSOL((*relaxinitsol)))
Definition: scip_relax.c:191
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:65
#define SCIP_DECL_RELAXEXITSOL(x)
Definition: type_relax.h:93
void SCIPrelaxSetExit(SCIP_RELAX *relax, SCIP_DECL_RELAXEXIT((*relaxexit)))
Definition: relax.c:447
datastructures for global SCIP settings
void SCIPrelaxSetInit(SCIP_RELAX *relax, SCIP_DECL_RELAXINIT((*relaxinit)))
Definition: relax.c:436