1    	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2    	/*                                                                           */
3    	/*                  This file is part of the program and library             */
4    	/*         SCIP --- Solving Constraint Integer Programs                      */
5    	/*                                                                           */
6    	/*    Copyright (C) 2002-2022 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 scipopt.org.         */
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   	 */
(1) Event missing_copy_ctor: Class "scip::ObjNodesel" owns resources that are freed in its destructor but has no user-written copy constructor.
(2) Event free_resource: The destructor frees member "scip_desc_". [details]
(3) Event free_resource: The destructor frees member "scip_name_". [details]
43   	class ObjNodesel : public ObjCloneable
44   	{
45   	public:
46   	   /*lint --e{1540}*/
47   	
48   	   /** SCIP data structure */
49   	   SCIP* scip_;
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 */
61   	   const int scip_memsavepriority_;
62   	
63   	   /** default constructor */
64   	   ObjNodesel(
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}*/
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_name_". [details]
87   	      SCIPfreeMemoryArray(scip_, &scip_name_);
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_desc_". [details]
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  	 */
173  	SCIP_EXPORT
174  	SCIP_RETCODE SCIPincludeObjNodesel(
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 */
181  	SCIP_EXPORT
182  	scip::ObjNodesel* SCIPfindObjNodesel(
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 */
188  	SCIP_EXPORT
189  	scip::ObjNodesel* SCIPgetObjNodesel(
190  	   SCIP*                 scip,               /**< SCIP data structure */
191  	   SCIP_NODESEL*         nodesel             /**< node selector */
192  	   );
193  	
194  	#endif
195