1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2 /* */ 3 /* This file is part of the program and library */ 4 /* SCIP --- Solving Constraint Integer Programs */ 5 /* */ 6 /* Copyright (c) 2002-2023 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 objcutsel.h 26 * @brief C++ wrapper for cut selectors 27 * @author Felipe Serrano 28 * @author Mark Turner 29 */ 30 31 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/ 32 33 #ifndef __SCIP_OBJCUTSEL_H__ 34 #define __SCIP_OBJCUTSEL_H__ 35 36 #include <cstring> 37 #include <utility> 38 39 #include "scip/scip.h" 40 #include "objscip/objcloneable.h" 41 42 namespace scip 43 { 44 45 /** @brief C++ wrapper for cut selectors 46 * 47 * This class defines the interface for cut selectors implemented in C++. 48 * 49 * - \ref CUTSEL "Instructions for implementing a cut selector" 50 * - \ref CUTSELECTORS "List of available cut selectors" 51 * - \ref type_cutsel.h "Corresponding C interface" 52 */ 53 class ObjCutsel : public ObjCloneable 54 { 55 public: 56 /*lint --e{1540}*/ 57 58 /** SCIP data structure */ 59 SCIP* scip_; 60 61 /** name of the cut selector */ 62 char* scip_name_; 63 64 /** description of the cut selector */ 65 char* scip_desc_; 66 67 /** priority of the cut selector */ 68 const int scip_priority_; 69 70 /** default constructor */ 71 ObjCutsel( 72 SCIP* scip, /**< SCIP data structure */ 73 const char* name, /**< name of cut selector */ 74 const char* desc, /**< description of cut selector */ 75 int priority /**< priority of the cut */ 76 ) 77 : scip_(scip), 78 scip_name_(0), 79 scip_desc_(0), 80 scip_priority_(priority) 81 { 82 SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) ); 83 SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) ); 84 } 85 86 /** copy constructor */ 87 ObjCutsel(const ObjCutsel& o) : ObjCutsel(o.scip_, o.scip_name_, o.scip_desc_, o.scip_priority_) {} 88 89 /** move constructor */ 90 ObjCutsel(ObjCutsel&& o) : scip_(o.scip_), scip_name_(0), scip_desc_(0), scip_priority_(o.scip_priority_) 91 { 92 std::swap(scip_name_, o.scip_name_); 93 std::swap(scip_desc_, o.scip_desc_); 94 } 95 96 /** destructor */ 97 virtual ~ObjCutsel() 98 { 99 /*lint --e{64}*/ 100 SCIPfreeMemoryArray(scip_, &scip_name_); 101 SCIPfreeMemoryArray(scip_, &scip_desc_); 102 } 103 104 /** assignment of polymorphic classes causes slicing and is therefore disabled. */ 105 ObjCutsel& operator=(const ObjCutsel& o) = delete; 106 107 /** assignment of polymorphic classes causes slicing and is therefore disabled. */ 108 ObjCutsel& operator=(ObjCutsel&& o) = delete; 109 110 /** destructor of cut selector to free user data (called when SCIP is exiting) 111 * 112 * @see SCIP_DECL_CUTSELFREE(x) in @ref type_cutsel.h 113 */ 114 virtual SCIP_DECL_CUTSELFREE(scip_free) 115 { /*lint --e{715}*/ 116 return SCIP_OKAY; 117 } 118 119 /** initialization method of cut selector (called after problem was transformed) 120 * 121 * @see SCIP_DECL_CUTSELINIT(x) in @ref type_cutsel.h 122 */ 123 virtual SCIP_DECL_CUTSELINIT(scip_init) 124 { /*lint --e{715}*/ 125 return SCIP_OKAY; 126 } 127 128 /** deinitialization method of cut selector (called before transformed problem is freed) 129 * 130 * @see SCIP_DECL_CUTSELEXIT(x) in @ref type_cutsel.h 131 */ 132 virtual SCIP_DECL_CUTSELEXIT(scip_exit) 133 { /*lint --e{715}*/ 134 return SCIP_OKAY; 135 } 136 137 /** solving process initialization method of cut selector (called when branch and bound process is about to begin) 138 * 139 * @see SCIP_DECL_CUTSELINITSOL(x) in @ref type_cutsel.h 140 */ 141 virtual SCIP_DECL_CUTSELINITSOL(scip_initsol) 142 { /*lint --e{715}*/ 143 return SCIP_OKAY; 144 } 145 146 /** solving process deinitialization method of cut selector (called before branch and bound process data is freed) 147 * 148 * @see SCIP_DECL_CUTSELEXITSOL(x) in @ref type_cutsel.h 149 */ 150 virtual SCIP_DECL_CUTSELEXITSOL(scip_exitsol) 151 { /*lint --e{715}*/ 152 return SCIP_OKAY; 153 } 154 155 /** cut selection method of cut selector 156 * 157 * @see SCIP_DECL_CUTSELSELECT(x) in @ref type_cutsel.h 158 */ 159 virtual SCIP_DECL_CUTSELSELECT(scip_select) = 0; 160 }; 161 162 } /* namespace scip */ 163 164 165 166 /** creates the cut selector for the given cut selector object and includes it in SCIP 167 * 168 * The method should be called in one of the following ways: 169 * 170 * 1. The user is responsible for deleting the object: 171 * SCIP_CALL( SCIPcreate(&scip) ); 172 * ... 173 * MyCutsel* mycutsel = new MyCutsel(...); 174 * SCIP_CALL( SCIPincludeObjCutsel(scip, &mycutsel, FALSE) ); 175 * ... 176 * SCIP_CALL( SCIPfree(&scip) ); 177 * delete mycutsel; // delete cutsel AFTER SCIPfree() ! 178 * 179 * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call: 180 * SCIP_CALL( SCIPcreate(&scip) ); 181 * ... 182 * SCIP_CALL( SCIPincludeObjCutsel(scip, new MyCutsel(...), TRUE) ); 183 * ... 184 * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyCutsel is called here 185 */ 186 SCIP_EXPORT 187 SCIP_RETCODE SCIPincludeObjCutsel( 188 SCIP* scip, /**< SCIP data structure */ 189 scip::ObjCutsel* objcutsel, /**< cut selector object */ 190 SCIP_Bool deleteobject /**< should the cut selector object be deleted when cut selector is freed? */ 191 ); 192 193 /** returns the cutsel object of the given name, or 0 if not existing */ 194 SCIP_EXPORT 195 scip::ObjCutsel* SCIPfindObjCutsel( 196 SCIP* scip, /**< SCIP data structure */ 197 const char* name /**< name of cut selector */ 198 ); 199 200 /** returns the cutsel object for the given cut selector */ 201 SCIP_EXPORT 202 scip::ObjCutsel* SCIPgetObjCutsel( 203 SCIP* scip, /**< SCIP data structure */ 204 SCIP_CUTSEL* cutsel /**< cut selector */ 205 ); 206 207 #endif 208