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