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 scip_cutsel.c 26 * @ingroup OTHER_CFILES 27 * @brief public methods for cut selector plugins 28 * @author Felipe Serrano 29 * @author Mark Turner 30 * 31 */ 32 33 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/ 34 35 #include "scip/debug.h" 36 #include "scip/cutsel.h" 37 #include "scip/pub_message.h" 38 #include "scip/scip_cutsel.h" 39 #include "scip/set.h" 40 #include "scip/struct_mem.h" 41 #include "scip/struct_scip.h" 42 #include "scip/struct_set.h" 43 44 /** creates a cut selector and includes it in SCIP 45 * 46 * @note this method has all cut selector callbacks as arguments and is thus changed every time a new 47 * callback is added in future releases; consider using SCIPincludeCutselBasic() and setter functions 48 * if you seek for a method which is less likely to change in future releases 49 */ 50 SCIP_RETCODE SCIPincludeCutsel( 51 SCIP* scip, /**< SCIP data structure */ 52 const char* name, /**< name of cut selector */ 53 const char* desc, /**< description of cut selector */ 54 int priority, /**< priority of the cut selector */ 55 SCIP_DECL_CUTSELCOPY ((*cutselcopy)), /**< copy method of cut selector or NULL if you don't want to copy your plugin into sub-SCIPs */ 56 SCIP_DECL_CUTSELFREE ((*cutselfree)), /**< destructor of cut selector */ 57 SCIP_DECL_CUTSELINIT ((*cutselinit)), /**< initialize cut selector */ 58 SCIP_DECL_CUTSELEXIT ((*cutselexit)), /**< deinitialize cut selector */ 59 SCIP_DECL_CUTSELINITSOL((*cutselinitsol)),/**< solving process initialization method of cut selector */ 60 SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)),/**< solving process deinitialization method of cut selector */ 61 SCIP_DECL_CUTSELSELECT((*cutselselect)), /**< cut selection method */ 62 SCIP_CUTSELDATA* cutseldata /**< cut selector data */ 63 ) 64 { 65 SCIP_CUTSEL* cutsel; 66 67 SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeCutsel", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) ); 68 69 /* check whether cut selector is already present */ 70 if( SCIPfindCutsel(scip, name) != NULL ) 71 { 72 SCIPerrorMessage("cut selector <%s> already included.\n", name); 73 return SCIP_INVALIDDATA; 74 } 75 76 SCIP_CALL( SCIPcutselCreate(&cutsel, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority, 77 cutselcopy, cutselfree, cutselinit, cutselexit, cutselinitsol, cutselexitsol, 78 cutselselect, cutseldata) ); 79 SCIP_CALL( SCIPsetIncludeCutsel(scip->set, cutsel) ); 80 81 return SCIP_OKAY; 82 } 83 84 /** Creates a cut selector and includes it in SCIP with its most fundamental callbacks. 85 * 86 * All non-fundamental (or optional) callbacks as, e.g., init and exit callbacks, will be set to NULL. Optional 87 * callbacks can be set via specific setter functions, see SCIPsetCutselCopy(), SCIPsetCutselFree(), 88 * SCIPsetCutselInit(), SCIPsetCutselExit(), SCIPsetCutselInitsol(), and SCIPsetCutselExitsol() 89 * 90 * @note if you want to set all callbacks with a single method call, consider using SCIPincludeCutsel() instead 91 */ 92 SCIP_RETCODE SCIPincludeCutselBasic( 93 SCIP* scip, /**< SCIP data structure */ 94 SCIP_CUTSEL** cutsel, /**< reference to a cut selector, or NULL */ 95 const char* name, /**< name of cut selector */ 96 const char* desc, /**< description of cut selector */ 97 int priority, /**< priority of the cut selector in standard mode */ 98 SCIP_DECL_CUTSELSELECT((*cutselselect)), /**< cut selection method */ 99 SCIP_CUTSELDATA* cutseldata /**< cut selector data */ 100 ) 101 { 102 SCIP_CUTSEL* cutselptr; 103 104 SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeCutselBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) ); 105 106 /* check whether cut selector is already present */ 107 if( SCIPfindCutsel(scip, name) != NULL ) 108 { 109 SCIPerrorMessage("cut selector <%s> already included.\n", name); 110 return SCIP_INVALIDDATA; 111 } 112 113 SCIP_CALL( SCIPcutselCreate(&cutselptr, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority, 114 NULL, NULL, NULL, NULL, NULL, NULL, 115 cutselselect, cutseldata) ); 116 SCIP_CALL( SCIPsetIncludeCutsel(scip->set, cutselptr) ); 117 118 if( cutsel != NULL ) 119 *cutsel = cutselptr; 120 121 return SCIP_OKAY; 122 } 123 124 /** sets copy method of cut selector */ 125 SCIP_RETCODE SCIPsetCutselCopy( 126 SCIP* scip, /**< SCIP data structure */ 127 SCIP_CUTSEL* cutsel, /**< cut selector */ 128 SCIP_DECL_CUTSELCOPY ((*cutselcopy)) /**< copy method of cut selector or NULL if you don't want to copy your plugin into sub-SCIPs */ 129 ) 130 { 131 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselCopy", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) ); 132 133 assert(cutsel != NULL); 134 135 SCIPcutselSetCopy(cutsel, cutselcopy); 136 137 return SCIP_OKAY; 138 } 139 140 /** sets destructor method of cut selector */ 141 SCIP_RETCODE SCIPsetCutselFree( 142 SCIP* scip, /**< SCIP data structure */ 143 SCIP_CUTSEL* cutsel, /**< cut selector */ 144 SCIP_DECL_CUTSELFREE ((*cutselfree)) /**< destructor of cut selector */ 145 ) 146 { 147 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselFree", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) ); 148 149 assert(cutsel != NULL); 150 151 SCIPcutselSetFree(cutsel, cutselfree); 152 153 return SCIP_OKAY; 154 } 155 156 /** sets initialization method of cut selector */ 157 SCIP_RETCODE SCIPsetCutselInit( 158 SCIP* scip, /**< SCIP data structure */ 159 SCIP_CUTSEL* cutsel, /**< cut selector */ 160 SCIP_DECL_CUTSELINIT ((*cutselinit)) /**< initialize cut selector */ 161 ) 162 { 163 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselInit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) ); 164 165 assert(cutsel != NULL); 166 167 SCIPcutselSetInit(cutsel, cutselinit); 168 169 return SCIP_OKAY; 170 } 171 172 /** sets deinitialization method of cut selector */ 173 SCIP_RETCODE SCIPsetCutselExit( 174 SCIP* scip, /**< SCIP data structure */ 175 SCIP_CUTSEL* cutsel, /**< cut selector */ 176 SCIP_DECL_CUTSELEXIT ((*cutselexit)) /**< deinitialize cut selector */ 177 ) 178 { 179 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselExit", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) ); 180 181 assert(cutsel != NULL); 182 183 SCIPcutselSetExit(cutsel, cutselexit); 184 185 return SCIP_OKAY; 186 } 187 188 /** sets solving process initialization method of cut selector */ 189 SCIP_RETCODE SCIPsetCutselInitsol( 190 SCIP* scip, /**< SCIP data structure */ 191 SCIP_CUTSEL* cutsel, /**< cut selector */ 192 SCIP_DECL_CUTSELINITSOL ((*cutselinitsol))/**< solving process initialization method of cut selector */ 193 ) 194 { 195 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselInitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) ); 196 197 assert(cutsel != NULL); 198 199 SCIPcutselSetInitsol(cutsel, cutselinitsol); 200 201 return SCIP_OKAY; 202 } 203 204 /** sets solving process deinitialization method of cut selector */ 205 SCIP_RETCODE SCIPsetCutselExitsol( 206 SCIP* scip, /**< SCIP data structure */ 207 SCIP_CUTSEL* cutsel, /**< cut selector */ 208 SCIP_DECL_CUTSELEXITSOL ((*cutselexitsol))/**< solving process deinitialization method of cut selector */ 209 ) 210 { 211 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselExitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) ); 212 213 assert(cutsel != NULL); 214 215 SCIPcutselSetExitsol(cutsel, cutselexitsol); 216 217 return SCIP_OKAY; 218 } 219 220 /** returns the cut selector of the given name, or NULL if not existing */ 221 SCIP_CUTSEL* SCIPfindCutsel( 222 SCIP* scip, /**< SCIP data structure */ 223 const char* name /**< name of cut selector */ 224 ) 225 { 226 assert(scip != NULL); 227 assert(scip->set != NULL); 228 assert(name != NULL); 229 230 return SCIPsetFindCutsel(scip->set, name); 231 } 232 233 /** returns the array of currently available cut selectors */ 234 SCIP_CUTSEL** SCIPgetCutsels( 235 SCIP* scip /**< SCIP data structure */ 236 ) 237 { 238 assert(scip != NULL); 239 assert(scip->set != NULL); 240 241 SCIPsetSortCutsels(scip->set); 242 243 return scip->set->cutsels; 244 } 245 246 /** returns the number of currently available cut selectors */ 247 int SCIPgetNCutsels( 248 SCIP* scip /**< SCIP data structure */ 249 ) 250 { 251 assert(scip != NULL); 252 assert(scip->set != NULL); 253 254 return scip->set->ncutsels; 255 } 256 257 /** sets the priority of a cut selector */ 258 SCIP_RETCODE SCIPsetCutselPriority( 259 SCIP* scip, /**< SCIP data structure */ 260 SCIP_CUTSEL* cutsel, /**< cut selector */ 261 int priority /**< new priority of the separator */ 262 ) 263 { 264 assert(scip != NULL); 265 assert(scip->set != NULL); 266 267 SCIPcutselSetPriority(cutsel, scip->set, priority); 268 269 return SCIP_OKAY; 270 } 271