Scippy

    SCIP

    Solving Constraint Integer Programs

    scip_relax.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_relax.c
    26 * @ingroup OTHER_CFILES
    27 * @brief public methods for relaxator 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/pub_message.h"
    47#include "scip/relax.h"
    48#include "scip/scip_relax.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 relaxation handler and includes it in SCIP
    55 *
    56 * @note method has all relaxation handler callbacks as arguments and is thus changed every time a new
    57 * callback is added
    58 * in future releases; consider using SCIPincludeRelaxBasic() and setter functions
    59 * if you seek for a method which is less likely to change in future releases
    60 */
    62 SCIP* scip, /**< SCIP data structure */
    63 const char* name, /**< name of relaxation handler */
    64 const char* desc, /**< description of relaxation handler */
    65 int priority, /**< priority of the relaxation handler (negative: after LP, non-negative: before LP) */
    66 int freq, /**< frequency for calling relaxation handler */
    67 SCIP_DECL_RELAXCOPY ((*relaxcopy)), /**< copy method of relaxation handler or NULL if you don't want to copy your plugin into sub-SCIPs */
    68 SCIP_DECL_RELAXFREE ((*relaxfree)), /**< destructor of relaxation handler */
    69 SCIP_DECL_RELAXINIT ((*relaxinit)), /**< initialize relaxation handler */
    70 SCIP_DECL_RELAXEXIT ((*relaxexit)), /**< deinitialize relaxation handler */
    71 SCIP_DECL_RELAXINITSOL((*relaxinitsol)), /**< solving process initialization method of relaxation handler */
    72 SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), /**< solving process deinitialization method of relaxation handler */
    73 SCIP_DECL_RELAXEXEC ((*relaxexec)), /**< execution method of relaxation handler */
    74 SCIP_RELAXDATA* relaxdata /**< relaxation handler data */
    75 )
    76{
    77 SCIP_RELAX* relax;
    78
    80
    81 /* check whether relaxation handler is already present */
    82 if( SCIPfindRelax(scip, name) != NULL )
    83 {
    84 SCIPerrorMessage("relaxation handler <%s> already included.\n", name);
    85 return SCIP_INVALIDDATA;
    86 }
    87
    88 SCIP_CALL( SCIPrelaxCreate(&relax, scip->set, scip->messagehdlr, scip->mem->setmem,
    89 name, desc, priority, freq, relaxcopy,
    90 relaxfree, relaxinit, relaxexit, relaxinitsol, relaxexitsol, relaxexec, relaxdata) );
    91 SCIP_CALL( SCIPsetIncludeRelax(scip->set, relax) );
    92
    93 return SCIP_OKAY;
    94}
    95
    96/** creates a relaxation handler and includes it in SCIP. All non fundamental
    97 * (or optional) callbacks as, e.g., init and exit callbacks, will be set to NULL.
    98 * Optional callbacks can be set via specific setter functions, see SCIPsetRelaxInit(), SCIPsetRelaxExit(),
    99 * SCIPsetRelaxCopy(), SCIPsetRelaxFree(), SCIPsetRelaxInitsol(), and SCIPsetRelaxExitsol()
    100 * @pre This method can be called if SCIP is in one of the following stages:
    101 * - \ref SCIP_STAGE_INIT
    102 * - \ref SCIP_STAGE_PROBLEM
    103 *
    104 * @note if you want to set all callbacks with a single method call, consider using SCIPincludeRelax() instead
    105 */
    107 SCIP* scip, /**< SCIP data structure */
    108 SCIP_RELAX** relaxptr, /**< reference to relaxation pointer, or NULL */
    109 const char* name, /**< name of relaxation handler */
    110 const char* desc, /**< description of relaxation handler */
    111 int priority, /**< priority of the relaxation handler (negative: after LP, non-negative: before LP) */
    112 int freq, /**< frequency for calling relaxation handler */
    113 SCIP_DECL_RELAXEXEC ((*relaxexec)), /**< execution method of relaxation handler */
    114 SCIP_RELAXDATA* relaxdata /**< relaxation handler data */
    115 )
    116{
    117 SCIP_RELAX* relax;
    118
    119 SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeRelaxBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
    120
    121 /* check whether relaxation handler is already present */
    122 if( SCIPfindRelax(scip, name) != NULL )
    123 {
    124 SCIPerrorMessage("relaxation handler <%s> already included.\n", name);
    125 return SCIP_INVALIDDATA;
    126 }
    127
    128 SCIP_CALL( SCIPrelaxCreate(&relax, scip->set, scip->messagehdlr, scip->mem->setmem,
    129 name, desc, priority, freq,
    130 NULL, NULL, NULL, NULL, NULL, NULL, relaxexec, relaxdata) );
    131 SCIP_CALL( SCIPsetIncludeRelax(scip->set, relax) );
    132
    133 if( relaxptr != NULL )
    134 *relaxptr = relax;
    135
    136 return SCIP_OKAY;
    137}
    138
    139/** sets copy method of relaxation handler */
    141 SCIP* scip, /**< SCIP data structure */
    142 SCIP_RELAX* relax, /**< relaxation handler */
    143 SCIP_DECL_RELAXCOPY ((*relaxcopy)) /**< copy method of relaxation handler or NULL if you don't want to copy your plugin into sub-SCIPs */
    144 )
    145{
    147
    148 assert(relax != NULL);
    149
    150 SCIPrelaxSetCopy(relax, relaxcopy);
    151
    152 return SCIP_OKAY;
    153}
    154
    155/** sets destructor method of relaxation handler */
    157 SCIP* scip, /**< SCIP data structure */
    158 SCIP_RELAX* relax, /**< relaxation handler */
    159 SCIP_DECL_RELAXFREE ((*relaxfree)) /**< destructor of relaxation handler */
    160 )
    161{
    163
    164 assert(relax != NULL);
    165
    166 SCIPrelaxSetFree(relax, relaxfree);
    167
    168 return SCIP_OKAY;
    169}
    170
    171/** sets initialization method of relaxation handler */
    173 SCIP* scip, /**< SCIP data structure */
    174 SCIP_RELAX* relax, /**< relaxation handler */
    175 SCIP_DECL_RELAXINIT ((*relaxinit)) /**< initialize relaxation handler */
    176 )
    177{
    179
    180 assert(relax != NULL);
    181
    182 SCIPrelaxSetInit(relax, relaxinit);
    183
    184 return SCIP_OKAY;
    185}
    186
    187/** sets deinitialization method of relaxation handler */
    189 SCIP* scip, /**< SCIP data structure */
    190 SCIP_RELAX* relax, /**< relaxation handler */
    191 SCIP_DECL_RELAXEXIT ((*relaxexit)) /**< deinitialize relaxation handler */
    192 )
    193{
    195
    196 assert(relax != NULL);
    197
    198 SCIPrelaxSetExit(relax, relaxexit);
    199
    200 return SCIP_OKAY;
    201}
    202
    203/** sets solving process initialization method of relaxation handler */
    205 SCIP* scip, /**< SCIP data structure */
    206 SCIP_RELAX* relax, /**< relaxation handler */
    207 SCIP_DECL_RELAXINITSOL((*relaxinitsol)) /**< solving process initialization method of relaxation handler */
    208 )
    209{
    211
    212 assert(relax != NULL);
    213
    214 SCIPrelaxSetInitsol(relax, relaxinitsol);
    215
    216 return SCIP_OKAY;
    217}
    218
    219/** sets solving process deinitialization method of relaxation handler */
    221 SCIP* scip, /**< SCIP data structure */
    222 SCIP_RELAX* relax, /**< relaxation handler */
    223 SCIP_DECL_RELAXEXITSOL((*relaxexitsol)) /**< solving process deinitialization method of relaxation handler */
    224 )
    225{
    227
    228 assert(relax != NULL);
    229
    230 SCIPrelaxSetExitsol(relax, relaxexitsol);
    231
    232 return SCIP_OKAY;
    233}
    234
    235
    236/** returns the relaxation handler of the given name, or NULL if not existing */
    238 SCIP* scip, /**< SCIP data structure */
    239 const char* name /**< name of relaxation handler */
    240 )
    241{
    242 assert(scip != NULL);
    243 assert(scip->set != NULL);
    244 assert(name != NULL);
    245
    246 return SCIPsetFindRelax(scip->set, name);
    247}
    248
    249/** returns the array of currently available relaxation handlers */
    251 SCIP* scip /**< SCIP data structure */
    252 )
    253{
    254 assert(scip != NULL);
    255 assert(scip->set != NULL);
    256
    258
    259 return scip->set->relaxs;
    260}
    261
    262/** returns the number of currently available relaxation handlers */
    264 SCIP* scip /**< SCIP data structure */
    265 )
    266{
    267 assert(scip != NULL);
    268 assert(scip->set != NULL);
    269
    270 return scip->set->nrelaxs;
    271}
    272
    273/** sets the priority of a relaxation handler */
    275 SCIP* scip, /**< SCIP data structure */
    276 SCIP_RELAX* relax, /**< relaxation handler */
    277 int priority /**< new priority of the relaxation handler */
    278 )
    279{
    280 assert(scip != NULL);
    281 assert(scip->set != NULL);
    282
    283 SCIPrelaxSetPriority(relax, scip->set, priority);
    284
    285 return SCIP_OKAY;
    286}
    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 SCIPsetRelaxCopy(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXCOPY((*relaxcopy)))
    Definition: scip_relax.c:140
    SCIP_RETCODE SCIPincludeRelax(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXCOPY((*relaxcopy)), SCIP_DECL_RELAXFREE((*relaxfree)), SCIP_DECL_RELAXINIT((*relaxinit)), SCIP_DECL_RELAXEXIT((*relaxexit)), SCIP_DECL_RELAXINITSOL((*relaxinitsol)), SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
    Definition: scip_relax.c:61
    SCIP_RELAX ** SCIPgetRelaxs(SCIP *scip)
    Definition: scip_relax.c:250
    int SCIPgetNRelaxs(SCIP *scip)
    Definition: scip_relax.c:263
    SCIP_RETCODE SCIPsetRelaxExitsol(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXEXITSOL((*relaxexitsol)))
    Definition: scip_relax.c:220
    SCIP_RETCODE SCIPsetRelaxExit(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXEXIT((*relaxexit)))
    Definition: scip_relax.c:188
    SCIP_RETCODE SCIPsetRelaxPriority(SCIP *scip, SCIP_RELAX *relax, int priority)
    Definition: scip_relax.c:274
    SCIP_RETCODE SCIPsetRelaxFree(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXFREE((*relaxfree)))
    Definition: scip_relax.c:156
    SCIP_RETCODE SCIPsetRelaxInit(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXINIT((*relaxinit)))
    Definition: scip_relax.c:172
    SCIP_RETCODE SCIPsetRelaxInitsol(SCIP *scip, SCIP_RELAX *relax, SCIP_DECL_RELAXINITSOL((*relaxinitsol)))
    Definition: scip_relax.c:204
    SCIP_RETCODE SCIPincludeRelaxBasic(SCIP *scip, SCIP_RELAX **relaxptr, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
    Definition: scip_relax.c:106
    SCIP_RELAX * SCIPfindRelax(SCIP *scip, const char *name)
    Definition: scip_relax.c:237
    public methods for message output
    #define SCIPerrorMessage
    Definition: pub_message.h:64
    void SCIPrelaxSetExitsol(SCIP_RELAX *relax, SCIP_DECL_RELAXEXITSOL((*relaxexitsol)))
    Definition: relax.c:536
    void SCIPrelaxSetInitsol(SCIP_RELAX *relax, SCIP_DECL_RELAXINITSOL((*relaxinitsol)))
    Definition: relax.c:525
    SCIP_RETCODE SCIPrelaxCreate(SCIP_RELAX **relax, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, int priority, int freq, SCIP_DECL_RELAXCOPY((*relaxcopy)), SCIP_DECL_RELAXFREE((*relaxfree)), SCIP_DECL_RELAXINIT((*relaxinit)), SCIP_DECL_RELAXEXIT((*relaxexit)), SCIP_DECL_RELAXINITSOL((*relaxinitsol)), SCIP_DECL_RELAXEXITSOL((*relaxexitsol)), SCIP_DECL_RELAXEXEC((*relaxexec)), SCIP_RELAXDATA *relaxdata)
    Definition: relax.c:173
    void SCIPrelaxSetInit(SCIP_RELAX *relax, SCIP_DECL_RELAXINIT((*relaxinit)))
    Definition: relax.c:503
    void SCIPrelaxSetExit(SCIP_RELAX *relax, SCIP_DECL_RELAXEXIT((*relaxexit)))
    Definition: relax.c:514
    void SCIPrelaxSetFree(SCIP_RELAX *relax, SCIP_DECL_RELAXFREE((*relaxfree)))
    Definition: relax.c:492
    void SCIPrelaxSetCopy(SCIP_RELAX *relax, SCIP_DECL_RELAXCOPY((*relaxcopy)))
    Definition: relax.c:481
    void SCIPrelaxSetPriority(SCIP_RELAX *relax, SCIP_SET *set, int priority)
    Definition: relax.c:587
    internal methods for relaxators
    public methods for relaxator plugins
    SCIP_RETCODE SCIPsetIncludeRelax(SCIP_SET *set, SCIP_RELAX *relax)
    Definition: set.c:4411
    SCIP_RELAX * SCIPsetFindRelax(SCIP_SET *set, const char *name)
    Definition: set.c:4435
    void SCIPsetSortRelaxs(SCIP_SET *set)
    Definition: set.c:4455
    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_RELAXINIT(x)
    Definition: type_relax.h:77
    #define SCIP_DECL_RELAXEXITSOL(x)
    Definition: type_relax.h:107
    #define SCIP_DECL_RELAXFREE(x)
    Definition: type_relax.h:69
    #define SCIP_DECL_RELAXINITSOL(x)
    Definition: type_relax.h:96
    #define SCIP_DECL_RELAXCOPY(x)
    Definition: type_relax.h:61
    #define SCIP_DECL_RELAXEXEC(x)
    Definition: type_relax.h:132
    #define SCIP_DECL_RELAXEXIT(x)
    Definition: type_relax.h:85
    struct SCIP_RelaxData SCIP_RELAXDATA
    Definition: type_relax.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