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