Scippy

SCIP

Solving Constraint Integer Programs

objnodesel.h
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 objnodesel.h
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 #ifndef __SCIP_OBJNODESEL_H__
33 #define __SCIP_OBJNODESEL_H__
34 
35 #include <cstring>
36 #include <utility>
37 
38 #include "scip/scip.h"
39 #include "objscip/objcloneable.h"
40 
41 namespace scip
42 {
43 
44 /** @brief C++ wrapper for primal heuristics
45  *
46  * This class defines the interface for node selectors implemented in C++. Note that there is a pure virtual
47  * function (this function has to be implemented). This function is: scip_comp().
48  *
49  * - \ref NODESEL "Instructions for implementing a node selector"
50  * - \ref NODESELECTORS "List of available node selectors"
51  * - \ref type_nodesel.h "Corresponding C interface"
52  */
53 class ObjNodesel : public ObjCloneable
54 {
55 public:
56  /*lint --e{1540}*/
57 
58  /** SCIP data structure */
60 
61  /** name of the node selector */
62  char* scip_name_;
63 
64  /** description of the node selector */
65  char* scip_desc_;
66 
67  /** priority of the node selector in standard mode */
68  const int scip_stdpriority_;
69 
70  /** priority of the node selector in memory saving mode */
72 
73  /** default constructor */
75  SCIP* scip, /**< SCIP data structure */
76  const char* name, /**< name of node selector */
77  const char* desc, /**< description of node selector */
78  int stdpriority, /**< priority of the node selector in standard mode */
79  int memsavepriority /**< priority of the node selector in memory saving mode */
80  )
81  : scip_(scip),
82  scip_name_(0),
83  scip_desc_(0),
84  scip_stdpriority_(stdpriority),
85  scip_memsavepriority_(memsavepriority)
86  {
87  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
88  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
89  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
90  }
91 
92  /** copy constructor */
94  : ObjNodesel(o.scip_, o.scip_name_, o.scip_desc_, o.scip_stdpriority_, o.scip_memsavepriority_)
95  {
96  }
97 
98  /** move constructor */
100  : scip_(o.scip_),
101  scip_name_(0),
102  scip_desc_(0),
103  scip_stdpriority_(o.scip_stdpriority_),
104  scip_memsavepriority_(o.scip_memsavepriority_)
105  {
106  std::swap(scip_name_, o.scip_name_);
107  std::swap(scip_desc_, o.scip_desc_);
108  }
109 
110  /** destructor */
111  virtual ~ObjNodesel()
112  {
113  /* the macro SCIPfreeMemoryArray does not need the first argument: */
114  /*lint --e{64}*/
115  SCIPfreeMemoryArray(scip_, &scip_name_);
116  SCIPfreeMemoryArray(scip_, &scip_desc_);
117  }
118 
119  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
120  ObjNodesel& operator=(const ObjNodesel& o) = delete;
121 
122  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
123  ObjNodesel& operator=(ObjNodesel&& o) = delete;
124 
125  /** destructor of node selector to free user data (called when SCIP is exiting)
126  *
127  * @see SCIP_DECL_NODESELFREE(x) in @ref type_nodesel.h
128  */
129  virtual SCIP_DECL_NODESELFREE(scip_free)
130  { /*lint --e{715}*/
131  return SCIP_OKAY;
132  }
133 
134  /** initialization method of node selector (called after problem was transformed)
135  *
136  * @see SCIP_DECL_NODESELINIT(x) in @ref type_nodesel.h
137  */
138  virtual SCIP_DECL_NODESELINIT(scip_init)
139  { /*lint --e{715}*/
140  return SCIP_OKAY;
141  }
142 
143  /** deinitialization method of node selector (called before transformed problem is freed)
144  *
145  * @see SCIP_DECL_NODESELEXIT(x) in @ref type_nodesel.h
146  */
147  virtual SCIP_DECL_NODESELEXIT(scip_exit)
148  { /*lint --e{715}*/
149  return SCIP_OKAY;
150  }
151 
152  /** solving process initialization method of node selector (called when branch and bound process is about to begin)
153  *
154  * @see SCIP_DECL_NODESELINITSOL(x) in @ref type_nodesel.h
155  */
156  virtual SCIP_DECL_NODESELINITSOL(scip_initsol)
157  { /*lint --e{715}*/
158  return SCIP_OKAY;
159  }
160 
161  /** solving process deinitialization method of node selector (called before branch and bound process data is freed)
162  *
163  * @see SCIP_DECL_NODESELEXITSOL(x) in @ref type_nodesel.h
164  */
165  virtual SCIP_DECL_NODESELEXITSOL(scip_exitsol)
166  { /*lint --e{715}*/
167  return SCIP_OKAY;
168  }
169 
170  /** node selection method of node selector
171  *
172  * @see SCIP_DECL_NODESELSELECT(x) in @ref type_nodesel.h
173  */
174  virtual SCIP_DECL_NODESELSELECT(scip_select) = 0;
175 
176  /** node comparison method of node selector
177  *
178  * @see SCIP_DECL_NODESELCOMP(x) in @ref type_nodesel.h
179  */
180  virtual SCIP_DECL_NODESELCOMP(scip_comp) = 0;
181 };
182 
183 } /* namespace scip */
184 
185 
186 
187 /** creates the node selector for the given node selector object and includes it in SCIP
188  *
189  * The method should be called in one of the following ways:
190  *
191  * 1. The user is resposible of deleting the object:
192  * SCIP_CALL( SCIPcreate(&scip) );
193  * ...
194  * MyNodesel* mynodesel = new MyNodesel(...);
195  * SCIP_CALL( SCIPincludeObjNodesel(scip, &mynodesel, FALSE) );
196  * ...
197  * SCIP_CALL( SCIPfree(&scip) );
198  * delete mynodesel; // delete nodesel AFTER SCIPfree() !
199  *
200  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
201  * SCIP_CALL( SCIPcreate(&scip) );
202  * ...
203  * SCIP_CALL( SCIPincludeObjNodesel(scip, new MyNodesel(...), TRUE) );
204  * ...
205  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyNodesel is called here
206  */
207 SCIP_EXPORT
209  SCIP* scip, /**< SCIP data structure */
210  scip::ObjNodesel* objnodesel, /**< node selector object */
211  SCIP_Bool deleteobject /**< should the node selector object be deleted when node selector is freed? */
212  );
213 
214 /** returns the nodesel object of the given name, or 0 if not existing */
215 SCIP_EXPORT
217  SCIP* scip, /**< SCIP data structure */
218  const char* name /**< name of node selector */
219  );
220 
221 /** returns the nodesel object for the given node selector */
222 SCIP_EXPORT
224  SCIP* scip, /**< SCIP data structure */
225  SCIP_NODESEL* nodesel /**< node selector */
226  );
227 
228 #endif
ObjNodesel(SCIP *scip, const char *name, const char *desc, int stdpriority, int memsavepriority)
Definition: objnodesel.h:74
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:76
SCIP_RETCODE SCIPincludeObjNodesel(SCIP *scip, scip::ObjNodesel *objnodesel, SCIP_Bool deleteobject)
Definition: objnodesel.cpp:219
C++ wrapper for primal heuristics.
Definition: objnodesel.h:53
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:80
virtual ~ObjNodesel()
Definition: objnodesel.h:111
virtual SCIP_DECL_NODESELINITSOL(scip_initsol)
Definition: objnodesel.h:156
char * scip_name_
Definition: objnodesel.h:62
ObjNodesel(ObjNodesel &&o)
Definition: objnodesel.h:99
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
virtual SCIP_DECL_NODESELFREE(scip_free)
Definition: objnodesel.h:129
definition of base class for all clonable classes
scip::ObjNodesel * SCIPfindObjNodesel(SCIP *scip, const char *name)
Definition: objnodesel.cpp:247
ObjNodesel(const ObjNodesel &o)
Definition: objnodesel.h:93
virtual SCIP_DECL_NODESELINIT(scip_init)
Definition: objnodesel.h:138
#define SCIP_Bool
Definition: def.h:93
const int scip_stdpriority_
Definition: objnodesel.h:68
scip::ObjNodesel * SCIPgetObjNodesel(SCIP *scip, SCIP_NODESEL *nodesel)
Definition: objnodesel.cpp:266
virtual SCIP_DECL_NODESELSELECT(scip_select)=0
const int scip_memsavepriority_
Definition: objnodesel.h:71
virtual SCIP_DECL_NODESELEXIT(scip_exit)
Definition: objnodesel.h:147
Definition of base class for all clonable classes.
Definition: objcloneable.h:47
virtual SCIP_DECL_NODESELEXITSOL(scip_exitsol)
Definition: objnodesel.h:165
ObjNodesel & operator=(const ObjNodesel &o)=delete
#define SCIP_CALL_ABORT(x)
Definition: def.h:372
char * scip_desc_
Definition: objnodesel.h:65
virtual SCIP_DECL_NODESELCOMP(scip_comp)=0
SCIP callable library.