Scippy

SCIP

Solving Constraint Integer Programs

objnodesel.cpp
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-2024 Zuse Institute Berlin (ZIB) */
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 objnodesel.cpp
26  * @brief C++ wrapper for node selectors
27  * @author Tobias Achterberg
28  */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #include <cassert>
33 
34 #include "objnodesel.h"
35 
36 
37 
38 
39 /*
40  * Data structures
41  */
42 
43 /** node selector data */
44 struct SCIP_NodeselData
45 {
46  scip::ObjNodesel* objnodesel; /**< node selector object */
47  SCIP_Bool deleteobject; /**< should the node selector object be deleted when node selector is freed? */
48 };
49 
50 
51 
52 
53 /*
54  * Callback methods of node selector
55  */
56 
57 extern "C"
58 {
59 
60 /** copy method for node selector plugins (called when SCIP copies plugins) */
61 static
62 SCIP_DECL_NODESELCOPY(nodeselCopyObj)
63 { /*lint --e{715}*/
64  SCIP_NODESELDATA* nodeseldata;
65 
66  assert(scip != NULL);
67 
68  nodeseldata = SCIPnodeselGetData(nodesel);
69  assert(nodeseldata != NULL);
70  assert(nodeseldata->objnodesel != NULL);
71  assert(nodeseldata->objnodesel->scip_ != scip);
72 
73  if( nodeseldata->objnodesel->iscloneable() )
74  {
75  scip::ObjNodesel* newobjnodesel;
76  newobjnodesel = dynamic_cast<scip::ObjNodesel*> (nodeseldata->objnodesel->clone(scip));
77 
78  /* call include method of node selector object */
79  SCIP_CALL( SCIPincludeObjNodesel(scip, newobjnodesel, TRUE) );
80  }
81 
82  return SCIP_OKAY;
83 }
84 
85 /** destructor of node selector to free user data (called when SCIP is exiting) */
86 static
87 SCIP_DECL_NODESELFREE(nodeselFreeObj)
88 { /*lint --e{715}*/
89  SCIP_NODESELDATA* nodeseldata;
90 
91  nodeseldata = SCIPnodeselGetData(nodesel);
92  assert(nodeseldata != NULL);
93  assert(nodeseldata->objnodesel != NULL);
94  assert(nodeseldata->objnodesel->scip_ == scip);
95 
96  /* call virtual method of nodesel object */
97  SCIP_CALL( nodeseldata->objnodesel->scip_free(scip, nodesel) );
98 
99  /* free nodesel object */
100  if( nodeseldata->deleteobject )
101  delete nodeseldata->objnodesel;
102 
103  /* free nodesel data */
104  delete nodeseldata;
105  SCIPnodeselSetData(nodesel, NULL); /*lint !e64*/
106 
107  return SCIP_OKAY;
108 }
109 
110 
111 /** initialization method of node selector (called after problem was transformed) */
112 static
113 SCIP_DECL_NODESELINIT(nodeselInitObj)
114 { /*lint --e{715}*/
115  SCIP_NODESELDATA* nodeseldata;
116 
117  nodeseldata = SCIPnodeselGetData(nodesel);
118  assert(nodeseldata != NULL);
119  assert(nodeseldata->objnodesel != NULL);
120  assert(nodeseldata->objnodesel->scip_ == scip);
121 
122  /* call virtual method of nodesel object */
123  SCIP_CALL( nodeseldata->objnodesel->scip_init(scip, nodesel) );
124 
125  return SCIP_OKAY;
126 }
127 
128 
129 /** deinitialization method of node selector (called before transformed problem is freed) */
130 static
131 SCIP_DECL_NODESELEXIT(nodeselExitObj)
132 { /*lint --e{715}*/
133  SCIP_NODESELDATA* nodeseldata;
134 
135  nodeseldata = SCIPnodeselGetData(nodesel);
136  assert(nodeseldata != NULL);
137  assert(nodeseldata->objnodesel != NULL);
138 
139  /* call virtual method of nodesel object */
140  SCIP_CALL( nodeseldata->objnodesel->scip_exit(scip, nodesel) );
141 
142  return SCIP_OKAY;
143 }
144 
145 
146 /** solving process initialization method of node selector (called when branch and bound process is about to begin) */
147 static
148 SCIP_DECL_NODESELINITSOL(nodeselInitsolObj)
149 { /*lint --e{715}*/
150  SCIP_NODESELDATA* nodeseldata;
151 
152  nodeseldata = SCIPnodeselGetData(nodesel);
153  assert(nodeseldata != NULL);
154  assert(nodeseldata->objnodesel != NULL);
155 
156  /* call virtual method of nodesel object */
157  SCIP_CALL( nodeseldata->objnodesel->scip_initsol(scip, nodesel) );
158 
159  return SCIP_OKAY;
160 }
161 
162 
163 /** solving process deinitialization method of node selector (called before branch and bound process data is freed) */
164 static
165 SCIP_DECL_NODESELEXITSOL(nodeselExitsolObj)
166 { /*lint --e{715}*/
167  SCIP_NODESELDATA* nodeseldata;
168 
169  nodeseldata = SCIPnodeselGetData(nodesel);
170  assert(nodeseldata != NULL);
171  assert(nodeseldata->objnodesel != NULL);
172 
173  /* call virtual method of nodesel object */
174  SCIP_CALL( nodeseldata->objnodesel->scip_exitsol(scip, nodesel) );
175 
176  return SCIP_OKAY;
177 }
178 
179 
180 /** node selection method of node selector */
181 static
182 SCIP_DECL_NODESELSELECT(nodeselSelectObj)
183 { /*lint --e{715}*/
184  SCIP_NODESELDATA* nodeseldata;
185 
186  nodeseldata = SCIPnodeselGetData(nodesel);
187  assert(nodeseldata != NULL);
188  assert(nodeseldata->objnodesel != NULL);
189 
190  /* call virtual method of nodesel object */
191  SCIP_CALL( nodeseldata->objnodesel->scip_select(scip, nodesel, selnode) );
192 
193  return SCIP_OKAY;
194 }
195 
196 
197 /** node comparison method of node selector */
198 static
199 SCIP_DECL_NODESELCOMP(nodeselCompObj)
200 { /*lint --e{715}*/
201  SCIP_NODESELDATA* nodeseldata;
202 
203  nodeseldata = SCIPnodeselGetData(nodesel);
204  assert(nodeseldata != NULL);
205  assert(nodeseldata->objnodesel != NULL);
206 
207  /* call virtual method of nodesel object */
208  return nodeseldata->objnodesel->scip_comp(scip, nodesel, node1, node2);
209 }
210 }
211 
212 
213 
214 /*
215  * node selector specific interface methods
216  */
217 
218 /** creates the node selector for the given node selector object and includes it in SCIP */
220  SCIP* scip, /**< SCIP data structure */
221  scip::ObjNodesel* objnodesel, /**< node selector object */
222  SCIP_Bool deleteobject /**< should the node selector object be deleted when node selector is freed? */
223  )
224 {
225  SCIP_NODESELDATA* nodeseldata;
226 
227  assert(scip != NULL);
228  assert(objnodesel != NULL);
229 
230  /* create node selector data */
231  nodeseldata = new SCIP_NODESELDATA;
232  nodeseldata->objnodesel = objnodesel;
233  nodeseldata->deleteobject = deleteobject;
234 
235  /* include node selector */
236  SCIP_CALL( SCIPincludeNodesel(scip, objnodesel->scip_name_, objnodesel->scip_desc_,
237  objnodesel->scip_stdpriority_, objnodesel->scip_memsavepriority_,
238  nodeselCopyObj,
239  nodeselFreeObj, nodeselInitObj, nodeselExitObj,
240  nodeselInitsolObj, nodeselExitsolObj, nodeselSelectObj, nodeselCompObj,
241  nodeseldata) ); /*lint !e429*/
242 
243  return SCIP_OKAY; /*lint !e429*/
244 }
245 
246 /** returns the nodesel object of the given name, or 0 if not existing */
248  SCIP* scip, /**< SCIP data structure */
249  const char* name /**< name of node selector */
250  )
251 {
252  SCIP_NODESEL* nodesel;
253  SCIP_NODESELDATA* nodeseldata;
254 
255  nodesel = SCIPfindNodesel(scip, name);
256  if( nodesel == NULL )
257  return 0;
258 
259  nodeseldata = SCIPnodeselGetData(nodesel);
260  assert(nodeseldata != NULL);
261 
262  return nodeseldata->objnodesel;
263 }
264 
265 /** returns the nodesel object for the given node selector */
267  SCIP* scip, /**< SCIP data structure */
268  SCIP_NODESEL* nodesel /**< node selector */
269  )
270 {
271  SCIP_NODESELDATA* nodeseldata;
272 
273  assert(scip != NULL);
274  nodeseldata = SCIPnodeselGetData(nodesel);
275  assert(nodeseldata != NULL);
276 
277  return nodeseldata->objnodesel;
278 }
#define NULL
Definition: def.h:267
C++ wrapper for primal heuristics.
Definition: objnodesel.h:53
static SCIP_DECL_NODESELSELECT(nodeselSelectObj)
Definition: objnodesel.cpp:182
static SCIP_DECL_NODESELCOMP(nodeselCompObj)
Definition: objnodesel.cpp:199
char * scip_name_
Definition: objnodesel.h:62
#define TRUE
Definition: def.h:93
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
static SCIP_DECL_NODESELINIT(nodeselInitObj)
Definition: objnodesel.cpp:113
struct SCIP_NodeselData SCIP_NODESELDATA
Definition: type_nodesel.h:52
static SCIP_DECL_NODESELEXITSOL(nodeselExitsolObj)
Definition: objnodesel.cpp:165
SCIP_NODESELDATA * SCIPnodeselGetData(SCIP_NODESEL *nodesel)
Definition: nodesel.c:1120
#define SCIP_CALL(x)
Definition: def.h:380
#define SCIP_Bool
Definition: def.h:91
const int scip_stdpriority_
Definition: objnodesel.h:68
const int scip_memsavepriority_
Definition: objnodesel.h:71
scip::ObjNodesel * SCIPgetObjNodesel(SCIP *scip, SCIP_NODESEL *nodesel)
Definition: objnodesel.cpp:266
static SCIP_DECL_NODESELEXIT(nodeselExitObj)
Definition: objnodesel.cpp:131
C++ wrapper for node selectors.
static SCIP_DECL_NODESELINITSOL(nodeselInitsolObj)
Definition: objnodesel.cpp:148
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
Definition: scip_nodesel.c:234
static SCIP_DECL_NODESELFREE(nodeselFreeObj)
Definition: objnodesel.cpp:87
char * scip_desc_
Definition: objnodesel.h:65
void SCIPnodeselSetData(SCIP_NODESEL *nodesel, SCIP_NODESELDATA *nodeseldata)
Definition: nodesel.c:1130
scip::ObjNodesel * SCIPfindObjNodesel(SCIP *scip, const char *name)
Definition: objnodesel.cpp:247
static SCIP_DECL_NODESELCOPY(nodeselCopyObj)
Definition: objnodesel.cpp:62
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:60
SCIP_RETCODE SCIPincludeObjNodesel(SCIP *scip, scip::ObjNodesel *objnodesel, SCIP_Bool deleteobject)
Definition: objnodesel.cpp:219