Scippy

SCIP

Solving Constraint Integer Programs

scip_nodesel.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_nodesel.c
17  * @brief public methods for node selector 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/nodesel.h"
37 #include "scip/pub_message.h"
38 #include "scip/scip_nodesel.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 node selector and includes it in SCIP.
45  *
46  * @note method has all node selector callbacks as arguments and is thus changed every time a new
47  * callback is added in future releases; consider using SCIPincludeNodeselBasic() 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 node selector */
53  const char* desc, /**< description of node selector */
54  int stdpriority, /**< priority of the node selector in standard mode */
55  int memsavepriority, /**< priority of the node selector in memory saving mode */
56  SCIP_DECL_NODESELCOPY ((*nodeselcopy)), /**< copy method of node selector or NULL if you don't want to copy your plugin into sub-SCIPs */
57  SCIP_DECL_NODESELFREE ((*nodeselfree)), /**< destructor of node selector */
58  SCIP_DECL_NODESELINIT ((*nodeselinit)), /**< initialize node selector */
59  SCIP_DECL_NODESELEXIT ((*nodeselexit)), /**< deinitialize node selector */
60  SCIP_DECL_NODESELINITSOL((*nodeselinitsol)),/**< solving process initialization method of node selector */
61  SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)),/**< solving process deinitialization method of node selector */
62  SCIP_DECL_NODESELSELECT((*nodeselselect)),/**< node selection method */
63  SCIP_DECL_NODESELCOMP ((*nodeselcomp)), /**< node comparison method */
64  SCIP_NODESELDATA* nodeseldata /**< node selector data */
65  )
66 {
67  SCIP_NODESEL* nodesel;
68 
69  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeNodesel", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
70 
71  /* check whether node selector is already present */
72  if( SCIPfindNodesel(scip, name) != NULL )
73  {
74  SCIPerrorMessage("node selector <%s> already included.\n", name);
75  return SCIP_INVALIDDATA;
76  }
77 
78  SCIP_CALL( SCIPnodeselCreate(&nodesel, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, stdpriority, memsavepriority,
79  nodeselcopy, nodeselfree, nodeselinit, nodeselexit, nodeselinitsol, nodeselexitsol,
80  nodeselselect, nodeselcomp, nodeseldata) );
81  SCIP_CALL( SCIPsetIncludeNodesel(scip->set, nodesel) );
82 
83  return SCIP_OKAY;
84 }
85 
86 /** Creates a node selector and includes it in SCIP with its most fundamental callbacks. 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 SCIPsetNodeselCopy(), SCIPsetNodeselFree(),
89  * SCIPsetNodeselInit(), SCIPsetNodeselExit(), SCIPsetNodeselInitsol(), and SCIPsetNodeselExitsol()
90  *
91  * @note if you want to set all callbacks with a single method call, consider using SCIPincludeNodesel() instead
92  */
94  SCIP* scip, /**< SCIP data structure */
95  SCIP_NODESEL** nodesel, /**< reference to a node selector, or NULL */
96  const char* name, /**< name of node selector */
97  const char* desc, /**< description of node selector */
98  int stdpriority, /**< priority of the node selector in standard mode */
99  int memsavepriority, /**< priority of the node selector in memory saving mode */
100  SCIP_DECL_NODESELSELECT((*nodeselselect)),/**< node selection method */
101  SCIP_DECL_NODESELCOMP ((*nodeselcomp)), /**< node comparison method */
102  SCIP_NODESELDATA* nodeseldata /**< node selector data */
103  )
104 {
105  SCIP_NODESEL* nodeselptr;
106 
107  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeNodeselBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
108 
109  /* check whether node selector is already present */
110  if( SCIPfindNodesel(scip, name) != NULL )
111  {
112  SCIPerrorMessage("node selector <%s> already included.\n", name);
113  return SCIP_INVALIDDATA;
114  }
115 
116  SCIP_CALL( SCIPnodeselCreate(&nodeselptr, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, stdpriority, memsavepriority,
117  NULL, NULL, NULL, NULL, NULL, NULL,
118  nodeselselect, nodeselcomp, nodeseldata) );
119  SCIP_CALL( SCIPsetIncludeNodesel(scip->set, nodeselptr) );
120 
121  if( nodesel != NULL )
122  *nodesel = nodeselptr;
123 
124  return SCIP_OKAY;
125 }
126 
127 /** sets copy method of node selector */
129  SCIP* scip, /**< SCIP data structure */
130  SCIP_NODESEL* nodesel, /**< node selector */
131  SCIP_DECL_NODESELCOPY ((*nodeselcopy)) /**< copy method of node selector or NULL if you don't want to copy your plugin into sub-SCIPs */
132  )
133 {
134  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetNodeselCopy", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
135 
136  assert(nodesel != NULL);
137 
138  SCIPnodeselSetCopy(nodesel, nodeselcopy);
139 
140  return SCIP_OKAY;
141 }
142 
143 /** sets destructor method of node selector */
145  SCIP* scip, /**< SCIP data structure */
146  SCIP_NODESEL* nodesel, /**< node selector */
147  SCIP_DECL_NODESELFREE ((*nodeselfree)) /**< destructor of node selector */
148  )
149 {
150  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetNodeselFree", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
151 
152  assert(nodesel != NULL);
153 
154  SCIPnodeselSetFree(nodesel, nodeselfree);
155 
156  return SCIP_OKAY;
157 }
158 
159 /** sets initialization method of node selector */
161  SCIP* scip, /**< SCIP data structure */
162  SCIP_NODESEL* nodesel, /**< node selector */
163  SCIP_DECL_NODESELINIT ((*nodeselinit)) /**< initialize node selector */
164  )
165 {
166  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetNodeselInit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
167 
168  assert(nodesel != NULL);
169 
170  SCIPnodeselSetInit(nodesel, nodeselinit);
171 
172  return SCIP_OKAY;
173 }
174 
175 /** sets deinitialization method of node selector */
177  SCIP* scip, /**< SCIP data structure */
178  SCIP_NODESEL* nodesel, /**< node selector */
179  SCIP_DECL_NODESELEXIT ((*nodeselexit)) /**< deinitialize node selector */
180  )
181 {
182  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetNodeselExit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
183 
184  assert(nodesel != NULL);
185 
186  SCIPnodeselSetExit(nodesel, nodeselexit);
187 
188  return SCIP_OKAY;
189 }
190 
191 /** sets solving process initialization method of node selector */
193  SCIP* scip, /**< SCIP data structure */
194  SCIP_NODESEL* nodesel, /**< node selector */
195  SCIP_DECL_NODESELINITSOL ((*nodeselinitsol))/**< solving process initialization method of node selector */
196  )
197 {
198  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetNodeselInitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
199 
200  assert(nodesel != NULL);
201 
202  SCIPnodeselSetInitsol(nodesel, nodeselinitsol);
203 
204  return SCIP_OKAY;
205 }
206 
207 /** sets solving process deinitialization method of node selector */
209  SCIP* scip, /**< SCIP data structure */
210  SCIP_NODESEL* nodesel, /**< node selector */
211  SCIP_DECL_NODESELEXITSOL ((*nodeselexitsol))/**< solving process deinitialization method of node selector */
212  )
213 {
214  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetNodeselExitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
215 
216  assert(nodesel != NULL);
217 
218  SCIPnodeselSetExitsol(nodesel, nodeselexitsol);
219 
220  return SCIP_OKAY;
221 }
222 
223 /** returns the node selector of the given name, or NULL if not existing */
225  SCIP* scip, /**< SCIP data structure */
226  const char* name /**< name of node selector */
227  )
228 {
229  assert(scip != NULL);
230  assert(scip->set != NULL);
231  assert(name != NULL);
232 
233  return SCIPsetFindNodesel(scip->set, name);
234 }
235 
236 /** returns the array of currently available node selectors */
238  SCIP* scip /**< SCIP data structure */
239  )
240 {
241  assert(scip != NULL);
242  assert(scip->set != NULL);
243 
244  return scip->set->nodesels;
245 }
246 
247 /** returns the number of currently available node selectors */
249  SCIP* scip /**< SCIP data structure */
250  )
251 {
252  assert(scip != NULL);
253  assert(scip->set != NULL);
254 
255  return scip->set->nnodesels;
256 }
257 
258 /** sets the priority of a node selector in standard mode */
260  SCIP* scip, /**< SCIP data structure */
261  SCIP_NODESEL* nodesel, /**< node selector */
262  int priority /**< new standard priority of the node selector */
263  )
264 {
265  assert(scip != NULL);
266  assert(scip->set != NULL);
267 
268  SCIPnodeselSetStdPriority(nodesel, scip->set, priority);
269 
270  return SCIP_OKAY;
271 }
272 
273 /** sets the priority of a node selector in memory saving mode */
275  SCIP* scip, /**< SCIP data structure */
276  SCIP_NODESEL* nodesel, /**< node selector */
277  int priority /**< new memory saving priority of the node selector */
278  )
279 {
280  assert(scip != NULL);
281  assert(scip->set != NULL);
282 
283  SCIPnodeselSetMemsavePriority(nodesel, scip->set, priority);
284 
285  return SCIP_OKAY;
286 }
287 
288 /** returns the currently used node selector */
290  SCIP* scip /**< SCIP data structure */
291  )
292 {
293  assert(scip != NULL);
294  assert(scip->set != NULL);
295 
296  return SCIPsetGetNodesel(scip->set, scip->stat);
297 }
SCIP_STAT * stat
Definition: struct_scip.h:69
void SCIPnodeselSetFree(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELFREE((*nodeselfree)))
Definition: nodesel.c:1140
#define SCIP_DECL_NODESELCOMP(x)
Definition: type_nodesel.h:126
#define NULL
Definition: def.h:253
SCIP_RETCODE SCIPsetNodeselMemsavePriority(SCIP *scip, SCIP_NODESEL *nodesel, int priority)
Definition: scip_nodesel.c:274
int nnodesels
Definition: struct_set.h:120
SCIP_RETCODE SCIPsetNodeselExitsol(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)))
Definition: scip_nodesel.c:208
public methods for node selector plugins
void SCIPnodeselSetInit(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELINIT((*nodeselinit)))
Definition: nodesel.c:1151
SCIP_NODESEL ** nodesels
Definition: struct_set.h:83
SCIP_RETCODE SCIPsetNodeselCopy(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELCOPY((*nodeselcopy)))
Definition: scip_nodesel.c:128
#define SCIP_DECL_NODESELINITSOL(x)
Definition: type_nodesel.h:83
SCIP_NODESEL ** SCIPgetNodesels(SCIP *scip)
Definition: scip_nodesel.c:237
SCIP_RETCODE SCIPsetNodeselExit(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELEXIT((*nodeselexit)))
Definition: scip_nodesel.c:176
SCIP_RETCODE SCIPsetNodeselFree(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELFREE((*nodeselfree)))
Definition: scip_nodesel.c:144
#define FALSE
Definition: def.h:73
SCIP_NODESEL * SCIPsetGetNodesel(SCIP_SET *set, SCIP_STAT *stat)
Definition: set.c:4660
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_RETCODE SCIPsetNodeselInitsol(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELINITSOL((*nodeselinitsol)))
Definition: scip_nodesel.c:192
int SCIPgetNNodesels(SCIP *scip)
Definition: scip_nodesel.c:248
#define SCIP_DECL_NODESELEXITSOL(x)
Definition: type_nodesel.h:94
SCIP_RETCODE SCIPsetNodeselStdPriority(SCIP *scip, SCIP_NODESEL *nodesel, int priority)
Definition: scip_nodesel.c:259
#define SCIP_DECL_NODESELINIT(x)
Definition: type_nodesel.h:64
struct SCIP_NodeselData SCIP_NODESELDATA
Definition: type_nodesel.h:38
SCIP_MEM * mem
Definition: struct_scip.h:61
#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
#define SCIP_DECL_NODESELFREE(x)
Definition: type_nodesel.h:56
internal methods for node selectors and node priority queues
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
Definition: scip_nodesel.c:224
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
void SCIPnodeselSetInitsol(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELINITSOL((*nodeselinitsol)))
Definition: nodesel.c:1173
SCIP_RETCODE SCIPnodeselCreate(SCIP_NODESEL **nodesel, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, int stdpriority, int memsavepriority, SCIP_DECL_NODESELCOPY((*nodeselcopy)), SCIP_DECL_NODESELFREE((*nodeselfree)), SCIP_DECL_NODESELINIT((*nodeselinit)), SCIP_DECL_NODESELEXIT((*nodeselexit)), SCIP_DECL_NODESELINITSOL((*nodeselinitsol)), SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)), SCIP_DECL_NODESELSELECT((*nodeselselect)), SCIP_DECL_NODESELCOMP((*nodeselcomp)), SCIP_NODESELDATA *nodeseldata)
Definition: nodesel.c:821
#define SCIP_DECL_NODESELEXIT(x)
Definition: type_nodesel.h:72
SCIP_NODESEL * SCIPsetFindNodesel(SCIP_SET *set, const char *name)
Definition: set.c:4640
void SCIPnodeselSetMemsavePriority(SCIP_NODESEL *nodesel, SCIP_SET *set, int priority)
Definition: nodesel.c:1092
methods for debugging
void SCIPnodeselSetExit(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELEXIT((*nodeselexit)))
Definition: nodesel.c:1162
datastructures for block memory pools and memory buffers
SCIP_RETCODE SCIPsetIncludeNodesel(SCIP_SET *set, SCIP_NODESEL *nodesel)
Definition: set.c:4609
SCIP_RETCODE SCIPincludeNodeselBasic(SCIP *scip, SCIP_NODESEL **nodesel, const char *name, const char *desc, int stdpriority, int memsavepriority, SCIP_DECL_NODESELSELECT((*nodeselselect)), SCIP_DECL_NODESELCOMP((*nodeselcomp)), SCIP_NODESELDATA *nodeseldata)
Definition: scip_nodesel.c:93
SCIP_NODESEL * SCIPgetNodesel(SCIP *scip)
Definition: scip_nodesel.c:289
void SCIPnodeselSetStdPriority(SCIP_NODESEL *nodesel, SCIP_SET *set, int priority)
Definition: nodesel.c:1068
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:65
SCIP_RETCODE SCIPincludeNodesel(SCIP *scip, const char *name, const char *desc, int stdpriority, int memsavepriority, SCIP_DECL_NODESELCOPY((*nodeselcopy)), SCIP_DECL_NODESELFREE((*nodeselfree)), SCIP_DECL_NODESELINIT((*nodeselinit)), SCIP_DECL_NODESELEXIT((*nodeselexit)), SCIP_DECL_NODESELINITSOL((*nodeselinitsol)), SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)), SCIP_DECL_NODESELSELECT((*nodeselselect)), SCIP_DECL_NODESELCOMP((*nodeselcomp)), SCIP_NODESELDATA *nodeseldata)
Definition: scip_nodesel.c:50
#define SCIP_DECL_NODESELCOPY(x)
Definition: type_nodesel.h:47
SCIP_RETCODE SCIPsetNodeselInit(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELINIT((*nodeselinit)))
Definition: scip_nodesel.c:160
void SCIPnodeselSetCopy(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELCOPY((*nodeselcopy)))
Definition: nodesel.c:1129
#define SCIP_DECL_NODESELSELECT(x)
Definition: type_nodesel.h:109
void SCIPnodeselSetExitsol(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)))
Definition: nodesel.c:1184
datastructures for global SCIP settings