Scippy

    SCIP

    Solving Constraint Integer Programs

    scip_cutsel.c
    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-2025 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 * @pre This method can be called if SCIP is in one of the following stages:
    46 * - \ref SCIP_STAGE_INIT
    47 * - \ref SCIP_STAGE_PROBLEM
    48 *
    49 * @note this method has all cut selector callbacks as arguments and is thus changed every time a new
    50 * callback is added in future releases; consider using SCIPincludeCutselBasic() and setter functions
    51 * if you seek for a method which is less likely to change in future releases
    52 */
    54 SCIP* scip, /**< SCIP data structure */
    55 const char* name, /**< name of cut selector */
    56 const char* desc, /**< description of cut selector */
    57 int priority, /**< priority of the cut selector */
    58 SCIP_DECL_CUTSELCOPY ((*cutselcopy)), /**< copy method of cut selector or NULL if you don't want to copy your plugin into sub-SCIPs */
    59 SCIP_DECL_CUTSELFREE ((*cutselfree)), /**< destructor of cut selector */
    60 SCIP_DECL_CUTSELINIT ((*cutselinit)), /**< initialize cut selector */
    61 SCIP_DECL_CUTSELEXIT ((*cutselexit)), /**< deinitialize cut selector */
    62 SCIP_DECL_CUTSELINITSOL((*cutselinitsol)),/**< solving process initialization method of cut selector */
    63 SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)),/**< solving process deinitialization method of cut selector */
    64 SCIP_DECL_CUTSELSELECT((*cutselselect)), /**< cut selection method */
    65 SCIP_CUTSELDATA* cutseldata /**< cut selector data */
    66 )
    67{
    68 SCIP_CUTSEL* cutsel;
    69
    71
    72 /* check whether cut selector is already present */
    73 if( SCIPfindCutsel(scip, name) != NULL )
    74 {
    75 SCIPerrorMessage("cut selector <%s> already included.\n", name);
    76 return SCIP_INVALIDDATA;
    77 }
    78
    79 SCIP_CALL( SCIPcutselCreate(&cutsel, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority,
    80 cutselcopy, cutselfree, cutselinit, cutselexit, cutselinitsol, cutselexitsol,
    81 cutselselect, cutseldata) );
    82 SCIP_CALL( SCIPsetIncludeCutsel(scip->set, cutsel) );
    83
    84 return SCIP_OKAY;
    85}
    86
    87/** Creates a cut selector and includes it in SCIP with its most fundamental callbacks.
    88 *
    89 * All non-fundamental (or optional) callbacks as, e.g., init and exit callbacks, will be set to NULL. Optional
    90 * callbacks can be set via specific setter functions, see SCIPsetCutselCopy(), SCIPsetCutselFree(),
    91 * SCIPsetCutselInit(), SCIPsetCutselExit(), SCIPsetCutselInitsol(), and SCIPsetCutselExitsol()
    92 * @pre This method can be called if SCIP is in one of the following stages:
    93 * - \ref SCIP_STAGE_INIT
    94 * - \ref SCIP_STAGE_PROBLEM
    95 *
    96 * @note if you want to set all callbacks with a single method call, consider using SCIPincludeCutsel() instead
    97 */
    99 SCIP* scip, /**< SCIP data structure */
    100 SCIP_CUTSEL** cutsel, /**< reference to a cut selector, or NULL */
    101 const char* name, /**< name of cut selector */
    102 const char* desc, /**< description of cut selector */
    103 int priority, /**< priority of the cut selector in standard mode */
    104 SCIP_DECL_CUTSELSELECT((*cutselselect)), /**< cut selection method */
    105 SCIP_CUTSELDATA* cutseldata /**< cut selector data */
    106 )
    107{
    108 SCIP_CUTSEL* cutselptr;
    109
    110 SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeCutselBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
    111
    112 /* check whether cut selector is already present */
    113 if( SCIPfindCutsel(scip, name) != NULL )
    114 {
    115 SCIPerrorMessage("cut selector <%s> already included.\n", name);
    116 return SCIP_INVALIDDATA;
    117 }
    118
    119 SCIP_CALL( SCIPcutselCreate(&cutselptr, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, priority,
    120 NULL, NULL, NULL, NULL, NULL, NULL,
    121 cutselselect, cutseldata) );
    122 SCIP_CALL( SCIPsetIncludeCutsel(scip->set, cutselptr) );
    123
    124 if( cutsel != NULL )
    125 *cutsel = cutselptr;
    126
    127 return SCIP_OKAY;
    128}
    129
    130/** sets copy method of cut selector */
    132 SCIP* scip, /**< SCIP data structure */
    133 SCIP_CUTSEL* cutsel, /**< cut selector */
    134 SCIP_DECL_CUTSELCOPY ((*cutselcopy)) /**< copy method of cut selector or NULL if you don't want to copy your plugin into sub-SCIPs */
    135 )
    136{
    138
    139 assert(cutsel != NULL);
    140
    141 SCIPcutselSetCopy(cutsel, cutselcopy);
    142
    143 return SCIP_OKAY;
    144}
    145
    146/** sets destructor method of cut selector */
    148 SCIP* scip, /**< SCIP data structure */
    149 SCIP_CUTSEL* cutsel, /**< cut selector */
    150 SCIP_DECL_CUTSELFREE ((*cutselfree)) /**< destructor of cut selector */
    151 )
    152{
    154
    155 assert(cutsel != NULL);
    156
    157 SCIPcutselSetFree(cutsel, cutselfree);
    158
    159 return SCIP_OKAY;
    160}
    161
    162/** sets initialization method of cut selector */
    164 SCIP* scip, /**< SCIP data structure */
    165 SCIP_CUTSEL* cutsel, /**< cut selector */
    166 SCIP_DECL_CUTSELINIT ((*cutselinit)) /**< initialize cut selector */
    167 )
    168{
    170
    171 assert(cutsel != NULL);
    172
    173 SCIPcutselSetInit(cutsel, cutselinit);
    174
    175 return SCIP_OKAY;
    176}
    177
    178/** sets deinitialization method of cut selector */
    180 SCIP* scip, /**< SCIP data structure */
    181 SCIP_CUTSEL* cutsel, /**< cut selector */
    182 SCIP_DECL_CUTSELEXIT ((*cutselexit)) /**< deinitialize cut selector */
    183 )
    184{
    186
    187 assert(cutsel != NULL);
    188
    189 SCIPcutselSetExit(cutsel, cutselexit);
    190
    191 return SCIP_OKAY;
    192}
    193
    194/** sets solving process initialization method of cut selector */
    196 SCIP* scip, /**< SCIP data structure */
    197 SCIP_CUTSEL* cutsel, /**< cut selector */
    198 SCIP_DECL_CUTSELINITSOL ((*cutselinitsol))/**< solving process initialization method of cut selector */
    199 )
    200{
    201 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselInitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
    202
    203 assert(cutsel != NULL);
    204
    205 SCIPcutselSetInitsol(cutsel, cutselinitsol);
    206
    207 return SCIP_OKAY;
    208}
    209
    210/** sets solving process deinitialization method of cut selector */
    212 SCIP* scip, /**< SCIP data structure */
    213 SCIP_CUTSEL* cutsel, /**< cut selector */
    214 SCIP_DECL_CUTSELEXITSOL ((*cutselexitsol))/**< solving process deinitialization method of cut selector */
    215 )
    216{
    217 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetCutselExitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
    218
    219 assert(cutsel != NULL);
    220
    221 SCIPcutselSetExitsol(cutsel, cutselexitsol);
    222
    223 return SCIP_OKAY;
    224}
    225
    226/** returns the cut selector of the given name, or NULL if not existing */
    228 SCIP* scip, /**< SCIP data structure */
    229 const char* name /**< name of cut selector */
    230 )
    231{
    232 assert(scip != NULL);
    233 assert(scip->set != NULL);
    234 assert(name != NULL);
    235
    236 return SCIPsetFindCutsel(scip->set, name);
    237}
    238
    239/** returns the array of currently available cut selectors */
    241 SCIP* scip /**< SCIP data structure */
    242 )
    243{
    244 assert(scip != NULL);
    245 assert(scip->set != NULL);
    246
    248
    249 return scip->set->cutsels;
    250}
    251
    252/** returns the number of currently available cut selectors */
    254 SCIP* scip /**< SCIP data structure */
    255 )
    256{
    257 assert(scip != NULL);
    258 assert(scip->set != NULL);
    259
    260 return scip->set->ncutsels;
    261}
    262
    263/** sets the priority of a cut selector */
    265 SCIP* scip, /**< SCIP data structure */
    266 SCIP_CUTSEL* cutsel, /**< cut selector */
    267 int priority /**< new priority of the separator */
    268 )
    269{
    270 assert(scip != NULL);
    271 assert(scip->set != NULL);
    272
    273 SCIPcutselSetPriority(cutsel, scip->set, priority);
    274
    275 return SCIP_OKAY;
    276}
    void SCIPcutselSetFree(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELFREE((*cutselfree)))
    Definition: cutsel.c:476
    void SCIPcutselSetInitsol(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELINITSOL((*cutselinitsol)))
    Definition: cutsel.c:509
    SCIP_RETCODE SCIPcutselCreate(SCIP_CUTSEL **cutsel, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, int priority, SCIP_DECL_CUTSELCOPY((*cutselcopy)), SCIP_DECL_CUTSELFREE((*cutselfree)), SCIP_DECL_CUTSELINIT((*cutselinit)), SCIP_DECL_CUTSELEXIT((*cutselexit)), SCIP_DECL_CUTSELINITSOL((*cutselinitsol)), SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)), SCIP_DECL_CUTSELSELECT((*cutselselect)), SCIP_CUTSELDATA *cutseldata)
    Definition: cutsel.c:128
    void SCIPcutselSetExitsol(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)))
    Definition: cutsel.c:520
    void SCIPcutselSetInit(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELINIT((*cutselinit)))
    Definition: cutsel.c:487
    void SCIPcutselSetExit(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELEXIT((*cutselexit)))
    Definition: cutsel.c:498
    void SCIPcutselSetCopy(SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELCOPY((*cutselcopy)))
    Definition: cutsel.c:465
    void SCIPcutselSetPriority(SCIP_CUTSEL *cutsel, SCIP_SET *set, int priority)
    Definition: cutsel.c:531
    internal methods for cut selectors
    methods for debugging
    #define SCIPcheckStage(scip, method, init, problem, transforming, transformed, initpresolve, presolving, exitpresolve, presolved, initsolve, solving, solved, exitsolve, freetrans, freescip)
    Definition: debug.h:364
    #define NULL
    Definition: def.h:248
    #define TRUE
    Definition: def.h:93
    #define FALSE
    Definition: def.h:94
    #define SCIP_CALL(x)
    Definition: def.h:355
    SCIP_RETCODE SCIPsetCutselInit(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELINIT((*cutselinit)))
    Definition: scip_cutsel.c:163
    SCIP_RETCODE SCIPsetCutselPriority(SCIP *scip, SCIP_CUTSEL *cutsel, int priority)
    Definition: scip_cutsel.c:264
    SCIP_RETCODE SCIPincludeCutselBasic(SCIP *scip, SCIP_CUTSEL **cutsel, const char *name, const char *desc, int priority, SCIP_DECL_CUTSELSELECT((*cutselselect)), SCIP_CUTSELDATA *cutseldata)
    Definition: scip_cutsel.c:98
    SCIP_RETCODE SCIPsetCutselCopy(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELCOPY((*cutselcopy)))
    Definition: scip_cutsel.c:131
    SCIP_CUTSEL * SCIPfindCutsel(SCIP *scip, const char *name)
    Definition: scip_cutsel.c:227
    SCIP_RETCODE SCIPsetCutselFree(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELFREE((*cutselfree)))
    Definition: scip_cutsel.c:147
    SCIP_RETCODE SCIPsetCutselInitsol(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELINITSOL((*cutselinitsol)))
    Definition: scip_cutsel.c:195
    SCIP_RETCODE SCIPsetCutselExitsol(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)))
    Definition: scip_cutsel.c:211
    SCIP_RETCODE SCIPsetCutselExit(SCIP *scip, SCIP_CUTSEL *cutsel, SCIP_DECL_CUTSELEXIT((*cutselexit)))
    Definition: scip_cutsel.c:179
    SCIP_RETCODE SCIPincludeCutsel(SCIP *scip, const char *name, const char *desc, int priority, SCIP_DECL_CUTSELCOPY((*cutselcopy)), SCIP_DECL_CUTSELFREE((*cutselfree)), SCIP_DECL_CUTSELINIT((*cutselinit)), SCIP_DECL_CUTSELEXIT((*cutselexit)), SCIP_DECL_CUTSELINITSOL((*cutselinitsol)), SCIP_DECL_CUTSELEXITSOL((*cutselexitsol)), SCIP_DECL_CUTSELSELECT((*cutselselect)), SCIP_CUTSELDATA *cutseldata)
    Definition: scip_cutsel.c:53
    SCIP_CUTSEL ** SCIPgetCutsels(SCIP *scip)
    Definition: scip_cutsel.c:240
    int SCIPgetNCutsels(SCIP *scip)
    Definition: scip_cutsel.c:253
    public methods for message output
    #define SCIPerrorMessage
    Definition: pub_message.h:64
    public methods for cut selector plugins
    void SCIPsetSortCutsels(SCIP_SET *set)
    Definition: set.c:4603
    SCIP_CUTSEL * SCIPsetFindCutsel(SCIP_SET *set, const char *name)
    Definition: set.c:4583
    SCIP_RETCODE SCIPsetIncludeCutsel(SCIP_SET *set, SCIP_CUTSEL *cutsel)
    Definition: set.c:4559
    internal methods for global SCIP settings
    datastructures for block memory pools and memory buffers
    SCIP main data structure.
    datastructures for global SCIP settings
    #define SCIP_DECL_CUTSELEXIT(x)
    Definition: type_cutsel.h:86
    #define SCIP_DECL_CUTSELEXITSOL(x)
    Definition: type_cutsel.h:108
    #define SCIP_DECL_CUTSELSELECT(x)
    Definition: type_cutsel.h:132
    #define SCIP_DECL_CUTSELFREE(x)
    Definition: type_cutsel.h:70
    #define SCIP_DECL_CUTSELINITSOL(x)
    Definition: type_cutsel.h:97
    struct SCIP_CutselData SCIP_CUTSELDATA
    Definition: type_cutsel.h:53
    #define SCIP_DECL_CUTSELINIT(x)
    Definition: type_cutsel.h:78
    #define SCIP_DECL_CUTSELCOPY(x)
    Definition: type_cutsel.h:62
    @ SCIP_INVALIDDATA
    Definition: type_retcode.h:52
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63