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