Scippy

    SCIP

    Solving Constraint Integer Programs

    scip_nodesel.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_nodesel.c
    26 * @ingroup OTHER_CFILES
    27 * @brief public methods for node selector plugins
    28 * @author Tobias Achterberg
    29 * @author Timo Berthold
    30 * @author Gerald Gamrath
    31 * @author Leona Gottwald
    32 * @author Stefan Heinz
    33 * @author Gregor Hendel
    34 * @author Thorsten Koch
    35 * @author Alexander Martin
    36 * @author Marc Pfetsch
    37 * @author Michael Winkler
    38 * @author Kati Wolter
    39 *
    40 * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
    41 */
    42
    43/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    44
    45#include "scip/debug.h"
    46#include "scip/nodesel.h"
    47#include "scip/pub_message.h"
    48#include "scip/scip_nodesel.h"
    49#include "scip/set.h"
    50#include "scip/struct_mem.h"
    51#include "scip/struct_scip.h"
    52#include "scip/struct_set.h"
    53
    54/** creates a node selector and includes it in SCIP.
    55 *
    56 * @pre This method can be called if SCIP is in one of the following stages:
    57 * - \ref SCIP_STAGE_INIT
    58 * - \ref SCIP_STAGE_PROBLEM
    59 *
    60 * @note method has all node selector callbacks as arguments and is thus changed every time a new
    61 * callback is added in future releases; consider using SCIPincludeNodeselBasic() and setter functions
    62 * if you seek for a method which is less likely to change in future releases
    63 */
    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 SCIP_DECL_NODESELCOPY ((*nodeselcopy)), /**< copy method of node selector or NULL if you don't want to copy your plugin into sub-SCIPs */
    71 SCIP_DECL_NODESELFREE ((*nodeselfree)), /**< destructor of node selector */
    72 SCIP_DECL_NODESELINIT ((*nodeselinit)), /**< initialize node selector */
    73 SCIP_DECL_NODESELEXIT ((*nodeselexit)), /**< deinitialize node selector */
    74 SCIP_DECL_NODESELINITSOL((*nodeselinitsol)),/**< solving process initialization method of node selector */
    75 SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)),/**< solving process deinitialization method of node selector */
    76 SCIP_DECL_NODESELSELECT((*nodeselselect)),/**< node selection method */
    77 SCIP_DECL_NODESELCOMP ((*nodeselcomp)), /**< node comparison method */
    78 SCIP_NODESELDATA* nodeseldata /**< node selector data */
    79 )
    80{
    81 SCIP_NODESEL* nodesel;
    82
    84
    85 /* check whether node selector is already present */
    86 if( SCIPfindNodesel(scip, name) != NULL )
    87 {
    88 SCIPerrorMessage("node selector <%s> already included.\n", name);
    89 return SCIP_INVALIDDATA;
    90 }
    91
    92 SCIP_CALL( SCIPnodeselCreate(&nodesel, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, stdpriority, memsavepriority,
    93 nodeselcopy, nodeselfree, nodeselinit, nodeselexit, nodeselinitsol, nodeselexitsol,
    94 nodeselselect, nodeselcomp, nodeseldata) );
    95 SCIP_CALL( SCIPsetIncludeNodesel(scip->set, nodesel) );
    96
    97 return SCIP_OKAY;
    98}
    99
    100/** Creates a node selector and includes it in SCIP with its most fundamental callbacks. All non-fundamental
    101 * (or optional) callbacks as, e.g., init and exit callbacks, will be set to NULL.
    102 * Optional callbacks can be set via specific setter functions, see SCIPsetNodeselCopy(), SCIPsetNodeselFree(),
    103 * SCIPsetNodeselInit(), SCIPsetNodeselExit(), SCIPsetNodeselInitsol(), and SCIPsetNodeselExitsol()
    104 *
    105 * @pre This method can be called if SCIP is in one of the following stages:
    106 * - \ref SCIP_STAGE_INIT
    107 * - \ref SCIP_STAGE_PROBLEM
    108 *
    109 * @note if you want to set all callbacks with a single method call, consider using SCIPincludeNodesel() instead
    110 */
    112 SCIP* scip, /**< SCIP data structure */
    113 SCIP_NODESEL** nodesel, /**< reference to a node selector, or NULL */
    114 const char* name, /**< name of node selector */
    115 const char* desc, /**< description of node selector */
    116 int stdpriority, /**< priority of the node selector in standard mode */
    117 int memsavepriority, /**< priority of the node selector in memory saving mode */
    118 SCIP_DECL_NODESELSELECT((*nodeselselect)),/**< node selection method */
    119 SCIP_DECL_NODESELCOMP ((*nodeselcomp)), /**< node comparison method */
    120 SCIP_NODESELDATA* nodeseldata /**< node selector data */
    121 )
    122{
    123 SCIP_NODESEL* nodeselptr;
    124
    125 SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeNodeselBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
    126
    127 /* check whether node selector is already present */
    128 if( SCIPfindNodesel(scip, name) != NULL )
    129 {
    130 SCIPerrorMessage("node selector <%s> already included.\n", name);
    131 return SCIP_INVALIDDATA;
    132 }
    133
    134 SCIP_CALL( SCIPnodeselCreate(&nodeselptr, scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, stdpriority, memsavepriority,
    135 NULL, NULL, NULL, NULL, NULL, NULL,
    136 nodeselselect, nodeselcomp, nodeseldata) );
    137 SCIP_CALL( SCIPsetIncludeNodesel(scip->set, nodeselptr) );
    138
    139 if( nodesel != NULL )
    140 *nodesel = nodeselptr;
    141
    142 return SCIP_OKAY;
    143}
    144
    145/** sets copy method of node selector */
    147 SCIP* scip, /**< SCIP data structure */
    148 SCIP_NODESEL* nodesel, /**< node selector */
    149 SCIP_DECL_NODESELCOPY ((*nodeselcopy)) /**< copy method of node selector or NULL if you don't want to copy your plugin into sub-SCIPs */
    150 )
    151{
    153
    154 assert(nodesel != NULL);
    155
    156 SCIPnodeselSetCopy(nodesel, nodeselcopy);
    157
    158 return SCIP_OKAY;
    159}
    160
    161/** sets destructor method of node selector */
    163 SCIP* scip, /**< SCIP data structure */
    164 SCIP_NODESEL* nodesel, /**< node selector */
    165 SCIP_DECL_NODESELFREE ((*nodeselfree)) /**< destructor of node selector */
    166 )
    167{
    169
    170 assert(nodesel != NULL);
    171
    172 SCIPnodeselSetFree(nodesel, nodeselfree);
    173
    174 return SCIP_OKAY;
    175}
    176
    177/** sets initialization method of node selector */
    179 SCIP* scip, /**< SCIP data structure */
    180 SCIP_NODESEL* nodesel, /**< node selector */
    181 SCIP_DECL_NODESELINIT ((*nodeselinit)) /**< initialize node selector */
    182 )
    183{
    185
    186 assert(nodesel != NULL);
    187
    188 SCIPnodeselSetInit(nodesel, nodeselinit);
    189
    190 return SCIP_OKAY;
    191}
    192
    193/** sets deinitialization method of node selector */
    195 SCIP* scip, /**< SCIP data structure */
    196 SCIP_NODESEL* nodesel, /**< node selector */
    197 SCIP_DECL_NODESELEXIT ((*nodeselexit)) /**< deinitialize node selector */
    198 )
    199{
    201
    202 assert(nodesel != NULL);
    203
    204 SCIPnodeselSetExit(nodesel, nodeselexit);
    205
    206 return SCIP_OKAY;
    207}
    208
    209/** sets solving process initialization method of node selector */
    211 SCIP* scip, /**< SCIP data structure */
    212 SCIP_NODESEL* nodesel, /**< node selector */
    213 SCIP_DECL_NODESELINITSOL ((*nodeselinitsol))/**< solving process initialization method of node selector */
    214 )
    215{
    216 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetNodeselInitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
    217
    218 assert(nodesel != NULL);
    219
    220 SCIPnodeselSetInitsol(nodesel, nodeselinitsol);
    221
    222 return SCIP_OKAY;
    223}
    224
    225/** sets solving process deinitialization method of node selector */
    227 SCIP* scip, /**< SCIP data structure */
    228 SCIP_NODESEL* nodesel, /**< node selector */
    229 SCIP_DECL_NODESELEXITSOL ((*nodeselexitsol))/**< solving process deinitialization method of node selector */
    230 )
    231{
    232 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetNodeselExitsol", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
    233
    234 assert(nodesel != NULL);
    235
    236 SCIPnodeselSetExitsol(nodesel, nodeselexitsol);
    237
    238 return SCIP_OKAY;
    239}
    240
    241/** returns the node selector of the given name, or NULL if not existing */
    243 SCIP* scip, /**< SCIP data structure */
    244 const char* name /**< name of node selector */
    245 )
    246{
    247 assert(scip != NULL);
    248 assert(scip->set != NULL);
    249 assert(name != NULL);
    250
    251 return SCIPsetFindNodesel(scip->set, name);
    252}
    253
    254/** returns the array of currently available node selectors */
    256 SCIP* scip /**< SCIP data structure */
    257 )
    258{
    259 assert(scip != NULL);
    260 assert(scip->set != NULL);
    261
    262 return scip->set->nodesels;
    263}
    264
    265/** returns the number of currently available node selectors */
    267 SCIP* scip /**< SCIP data structure */
    268 )
    269{
    270 assert(scip != NULL);
    271 assert(scip->set != NULL);
    272
    273 return scip->set->nnodesels;
    274}
    275
    276/** sets the priority of a node selector in standard mode */
    278 SCIP* scip, /**< SCIP data structure */
    279 SCIP_NODESEL* nodesel, /**< node selector */
    280 int priority /**< new standard priority of the node selector */
    281 )
    282{
    283 assert(scip != NULL);
    284 assert(scip->set != NULL);
    285
    286 SCIPnodeselSetStdPriority(nodesel, scip->set, priority);
    287
    288 return SCIP_OKAY;
    289}
    290
    291/** sets the priority of a node selector in memory saving mode */
    293 SCIP* scip, /**< SCIP data structure */
    294 SCIP_NODESEL* nodesel, /**< node selector */
    295 int priority /**< new memory saving priority of the node selector */
    296 )
    297{
    298 assert(scip != NULL);
    299 assert(scip->set != NULL);
    300
    301 SCIPnodeselSetMemsavePriority(nodesel, scip->set, priority);
    302
    303 return SCIP_OKAY;
    304}
    305
    306/** returns the currently used node selector */
    308 SCIP* scip /**< SCIP data structure */
    309 )
    310{
    311 assert(scip != NULL);
    312 assert(scip->set != NULL);
    313
    314 return SCIPsetGetNodesel(scip->set, scip->stat);
    315}
    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_NODESEL ** SCIPgetNodesels(SCIP *scip)
    Definition: scip_nodesel.c:255
    SCIP_RETCODE SCIPincludeNodeselBasic(SCIP *scip, SCIP_NODESEL **nodesel, const char *name, const char *desc, int stdpriority, int memsavepriority, SCIP_DECL_NODESELSELECT((*nodeselselect)), SCIP_DECL_NODESELCOMP((*nodeselcomp)), SCIP_NODESELDATA *nodeseldata)
    Definition: scip_nodesel.c:111
    SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
    Definition: scip_nodesel.c:242
    SCIP_RETCODE SCIPsetNodeselStdPriority(SCIP *scip, SCIP_NODESEL *nodesel, int priority)
    Definition: scip_nodesel.c:277
    SCIP_RETCODE SCIPsetNodeselFree(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELFREE((*nodeselfree)))
    Definition: scip_nodesel.c:162
    SCIP_RETCODE SCIPsetNodeselExit(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELEXIT((*nodeselexit)))
    Definition: scip_nodesel.c:194
    SCIP_RETCODE SCIPsetNodeselInit(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELINIT((*nodeselinit)))
    Definition: scip_nodesel.c:178
    int SCIPgetNNodesels(SCIP *scip)
    Definition: scip_nodesel.c:266
    SCIP_RETCODE SCIPsetNodeselCopy(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELCOPY((*nodeselcopy)))
    Definition: scip_nodesel.c:146
    SCIP_RETCODE SCIPsetNodeselMemsavePriority(SCIP *scip, SCIP_NODESEL *nodesel, int priority)
    Definition: scip_nodesel.c:292
    SCIP_RETCODE SCIPincludeNodesel(SCIP *scip, const char *name, const char *desc, int stdpriority, int memsavepriority, SCIP_DECL_NODESELCOPY((*nodeselcopy)), SCIP_DECL_NODESELFREE((*nodeselfree)), SCIP_DECL_NODESELINIT((*nodeselinit)), SCIP_DECL_NODESELEXIT((*nodeselexit)), SCIP_DECL_NODESELINITSOL((*nodeselinitsol)), SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)), SCIP_DECL_NODESELSELECT((*nodeselselect)), SCIP_DECL_NODESELCOMP((*nodeselcomp)), SCIP_NODESELDATA *nodeseldata)
    Definition: scip_nodesel.c:64
    SCIP_NODESEL * SCIPgetNodesel(SCIP *scip)
    Definition: scip_nodesel.c:307
    SCIP_RETCODE SCIPsetNodeselExitsol(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)))
    Definition: scip_nodesel.c:226
    SCIP_RETCODE SCIPsetNodeselInitsol(SCIP *scip, SCIP_NODESEL *nodesel, SCIP_DECL_NODESELINITSOL((*nodeselinitsol)))
    Definition: scip_nodesel.c:210
    void SCIPnodeselSetFree(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELFREE((*nodeselfree)))
    Definition: nodesel.c:1297
    void SCIPnodeselSetInitsol(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELINITSOL((*nodeselinitsol)))
    Definition: nodesel.c:1330
    SCIP_RETCODE SCIPnodeselCreate(SCIP_NODESEL **nodesel, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, int stdpriority, int memsavepriority, SCIP_DECL_NODESELCOPY((*nodeselcopy)), SCIP_DECL_NODESELFREE((*nodeselfree)), SCIP_DECL_NODESELINIT((*nodeselinit)), SCIP_DECL_NODESELEXIT((*nodeselexit)), SCIP_DECL_NODESELINITSOL((*nodeselinitsol)), SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)), SCIP_DECL_NODESELSELECT((*nodeselselect)), SCIP_DECL_NODESELCOMP((*nodeselcomp)), SCIP_NODESELDATA *nodeseldata)
    Definition: nodesel.c:978
    void SCIPnodeselSetCopy(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELCOPY((*nodeselcopy)))
    Definition: nodesel.c:1286
    void SCIPnodeselSetStdPriority(SCIP_NODESEL *nodesel, SCIP_SET *set, int priority)
    Definition: nodesel.c:1225
    void SCIPnodeselSetExitsol(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELEXITSOL((*nodeselexitsol)))
    Definition: nodesel.c:1341
    void SCIPnodeselSetInit(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELINIT((*nodeselinit)))
    Definition: nodesel.c:1308
    void SCIPnodeselSetExit(SCIP_NODESEL *nodesel, SCIP_DECL_NODESELEXIT((*nodeselexit)))
    Definition: nodesel.c:1319
    void SCIPnodeselSetMemsavePriority(SCIP_NODESEL *nodesel, SCIP_SET *set, int priority)
    Definition: nodesel.c:1249
    internal methods for node selectors and node priority queues
    public methods for message output
    #define SCIPerrorMessage
    Definition: pub_message.h:64
    public methods for node selector plugins
    SCIP_NODESEL * SCIPsetFindNodesel(SCIP_SET *set, const char *name)
    Definition: set.c:5062
    SCIP_RETCODE SCIPsetIncludeNodesel(SCIP_SET *set, SCIP_NODESEL *nodesel)
    Definition: set.c:5031
    SCIP_NODESEL * SCIPsetGetNodesel(SCIP_SET *set, SCIP_STAT *stat)
    Definition: set.c:5082
    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_NODESELEXIT(x)
    Definition: type_nodesel.h:86
    #define SCIP_DECL_NODESELCOMP(x)
    Definition: type_nodesel.h:140
    #define SCIP_DECL_NODESELINITSOL(x)
    Definition: type_nodesel.h:97
    #define SCIP_DECL_NODESELCOPY(x)
    Definition: type_nodesel.h:61
    #define SCIP_DECL_NODESELEXITSOL(x)
    Definition: type_nodesel.h:108
    #define SCIP_DECL_NODESELINIT(x)
    Definition: type_nodesel.h:78
    #define SCIP_DECL_NODESELSELECT(x)
    Definition: type_nodesel.h:123
    #define SCIP_DECL_NODESELFREE(x)
    Definition: type_nodesel.h:70
    struct SCIP_NodeselData SCIP_NODESELDATA
    Definition: type_nodesel.h:52
    @ SCIP_INVALIDDATA
    Definition: type_retcode.h:52
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63