Scippy

    SCIP

    Solving Constraint Integer Programs

    objprobdata.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 objprobdata.h
    26 * @brief C++ wrapper for user problem data
    27 * @author Tobias Achterberg
    28 */
    29
    30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
    31
    32#ifndef __SCIP_OBJPROBDATA_H__
    33#define __SCIP_OBJPROBDATA_H__
    34
    35
    36#include <cassert>
    37
    38#include "scip/scip.h"
    40
    41namespace scip
    42{
    43
    44/** @brief C++ wrapper for user problem data
    45 *
    46 * This class defines the interface for user problem data implemented in C++. This class can be accessed at any time
    47 * using the methods SCIPgetObjProbData(). Therefore, it can be used to store data which has to be accessible within
    48 * several plugins.
    49 *
    50 * - \ref type_prob.h "Corresponding C interface"
    51 */
    53{
    54public:
    55 /** default constructor */
    57 {
    58 }
    59
    60 /** destructor */
    61 virtual ~ObjProbData()
    62 {
    63 }
    64
    65 /** assignment of polymorphic classes causes slicing and is therefore disabled. */
    66 ObjProbData& operator=(const ObjProbData& o) = delete;
    67
    68 /** assignment of polymorphic classes causes slicing and is therefore disabled. */
    70
    71 /** destructor of user problem data to free original user data (called when original problem is freed)
    72 *
    73 * If the "deleteobject" flag in the SCIPcreateObjProb() method was set to TRUE, this method is not needed,
    74 * because all the work to delete the user problem data can be done in the destructor of the user problem
    75 * data object. If the "deleteobject" flag was set to FALSE, and the user problem data object stays alive
    76 * after the SCIP problem is freed, this method should delete all the problem specific data that is no
    77 * longer needed.
    78 */ /*lint -e715*/
    80 SCIP* scip /**< SCIP data structure */
    81 )
    82 { /*lint --e{715}*/
    83 return SCIP_OKAY;
    84 }
    85
    86 /** creates user data of transformed problem by transforming the original user problem data
    87 * (called after problem was transformed)
    88 *
    89 * The user has two possibilities to implement this method:
    90 * 1. Return the pointer to the original problem data object (this) as pointer to the transformed problem data
    91 * object. The user may modify some internal attributes, but he has to make sure, that these modifications are
    92 * reversed in the scip_deltrans() method, such that the original problem data is restored. In this case,
    93 * he should set *deleteobject to FALSE, because the problem data must not be destructed by SCIP after the
    94 * solving process is terminated.
    95 * 2. Call the copy constructor of the problem data object and return the created copy as transformed problem
    96 * data object. In this case, he probably wants to set *deleteobject to TRUE, thus letting SCIP call the
    97 * destructor of the object if the transformed problem data is no longer needed.
    98 */ /*lint -e715*/
    100 SCIP* scip, /**< SCIP data structure */
    101 ObjProbData** objprobdata, /**< pointer to store the transformed problem data object */
    102 SCIP_Bool* deleteobject /**< pointer to store whether SCIP should delete the object after solving */
    103 )
    104 { /*lint --e{715}*/
    105 assert(objprobdata != NULL);
    106 assert(deleteobject != NULL);
    107
    108 /* the default implementation just copies the pointer to the problem data object;
    109 * SCIP must not destruct the transformed problem data object, because the original problem data must stay alive
    110 */
    111 *objprobdata = this;
    112 *deleteobject = FALSE;
    113
    114 return SCIP_OKAY;
    115 }
    116
    117 /** destructor of user problem data to free transformed user data (called when transformed problem is freed)
    118 *
    119 * If the "*deleteobject" flag in the scip_trans() method was set to TRUE, this method is not needed,
    120 * because all the work to delete the user problem data can be done in the destructor of the user problem
    121 * data object. If the "*deleteobject" flag was set to FALSE, and the user problem data object stays alive
    122 * after the SCIP problem is freed, this method should delete all the problem specific data that is no
    123 * longer needed.
    124 */ /*lint -e715*/
    126 SCIP* scip /**< SCIP data structure */
    127 )
    128 { /*lint --e{715}*/
    129 return SCIP_OKAY;
    130 }
    131
    132 /** solving process initialization method of transformed data (called before the branch and bound process begins)
    133 *
    134 * This method is called before the branch and bound process begins and can be used to initialize user problem
    135 * data that depends for example on the number of active problem variables, because these are now fixed.
    136 */ /*lint -e715*/
    138 SCIP* scip /**< SCIP data structure */
    139 )
    140 { /*lint --e{715}*/
    141 return SCIP_OKAY;
    142 }
    143
    144 /** solving process deinitialization method of transformed data (called before the branch and bound data is freed)
    145 *
    146 * This method is called before the branch and bound data is freed and should be used to free all data that
    147 * was allocated in the solving process initialization method. The user has to make sure, that all LP rows associated
    148 * to the transformed user problem data are released.
    149 */ /*lint -e715*/
    151 SCIP* scip, /**< SCIP data structure */
    152 SCIP_Bool restart /**< was this exit solve call triggered by a restart? */
    153 )
    154 { /*lint --e{715}*/
    155 return SCIP_OKAY;
    156 }
    157
    158 /** copies user data of source SCIP for the target SCIP
    159 *
    160 * This method should copy the problem data of the source SCIP and create a target problem data for (target)
    161 * SCIP. Implementing this callback is optional. If the copying process was successful the target SCIP gets this
    162 * problem data assigned. In case the result pointer is set to SCIP_DIDNOTRUN the target SCIP will have no problem data
    163 * at all.
    164 *
    165 * The variable map and the constraint map can be used via the function SCIPgetVarCopy() and SCIPgetConsCopy(),
    166 * respectively, to get for certain variables and constraints of the source SCIP the counter parts in the target
    167 * SCIP. You should be very carefully in using these two methods since they could lead to an infinite loop due to
    168 * recursion.
    169 *
    170 * possible return values for *result:
    171 * - SCIP_DIDNOTRUN : the copying process was not performed
    172 * - SCIP_SUCCESS : the copying process was successfully performed
    173 */ /*lint -e715*/
    175 SCIP* scip, /**< SCIP data structure */
    176 SCIP* sourcescip, /**< source SCIP main data structure */
    177 SCIP_HASHMAP* varmap, /**< a hashmap which stores the mapping of source variables to corresponding
    178 * target variables */
    179 SCIP_HASHMAP* consmap, /**< a hashmap which stores the mapping of source contraints to corresponding
    180 * target constraints */
    181 ObjProbData** objprobdata, /**< pointer to store the copied problem data object */
    182 SCIP_Bool global, /**< create a global or a local copy? */
    183 SCIP_RESULT* result /**< pointer to store the result of the call */
    184 )
    185 { /*lint --e{715}*/
    186 (*objprobdata) = 0;
    187 (*result) = SCIP_DIDNOTRUN;
    188 return SCIP_OKAY;
    189 }
    190};
    191
    192} /* namespace scip */
    193
    194
    195
    196/** creates empty problem, initializes all solving data structures, and sets the user problem data to point to the
    197 * given user data object
    198 *
    199 * The method should be called in one of the following ways:
    200 *
    201 * 1. The user is resposible of deleting the object:
    202 * SCIP_CALL( SCIPcreate(&scip) );
    203 * ...
    204 * MyProbData* myprobdata = new MyProbData(...);
    205 * SCIP_CALL( SCIPcreateObjProb(scip, "probname", &myprobdata, FALSE) );
    206 * ... // solve the problem
    207 * SCIP_CALL( SCIPfreeProb(scip) );
    208 * delete myprobdata; // delete probdata AFTER SCIPfreeProb() !
    209 * ...
    210 * SCIP_CALL( SCIPfree(&scip) );
    211 *
    212 * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfreeProb() call:
    213 * SCIP_CALL( SCIPcreate(&scip) );
    214 * ...
    215 * SCIP_CALL( SCIPcreateObjProb(scip, "probname", new MyProbData(...), TRUE) );
    216 * ...
    217 * SCIP_CALL( SCIPfree(&scip) ); // problem is freed and destructor of MyProbData is called here
    218 */
    219SCIP_EXPORT
    221 SCIP* scip, /**< SCIP data structure */
    222 const char* name, /**< problem name */
    223 scip::ObjProbData* objprobdata, /**< user problem data object */
    224 SCIP_Bool deleteobject /**< should the user problem data object be deleted when problem is freed? */
    225 );
    226
    227/** gets user problem data object
    228 * Warning! This method should only be called after a problem was created with SCIPcreateObjProb().
    229 * Otherwise, a segmentation fault may arise, or an undefined pointer is returned.
    230 */
    231SCIP_EXPORT
    233 SCIP* scip /**< SCIP data structure */
    234 );
    235
    236#endif
    C++ wrapper for user problem data.
    Definition: objprobdata.h:53
    ObjProbData & operator=(ObjProbData &&o)=delete
    ObjProbData & operator=(const ObjProbData &o)=delete
    virtual SCIP_RETCODE scip_delorig(SCIP *scip)
    Definition: objprobdata.h:79
    virtual SCIP_RETCODE scip_exitsol(SCIP *scip, SCIP_Bool restart)
    Definition: objprobdata.h:150
    virtual SCIP_RETCODE scip_copy(SCIP *scip, SCIP *sourcescip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, ObjProbData **objprobdata, SCIP_Bool global, SCIP_RESULT *result)
    Definition: objprobdata.h:174
    virtual SCIP_RETCODE scip_trans(SCIP *scip, ObjProbData **objprobdata, SCIP_Bool *deleteobject)
    Definition: objprobdata.h:99
    virtual SCIP_RETCODE scip_initsol(SCIP *scip)
    Definition: objprobdata.h:137
    virtual ~ObjProbData()
    Definition: objprobdata.h:61
    virtual SCIP_RETCODE scip_deltrans(SCIP *scip)
    Definition: objprobdata.h:125
    #define NULL
    Definition: def.h:248
    #define SCIP_Bool
    Definition: def.h:91
    #define FALSE
    Definition: def.h:94
    definition of base class for all clonable classes
    SCIP_RETCODE SCIPcreateObjProb(SCIP *scip, const char *name, scip::ObjProbData *objprobdata, SCIP_Bool deleteobject)
    scip::ObjProbData * SCIPgetObjProbData(SCIP *scip)
    SCIP callable library.
    @ SCIP_DIDNOTRUN
    Definition: type_result.h:42
    enum SCIP_Result SCIP_RESULT
    Definition: type_result.h:61
    @ SCIP_OKAY
    Definition: type_retcode.h:42
    enum SCIP_Retcode SCIP_RETCODE
    Definition: type_retcode.h:63