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