Scippy

    SCIP

    Solving Constraint Integer Programs

    objsepa.h
    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 objsepa.h
    26 * @brief C++ wrapper for cut separators
    27 * @author Tobias Achterberg
    28 */
    29
    30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    31
    32#ifndef __SCIP_OBJSEPA_H__
    33#define __SCIP_OBJSEPA_H__
    34
    35#include <cstring>
    36#include <utility>
    37
    38#include "scip/scip.h"
    40
    41namespace scip
    42{
    43
    44/** @brief C++ wrapper for cut separators
    45 *
    46 * This class defines the interface for cut separators implemented in C++.
    47 *
    48 * - \ref SEPA "Instructions for implementing a cut separator"
    49 * - \ref SEPARATORS "List of available cut separators"
    50 * - \ref type_sepa.h "Corresponding C interface"
    51 */
    52class ObjSepa : public ObjCloneable
    53{
    54public:
    55 /*lint --e{1540}*/
    56
    57 /** SCIP data structure */
    59
    60 /** name of the cut separator */
    62
    63 /** description of the cut separator */
    65
    66 /** default priority of the cut separator */
    67 const int scip_priority_;
    68
    69 /** frequency for calling separator */
    70 const int scip_freq_;
    71
    72 /** maximal relative distance from current node's dual bound to primal bound compared to best node's dual bound for applying
    73 * separation (0.0: only on current best node, 1.0: on all nodes)
    74 */
    76
    77 /** does the separator use a secondary SCIP instance? */
    79
    80 /** should separator be delayed, if other separators found cuts? */
    82
    83 /** default constructor */
    85 SCIP* scip, /**< SCIP data structure */
    86 const char* name, /**< name of cut separator */
    87 const char* desc, /**< description of cut separator */
    88 int priority, /**< priority of the cut separator */
    89 int freq, /**< frequency for calling separator */
    90 SCIP_Real maxbounddist, /**< maximal relative distance from current node's dual bound to primal bound compared
    91 * to best node's dual bound for applying separation */
    92 SCIP_Bool usessubscip, /**< does the separator use a secondary SCIP instance? */
    93 SCIP_Bool delay /**< should separator be delayed, if other separators found cuts? */
    94 )
    95 : scip_(scip),
    96 scip_name_(0),
    97 scip_desc_(0),
    98 scip_priority_(priority),
    99 scip_freq_(freq),
    100 scip_maxbounddist_(maxbounddist),
    101 scip_usessubscip_(usessubscip),
    102 scip_delay_(delay)
    103 {
    104 /* the macro SCIPduplicateMemoryArray does not need the first argument: */
    105 SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
    106 SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
    107 }
    108
    109 /** copy constructor */
    110 ObjSepa(const ObjSepa& o)
    113 {
    114 }
    115
    116 /** move constructor */
    118 : scip_(o.scip_),
    119 scip_name_(0),
    120 scip_desc_(0),
    126 {
    127 std::swap(scip_name_, o.scip_name_);
    128 std::swap(scip_desc_, o.scip_desc_);
    129 }
    130
    131 /** destructor */
    132 virtual ~ObjSepa()
    133 {
    134 /* the macro SCIPfreeMemoryArray does not need the first argument: */
    135 /*lint --e{64}*/
    138 }
    139
    140 /** assignment of polymorphic classes causes slicing and is therefore disabled. */
    141 ObjSepa& operator=(const ObjSepa& o) = delete;
    142
    143 /** assignment of polymorphic classes causes slicing and is therefore disabled. */
    144 ObjSepa& operator=(ObjSepa&& o) = delete;
    145
    146 /** destructor of cut separator to free user data (called when SCIP is exiting)
    147 *
    148 * @see SCIP_DECL_SEPAFREE(x) in @ref type_sepa.h
    149 */
    150 virtual SCIP_DECL_SEPAFREE(scip_free)
    151 { /*lint --e{715}*/
    152 return SCIP_OKAY;
    153 }
    154
    155 /** initialization method of cut separator (called after problem was transformed)
    156 *
    157 * @see SCIP_DECL_SEPAINIT(x) in @ref type_sepa.h
    158 */
    159 virtual SCIP_DECL_SEPAINIT(scip_init)
    160 { /*lint --e{715}*/
    161 return SCIP_OKAY;
    162 }
    163
    164 /** deinitialization method of cut separator (called before transformed problem is freed)
    165 *
    166 * @see SCIP_DECL_SEPAEXIT(x) in @ref type_sepa.h
    167 */
    168 virtual SCIP_DECL_SEPAEXIT(scip_exit)
    169 { /*lint --e{715}*/
    170 return SCIP_OKAY;
    171 }
    172
    173 /** solving process initialization method of separator (called when branch and bound process is about to begin)
    174 *
    175 * @see SCIP_DECL_SEPAINITSOL(x) in @ref type_sepa.h
    176 */
    177 virtual SCIP_DECL_SEPAINITSOL(scip_initsol)
    178 { /*lint --e{715}*/
    179 return SCIP_OKAY;
    180 }
    181
    182 /** solving process deinitialization method of separator (called before branch and bound process data is freed)
    183 *
    184 * @see SCIP_DECL_SEPAEXITSOL(x) in @ref type_sepa.h
    185 */
    186 virtual SCIP_DECL_SEPAEXITSOL(scip_exitsol)
    187 { /*lint --e{715}*/
    188 return SCIP_OKAY;
    189 }
    190
    191 /** LP solution separation method of separator
    192 *
    193 * @see SCIP_DECL_SEPAEXECLP(x) in @ref type_sepa.h
    194 */
    195 virtual SCIP_DECL_SEPAEXECLP(scip_execlp)
    196 { /*lint --e{715}*/
    197 assert(result != NULL);
    198 *result = SCIP_DIDNOTRUN;
    199 return SCIP_OKAY;
    200 }
    201
    202 /** arbitrary primal solution separation method of separator
    203 *
    204 * @see SCIP_DECL_SEPAEXECSOL(x) in @ref type_sepa.h
    205 */
    206 virtual SCIP_DECL_SEPAEXECSOL(scip_execsol)
    207 { /*lint --e{715}*/
    208 assert(result != NULL);
    209 *result = SCIP_DIDNOTRUN;
    210 return SCIP_OKAY;
    211 }
    212};
    213
    214} /* namespace scip */
    215
    216
    217
    218/** creates the cut separator for the given cut separator object and includes it in SCIP
    219 *
    220 * The method should be called in one of the following ways:
    221 *
    222 * 1. The user is resposible of deleting the object:
    223 * SCIP_CALL( SCIPcreate(&scip) );
    224 * ...
    225 * MySepa* mysepa = new MySepa(...);
    226 * SCIP_CALL( SCIPincludeObjSepa(scip, &mysepa, FALSE) );
    227 * ...
    228 * SCIP_CALL( SCIPfree(&scip) );
    229 * delete mysepa; // delete sepa AFTER SCIPfree() !
    230 *
    231 * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
    232 * SCIP_CALL( SCIPcreate(&scip) );
    233 * ...
    234 * SCIP_CALL( SCIPincludeObjSepa(scip, new MySepa(...), TRUE) );
    235 * ...
    236 * SCIP_CALL( SCIPfree(&scip) ); // destructor of MySepa is called here
    237 */
    238SCIP_EXPORT
    240 SCIP* scip, /**< SCIP data structure */
    241 scip::ObjSepa* objsepa, /**< cut separator object */
    242 SCIP_Bool deleteobject /**< should the cut separator object be deleted when cut separator is freed? */
    243 );
    244
    245/** returns the sepa object of the given name, or 0 if not existing */
    246SCIP_EXPORT
    248 SCIP* scip, /**< SCIP data structure */
    249 const char* name /**< name of cut separator */
    250 );
    251
    252/** returns the sepa object for the given cut separator */
    253SCIP_EXPORT
    255 SCIP* scip, /**< SCIP data structure */
    256 SCIP_SEPA* sepa /**< cut separator */
    257 );
    258
    259#endif
    C++ wrapper for cut separators.
    Definition: objsepa.h:53
    virtual SCIP_DECL_SEPAEXECSOL(scip_execsol)
    Definition: objsepa.h:206
    virtual SCIP_DECL_SEPAEXIT(scip_exit)
    Definition: objsepa.h:168
    char * scip_desc_
    Definition: objsepa.h:64
    const SCIP_Bool scip_delay_
    Definition: objsepa.h:81
    virtual SCIP_DECL_SEPAFREE(scip_free)
    Definition: objsepa.h:150
    ObjSepa(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_Real maxbounddist, SCIP_Bool usessubscip, SCIP_Bool delay)
    Definition: objsepa.h:84
    virtual SCIP_DECL_SEPAEXITSOL(scip_exitsol)
    Definition: objsepa.h:186
    const SCIP_Real scip_maxbounddist_
    Definition: objsepa.h:75
    SCIP * scip_
    Definition: objsepa.h:58
    ObjSepa(const ObjSepa &o)
    Definition: objsepa.h:110
    virtual SCIP_DECL_SEPAINIT(scip_init)
    Definition: objsepa.h:159
    virtual SCIP_DECL_SEPAINITSOL(scip_initsol)
    Definition: objsepa.h:177
    ObjSepa(ObjSepa &&o)
    Definition: objsepa.h:117
    ObjSepa & operator=(ObjSepa &&o)=delete
    const SCIP_Bool scip_usessubscip_
    Definition: objsepa.h:78
    const int scip_freq_
    Definition: objsepa.h:70
    ObjSepa & operator=(const ObjSepa &o)=delete
    const int scip_priority_
    Definition: objsepa.h:67
    virtual ~ObjSepa()
    Definition: objsepa.h:132
    char * scip_name_
    Definition: objsepa.h:61
    virtual SCIP_DECL_SEPAEXECLP(scip_execlp)
    Definition: objsepa.h:195
    #define NULL
    Definition: def.h:248
    #define SCIP_Bool
    Definition: def.h:91
    #define SCIP_Real
    Definition: def.h:156
    #define SCIP_CALL_ABORT(x)
    Definition: def.h:334
    #define SCIPduplicateMemoryArray(scip, ptr, source, num)
    Definition: scip_mem.h:76
    #define SCIPfreeMemoryArray(scip, ptr)
    Definition: scip_mem.h:80
    definition of base class for all clonable classes
    SCIP_RETCODE SCIPincludeObjSepa(SCIP *scip, scip::ObjSepa *objsepa, SCIP_Bool deleteobject)
    Definition: objsepa.cpp:220
    scip::ObjSepa * SCIPgetObjSepa(SCIP *scip, SCIP_SEPA *sepa)
    Definition: objsepa.cpp:266
    scip::ObjSepa * SCIPfindObjSepa(SCIP *scip, const char *name)
    Definition: objsepa.cpp:247
    SCIP callable library.
    Definition of base class for all clonable classes.
    Definition: objcloneable.h:48
    @ SCIP_DIDNOTRUN
    Definition: type_result.h:42
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63