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