Scippy

SCIP

Solving Constraint Integer Programs

objvardata.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-2024 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 objvardata.h
26 * @brief C++ wrapper for user variable data
27 * @author Tobias Achterberg
28 */
29
30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31
32#ifndef __SCIP_OBJVARDATA_H__
33#define __SCIP_OBJVARDATA_H__
34
35
36#include <cassert>
37
38#include "scip/scip.h"
40
41namespace scip
42{
43
44/** @brief C++ wrapper for user variable data
45 *
46 * This class defines the interface for user variable data implemented in C++. Each variable can be equipped with a
47 * variable data class. This data can be accessed via the function SCIPgetObjVardata() at any time after it is created
48 * and before it is deleted.
49 *
50 * - \ref type_var.h "Corresponding C interface"
51 */
53{
54public:
55 /** default constructor */
57 {
58 }
59
60 /** destructor */
61 virtual ~ObjVardata()
62 {
63 }
64
65 /** assignment of polymorphic classes causes slicing and is therefore disabled. */
66 ObjVardata& operator=(const ObjVardata& o) = delete;
67
68 /** assignment of polymorphic classes causes slicing and is therefore disabled. */
70
71 /** destructor of user variable data to free original user data (called when original variable is freed)
72 *
73 * If the "deleteobject" flag in the SCIPcreateObjVar() method was set to TRUE, this method is not needed,
74 * because all the work to delete the user variable data can be done in the destructor of the user variable
75 * data object. If the "deleteobject" flag was set to FALSE, and the user variable data object stays alive
76 * after the SCIP variable is freed, this method should delete all the variable specific data that is no
77 * longer needed.
78 */ /*lint -e715*/
80 SCIP* scip, /**< SCIP data structure */
81 SCIP_VAR* var /**< original variable, the data to free is belonging to */
82 )
83 { /*lint --e{715}*/
84 return SCIP_OKAY;
85 }
86
87 /** creates user data of transformed variable by transforming the original user variable data
88 * (called after variable was transformed)
89 *
90 * The user has two possibilities to implement this method:
91 * 1. Return the pointer to the original variable data object (this) as pointer to the transformed variable data
92 * object. The user may modify some internal attributes, but he has to make sure, that these modifications are
93 * reversed in the scip_deltrans() method, such that the original variable data is restored. In this case,
94 * he should set *deleteobject to FALSE, because the variable data must not be destructed by SCIP after the
95 * solving process is terminated.
96 * 2. Call the copy constructor of the variable data object and return the created copy as transformed variable
97 * data object. In this case, he probably wants to set *deleteobject to TRUE, thus letting SCIP call the
98 * destructor of the object if the transformed variable data is no longer needed.
99 */ /*lint -e715*/
101 SCIP* scip, /**< SCIP data structure */
102 SCIP_VAR* var, /**< transformed variable, the data to create is belonging to */
103 ObjVardata** objvardata, /**< pointer to store the transformed variable data object */
104 SCIP_Bool* deleteobject /**< pointer to store whether SCIP should delete the object after solving */
105 )
106 { /*lint --e{715}*/
107 assert(objvardata != NULL);
108 assert(deleteobject != NULL);
109
110 /* the default implementation just copies the pointer to the variable data object;
111 * SCIP must not destruct the transformed variable data object, because the original variable data must stay alive
112 */
113 *objvardata = this;
114 *deleteobject = FALSE;
115
116 return SCIP_OKAY;
117 }
118
119 /** destructor of user variable data to free transformed user data (called when transformed variable is freed)
120 *
121 * If the "*deleteobject" flag in the scip_trans() method was set to TRUE, this method is not needed,
122 * because all the work to delete the user variable data can be done in the destructor of the user variable
123 * data object. If the "*deleteobject" flag was set to FALSE, and the user variable data object stays alive
124 * after the SCIP variable is freed, this method should delete all the variable specific data that is no
125 * longer needed.
126 */ /*lint -e715*/
128 SCIP* scip, /**< SCIP data structure */
129 SCIP_VAR* var /**< transformed variable, the data to free is belonging to */
130 )
131 { /*lint --e{715}*/
132 return SCIP_OKAY;
133 }
134
135 /** copies variable data of source SCIP variable for the target SCIP variable
136 *
137 * This method should copy the variable data of the source SCIP and create a target variable data for target
138 * variable. This callback is optional. If the copying process was successful, the target variable gets this variable
139 * data assigned. In case the result pointer is set to SCIP_DIDNOTRUN, the target variable will have no variable data at
140 * all.
141 *
142 * The variable map and the constraint map can be used via the function SCIPgetVarCopy() and SCIPgetConsCopy(),
143 * respectively, to get for certain variables and constraints of the source SCIP the counter parts in the target
144 * SCIP. You should be very carefully in using these two methods since they could lead to infinite loop.
145 *
146 * possible return values for *result:
147 * - SCIP_DIDNOTRUN : the copying process was not performed
148 * - SCIP_SUCCESS : the copying process was successfully performed
149 */ /*lint -e715*/
151 SCIP* scip, /**< SCIP data structure */
152 SCIP* sourcescip, /**< source SCIP main data structure */
153 SCIP_VAR* sourcevar, /**< variable of the source SCIP */
154 SCIP_HASHMAP* varmap, /**< a hashmap which stores the mapping of source variables to corresponding
155 * target variables */
156 SCIP_HASHMAP* consmap, /**< a hashmap which stores the mapping of source contraints to corresponding
157 * target constraints */
158 SCIP_VAR* targetvar, /**< variable of the (targert) SCIP (targetvar is the copy of sourcevar) */
159 ObjVardata** objvardata, /**< pointer to store the copied variable data object */
160 SCIP_RESULT* result /**< pointer to store the result of the call */
161 )
162 { /*lint --e{715}*/
163 assert(objvardata != NULL);
164 assert(result != NULL);
165 *objvardata = 0;
166 *result = SCIP_DIDNOTRUN;
167 return SCIP_OKAY;
168 }
169};
170
171} /* namespace scip */
172
173
174
175/** create and capture problem variable and associates the given variable data with the variable;
176 * if variable is of integral type, fractional bounds are automatically rounded
177 */
178SCIP_EXPORT
180 SCIP* scip, /**< SCIP data structure */
181 SCIP_VAR** var, /**< pointer to variable object */
182 const char* name, /**< name of variable, or NULL for automatic name creation */
183 SCIP_Real lb, /**< lower bound of variable */
184 SCIP_Real ub, /**< upper bound of variable */
185 SCIP_Real obj, /**< objective function value */
186 SCIP_VARTYPE vartype, /**< type of variable */
187 SCIP_Bool initial, /**< should var's column be present in the initial root LP? */
188 SCIP_Bool removable, /**< is var's column removable from the LP (due to aging or cleanup)? */
189 scip::ObjVardata* objvardata, /**< user variable data object */
190 SCIP_Bool deleteobject /**< should the user variable data object be deleted when variable is freed? */
191 );
192
193/** gets user variable data object for given problem variable
194 * Warning! This method should only be called after a variable was created with SCIPcreateObjVar().
195 * Otherwise, a segmentation fault may arise, or an undefined pointer is returned.
196 */
197SCIP_EXPORT
199 SCIP* scip, /**< SCIP data structure */
200 SCIP_VAR* var /**< problem variable */
201 );
202
203#endif
C++ wrapper for user variable data.
Definition: objvardata.h:53
virtual SCIP_RETCODE scip_delorig(SCIP *scip, SCIP_VAR *var)
Definition: objvardata.h:79
ObjVardata & operator=(ObjVardata &&o)=delete
virtual SCIP_RETCODE scip_trans(SCIP *scip, SCIP_VAR *var, ObjVardata **objvardata, SCIP_Bool *deleteobject)
Definition: objvardata.h:100
virtual SCIP_RETCODE scip_copy(SCIP *scip, SCIP *sourcescip, SCIP_VAR *sourcevar, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_VAR *targetvar, ObjVardata **objvardata, SCIP_RESULT *result)
Definition: objvardata.h:150
virtual SCIP_RETCODE scip_deltrans(SCIP *scip, SCIP_VAR *var)
Definition: objvardata.h:127
virtual ~ObjVardata()
Definition: objvardata.h:61
ObjVardata & operator=(const ObjVardata &o)=delete
#define NULL
Definition: def.h:267
#define SCIP_Bool
Definition: def.h:91
#define SCIP_Real
Definition: def.h:173
#define FALSE
Definition: def.h:94
definition of base class for all clonable classes
SCIP_RETCODE SCIPcreateObjVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, scip::ObjVardata *objvardata, SCIP_Bool deleteobject)
Definition: objvardata.cpp:175
scip::ObjVardata * SCIPgetObjVardata(SCIP *scip, SCIP_VAR *var)
Definition: objvardata.cpp:207
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
enum SCIP_Vartype SCIP_VARTYPE
Definition: type_var.h:73